chombo-discharge
CD_ItoLayoutImplem.H
Go to the documentation of this file.
1 /* chombo-discharge
2  * Copyright © 2021 SINTEF Energy Research.
3  * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4  */
5 
12 #ifndef CD_ItoLayoutImplem_H
13 #define CD_ItoLayoutImplem_H
14 
15 // Chombo includes
16 #include <CH_Timer.H>
17 
18 // Our includes
19 #include <CD_ItoLayout.H>
20 #include <CD_ItoIterator.H>
21 #include <CD_NamespaceHeader.H>
22 
23 template <class T>
24 ItoLayout<T>::ItoLayout(const Vector<RefCountedPtr<ItoSpecies>>& a_species)
25 {
26  this->define(a_species);
27  m_solvers.resize(0);
28 }
29 
30 template <class T>
32 {}
33 
34 template <class T>
37 {
38  return ItoIterator<T>(*this);
39 }
40 
41 template <class T>
42 const std::string
44 {
45  return m_realm;
46 }
47 
48 template <class T>
49 void
50 ItoLayout<T>::setRealm(const std::string a_realm)
51 {
52  m_realm = a_realm;
53 
54  for (auto solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
55  solver_it()->setRealm(m_realm);
56  }
57 }
58 
59 template <class T>
60 void
61 ItoLayout<T>::define(const Vector<RefCountedPtr<ItoSpecies>>& a_species)
62 {
63  m_isDefined = true;
64 }
65 
66 template <class T>
67 void
69 {
70  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
71  iter()->parseOptions();
72  }
73 }
74 
75 template <class T>
76 void
78 {
79  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
80  iter()->parseRuntimeOptions();
81  }
82 }
83 
84 template <class T>
85 void
87 {
88  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
89  iter()->allocate();
90  }
91 }
92 
93 template <class T>
94 void
95 ItoLayout<T>::addSolver(RefCountedPtr<T>& a_solver)
96 {
97  m_solvers.push_back(a_solver);
98 }
99 
100 template <class T>
101 void
103 {
104  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
105  iter()->interpolateVelocities();
106  }
107 }
108 
109 template <class T>
110 void
111 ItoLayout<T>::preRegrid(const int a_lbase, const int a_finestLevel)
112 {
113  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
114  iter()->preRegrid(a_lbase, a_finestLevel);
115  }
116 }
117 
118 template <class T>
119 void
121 {
122  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
123  iter()->initialData();
124  }
125 }
126 
127 template <class T>
128 void
129 ItoLayout<T>::regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel)
130 {
131  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
132  iter()->regrid(a_lmin, a_oldFinestLevel, a_newFinestLevel);
133  }
134 }
135 
136 template <class T>
137 void
139 {
140  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
141  iter()->registerOperators();
142  }
143 }
144 
145 template <class T>
146 void
147 ItoLayout<T>::setAmr(const RefCountedPtr<AmrMesh>& a_amrMesh)
148 {
149  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
150  iter()->setAmr(a_amrMesh);
151  }
152 }
153 
154 template <class T>
155 void
156 ItoLayout<T>::setComputationalGeometry(const RefCountedPtr<ComputationalGeometry>& a_computationalGeometry)
157 {
158  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
159  iter()->setComputationalGeometry(a_computationalGeometry);
160  }
161 }
162 
163 template <class T>
164 void
165 ItoLayout<T>::setPhase(phase::which_phase a_phase)
166 {
167  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
168  iter()->setPhase(a_phase);
169  }
170 }
171 
172 template <class T>
173 void
174 ItoLayout<T>::setVerbosity(const int a_verbosity)
175 {
176  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
177  iter()->setVerbosity(a_verbosity);
178  }
179 }
180 
181 template <class T>
182 void
183 ItoLayout<T>::setTime(const int a_step, const Real a_time, const Real a_dt)
184 {
185  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
186  iter()->setTime(a_step, a_time, a_dt);
187  }
188 }
189 
190 template <class T>
191 void
193 {
194  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
195  iter()->organizeParticlesByCell(a_whichContainer);
196  }
197 }
198 
199 template <class T>
200 void
202 {
203  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
204  iter()->organizeParticlesByPatch(a_whichContainer);
205  }
206 }
207 
208 template <class T>
209 void
210 ItoLayout<T>::makeSuperparticles(const ItoSolver::WhichContainer a_whichContainer, const int a_ppc)
211 {
212  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
213  iter()->makeSuperparticles(a_whichContainer, a_ppc);
214  }
215 }
216 
217 template <class T>
218 void
219 ItoLayout<T>::makeSuperparticles(const ItoSolver::WhichContainer a_whichContainer, const Vector<int> a_ppc)
220 {
221  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
222  iter()->makeSuperparticles(a_whichContainer, a_ppc);
223  }
224 }
225 
226 template <class T>
227 void
229 {
230  this->depositParticles(ItoSolver::WhichContainer::Bulk);
231 }
232 
233 template <class T>
234 void
236 {
237  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
238  iter()->depositParticles(a_whichContainer);
239  }
240 }
241 
242 template <class T>
243 void
245 {
246  this->remap(ItoSolver::WhichContainer::Bulk);
247 }
248 
249 template <class T>
250 void
252 {
253  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
254  iter()->remap(a_whichContainer);
255  }
256 }
257 
258 template <class T>
259 size_t
260 ItoLayout<T>::getNumParticles(const ItoSolver::WhichContainer a_whichContainer, const bool a_localOnly)
261 {
262  size_t ret = 0;
263  for (auto iter = this->iterator(); iter.ok(); ++iter) {
264  ret += iter()->getNumParticles(a_whichContainer, a_localOnly);
265  }
266 
267  return ret;
268 }
269 
270 template <class T>
271 Real
273 {
274  Real minDt = std::numeric_limits<Real>::max();
275 
276  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
277  const Real thisDt = iter()->computeDt();
278  minDt = std::min(minDt, thisDt);
279  }
280 
281  return minDt;
282 }
283 
284 template <class T>
285 Real
287 {
288  Real minDt = std::numeric_limits<Real>::max();
289 
290  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
291  const Real thisDt = iter()->computeAdvectiveDt();
292  minDt = std::min(minDt, thisDt);
293  }
294 
295  return minDt;
296 }
297 
298 template <class T>
299 Real
300 ItoLayout<T>::computeHopDt(const Real a_maxCellsToMove)
301 {
302  Real minDt = std::numeric_limits<Real>::max();
303 
304  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
305  const Real thisDt = iter()->computeHopDt(a_maxCellsToMove);
306  minDt = std::min(minDt, thisDt);
307  }
308 
309  return minDt;
310 }
311 
312 template <class T>
313 Real
315 {
316  Real minDt = std::numeric_limits<Real>::max();
317 
318  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
319  const Real thisDt = iter()->computeDiffusiveDt();
320  minDt = std::min(minDt, thisDt);
321  }
322 
323  return minDt;
324 }
325 
326 template <class T>
327 Vector<RefCountedPtr<T>>&
329 {
330  return m_solvers;
331 }
332 
333 template <class T>
334 Vector<RefCountedPtr<ItoSpecies>>&
336 {
337  return m_species;
338 }
339 
340 template <class T>
341 Vector<EBAMRCellData*>
343 {
344  Vector<EBAMRCellData*> ret(m_solvers.size(), nullptr);
345  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
346  ret[iter.index()] = &(iter()->getVelocityFunction());
347  }
348 
349  return ret;
350 }
351 
352 template <class T>
353 Vector<EBAMRCellData*>
355 {
356  Vector<EBAMRCellData*> ret(m_solvers.size(), nullptr);
357  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
358  ret[iter.index()] = &(iter()->getPhi());
359  }
360 
361  return ret;
362 }
363 
364 template <class T>
365 Vector<EBAMRCellData*>
367 {
368  Vector<EBAMRCellData*> ret(m_solvers.size(), nullptr);
369  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
370  ret[iter.index()] = &(iter()->getDiffusionFunction());
371  }
372 
373  return ret;
374 }
375 
376 template <class T>
377 Vector<EBAMRCellData*>
379 {
380  Vector<EBAMRCellData*> ret(m_solvers.size(), nullptr);
381  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
382  ret[iter.index()] = &(iter()->getMobilityFunction());
383  }
384 
385  return ret;
386 }
387 
388 template <class T>
389 Vector<ParticleContainer<ItoParticle>*>
391 {
392  Vector<ParticleContainer<ItoParticle>*> ret(m_solvers.size(), nullptr);
393  for (ItoIterator<T> iter = this->iterator(); iter.ok(); ++iter) {
394  ret[iter.index()] = &(iter()->getParticles(a_container));
395  }
396 
397  return ret;
398 }
399 
400 template <class T>
401 phase::which_phase
403 {
404  return m_phase;
405 }
406 
407 template <class T, class S>
409 {}
410 
411 template <class T, class S>
413 {}
414 
415 template <class T, class S>
416 RefCountedPtr<ItoLayout<T>>
417 ItoFactory<T, S>::newLayout(const Vector<RefCountedPtr<ItoSpecies>>& a_species) const
418 {
419 
420  auto itoLayout = RefCountedPtr<ItoLayout<T>>(new ItoLayout<T>(a_species));
421 
422  // Cast solvers and instantiate them
423  for (int i = 0; i < a_species.size(); i++) {
424  RefCountedPtr<T> solver = RefCountedPtr<T>(static_cast<T*>(new S()));
425  solver->setSpecies(a_species[i]);
426  solver->setVerbosity(-1);
427  itoLayout->addSolver(solver);
428  }
429 
430  return itoLayout;
431 }
432 
433 #include <CD_NamespaceFooter.H>
434 
435 #endif
Declaration of an iterator class for ItoLayout.
Declaration of a class that holds a set of ItoSolvers.
~ItoFactory()
Destructor (does nothing).
Definition: CD_ItoLayoutImplem.H:412
ItoFactory()
Constructor.
Definition: CD_ItoLayoutImplem.H:408
RefCountedPtr< ItoLayout< T > > newLayout(const Vector< RefCountedPtr< ItoSpecies >> &a_species) const
Factory method which creates a new layout from a set of species. This can do automated casting betwee...
Definition: CD_ItoLayoutImplem.H:417
"Iterator" class for going through solvers in an ItoLayout.
Definition: CD_ItoIterator.H:24
virtual bool ok()
Ok or not.
Definition: CD_ItoIteratorImplem.H:71
Class for holding a set of ItoSolvers.
Definition: CD_ItoLayout.H:30
virtual Real computeAdvectiveDt()
Compute the classical advection time step for all solvers. This returns dt = dx/max(v) where max(v) t...
Definition: CD_ItoLayoutImplem.H:286
virtual void allocate()
Allocate internals for all solvers.
Definition: CD_ItoLayoutImplem.H:86
virtual void parseRuntimeOptions()
Utility function – parse runtime options for all solvers.
Definition: CD_ItoLayoutImplem.H:77
virtual Vector< EBAMRCellData * > getDiffusionFunctions()
Get all diffusion coefficients.
Definition: CD_ItoLayoutImplem.H:366
virtual Real computeDt()
Compute smallest possible time step.
Definition: CD_ItoLayoutImplem.H:272
virtual void addSolver(RefCountedPtr< T > &a_solver)
Add solver to the list of solvers.
Definition: CD_ItoLayoutImplem.H:95
virtual Vector< EBAMRCellData * > getMobilityFunctions()
Get all mobility mesh functions.
Definition: CD_ItoLayoutImplem.H:378
virtual void makeSuperparticles(const ItoSolver::WhichContainer a_whichContainer, const int a_ppc)
Rearrange the input container particle into new superparticles – this is done for all solvers.
Definition: CD_ItoLayoutImplem.H:210
virtual void setRealm(const std::string a_realm)
Set the realm where the solvers are defined.
Definition: CD_ItoLayoutImplem.H:50
virtual ItoIterator< T > iterator()
Return a fresh iterator. The iterator is a simple random access object that can iterate through the s...
Definition: CD_ItoLayoutImplem.H:36
virtual void setVerbosity(const int a_verbosity)
Set verbosity for each solver.
Definition: CD_ItoLayoutImplem.H:174
virtual void initialData()
Fill all solvers with initial data.
Definition: CD_ItoLayoutImplem.H:120
virtual void organizeParticlesByCell(const ItoSolver::WhichContainer a_whichContainer)
Sort ItoSolver particles by cell – this is done for all solvers.
Definition: CD_ItoLayoutImplem.H:192
virtual void interpolateVelocities()
Interpolate velocities.
Definition: CD_ItoLayoutImplem.H:102
virtual Real computeDiffusiveDt()
Compute the classical diffusive time step dt = dx*dx/(2*D) where D is the diffusion coefficient (not ...
Definition: CD_ItoLayoutImplem.H:314
virtual void regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel)
Regrid method – calls the regrid method for each solver.
Definition: CD_ItoLayoutImplem.H:129
virtual Vector< RefCountedPtr< ItoSpecies > > & getSpecies()
Get species.
Definition: CD_ItoLayoutImplem.H:335
virtual void parseOptions()
Utility function – parse options for all solvers.
Definition: CD_ItoLayoutImplem.H:68
virtual Real computeHopDt(const Real a_maxCellsToMove)
Compute the largest dt which restricts all particles to move less than a_maxCellsToMove.
Definition: CD_ItoLayoutImplem.H:300
virtual void organizeParticlesByPatch(const ItoSolver::WhichContainer a_whichContainer)
Sort ItoSolver particles by patch – this is done for all solvers.
Definition: CD_ItoLayoutImplem.H:201
ItoLayout()=delete
Disallowed weak construction.
virtual Vector< EBAMRCellData * > getVelocityFunctions()
Get all velocity functions.
Definition: CD_ItoLayoutImplem.H:342
virtual Vector< ParticleContainer< ItoParticle > * > getParticles(const ItoSolver::WhichContainer a_whichContainer)
Get particle containers of a particular container type.
Definition: CD_ItoLayoutImplem.H:390
virtual phase::which_phase getPhase() const
Return phase where the solvers are defined.
Definition: CD_ItoLayoutImplem.H:402
virtual void setTime(const int a_step, const Real a_time, const Real a_dt)
Set time for each solver.
Definition: CD_ItoLayoutImplem.H:183
virtual ~ItoLayout()
Destructor (does nothing).
Definition: CD_ItoLayoutImplem.H:31
virtual void setComputationalGeometry(const RefCountedPtr< ComputationalGeometry > &a_computationalGeometry)
Set the computational geometry. This sets the computational geometry for each solver.
Definition: CD_ItoLayoutImplem.H:156
virtual void remap()
Remap function – calls remap(ItoSolver::WhichContainer::bulk) for each solver.
Definition: CD_ItoLayoutImplem.H:244
virtual void depositParticles()
All solvers deposit their particles.
Definition: CD_ItoLayoutImplem.H:228
virtual const std::string getRealm() const
Get the realm name where the solvers are defined.
Definition: CD_ItoLayoutImplem.H:43
virtual void preRegrid(const int a_lbase, const int a_finestLevel)
Utility function which caches states before regrid step.
Definition: CD_ItoLayoutImplem.H:111
virtual void define(const Vector< RefCountedPtr< ItoSpecies >> &a_species)
Define function.
Definition: CD_ItoLayoutImplem.H:61
virtual Vector< RefCountedPtr< T > > & getSolvers()
Get solvers all solvers.
Definition: CD_ItoLayoutImplem.H:328
virtual size_t getNumParticles(const ItoSolver::WhichContainer a_ptype, const bool a_localOnly)
Get total number of particles.
Definition: CD_ItoLayoutImplem.H:260
virtual void setAmr(const RefCountedPtr< AmrMesh > &a_amr)
Set AmrMesh object for each solver.
Definition: CD_ItoLayoutImplem.H:147
virtual void registerOperators()
Register operators. Calls registerOperators for each solver.
Definition: CD_ItoLayoutImplem.H:138
virtual Vector< EBAMRCellData * > getDensities()
Get all densities.
Definition: CD_ItoLayoutImplem.H:354
virtual void setPhase(phase::which_phase a_phase)
Set phase for each solver.
Definition: CD_ItoLayoutImplem.H:165
WhichContainer
Enum class for distinguishing various types of particle containers.
Definition: CD_ItoSolver.H:49
Real max(const Real &a_input) noexcept
Get the maximum of the input, reduced over MPI ranks (in the Chombo communicator)
Definition: CD_ParallelOpsImplem.H:176
Real min(const Real &a_input) noexcept
Get the minimum of the input, reduced over MPI ranks (in the Chombo communicator)
Definition: CD_ParallelOpsImplem.H:58