chombo-discharge
CD_CdrLayoutImplem.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_CdrLayoutImplem_H
13 #define CD_CdrLayoutImplem_H
14 
15 // Our includes
16 #include <CD_CdrLayout.H>
17 #include <CD_CdrIterator.H>
18 #include <CD_Units.H>
19 #include <CD_DataOps.H>
20 #include <CD_NamespaceHeader.H>
21 
22 template <class T>
23 CdrLayout<T>::CdrLayout(const Vector<RefCountedPtr<CdrSpecies>>& a_species)
24 {
25  CH_TIME("CdrLayout<T>::CdrLayout()");
26 
27  // Default settings.
28  m_verbosity = -1;
29  m_species = a_species;
30  m_realm = Realm::Primal;
31 
32  m_solvers.resize(0);
33 }
34 
35 template <class T>
37 {
38  CH_TIME("CdrLayout<T>::~CdrLayout()");
39 }
40 
41 template <class T>
42 phase::which_phase
44 {
45  CH_TIME("CdrLayout<T>::getPhase()");
46  if (m_verbosity > 6) {
47  pout() << "CdrLayout<T>::getPhase()" << endl;
48  }
49 
50  return m_phase;
51 }
52 
53 template <class T>
56 {
57  CH_TIME("CdrLayout<T>::iterator()");
58  if (m_verbosity > 6) {
59  pout() << "CdrLayout<T>::iterator()" << endl;
60  }
61 
62  return CdrIterator<T>(*this);
63 }
64 
65 template <class T>
66 std::string
68 {
69  CH_TIME("CdrLayout<T>::getRealm()");
70  if (m_verbosity > 6) {
71  pout() << "CdrLayout<T>::getRealm()" << endl;
72  }
73 
74  return m_realm;
75 }
76 
77 template <class T>
78 void
79 CdrLayout<T>::setRealm(const std::string a_realm)
80 {
81  CH_TIME("CdrLayout<T>::setRealm()");
82  if (m_verbosity > 6) {
83  pout() << "CdrLayout<T>::setRealm()" << endl;
84  }
85 
86  m_realm = a_realm;
87 
88  for (auto solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
89  solver_it()->setRealm(a_realm);
90  }
91 }
92 
93 template <class T>
94 void
95 CdrLayout<T>::addSolver(RefCountedPtr<T>& a_solver)
96 {
97  CH_TIME("CdrLayout<T>::addSolver(RefCountedPtr<T>");
98  if (m_verbosity > 6) {
99  pout() << "CdrLayout<T>::addSolver()" << endl;
100  }
101 
102  m_solvers.push_back(a_solver);
103 }
104 
105 template <class T>
106 void
108 {
109  CH_TIME("CdrLayout<T>::parseOptions()");
110  if (m_verbosity > 6) {
111  pout() << "CdrLayout<T>::parseOptions()" << endl;
112  }
113 
114  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
115  solver_it()->parseOptions();
116  }
117 }
118 
119 template <class T>
120 void
122 {
123  CH_TIME("CdrLayout<T>::parseRuntimeOptions()");
124  if (m_verbosity > 6) {
125  pout() << "CdrLayout<T>::parseRuntimeOptions()" << endl;
126  }
127 
128  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
129  solver_it()->parseRuntimeOptions();
130  }
131 }
132 
133 template <class T>
134 void
136 {
137  CH_TIME("CdrLayout<T>::allocate()");
138  if (m_verbosity > 6) {
139  pout() << "CdrLayout<T>::allocate()" << endl;
140  }
141 
142  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
143  solver_it()->allocate();
144  }
145 }
146 
147 template <class T>
148 void
150 {
151  CH_TIME("CdrLayout<T>::deallocate()");
152  if (m_verbosity > 6) {
153  pout() << "CdrLayout<T>::deallocate()" << endl;
154  }
155 
156  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
157  solver_it()->deallocate();
158  }
159 }
160 
161 template <class T>
162 void
163 CdrLayout<T>::preRegrid(const int a_lbase, const int a_oldFinestLevel)
164 {
165  CH_TIME("CdrLayout<T>::preRegrid(int, int)");
166  if (m_verbosity > 6) {
167  pout() << "CdrLayout<T>::preRegrid(int, int)" << endl;
168  }
169 
170  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
171  solver_it()->preRegrid(a_lbase, a_oldFinestLevel);
172  }
173 }
174 
175 template <class T>
176 void
178 {
179  CH_TIME("CdrLayout<T>::initialData()");
180  if (m_verbosity > 6) {
181  pout() << "CdrLayout<T>::initialData()" << endl;
182  }
183 
184  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
185  solver_it()->initialData();
186  }
187 }
188 
189 template <class T>
190 void
191 CdrLayout<T>::regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel)
192 {
193  CH_TIME("CdrLayout<T>::regrid(int, int, int)");
194  if (m_verbosity > 5) {
195  pout() << "CdrLayout<T>::regrid(int, int, int)" << endl;
196  }
197 
198  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
199  solver_it()->regrid(a_lmin, a_oldFinestLevel, a_newFinestLevel);
200  }
201 }
202 
203 template <class T>
204 void
206 {
207  CH_TIME("CdrLayout<T>::registerOperators()");
208  if (m_verbosity > 5) {
209  pout() << "CdrLayout<T>::registerOperators()" << endl;
210  }
211 
212  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
213  solver_it()->registerOperators();
214  }
215 }
216 
217 template <class T>
218 void
219 CdrLayout<T>::setAmr(const RefCountedPtr<AmrMesh>& a_amrMesh)
220 {
221  CH_TIME("CdrLayout<T>::setAmr(RefCountedPtr<AmrMesh>)");
222  if (m_verbosity > 5) {
223  pout() << "CdrLayout<T>::setAmr(RefCountedPtr<AmrMesh>)" << endl;
224  }
225 
226  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
227  solver_it()->setAmr(a_amrMesh);
228  }
229 }
230 
231 template <class T>
232 void
233 CdrLayout<T>::setComputationalGeometry(const RefCountedPtr<ComputationalGeometry>& a_computationalGeometry)
234 {
235  CH_TIME("CdrLayout<T>::setComputationalGeometry(RefCountedPtr<ComputationalGeometry>)");
236  if (m_verbosity > 5) {
237  pout() << "CdrLayout<T>::setComputationalGeometry(RefCountedPtr<ComputationalGeometry>)" << endl;
238  }
239 
240  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
241  solver_it()->setComputationalGeometry(a_computationalGeometry);
242  }
243 }
244 
245 template <class T>
246 void
247 CdrLayout<T>::setPhase(const phase::which_phase a_phase)
248 {
249  CH_TIME("CdrLayout<T>::setPhase(phase::which_phase)");
250  if (m_verbosity > 5) {
251  pout() << "CdrLayout<T>::setPhase(phase::which_phase)" << endl;
252  }
253 
254  m_phase = a_phase;
255 
256  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
257  solver_it()->setPhase(m_phase);
258  }
259 }
260 
261 template <class T>
262 void
263 CdrLayout<T>::setVerbosity(const int a_verbosity)
264 {
265  CH_TIME("CdrLayout<T>::setVerbosity(int)");
266  m_verbosity = a_verbosity;
267  if (m_verbosity > 5) {
268  pout() << "CdrLayout<T>::setVerbosity(int)" << endl;
269  }
270 
271  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
272  solver_it()->setVerbosity(a_verbosity);
273  }
274 }
275 
276 template <class T>
277 void
278 CdrLayout<T>::setTime(const int a_step, const Real a_time, const Real a_dt)
279 {
280  CH_TIME("CdrLayout<T>::setTime(int, int, int)");
281  if (m_verbosity > 5) {
282  pout() << "CdrLayout<T>::setTime(int, int, int)" << endl;
283  }
284 
285  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
286  solver_it()->setTime(a_step, a_time, a_dt);
287  }
288 }
289 
290 template <class T>
291 void
293 {
294  CH_TIME("CdrLayout<T>::writePlotFile()");
295  if (m_verbosity > 5) {
296  pout() << "CdrLayout<T>::writePlotFile()" << endl;
297  }
298 
299  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
300  solver_it()->writePlotFile();
301  }
302 }
303 
304 template <class T>
305 Real
307 {
308  CH_TIME("CdrLayout<T>::computeAdvectionDt()");
309  if (m_verbosity > 5) {
310  pout() << "CdrLayout<T>::computeAdvectionDt()" << endl;
311  }
312 
313  Real dt = std::numeric_limits<Real>::max();
314 
315  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
316  const Real curDt = solver_it()->computeAdvectionDt();
317 
318  dt = std::min(dt, curDt);
319  }
320 
321  return dt;
322 }
323 
324 template <class T>
325 Real
327 {
328  CH_TIME("CdrLayout<T>::computeDiffusionDt()");
329  if (m_verbosity > 5) {
330  pout() << "CdrLayout<T>::computeDiffusionDt()" << endl;
331  }
332 
333  Real dt = std::numeric_limits<Real>::max();
334 
335  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
336  const Real curDt = solver_it()->computeDiffusionDt();
337 
338  dt = std::min(dt, curDt);
339  }
340 
341  return dt;
342 }
343 
344 template <class T>
345 Real
347 {
348  CH_TIME("CdrLayout<T>::computeAdvectionDiffusionDt()");
349  if (m_verbosity > 5) {
350  pout() << "CdrLayout<T>::computeAdvectionDiffusionDt()" << endl;
351  }
352 
353  Real dt = std::numeric_limits<Real>::max();
354 
355  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
356  const Real curDt = solver_it()->computeAdvectionDiffusionDt();
357 
358  dt = std::min(dt, curDt);
359  }
360 
361  return dt;
362 }
363 
364 template <class T>
365 Vector<RefCountedPtr<T>>&
367 {
368  CH_TIME("CdrLayout<T>::getSolvers()");
369  if (m_verbosity > 5) {
370  pout() << "CdrLayout<T>::getSolvers()" << endl;
371  }
372 
373  return (m_solvers);
374 }
375 
376 template <class T>
377 Vector<RefCountedPtr<CdrSpecies>>&
379 {
380  CH_TIME("CdrLayout<T>::getSpecies()");
381  if (m_verbosity > 5) {
382  pout() << "CdrLayout<T>::getSpecies()" << endl;
383  }
384 
385  return (m_species);
386 }
387 
388 template <class T>
389 Vector<EBAMRCellData*>
391 {
392  CH_TIME("CdrLayout<T>::getPhis()");
393  if (m_verbosity > 5) {
394  pout() << "CdrLayout<T>::getPhis()" << endl;
395  }
396 
397  Vector<EBAMRCellData*> states;
398 
399  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
400  states.push_back(&(solver_it()->getPhi()));
401  }
402 
403  return states;
404 }
405 
406 template <class T>
407 Vector<EBAMRCellData*>
409 {
410  CH_TIME("CdrLayout<T>::getSources()");
411  if (m_verbosity > 5) {
412  pout() << "CdrLayout<T>::getSources()" << endl;
413  }
414 
415  Vector<EBAMRCellData*> sources;
416 
417  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
418  sources.push_back(&(solver_it()->getSource()));
419  }
420 
421  return sources;
422 }
423 
424 template <class T>
425 Vector<EBAMRCellData*>
427 {
428  CH_TIME("CdrLayout<T>::getVelocities()");
429  if (m_verbosity > 5) {
430  pout() << "CdrLayout<T>::getVelocities()" << endl;
431  }
432 
433  Vector<EBAMRCellData*> velocities;
434 
435  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
436  velocities.push_back(&(solver_it()->getCellCenteredVelocity()));
437  }
438 
439  return velocities;
440 }
441 
442 template <class T>
443 Vector<EBAMRCellData*>
445 {
446  CH_TIME("CdrLayout<T>::getCellCenteredDiffusionCoefficients()");
447  if (m_verbosity > 5) {
448  pout() << "CdrLayout<T>::getCellCenteredDiffusionCoefficients()" << endl;
449  }
450 
451  Vector<EBAMRCellData*> diffCo;
452 
453  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
454  diffCo.push_back(&(solver_it()->getCellCenteredDiffusionCoefficient()));
455  }
456 
457  return diffCo;
458 }
459 
460 template <class T>
461 Vector<EBAMRFluxData*>
463 {
464  CH_TIME("CdrLayout<T>::getFaceCenteredDiffusionCoefficient()");
465  if (m_verbosity > 5) {
466  pout() << "CdrLayout<T>::getFaceCenteredDiffusionCoefficient()" << endl;
467  }
468 
469  Vector<EBAMRFluxData*> diffCo;
470 
471  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
472  diffCo.push_back(&(solver_it()->getFaceCenteredDiffusionCoefficient()));
473  }
474 
475  return diffCo;
476 }
477 
478 template <class T>
479 Vector<EBAMRIVData*>
481 {
482  CH_TIME("CdrLayout<T>::getEbCenteredDiffusionCoefficient");
483  if (m_verbosity > 5) {
484  pout() << "CdrLayout<T>::getEbCenteredDiffusionCoefficient" << endl;
485  }
486 
487  Vector<EBAMRIVData*> diffCo;
488 
489  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
490  diffCo.push_back(&(solver_it()->getEbCenteredDiffusionCoefficient()));
491  }
492 
493  return diffCo;
494 }
495 
496 template <class T>
497 Vector<EBAMRIVData*>
499 {
500  CH_TIME("CdrLayout<T>::getEbFlux()");
501  if (m_verbosity > 5) {
502  pout() << "CdrLayout<T>::getEbFlux()" << endl;
503  }
504 
505  Vector<EBAMRIVData*> ebFlux;
506 
507  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
508  ebFlux.push_back(&(solver_it()->getEbFlux()));
509  }
510 
511  return ebFlux;
512 }
513 
514 template <class T>
515 Vector<EBAMRIFData*>
517 {
518  CH_TIME("CdrLayout<T>::getDomainFlux()");
519  if (m_verbosity > 5) {
520  pout() << "CdrLayout<T>::getDomainFlux()" << endl;
521  }
522 
523  Vector<EBAMRIFData*> domainFlux;
524 
525  for (CdrIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
526  domainFlux.push_back(&(solver_it()->getDomainFlux()));
527  }
528 
529  return domainFlux;
530 }
531 
532 template <class T, class S>
534 {
535  CH_TIME("CdrFactory<T, S>::CdrFactory()");
536 }
537 
538 template <class T, class S>
540 {
541  CH_TIME("CdrFactory<T, S>::~CdrFactory()");
542 }
543 
544 template <class T, class S>
545 RefCountedPtr<CdrLayout<T>>
546 CdrFactory<T, S>::newLayout(const Vector<RefCountedPtr<CdrSpecies>>& a_species) const
547 {
548  CH_TIME("CdrFactory<T, S>::newLayout(Vector<RefCountedPtr<CdrSpecies> >)");
549 
550  // Instatiate the return CdrLayout object first.
551  auto cdr = RefCountedPtr<CdrLayout<T>>(new CdrLayout<T>(a_species));
552 
553  // Cast solvers and instantiate them
554  for (int i = 0; i < a_species.size(); i++) {
555 
556  auto solver = RefCountedPtr<T>(static_cast<T*>(new S()));
557 
558  solver->setSpecies(a_species[i]);
559  solver->setPhase(phase::gas);
560  solver->setVerbosity(-1);
561 
562  cdr->addSolver(solver);
563  }
564 
565  return cdr;
566 }
567 
568 #include <CD_NamespaceFooter.H>
569 
570 #endif
Declaration of an iterator class for CdrLayout (for iterating through subsets of solvers).
Declaration of a class that holds a set of CdrSolvers (to cut down on typing).
Agglomeration of useful data operations.
Declaration of various useful units.
CdrFactory()
Default constructor (does nothing)
Definition: CD_CdrLayoutImplem.H:533
RefCountedPtr< CdrLayout< T > > newLayout(const Vector< RefCountedPtr< CdrSpecies >> &a_species) const
Factory method, create a new CdrLayout.
Definition: CD_CdrLayoutImplem.H:546
~CdrFactory()
Default constructor (does nothing)
Definition: CD_CdrLayoutImplem.H:539
Iterator class for CdrLayout. This allows iteration through solvers (or subsets of solvers).
Definition: CD_CdrIterator.H:27
virtual bool ok() const
Ok or not.
Definition: CD_CdrIteratorImplem.H:76
Class for holding a set of CdrSolvers.
Definition: CD_CdrLayout.H:37
virtual void setPhase(const phase::which_phase a_phase=phase::gas)
Set phase.
Definition: CD_CdrLayoutImplem.H:247
virtual std::string getRealm() const
Get the realm where the Cdr solvers live.
Definition: CD_CdrLayoutImplem.H:67
virtual void parseOptions()
Parse class options.
Definition: CD_CdrLayoutImplem.H:107
virtual void parseRuntimeOptions()
Parse runtime options.
Definition: CD_CdrLayoutImplem.H:121
virtual Vector< EBAMRCellData * > getPhis()
Get all cell-centered states.
Definition: CD_CdrLayoutImplem.H:390
virtual Vector< EBAMRIVData * > getEbFlux()
Get all EB flux data holders.
Definition: CD_CdrLayoutImplem.H:498
virtual Vector< EBAMRCellData * > getSources()
Get all source terms.
Definition: CD_CdrLayoutImplem.H:408
virtual phase::which_phase getPhase() const
Get phase.
Definition: CD_CdrLayoutImplem.H:43
virtual void preRegrid(const int a_lbase, const int a_oldFinestLevel)
Call preRegrid(...) method for all the CdrSolvers.
Definition: CD_CdrLayoutImplem.H:163
virtual Vector< EBAMRIFData * > getDomainFlux()
Get domain flux data holders.
Definition: CD_CdrLayoutImplem.H:516
virtual Vector< EBAMRCellData * > getVelocities()
Get all cell-centered velocities.
Definition: CD_CdrLayoutImplem.H:426
virtual void writePlotFile()
Convenience function. All solvers write plot files (for debugging purposes)
Definition: CD_CdrLayoutImplem.H:292
virtual void setComputationalGeometry(const RefCountedPtr< ComputationalGeometry > &a_computationalGeometry)
Set the computational geometry for all CdrSolvers.
Definition: CD_CdrLayoutImplem.H:233
virtual void setAmr(const RefCountedPtr< AmrMesh > &a_amrMesh)
Set AmrMesh for all CdrSolvers.
Definition: CD_CdrLayoutImplem.H:219
virtual Real computeDiffusionDt()
Get time step for explicit diffusion.
Definition: CD_CdrLayoutImplem.H:326
virtual ~CdrLayout()
Destructor.
Definition: CD_CdrLayoutImplem.H:36
virtual void addSolver(RefCountedPtr< T > &a_solver)
Add solver. This appends a_solver to m_solvers.
Definition: CD_CdrLayoutImplem.H:95
virtual Vector< EBAMRIVData * > getEbCenteredDiffusionCoefficient()
Get all EB-centered diffusion coefficients.
Definition: CD_CdrLayoutImplem.H:480
virtual void setTime(const int a_step, const Real a_time, const Real a_dt)
Set time.
Definition: CD_CdrLayoutImplem.H:278
virtual Real computeAdvectionDiffusionDt()
Get the time step for explicit advection-diffusion.
Definition: CD_CdrLayoutImplem.H:346
virtual Vector< EBAMRFluxData * > getFaceCenteredDiffusionCoefficient()
Get all face-centered diffusion coefficients.
Definition: CD_CdrLayoutImplem.H:462
virtual void setVerbosity(const int a_verbosity)
Set verbosity for all CdrSolvers.
Definition: CD_CdrLayoutImplem.H:263
virtual void registerOperators()
Register operators.
Definition: CD_CdrLayoutImplem.H:205
CdrLayout()=delete
Disallowed weak constructor. Use the full constructor.
virtual Vector< RefCountedPtr< T > > & getSolvers()
Get solvers.
Definition: CD_CdrLayoutImplem.H:366
virtual void regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel)
Regrid method. Calls regrid(...) for every CdrSolver.
Definition: CD_CdrLayoutImplem.H:191
virtual Vector< EBAMRCellData * > getCellCenteredDiffusionCoefficients()
Get all cell-centered diffusion coefficients.
Definition: CD_CdrLayoutImplem.H:444
virtual void allocate()
Allocate internal storage for solvers.
Definition: CD_CdrLayoutImplem.H:135
virtual void initialData()
Initial data. Fill all solvers with initial data.
Definition: CD_CdrLayoutImplem.H:177
virtual Vector< RefCountedPtr< CdrSpecies > > & getSpecies()
Get species.
Definition: CD_CdrLayoutImplem.H:378
virtual CdrIterator< T > iterator()
Get an iterator which can iterate through the various Cdr solvers.
Definition: CD_CdrLayoutImplem.H:55
virtual Real computeAdvectionDt()
Get CFL time for advection.
Definition: CD_CdrLayoutImplem.H:306
virtual void setRealm(const std::string a_realm)
Set realm for all CdrSolvers.
Definition: CD_CdrLayoutImplem.H:79
virtual void deallocate()
Deallocate solver internals.
Definition: CD_CdrLayoutImplem.H:149
static const std::string Primal
Identifier for perimal realm.
Definition: CD_Realm.H:47
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