chombo-discharge
CD_RtLayoutImplem.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_RtLayoutImplem_H
13 #define CD_RtLayoutImplem_H
14 
15 // Chombo includes
16 #include <CH_Timer.H>
17 
18 // Our includes
19 #include <CD_RtIterator.H>
20 #include <CD_RtLayout.H>
21 #include <CD_NamespaceHeader.H>
22 
23 template <class T>
24 RtLayout<T>::RtLayout(const Vector<RefCountedPtr<RtSpecies>>& a_RtSpecies)
25 {
26  CH_TIME("RtLayout<T>::RtLayout(Vector)");
27 
28  // Default settings.
29  m_verbosity = -1;
30  m_species = a_RtSpecies;
31  m_solvers.resize(0);
32 }
33 
34 template <class T>
36 {
37  CH_TIME("RtLayout<T>::~RtLayout");
38 }
39 
40 template <class T>
43 {
44  return RtIterator<T>(*this);
45 }
46 
47 template <class T>
48 const std::string
50 {
51  return m_realm;
52 }
53 
54 template <class T>
55 void
56 RtLayout<T>::setRealm(const std::string a_realm)
57 {
58  m_realm = a_realm;
59 
60  for (auto solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
61  solver_it()->setRealm(m_realm);
62  }
63 }
64 
65 template <class T>
66 void
67 RtLayout<T>::addSolver(RefCountedPtr<T> a_solver)
68 {
69  m_solvers.push_back(a_solver);
70 }
71 
72 template <class T>
73 void
75 {
76  CH_TIME("RtLayout<T>::parseOptions");
77  if (m_verbosity > 6) {
78  pout() << "RtLayout<T>::parseOptions" << endl;
79  }
80 
81  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
82  RefCountedPtr<T>& solver = solver_it();
83  solver->parseOptions();
84  }
85 }
86 
87 template <class T>
88 void
90 {
91  CH_TIME("RtLayout<T>::parseRuntimeOptions");
92  if (m_verbosity > 6) {
93  pout() << "RtLayout<T>::parseRuntimeOptions" << endl;
94  }
95 
96  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
97  RefCountedPtr<T>& solver = solver_it();
98  solver->parseRuntimeOptions();
99  }
100 }
101 
102 template <class T>
103 void
105 {
106  CH_TIME("RtLayout<T>::allocate");
107  if (m_verbosity > 6) {
108  pout() << "RtLayout<T>::allocate" << endl;
109  }
110 
111  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
112  RefCountedPtr<T>& solver = solver_it();
113  solver->allocate();
114  }
115 }
116 
117 template <class T>
118 void
119 RtLayout<T>::preRegrid(const int a_base, const int a_finestLevel)
120 {
121  CH_TIME("RtLayout<T>::preRegrid");
122  if (m_verbosity > 6) {
123  pout() << "RtLayout<T>::preRegrid" << endl;
124  }
125 
126  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
127  RefCountedPtr<T>& solver = solver_it();
128  solver->preRegrid(a_base, a_finestLevel);
129  }
130 }
131 
132 template <class T>
133 void
135 {
136  CH_TIME("RtLayout<T>::deallocate");
137  if (m_verbosity > 6) {
138  pout() << "RtLayout<T>::deallocate" << endl;
139  }
140 
141  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
142  RefCountedPtr<T>& solver = solver_it();
143  solver->deallocate();
144  }
145 }
146 
147 template <class T>
148 void
149 RtLayout<T>::setAmr(const RefCountedPtr<AmrMesh>& a_amr)
150 {
151  CH_TIME("RtLayout<T>::setAmr");
152  if (m_verbosity > 5) {
153  pout() << "RtLayout<T>::setAmr" << endl;
154  }
155 
156  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
157  RefCountedPtr<T>& solver = solver_it();
158  solver->setAmr(a_amr);
159  }
160 }
161 
162 template <class T>
163 void
164 RtLayout<T>::setComputationalGeometry(const RefCountedPtr<ComputationalGeometry>& a_computationalGeometry)
165 {
166  CH_TIME("RtLayout<T>::setComputationalGeometry");
167  if (m_verbosity > 5) {
168  pout() << "RtLayout<T>::setComputationalGeometry" << endl;
169  }
170 
171  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
172  RefCountedPtr<T>& solver = solver_it();
173  solver->setComputationalGeometry(a_computationalGeometry);
174  }
175 }
176 
177 template <class T>
178 void
179 RtLayout<T>::setPhase(phase::which_phase a_phase)
180 {
181  CH_TIME("RtLayout<T>::setPhase");
182  if (m_verbosity > 5) {
183  pout() << "RtLayout<T>::setPhase" << endl;
184  }
185 
186  m_phase = a_phase;
187 
188  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
189  RefCountedPtr<T>& solver = solver_it();
190  solver->setPhase(a_phase);
191  }
192 }
193 
194 template <class T>
195 void
196 RtLayout<T>::setVerbosity(const int a_verbosity)
197 {
198  CH_TIME("RtLayout<T>::setVerbosity");
199 
200  m_verbosity = a_verbosity;
201  if (m_verbosity > 5) {
202  pout() << "RtLayout<T>::setVerbosity" << endl;
203  }
204 
205  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
206  RefCountedPtr<T>& solver = solver_it();
207  solver->setVerbosity(a_verbosity);
208  }
209 }
210 
211 template <class T>
212 void
214 {
215  CH_TIME("RtLayout<T>::sanityCheck");
216  if (m_verbosity > 5) {
217  pout() << "RtLayout<T>::sanityCheck" << endl;
218  }
219 
220  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
221  RefCountedPtr<T>& solver = solver_it();
222  solver->sanityCheck();
223  }
224 }
225 
226 template <class T>
227 void
228 RtLayout<T>::setTime(const int a_step, const Real a_time, const Real a_dt)
229 {
230  CH_TIME("RtLayout<T>::setTime");
231  if (m_verbosity > 5) {
232  pout() << "RtLayout<T>::setTime" << endl;
233  }
234 
235  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
236  RefCountedPtr<T>& solver = solver_it();
237  solver->setTime(a_step, a_time, a_dt);
238  }
239 }
240 
241 template <class T>
242 void
243 RtLayout<T>::regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel)
244 {
245  CH_TIME("RtLayout<T>::regrid");
246  if (m_verbosity > 5) {
247  pout() << "RtLayout<T>::regrid" << endl;
248  }
249 
250  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
251  RefCountedPtr<T>& solver = solver_it();
252  solver->regrid(a_lmin, a_oldFinestLevel, a_newFinestLevel);
253  }
254 }
255 
256 template <class T>
257 void
259 {
260  CH_TIME("RtLayout<T>::registerOperators");
261  if (m_verbosity > 5) {
262  pout() << "RtLayout<T>::registerOperators" << endl;
263  }
264 
265  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
266  RefCountedPtr<T>& solver = solver_it();
267  solver->registerOperators();
268  }
269 }
270 
271 template <class T>
272 void
274 {
275  CH_TIME("RtLayout<T>::setSource(ebamrcell)");
276  if (m_verbosity > 5) {
277  pout() << "RtLayout<T>::setSource(ebamrcell)" << endl;
278  }
279 
280  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
281  RefCountedPtr<T>& solver = solver_it();
282  solver->setSource(a_source);
283  }
284 }
285 
286 template <class T>
287 void
288 RtLayout<T>::setSource(const Real a_source)
289 {
290  CH_TIME("RtLayout<T>::setSource(constant)");
291  if (m_verbosity > 5) {
292  pout() << "RtLayout<T>::setSource(constant)" << endl;
293  }
294 
295  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
296  RefCountedPtr<T>& solver = solver_it();
297  solver->setSource(a_source);
298  }
299 }
300 
301 template <class T>
302 void
303 RtLayout<T>::setStationary(const bool a_stationary)
304 {
305  CH_TIME("RtLayout<T>::setStationary");
306  if (m_verbosity > 5) {
307  pout() << "RtLayout<T>::setStationary" << endl;
308  }
309 
310  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
311  RefCountedPtr<T>& solver = solver_it();
312  solver->setStationary(a_stationary);
313  }
314 }
315 
316 template <class T>
317 void
319 {
320  CH_TIME("RtLayout<T>::writePlotFile");
321  if (m_verbosity > 5) {
322  pout() << "RtLayout<T>::writePlotFile" << endl;
323  }
324 
325  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
326  RefCountedPtr<T>& solver = solver_it();
327  solver->writePlotFile();
328  }
329 }
330 
331 template <class T>
332 void
333 RtLayout<T>::advance(const Real a_dt)
334 {
335  CH_TIME("RtLayout<T>::advance");
336  if (m_verbosity > 6) {
337  pout() << "RtLayout<T>::advance" << endl;
338  }
339 
340  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
341  RefCountedPtr<T>& solver = solver_it();
342  solver->advance(a_dt, solver->getPhi(), solver->getSource());
343  }
344 }
345 
346 template <class T>
347 void
349 {
350  CH_TIME("RtLayout<T>::initialData");
351  if (m_verbosity > 6) {
352  pout() << "RtLayout<T>::initialData" << endl;
353  }
354 
355  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
356  RefCountedPtr<T>& solver = solver_it();
357  solver->initialData();
358  }
359 }
360 
361 template <class T>
362 bool
364 {
365  CH_TIME("RtLayout<T>::isStationary");
366  if (m_verbosity > 5) {
367  pout() << "RtLayout<T>::isStationary" << endl;
368  }
369 
370  bool stationary = true;
371 
372  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
373  RefCountedPtr<T>& solver = solver_it();
374 
375  if (solver->isStationary() == false) {
376  stationary = false;
377  }
378  }
379 
380  return stationary;
381 }
382 
383 template <class T>
384 phase::which_phase
386 {
387  CH_TIME("RtLayout<T>::getPhase");
388  if (m_verbosity > 5) {
389  pout() << "RtLayout<T>::getPhase" << endl;
390  }
391 
392  return m_phase;
393 }
394 
395 template <class T>
396 Vector<RefCountedPtr<T>>&
398 {
399  return m_solvers;
400 }
401 
402 template <class T>
403 Vector<RefCountedPtr<RtSpecies>>&
405 {
406  return m_species;
407 }
408 
409 template <class T>
410 Vector<EBAMRCellData*>
412 {
413  CH_TIME("RtLayout<T>::getSources");
414  if (m_verbosity > 5) {
415  pout() << "RtLayout<T>::getSources" << endl;
416  }
417 
418  Vector<EBAMRCellData*> sources;
419 
420  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
421  RefCountedPtr<T>& solver = solver_it();
422  sources.push_back(&(solver->getSource()));
423  }
424 
425  return sources;
426 }
427 
428 template <class T>
429 Vector<EBAMRCellData*>
431 {
432  CH_TIME("RtLayout<T>::getPhis");
433  if (m_verbosity > 5) {
434  pout() << "RtLayout<T>::getPhis" << endl;
435  }
436 
437  Vector<EBAMRCellData*> states;
438 
439  for (RtIterator<T> solver_it = this->iterator(); solver_it.ok(); ++solver_it) {
440  RefCountedPtr<T>& solver = solver_it();
441  states.push_back(&(solver->getPhi()));
442  }
443 
444  return states;
445 }
446 
447 template <class T, class S>
449 {}
450 
451 template <class T, class S>
453 {}
454 
455 template <class T, class S>
456 RefCountedPtr<RtLayout<T>>
457 RtFactory<T, S>::newLayout(const Vector<RefCountedPtr<RtSpecies>>& a_species) const
458 {
459  // Build rte layout
460  auto rte = RefCountedPtr<RtLayout<T>>(new RtLayout<T>(a_species));
461  auto spe = a_species;
462 
463  // Cast solvers and instantiate them
464  for (int i = 0; i < a_species.size(); i++) {
465  auto solver = RefCountedPtr<T>(static_cast<T*>(new S()));
466  solver->setRtSpecies(spe[i]);
467  solver->setPhase(phase::gas);
468  solver->setVerbosity(-1);
469  rte->addSolver(solver);
470  }
471 
472  return rte;
473 }
474 
475 #include <CD_NamespaceFooter.H>
476 
477 #endif
Iterator class for RtLayout.
Declaration of a class that holds a set of RtSolvers.
~RtFactory()
Destructor (does nothing)
Definition: CD_RtLayoutImplem.H:452
RtFactory()
Constructor (does nothing)
Definition: CD_RtLayoutImplem.H:448
RefCountedPtr< RtLayout< T > > newLayout(const Vector< RefCountedPtr< RtSpecies >> &a_species) const
Get a new Layout. This will cast S to a specific class (T)
Definition: CD_RtLayoutImplem.H:457
Iterator class for RtLayout.
Definition: CD_RtIterator.H:24
virtual bool ok()
Check if we can cycle further through the solvers.
Definition: CD_RtIteratorImplem.H:63
Class for holding a set of RtSolvers. T must derive from RtSolver.
Definition: CD_RtLayout.H:27
virtual void setVerbosity(const int a_verbosity)
Set verbosity.
Definition: CD_RtLayoutImplem.H:196
virtual void setComputationalGeometry(const RefCountedPtr< ComputationalGeometry > &a_computationalGeometry)
Set the computational geometry.
Definition: CD_RtLayoutImplem.H:164
virtual const std::string getRealm() const
Get realm where the solvers are allocated.
Definition: CD_RtLayoutImplem.H:49
virtual Vector< RefCountedPtr< T > > & getSolvers()
Get solvers.
Definition: CD_RtLayoutImplem.H:397
virtual void parseOptions()
Parse options.
Definition: CD_RtLayoutImplem.H:74
virtual void setStationary(const bool a_stationary)
Turn on/off stationary.
Definition: CD_RtLayoutImplem.H:303
virtual void sanityCheck()
Do a sanity check.
Definition: CD_RtLayoutImplem.H:213
virtual void setTime(const int a_step, const Real a_time, const Real a_dt)
Set time.
Definition: CD_RtLayoutImplem.H:228
virtual Vector< EBAMRCellData * > getSources()
Get all source terms.
Definition: CD_RtLayoutImplem.H:411
virtual void registerOperators()
Register operators.
Definition: CD_RtLayoutImplem.H:258
virtual void setSource(const EBAMRCellData &a_source)
Convenience function. Set source terms for all species. Mostly used for debugging.
Definition: CD_RtLayoutImplem.H:273
virtual bool isStationary()
Check if solvers are stationary.
Definition: CD_RtLayoutImplem.H:363
virtual Vector< EBAMRCellData * > getPhis()
Get all states.
Definition: CD_RtLayoutImplem.H:430
virtual void deallocate()
Deallocate internal storage for solvers.
Definition: CD_RtLayoutImplem.H:134
virtual void setAmr(const RefCountedPtr< AmrMesh > &a_amr)
Set amr.
Definition: CD_RtLayoutImplem.H:149
virtual void regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel)
Regrid all solvers.
Definition: CD_RtLayoutImplem.H:243
virtual void addSolver(RefCountedPtr< T > a_solver)
Add a new solver to the solver layout.
Definition: CD_RtLayoutImplem.H:67
virtual void parseRuntimeOptions()
Parse runtime options.
Definition: CD_RtLayoutImplem.H:89
virtual Vector< RefCountedPtr< RtSpecies > > & getSpecies()
Get species.
Definition: CD_RtLayoutImplem.H:404
RtLayout(const Vector< RefCountedPtr< RtSpecies >> &a_RtSpecies)
Full constructor.
Definition: CD_RtLayoutImplem.H:24
virtual RtIterator< T > iterator()
Get iterator.
Definition: CD_RtLayoutImplem.H:42
virtual ~RtLayout()
Destructor (does nothing)
Definition: CD_RtLayoutImplem.H:35
virtual void setRealm(const std::string a_realm)
Set realm for solvers.
Definition: CD_RtLayoutImplem.H:56
virtual void writePlotFile()
Convenience function. All solvers write plot files.
Definition: CD_RtLayoutImplem.H:318
virtual void preRegrid(const int a_base, const int a_oldFinestLevel)
Pre regrid stuff.
Definition: CD_RtLayoutImplem.H:119
virtual void initialData()
Fill with initial data.
Definition: CD_RtLayoutImplem.H:348
virtual void advance(const Real a_dt)
Convenience function. Call advance method for each solver.
Definition: CD_RtLayoutImplem.H:333
virtual phase::which_phase getPhase()
Get phase.
Definition: CD_RtLayoutImplem.H:385
virtual void allocate()
Allocate internal storage for solvers.
Definition: CD_RtLayoutImplem.H:104
virtual void setPhase(phase::which_phase a_phase=phase::gas)
Set phase.
Definition: CD_RtLayoutImplem.H:179