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