OpenLB 1.7
Loading...
Searching...
No Matches
particleTasks.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2021 Nicolas Hafen, Mathias J. Krause
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24
25/* This file containes particle tasks that can be passed to the particle manager.
26 * Those need to provide an execute method, and two booleans specifying the coupling
27 * and the necessity for beeing looped over all particles.
28*/
29
30#ifndef PARTICLE_TASKS_H
31#define PARTICLE_TASKS_H
32
33
34#include <cassert>
35
36namespace olb {
37
38namespace particles {
39
41template<typename T, typename DESCRIPTOR, typename PARTICLETYPE,
42 typename FORCEFUNCTOR=SuperLatticeMomentumExchangeForce<T, DESCRIPTOR, PARTICLETYPE>>
44 auto static execute(
45 ParticleSystem<T,PARTICLETYPE>& particleSystem,
48 UnitConverter<T,DESCRIPTOR> const& converter,
49 Vector<bool,DESCRIPTOR::d> periodicity =
51 std::size_t iP0=0 )
52 {
53 //Momentum Exchange/Loss
54 FORCEFUNCTOR forceFunctor( sLattice, sGeometry,
55 particleSystem, converter, periodicity, iP0 );
56 //Store boundary force in particles
57 dynamics::applySerializableParticleForce( forceFunctor, particleSystem, iP0 );
58 }
59 static constexpr bool latticeCoupling = true;
60 static constexpr bool particleLoop = false;
61};
62
64template<typename T, typename PARTICLETYPE>
66 auto static execute(
69 Vector<T,PARTICLETYPE::d> externalAcceleration,
70 T timeStepSize, int globiC=0)
71 {
72 using namespace descriptors;
73 //Apply acceleration
74 Vector<T,PARTICLETYPE::d> force = particle.template getField<FORCING,FORCE>();
75 T mass = particle.template getField<PHYSPROPERTIES,MASS>();
76 force += externalAcceleration * mass;
77 particle.template setField<FORCING,FORCE>( force );
78 }
79 static constexpr bool latticeCoupling = false;
80 static constexpr bool particleLoop = true;
81};
82
84template<typename T, typename PARTICLETYPE>
86 auto static execute(
87 ParticleSystem<T,PARTICLETYPE>& particleSystem,
89 Vector<T,PARTICLETYPE::d>& externalAcceleration,
90 T timeStepSize, int globiC=0 )
91 {
92 //Call process on particle dynamics
93 if constexpr (!access::providesDynamicsID<PARTICLETYPE>()){
94 particle.process(timeStepSize);
95 } else {
96 unsigned short dynamicsID = access::getDynamicsID( particle );
97 particle.process(timeStepSize, dynamicsID);
98 }
99 }
100 static constexpr bool latticeCoupling = false;
101 static constexpr bool particleLoop = true;
102};
103
105template<typename T, typename DESCRIPTOR, typename PARTICLETYPE>
107 auto static execute(
108 ParticleSystem<T,PARTICLETYPE>& particleSystem,
109 Particle<T,PARTICLETYPE>& particle,
112 UnitConverter<T,DESCRIPTOR> const& converter,
113 int globiC = 0,
114 Vector<bool,DESCRIPTOR::d> periodicity =
116 {
117 using namespace descriptors;
118 //Write particle field
119 setSuperParticleField( sGeometry, sLattice, converter, particle, periodicity );
120 }
121 static constexpr bool latticeCoupling = true;
122 static constexpr bool particleLoop = true;
123};
124
125
126
127
128
129
130
131#ifdef PARALLEL_MODE_MPI
132
133
134
136template<typename T, typename PARTICLETYPE>
138 auto static execute(
140 Particle<T,PARTICLETYPE>& particle,
141 Vector<T,PARTICLETYPE::d>& externalAcceleration,
142 T timeStepSize, int globiC )
143 {
144 using PCONDITION = std::conditional_t<
145 access::providesSurface<PARTICLETYPE>(),
146 conditions::valid_particle_centres, //only consider centre for resolved
147 conditions::valid_particles>; //only consider valid
148 //Call process on particle dynamics when meeting PCONDITION
149 doWhenMeetingCondition<T,PARTICLETYPE,PCONDITION>( particle,
150 [&](Particle<T,PARTICLETYPE> particle){
151 particle.process(timeStepSize);
152 }, globiC );
153 }
154 static constexpr bool latticeCoupling = false;
155 static constexpr bool particleLoop = true;
156};
157
158
162template<typename T, typename DESCRIPTOR, typename PARTICLETYPE,
165 auto static execute(
167 const SuperGeometry<T,DESCRIPTOR::d>& sGeometry,
169 UnitConverter<T,DESCRIPTOR> const& converter,
170 Vector<bool,DESCRIPTOR::d> periodicity =
172 std::size_t iP0=0 )
173 {
174 constexpr unsigned D = DESCRIPTOR::d;
175 const PhysR<T,D> min = communication::getCuboidMin<T,D>(sGeometry.getCuboidGeometry());
176 const PhysR<T,D> max = communication::getCuboidMax<T,D>(sGeometry.getCuboidGeometry(), min);
177
178 //Test output
180 [&](ParticleSystem<T,PARTICLETYPE>& particleSystem, int iC, int globiC){
181
182 auto& blockLattice = sLattice.getBlock(iC);
183 auto& blockGeometry = sGeometry.getBlockGeometry(iC);
184
185 //Momentum Exchange/Loss
186 FORCEFUNCTOR forceFunctor( blockLattice, blockGeometry,
187 particleSystem, converter, min, max, periodicity, iP0 );
188
189 //Store boundary force in particles
190 // - if not serialized, allows for additional filtering (e.g. active_particles)
191 if constexpr (FORCEFUNCTOR::serializeForce){
192 dynamics::applySerializableParticleForce( forceFunctor, particleSystem, iP0 );
193 } else {
194 using PCONDITION = conditions::active_particles; //TODO: remove hardcoded active_particle limitation
195 dynamics::applyLocalParticleForce<T,PARTICLETYPE,FORCEFUNCTOR,PCONDITION>(
196 forceFunctor, particleSystem, iP0 );
197 }
198 });
199 }
200 static constexpr bool latticeCoupling = true;
201 static constexpr bool particleLoop = false;
202};
203
204
206template<typename T, typename PARTICLETYPE>
208 auto static execute(
210 const T physDeltaX,
211 const communication::ParticleCommunicator& communicator,
212 const Vector<bool, PARTICLETYPE::d>& periodicity
213 )
214 {
215 //Update particle distribution
216 communication::updateParticleCuboidDistribution( sParticleSystem, physDeltaX,
217//#ifdef PARALLEL_MODE_MPI
218 communicator.particleDistribution,
219//#endif
220 periodicity
221 );
222 }
223 static constexpr bool latticeCoupling = false;
224 static constexpr bool particleLoop = false;
225};
226
228template<typename T, typename PARTICLETYPE>
230 auto static execute(
232 const communication::ParticleCommunicator& communicator
233 )
234 {
235 using namespace descriptors;
236
237 //Retrieve dimension of force data
238 constexpr unsigned D = PARTICLETYPE::d;
239 constexpr unsigned Drot = utilities::dimensions::convert<D>::rotation;
240 constexpr unsigned forceDataSize = D+Drot;
241
242 //Create globalIdDataMap
243 std::map<std::size_t, Vector<T,forceDataSize>> globalIdDataMap;
244
245 //Communicate surface force and add to globalIdDatamap
246 communication::communicateSurfaceForce( sParticleSystem, globalIdDataMap
247//#ifdef PARALLEL_MODE_MPI
248 , communicator.surfaceForceComm
249//#endif
250 );
251
252 //Assign data in globalIdData Map to correct particle
253 communication::assignSurfaceForce( sParticleSystem, globalIdDataMap );
254 }
255 static constexpr bool latticeCoupling = false;
256 static constexpr bool particleLoop = false;
257};
258
259
261template<typename T, typename DESCRIPTOR, typename PARTICLETYPE>
263 auto static execute(
265 Particle<T,PARTICLETYPE>& particle,
266 const SuperGeometry<T,DESCRIPTOR::d>& sGeometry,
268 UnitConverter<T,DESCRIPTOR> const& converter,
269 int globiC,
270 Vector<bool,DESCRIPTOR::d> periodicity =
272 {
273 constexpr unsigned D = DESCRIPTOR::d;
274 using namespace descriptors;
275
276 //Retrieve load balancer and local iC
277 auto& superStructure = sParticleSystem.getSuperStructure();
278 auto& loadBalancer = superStructure.getLoadBalancer();
279 int iC = loadBalancer.loc(globiC);
280
281 //Retrieve blockLattice and blockGeometry
282 auto& blockLattice = sLattice.getBlock(iC);
283 auto& blockGeometry = sGeometry.getBlockGeometry(iC);
284
285 //Write particle to field
286 if(isPeriodic(periodicity)) {
287 const PhysR<T,D> min = communication::getCuboidMin<T,D>(sGeometry.getCuboidGeometry());
288 const PhysR<T,D> max = communication::getCuboidMax<T,D>(sGeometry.getCuboidGeometry(), min);
289
290 setBlockParticleField( blockGeometry, blockLattice, converter, min, max,
291 particle, periodicity);
292 } else {
293 setBlockParticleField( blockGeometry, blockLattice, converter, particle );
294 }
295 }
296 static constexpr bool latticeCoupling = true;
297 static constexpr bool particleLoop = true;
298};
299
300
301
303template<typename T, typename PARTICLETYPE>
305 auto static execute(
307 Particle<T,PARTICLETYPE>& particle,
308 Vector<T,PARTICLETYPE::d> externalAcceleration,
309 T timeStepSize, int globiC=0)
310 {
311 using namespace descriptors;
312 //Apply acceleration
313 Vector<T,PARTICLETYPE::d> force = particle.template getField<FORCING,FORCE>();
314 T mass = particle.template getField<PHYSPROPERTIES,MASS>();
315 force += externalAcceleration * mass;
316 particle.template setField<FORCING,FORCE>( force );
317 }
318 static constexpr bool latticeCoupling = false;
319 static constexpr bool particleLoop = true;
320};
321
322
323
325//- for use in examples
326//- differentiating between resolved and subgrid particles
327
328template<typename T, typename DESCRIPTOR, typename PARTICLETYPE>
329using couple_lattice_to_particles = std::conditional_t<
330 access::providesSurface<PARTICLETYPE>(),
331 std::conditional_t<
332 access::providesParallelization<PARTICLETYPE>(),
333 couple_lattice_to_parallel_particles<T,DESCRIPTOR,PARTICLETYPE,
335 couple_lattice_to_particles_single_cuboid<T,DESCRIPTOR,PARTICLETYPE,
337 couple_lattice_to_parallel_particles<T,DESCRIPTOR,PARTICLETYPE,
339>;
340
341template<typename T, typename DESCRIPTOR, typename PARTICLETYPE>
342using couple_particles_to_lattice = std::conditional_t<
343 access::providesParallelization<PARTICLETYPE>(),
346>;
347
348template<typename T, typename PARTICLETYPE>
349using process_dynamics = std::conditional_t<
350 access::providesParallelization<PARTICLETYPE>(),
353>;
354
355template<typename T, typename PARTICLETYPE>
356using apply_gravity = std::conditional_t<
357 access::providesParallelization<PARTICLETYPE>(),
360>;
361
362template<typename T, typename PARTICLETYPE>
364
365#else
366//NON-MPI support for resolved particles
367
368template<typename T, typename DESCRIPTOR, typename PARTICLETYPE>
370 couple_lattice_to_particles_single_cuboid<T,DESCRIPTOR,PARTICLETYPE,
372
373template<typename T, typename DESCRIPTOR, typename PARTICLETYPE>
376
377template<typename T, typename PARTICLETYPE>
378using process_dynamics =
380
381template<typename T, typename PARTICLETYPE>
382using apply_gravity =
384
385
386#endif
387
388
389
390
391} //namespace particles
392
393} //namespace olb
394
395
396#endif
Functor that returns forces acting on a particle surface, returns data in output for every particle i...
Representation of a statistic for a parallel 2D geometry.
BlockGeometry< T, D > & getBlockGeometry(int locIC)
Read and write access to a single block geometry.
Functor that returns forces acting on a particle surface, returns data in output for every particle i...
Super class maintaining block lattices for a cuboid decomposition.
BlockLattice< T, DESCRIPTOR > & getBlock(int locC)
Return BlockLattice with local index locC.
CuboidGeometry< T, D > & getCuboidGeometry()
Read and write access to cuboid geometry.
LoadBalancer< T > & getLoadBalancer()
Read and write access to the load balancer.
Conversion between physical and lattice units, as well as discretization.
Plain old scalar vector.
Definition vector.h:47
void process(T timeStepSize, unsigned short iDyn=0)
Apply processing to the particle according to dynamics at iDyn.
Definition particle.hh:110
SuperStructure< T, PARTICLETYPE::d > & getSuperStructure()
unsigned short getDynamicsID(Particle< T, PARTICLETYPE > &particle)
void forSystemsInSuperParticleSystem(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, F f)
void communicateSurfaceForce(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, std::map< std::size_t, Vector< T, forceDataSize > > &globalIdDataMap, MPI_Comm surfaceForceComm)
void updateParticleCuboidDistribution(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, const T physDeltaX, MPI_Comm particleDistributionComm, const Vector< bool, PARTICLETYPE::d > &periodicity)
Definition relocation.h:667
void assignSurfaceForce(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, std::map< std::size_t, Vector< T, forceDataSize > > &globalIdDataMap)
void applySerializableParticleForce(FORCEFUNCTOR &forceF, ParticleSystem< T, PARTICLETYPE > &particleSystem, std::size_t iP0=0)
Apply boundary force provided by force functor to the particle center as torque and force.
std::conditional_t< access::providesParallelization< PARTICLETYPE >(), apply_external_acceleration_parallel< T, PARTICLETYPE >, apply_external_acceleration_single_cuboid< T, PARTICLETYPE > > apply_gravity
std::conditional_t< access::providesParallelization< PARTICLETYPE >(), couple_parallel_particles_to_lattice< T, DESCRIPTOR, PARTICLETYPE >, couple_particles_to_lattice_single_cuboid< T, DESCRIPTOR, PARTICLETYPE > > couple_particles_to_lattice
constexpr bool isPeriodic(const Vector< bool, D > &periodic)
void setBlockParticleField(const BlockGeometry< T, DESCRIPTOR::d > &blockGeometry, BlockLattice< T, DESCRIPTOR > &blockLattice, UnitConverter< T, DESCRIPTOR > const &converter, Particle< T, PARTICLETYPE > &particle)
std::conditional_t< access::providesParallelization< PARTICLETYPE >(), process_dynamics_parallel< T, PARTICLETYPE >, process_dynamics_single_cuboid< T, PARTICLETYPE > > process_dynamics
std::conditional_t< access::providesSurface< PARTICLETYPE >(), std::conditional_t< access::providesParallelization< PARTICLETYPE >(), couple_lattice_to_parallel_particles< T, DESCRIPTOR, PARTICLETYPE, BlockLatticeMomentumExchangeForce< T, DESCRIPTOR, PARTICLETYPE > >, couple_lattice_to_particles_single_cuboid< T, DESCRIPTOR, PARTICLETYPE, SuperLatticeMomentumExchangeForce< T, DESCRIPTOR, PARTICLETYPE > > >, couple_lattice_to_parallel_particles< T, DESCRIPTOR, PARTICLETYPE, BlockLatticeStokesDragForce< T, DESCRIPTOR, PARTICLETYPE, false > > > couple_lattice_to_particles
Aliases.
void setSuperParticleField(const SuperGeometry< T, DESCRIPTOR::d > &sGeometry, SuperLattice< T, DESCRIPTOR > &sLattice, UnitConverter< T, DESCRIPTOR > const &converter, Particle< T, PARTICLETYPE > &particle, const Vector< bool, DESCRIPTOR::d > &periodicity)
Set particle field with peridic support.
Top level namespace for all of OpenLB.
Apply external acceleration (e.g. for apply gravity)
static auto execute(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, Particle< T, PARTICLETYPE > &particle, Vector< T, PARTICLETYPE::d > externalAcceleration, T timeStepSize, int globiC=0)
Apply external acceleration (e.g. for apply gravity)
static auto execute(ParticleSystem< T, PARTICLETYPE > &ParticleSystem, Particle< T, PARTICLETYPE > &particle, Vector< T, PARTICLETYPE::d > externalAcceleration, T timeStepSize, int globiC=0)
Communicate surface force of parallel particles.
static auto execute(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, const communication::ParticleCommunicator &communicator)
MPI_Comm surfaceForceComm
Communicator for particle distribution communication.
Couple lattice to parallel particles.
static auto execute(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, const SuperGeometry< T, DESCRIPTOR::d > &sGeometry, SuperLattice< T, DESCRIPTOR > &sLattice, UnitConverter< T, DESCRIPTOR > const &converter, Vector< bool, DESCRIPTOR::d > periodicity=Vector< bool, DESCRIPTOR::d >(false), std::size_t iP0=0)
static auto execute(ParticleSystem< T, PARTICLETYPE > &particleSystem, SuperGeometry< T, DESCRIPTOR::d > &sGeometry, SuperLattice< T, DESCRIPTOR > &sLattice, UnitConverter< T, DESCRIPTOR > const &converter, Vector< bool, DESCRIPTOR::d > periodicity=Vector< bool, DESCRIPTOR::d >(false), std::size_t iP0=0)
static auto execute(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, Particle< T, PARTICLETYPE > &particle, const SuperGeometry< T, DESCRIPTOR::d > &sGeometry, SuperLattice< T, DESCRIPTOR > &sLattice, UnitConverter< T, DESCRIPTOR > const &converter, int globiC, Vector< bool, DESCRIPTOR::d > periodicity=Vector< bool, DESCRIPTOR::d >(false))
static auto execute(ParticleSystem< T, PARTICLETYPE > &particleSystem, Particle< T, PARTICLETYPE > &particle, SuperGeometry< T, DESCRIPTOR::d > &sGeometry, SuperLattice< T, DESCRIPTOR > &sLattice, UnitConverter< T, DESCRIPTOR > const &converter, int globiC=0, Vector< bool, DESCRIPTOR::d > periodicity=Vector< bool, DESCRIPTOR::d >(false))
static auto execute(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, Particle< T, PARTICLETYPE > &particle, Vector< T, PARTICLETYPE::d > &externalAcceleration, T timeStepSize, int globiC)
static auto execute(ParticleSystem< T, PARTICLETYPE > &particleSystem, Particle< T, PARTICLETYPE > &particle, Vector< T, PARTICLETYPE::d > &externalAcceleration, T timeStepSize, int globiC=0)
Update particle core distribution of parallel particles.
static auto execute(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, const T physDeltaX, const communication::ParticleCommunicator &communicator, const Vector< bool, PARTICLETYPE::d > &periodicity)
Converts dimensions by deriving from given cartesian dimension D.