OpenLB 1.7
Loading...
Searching...
No Matches
particleManager.hh
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2022 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#ifndef PARTICLE_MANAGER_HH
25#define PARTICLE_MANAGER_HH
26
27
29
30//#define VERBOSE_PARTICLEMANAGER
31
32namespace olb {
33
34namespace particles {
35
36namespace dynamics {
37
38template<typename T, typename DESCRIPTOR, typename PARTICLETYPE>
40 XParticleSystem<T,PARTICLETYPE>& xParticleSystem,
43 UnitConverter<T,DESCRIPTOR> const& converter,
44 Vector<T,PARTICLETYPE::d> externalAcceleration,
46 : _xParticleSystem(xParticleSystem), _sGeometry(sGeometry),
47 _sLattice(sLattice), _converter(converter), _externalAcceleration(externalAcceleration),
48 _periodic(periodic)
49{}
50
51//Unpack tasks requiring loop
52template<typename T, typename DESCRIPTOR, typename PARTICLETYPE>
53template<typename taskList, typename ISEQ>
55 Particle<T,PARTICLETYPE>& particle, T timeStepSize, ISEQ indexSequence, int globiC)
56{
57 //Define function for task execution
58 auto executeTask = [&](auto task){
59 //Derive type of task
60 using TASK = typename decltype(task)::type;
61#ifdef VERBOSE_PARTICLEMANAGER
62 OstreamManager clout( std::cout,"ParticleManager" );
63 if constexpr (access::providesParallelization<PARTICLETYPE>()){
64 clout.setMultiOutput(true);
65 }
66 std::string taskStr = typeid(TASK).name();
67 taskStr.resize(50);
68 clout << "-TaskLooped(globiC=" << globiC
69 <<")-Particle " << particle.getId() << ": "
70 << taskStr << std::endl;
71 clout.setMultiOutput(false);
72#endif
73 //Evaluate coupling method
74 if constexpr(TASK::latticeCoupling){
75 TASK::execute( _xParticleSystem, particle, _sGeometry, _sLattice, _converter, globiC, _periodic );
76 } else {
77 TASK::execute( _xParticleSystem, particle, _externalAcceleration, timeStepSize, globiC );
78 }
79 };
80 //Execute single tasks
81 meta::list_for_each_index<taskList>(executeTask,indexSequence);
82}
83
84template<typename T, typename DESCRIPTOR, typename PARTICLETYPE>
85template<typename ...TASKLIST>
87#ifdef VERBOSE_PARTICLEMANAGER
88 OstreamManager clout( std::cout,"ParticleManager" );
89 clout << "TASKLIST:" << std::endl;
91#endif
92 //Create meta::list of TASKLIST parameter pack
93 using taskList = typename meta::list<TASKLIST...>;
94 //Retrieve index sequence for tasks to be executed without loop
95 auto indexSequenceNoLoop =
96 meta::filter_index_sequence<taskList,requires_no_loop>();
97 //Define function for tasks not requiring loop
98 auto executeNoLoopTask = [&](auto task){
99 using TASK = typename decltype(task)::type;
100#ifdef VERBOSE_PARTICLEMANAGER
102 OstreamManager clout( std::cout,"ParticleManager" );
103 if constexpr (access::providesParallelization<PARTICLETYPE>()){
104 clout.setMultiOutput(true);
105 }
106 std::string taskStr = typeid(TASK).name();
107 taskStr.resize(50);
108 clout << "-Task: " << taskStr << std::endl;
109 clout.setMultiOutput(false);
111#endif
112 if constexpr(TASK::latticeCoupling){
113 TASK::execute( _xParticleSystem, _sGeometry, _sLattice, _converter, _periodic );
114 } else {
115 if constexpr (std::is_invocable_v<decltype(TASK::execute),
119 {
120 TASK::execute( _xParticleSystem, _converter.getPhysDeltaX(),
121 _communicator, _periodic);
122 }
123 else {
124 TASK::execute( _xParticleSystem, _communicator);
125 }
126 }
127#ifdef VERBOSE_PARTICLEMANAGER
129#endif
130 };
131 //Define function for sequence of tasks requiring loop
132 auto executeLoopedTasks = [&](auto indexSequence){
133 if constexpr( access::providesParallelization<PARTICLETYPE>() ){
134 //Loop over valid particles
136 conditions::valid_particles>( _xParticleSystem,
137 [&](Particle<T,PARTICLETYPE>& particle,
138 ParticleSystem<T,PARTICLETYPE>& particleSystem, int globiC){
139 //Unpack tasks to be looped
140 unpackTasksLooped<taskList>( particle, timeStepSize, indexSequence, globiC );
141 });
142 } else {
143 //Loop over all particles
144 forParticlesInParticleSystem<T,PARTICLETYPE,conditions::all_particles>( _xParticleSystem,
145 [&](Particle<T,PARTICLETYPE>& particle){
146 //Unpack tasks to be looped
147 unpackTasksLooped<taskList>( particle, timeStepSize, indexSequence, 0 );
148 });
149 }
150 };
151 //Evaluate index sequence and evaluate tasks or tasks sequences
152 //- Example execution:
153 // Direct: T1
154 // Looped: [T2,T3,T4] (iterate taks for same particle)
155 // Direct: T5
156 // Direct: T6
157 // Looped: [T7,T8] (iterate taks for same particle)
158 meta::index_sequence_for_subsequence<taskList>(
159 executeNoLoopTask, executeLoopedTasks, indexSequenceNoLoop);
160}
161
162template<typename T, typename DESCRIPTOR, typename PARTICLETYPE>
163template<typename ...TASKLIST>
164void ParticleManager<T,DESCRIPTOR,PARTICLETYPE>::execute(){ execute<TASKLIST...>(_converter.getPhysDeltaT()); }
165
166template<typename T, typename DESCRIPTOR, typename PARTICLETYPE>
170
171template<typename T, typename DESCRIPTOR, typename PARTICLETYPE>
173{
174 _externalAcceleration = externalAcceleration;
175}
176
177
178} //namespace dynamics
179
180} //namespace particles
181
182} //namespace olb
183
184
185#endif
class for marking output with some text
void setMultiOutput(bool b)
enable message output for all MPI processes, disabled by default
Representation of a statistic for a parallel 2D geometry.
Super class maintaining block lattices for a cuboid decomposition.
Conversion between physical and lattice units, as well as discretization.
Plain old scalar vector.
Definition vector.h:47
std::size_t getId() const
Return memory ID of the currently represented particle.
Definition particle.hh:67
ParticleManager(XParticleSystem< T, PARTICLETYPE > &xParticleSystem, SuperGeometry< T, DESCRIPTOR::d > &sGeometry, SuperLattice< T, DESCRIPTOR > &sLattice, UnitConverter< T, DESCRIPTOR > const &converter, Vector< T, PARTICLETYPE::d > externalAcceleration=Vector< T, PARTICLETYPE::d >(0.), Vector< bool, PARTICLETYPE::d > periodic=Vector< bool, PARTICLETYPE::d >(false))
const communication::ParticleCommunicator & getParticleCommunicator()
void setExternalAcceleration(const Vector< T, PARTICLETYPE::d > &externalAcceleration)
Set external acceleration.
void synchronizeIO(unsigned tDelay=100, MPI_Comm comm=MPI_COMM_WORLD)
Synchronizes the processes and wait to ensure correct cout order.
void forParticlesInSuperParticleSystem(SuperParticleSystem< T, PARTICLETYPE > &sParticleSystem, F f)
std::conditional_t< PARTICLETYPE::template providesNested< descriptors::PARALLELIZATION >(), SuperParticleSystem< T, PARTICLETYPE >, ParticleSystem< T, PARTICLETYPE > > XParticleSystem
MpiManager & mpi()
Top level namespace for all of OpenLB.
Plain wrapper for list of types.
Definition meta.h:276