Collision check and particlePosition -> random

- A new class is added for simple collision check
- position particles in utility is upgraded
- morton sorting is not active yet for particlesPhasicFlow
This commit is contained in:
Hamidreza Norouzi
2024-04-13 07:07:36 -07:00
parent 89d7e1f0ba
commit e395c379cb
15 changed files with 353 additions and 399 deletions

View File

@ -9,6 +9,7 @@ particles/regularParticleIdHandler/regularParticleIdHandler.cpp
SphereParticles/sphereShape/sphereShape.cpp
SphereParticles/sphereParticles/sphereParticles.cpp
SphereParticles/sphereParticles/sphereParticlesKernels.cpp
Insertion/collisionCheck/collisionCheck.cpp
Insertion/insertionRegion/insertionRegion.cpp
Insertion/insertion/insertion.cpp
Insertion/shapeMixture/shapeMixture.cpp

View File

@ -0,0 +1,91 @@
#include "collisionCheck.hpp"
bool
pFlow::collisionCheck::build()
{
fill(head_, static_cast<uint32>(-1));
fill(next_, static_cast<uint32>(-1));
for (auto i = 0uL; i < position_.size(); i++)
{
if(!searchBox_.isInside(position_[i]))
{
fatalErrorInFunction<<
"Point "<< position_[i]<< "is not in search box"<<endl;
}
const auto ind = pointIndex(position_[i]);
next_[i] = head_(ind.x(), ind.y(), ind.z());
head_(ind.x(), ind.y(), ind.z()) = static_cast<uint32>(i);
}
return true;
}
pFlow::collisionCheck::collisionCheck(
box sBox,
real dx,
const realx3Vector& pos,
const realVector& diam
)
: searchBox_(sBox),
dx_(dx),
nCells_((sBox.maxPoint() - sBox.minPoint()) / dx + realx3(1.0)),
position_(pos),
diameters_(diam),
next_("next", pos.size()),
head_("head", nCells_.x(), nCells_.y(), nCells_.z())
{
if(!build())
{
fatalExit;
}
}
bool
pFlow::collisionCheck::checkPoint(const realx3& p, const real d) const
{
if(!searchBox_.isInside(p)) return false;
const auto ind = pointIndex(p);
uint32 n = head_(ind.x(), ind.y(), ind.z());
while( n != -1)
{
if( (position_[n]-p).length() - 0.5*(diameters_[n]+d )<0.0 )
{
return false;
}
n = next_[n];
}
return true;
}
bool
pFlow::collisionCheck::mapLastAddedParticle()
{
size_t n = position_.size()-1;
if( next_.size() != n )
{
fatalErrorInFunction<<
"size mismatch of next and position"<<endl;
return false;
}
next_.push_back(-1);
const auto& p = position_[n];
if(!searchBox_.isInside(p))
{
fatalErrorInFunction<<
"Point "<< p <<" is not inside the search box"<<endl;
return false;
}
const auto ind = pointIndex(p);
next_[n] = head_(ind.x(), ind.y(), ind.z());
head_(ind.x(), ind.y(), ind.z()) = static_cast<uint32>(n);
return true;
}

View File

@ -0,0 +1,54 @@
#ifndef __collisionCheck_hpp__
#define __collisionCheck_hpp__
#include "Vectors.hpp"
#include "VectorSingles.hpp"
#include "box.hpp"
namespace pFlow
{
class collisionCheck
{
private:
box searchBox_;
real dx_;
int32x3 nCells_;
const realx3Vector& position_;
const realVector& diameters_;
uint32Vector next_;
ViewType3D<uint32, HostSpace> head_;
int32x3 pointIndex(const realx3& p)const
{
return int32x3( (p - searchBox_.minPoint())/dx_ );
}
bool build();
public:
collisionCheck(
box sBox,
real dx,
const realx3Vector& pos,
const realVector& diam
);
bool checkPoint(const realx3& p, const real d)const;
bool mapLastAddedParticle();
};
}
#endif //__collisionCheck_hpp__

View File

@ -65,9 +65,19 @@ public:
//// - Methods
virtual bool isInside(const realx3& point) const override;
bool isInside(const realx3& point) const override;
virtual realx3 peek() const override;
realx3 peek() const override;
const realx3& minPoint()const override
{
return region_.minPoint();
}
const realx3& maxPoint()const override
{
return region_.maxPoint();
}
//// - IO operatoins

View File

@ -62,6 +62,16 @@ public:
realx3 peek() const;
const auto& minPoint()const
{
return minPoint_;
}
const auto& maxPoint()const
{
return maxPoint_;
}
//// IO operation
bool read(const dictionary& dict);

View File

@ -57,6 +57,10 @@ public:
virtual realx3 peek() const = 0;
virtual const realx3& minPoint()const = 0;
virtual const realx3& maxPoint()const = 0;
//// - IO operatoins
virtual bool read(const dictionary& dict) = 0;