26#ifndef PARTICLE_UTILITIES_H
27#define PARTICLE_UTILITIES_H
30#include <unordered_set>
52 T distB = (1/std::sqrt(2))*distA;
53 T distC = (1/std::sqrt(2))*distB;
56 std::array<Vector<T,3>,26> pointsOnSphericalHull = {
57 Vector<T,3>(position[0]-distC, position[1]-distC, position[2]-distC),
58 Vector<T,3>(position[0], position[1]-distB, position[2]-distB),
59 Vector<T,3>(position[0]+distC, position[1]-distC, position[2]-distC),
61 Vector<T,3>(position[0]-distB, position[1], position[2]-distB),
62 Vector<T,3>(position[0], position[1], position[2]-distA),
63 Vector<T,3>(position[0]+distB, position[1], position[2]-distB),
65 Vector<T,3>(position[0]-distC, position[1]+distC, position[2]-distC),
66 Vector<T,3>(position[0], position[1]+distB, position[2]-distB),
67 Vector<T,3>(position[0]+distC, position[1]+distC, position[2]-distC),
70 Vector<T,3>(position[0]-distB, position[1]-distB, position[2] ),
71 Vector<T,3>(position[0], position[1]-distA, position[2] ),
72 Vector<T,3>(position[0]+distB, position[1]-distB, position[2] ),
74 Vector<T,3>(position[0]-distA, position[1], position[2] ),
76 Vector<T,3>(position[0]+distA, position[1], position[2] ),
78 Vector<T,3>(position[0]-distB, position[1]+distB, position[2] ),
79 Vector<T,3>(position[0], position[1]+distA, position[2] ),
80 Vector<T,3>(position[0]+distB, position[1]+distB, position[2] ),
83 Vector<T,3>(position[0]-distC, position[1]-distC, position[2]+distC),
84 Vector<T,3>(position[0], position[1]-distB, position[2]+distB),
85 Vector<T,3>(position[0]+distC, position[1]-distC, position[2]+distC),
87 Vector<T,3>(position[0]-distB, position[1], position[2]+distB),
88 Vector<T,3>(position[0], position[1], position[2]+distA),
89 Vector<T,3>(position[0]+distB, position[1], position[2]+distB),
91 Vector<T,3>(position[0]-distC, position[1]+distC, position[2]+distC),
92 Vector<T,3>(position[0], position[1]+distB, position[2]+distB),
93 Vector<T,3>(position[0]+distC, position[1]+distC, position[2]+distC)
96 return pointsOnSphericalHull;
105 T distB = (1/std::sqrt(2))*distA;
108 std::array<Vector<T,2>,8> pointsOnSphericalHull = {
122 return pointsOnSphericalHull;
126 template<
typename T,
unsigned D>
129 if constexpr(D==3 || D==2){
132 std::cerr <<
"ERROR: Only 2D and 3D supported!" << std::endl;
136 template<
typename T,
typename PARTICLETYPE>
145template<
typename T,
typename PARTICLETYPE>
151 auto& sParticleSystem = xParticleSystem;
157 while(iP < particleSystem.
size()){
158 auto particle = particleSystem.
get(iP);
164 auto& container = particleSystem.
get();
165 container.erase( particle.
getId() );
171 auto& particleSystem = xParticleSystem;
173 while(iP < particleSystem.size()){
174 auto particle = particleSystem.get(iP);
180 auto& container = particleSystem.get();
181 container.erase( particle.
getId() );
188template<
typename T,
typename PARTICLETYPE, std::
size_t selectedID,
typename F>
191 using PCOND = std::conditional_t<
193 conditions::template valid_particle_matching_ID<selectedID>,
194 conditions::template particle_matching_ID<selectedID>
201template<
typename T,
typename PARTICLETYPE,
typename PCONDITION=conditions::val
id_particles>
203 std::size_t globalIDrequested, std::size_t& localParticleID )
205 using namespace descriptors;
206 static_assert(PARTICLETYPE::template providesNested<PARALLELIZATION,ID>(),
"Field PARALLELIZATION:ID has to be provided");
211 for (std::size_t iP=0; iP<particleSystem.
size(); ++iP) {
213 auto particle = particleSystem.
get(iP);
217 auto globalID = particle.template getField<PARALLELIZATION,ID>();
218 if (globalID==globalIDrequested){
219 localParticleID = particle.
getId();
232namespace communication {
239template<
typename T,
typename PARTICLETYPE,
typename PCONDITION=conditions::val
id_particle_centres,
bool sync=true>
241 std::size_t globalIDrequested, std::size_t& localParticleID,
int& globiC )
243 using namespace descriptors;
244 static_assert(PARTICLETYPE::template providesNested<PARALLELIZATION,ID>(),
"Field PARALLELIZATION:ID has to be provided");
252 for (
int iC=0; iC<loadBalancer.size(); ++iC){
254 int globiC = loadBalancer.glob(iC);
257 auto& particleSystem = *bParticleSystems[iC];
260 for (std::size_t iP=0; iP<particleSystem.size(); ++iP) {
262 auto particle = particleSystem.get(iP);
266 auto globalID = particle.template getField<PARALLELIZATION,ID>();
267 if (globalID==globalIDrequested){
268 localParticleID = particle.
getId();
280#ifdef PARALLEL_MODE_MPI
297template<
typename T,
unsigned D,
typename F=std::function<
void(
int)>,
298 bool domainWarning=false,
bool checkDiscretePo
ints=false>
303 int globiC, F f=[](
int){} )
306 if constexpr(checkDiscretePoints) {
315 const bool cuboidFound =
getCuboid(cuboidDecomposition,
316 periodicity, point, globiConHull);
317 if constexpr(domainWarning){
319 std::cerr <<
"Warning [during getSurfaceTouchingICs]: Cuboid not found for point "
320 << point << std::endl;
324 if (cuboidFound && globiConHull!=globiC){
326 if(iCs.insert(globiConHull).second) {
334 const T physDeltaX = cuboidDecomposition.
getMotherCuboid().getDeltaR();
336 cuboidDecomposition,
util::ceil(circumRadius/physDeltaX), globiC);
338 for(
const int entry : tmp) {
339 if( globiC != entry ) {
346 __builtin_unreachable();
349template<
typename T,
typename PARTICLETYPE,
typename F=std::function<
void(
int)>>
354 int globiC, F f=[](
int){} )
357 for(
int neighbor: neighbors) {
365template<
typename T,
unsigned D,
typename F=std::function<
void(
int)>,
366 bool domainWarning=false>
371 int globiC, F f=[](
int){} )
374 cuboidDecomposition, position, circumRadius, periodicity, globiC, f)};
375 std::vector<int> listOfICs;
376 listOfICs.insert(listOfICs.end(), touchedICs.begin(), touchedICs.end());
393template<
typename T,
typename PARTICLETYPE,
typename ...NESTED_FIELDS>
395 using namespace descriptors;
397 std::size_t iPfirstB=particleSystem.
size();
399 for (std::size_t iP=0; iP<particleSystem.
size(); ++iP){
400 auto particle = particleSystem.
get(iP);
401 bool active = particle.template getField<NESTED_FIELDS...>();
408 for (std::size_t iP=iPfirstB; iP<particleSystem.
size(); ++iP){
409 auto particle = particleSystem.
get(iP);
410 bool active = particle.template getField<NESTED_FIELDS...>();
Decomposition of a physical volume into a set of disjoint cuboids.
const Cuboid< T, D > & getMotherCuboid() const
Returns the smallest cuboid that includes all cuboids of the structure.
LoadBalancer< T > & getLoadBalancer()
Read and write access to the load balancer.
auto & get()
Expose container.
void swapParticles(std::size_t iP, std::size_t jP)
Swap particles by index.
constexpr std::size_t size()
Size of ParticleSystem.
std::size_t getId() const
Return memory ID of the currently represented particle.
SuperStructure< T, PARTICLETYPE::d > & getSuperStructure()
std::vector< ParticleSystem< T, PARTICLETYPE > * > & getBlockParticleSystems()
const std::vector< std::set< int > > & getCuboidNeighborhood()
void reduceAndBcast(T &reductVal, MPI_Op op, int root=0, MPI_Comm comm=MPI_COMM_WORLD)
Reduction operation, followed by a broadcast.
constexpr bool providesParallelization()
Provides group PARALLELIZATION.
constexpr bool providesValid()
Provides field INVALID.
T getRadius(Particle< T, PARTICLETYPE > &particle)
Vector< T, PARTICLETYPE::d > getPosition(Particle< T, PARTICLETYPE > particle)
void forSystemsInSuperParticleSystem(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, F f)
std::set< int > getSurfaceTouchingICs(CuboidDecomposition< T, D > &cuboidDecomposition, Vector< T, D > position, T circumRadius, const Vector< bool, D > &periodicity, int globiC, F f=[](int){})
Get a set of surface touching iCs (that are not globiC) Allows to run an optional function per unique...
std::vector< int > getVectorOfSurfaceTouchingICs(CuboidDecomposition< T, D > &cuboidDecomposition, Vector< T, D > position, T circumRadius, const Vector< bool, D > &periodicity, int globiC, F f=[](int){})
bool getCuboid(const CuboidDecomposition< T, D > &cuboidDecomposition, const Vector< bool, D > &periodicity, const PhysR< T, D > &position, int &iC)
Function returns true if cuboid was found and gives iC.
std::vector< int > getNeighborCuboids(CuboidDecomposition< T, D > &cuboidDecomposition, unsigned offset, int globiC)
Get neighbour cuboids.
bool searchParticleGlobally(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, std::size_t globalIDrequested, std::size_t &localParticleID, int &globiC)
Search particle in SuperParticleSystem by globalParticleID and return globiC if found.
std::size_t partitionParticleSystem(ParticleSystem< T, PARTICLETYPE > &particleSystem)
std::conditional_t< PARTICLETYPE::template providesNested< descriptors::PARALLELIZATION >(), SuperParticleSystem< T, PARTICLETYPE >, ParticleSystem< T, PARTICLETYPE > > XParticleSystem
void purgeInvalidParticles(XParticleSystem< T, PARTICLETYPE > &xParticleSystem)
void doWhenMeetingCondition(Particle< T, PARTICLETYPE > &particle, F f)
std::array< Vector< T, 3 >, 26 > discretePointsOnSphericalHull(Vector< T, 3 > position, T radius)
bool searchParticleLocally(ParticleSystem< T, PARTICLETYPE > &particleSystem, std::size_t globalIDrequested, std::size_t &localParticleID)
void doForParticleMatchingID(XParticleSystem< T, PARTICLETYPE > &xParticleSystem, F f)
void forParticlesInXParticleSystem(XParticleSystem< T, PARTICLETYPE > &xParticleSystem, F f)
Iterate over particles in x particle system.
ADf< T, DIM > ceil(const ADf< T, DIM > &a)
Top level namespace for all of OpenLB.
static constexpr auto calculate(Particle< T, PARTICLETYPE > &particle)
static constexpr auto calculate(Vector< T, D > position, T radius)