# PhasicFlow: src/Particles/Insertion/collisionCheck/collisionCheck.cpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

collisionCheck.cpp
Go to the documentation of this file.
#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);
const auto startInd = max(ind - 1 ,int32x3(0));
const auto endInd = min( ind+1 ,nCells_-1);
for(int32 i=startInd.x(); i<=endInd.x(); i++)
{
for(int32 j=startInd.y(); j<=endInd.y(); j++)
{
for(int32 k=startInd.z(); k<=endInd.z(); k++)
{
uint32 n = head_(i, j, k);
while( n != static_cast< uint32 >(-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(static_cast< uint32 >(-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;
}
pFlow::collisionCheck::build
bool build()
Definition: collisionCheck.cpp:4
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::fill
void fill(Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:44
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::collisionCheck::collisionCheck
collisionCheck(box sBox, real dx, const realx3Vector &pos, const realVector &diam)
Definition: collisionCheck.cpp:25
pFlow::collisionCheck::head_
ViewType3D< uint32, HostSpace > head_
Definition: collisionCheck.hpp:29
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::max
T max(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:79
pFlow::Vector::size
auto size() const
Size of the vector.
Definition: Vector.hpp:265
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::collisionCheck::pointIndex
int32x3 pointIndex(const realx3 &p) const
Definition: collisionCheck.hpp:31
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
length
INLINE_FUNCTION_HD T length(const triple< T > &v1)
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::collisionCheck::mapLastAddedParticle
bool mapLastAddedParticle()
Definition: collisionCheck.cpp:79
pFlow::collisionCheck::searchBox_
box searchBox_
Definition: collisionCheck.hpp:17
collisionCheck.hpp
pFlow::collisionCheck::position_
const realx3Vector & position_
Definition: collisionCheck.hpp:23
pFlow::collisionCheck::checkPoint
bool checkPoint(const realx3 &p, const real d) const
Definition: collisionCheck.cpp:46
pFlow::collisionCheck::next_
uint32Vector next_
Definition: collisionCheck.hpp:27
pFlow::int32x3
triple< int32 > int32x3
Definition: types.hpp:38
pFlow::min
T min(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:28
n
uint32 n
Definition: NBSLoop.hpp:24
pFlow::box
Definition: box.hpp:32
pFlow::triple< real >
pFlow::box::isInside
INLINE_FUNCTION_HD bool isInside(const realx3 &point) const
Definition: box.hpp:84
pFlow::Vector< realx3 >