chombo-discharge
CD_MeshODESolver.H
Go to the documentation of this file.
1 /* chombo-discharge
2  * Copyright © 2022 SINTEF Energy Research.
3  * Please refer to Copyright.txt and LICENSE in the chombo-discharge root directory.
4  */
5 
12 #ifndef CD_MeshODESolver_H
13 #define CD_MeshODESolver_H
14 
15 // Std includes
16 #include <array>
17 
18 // Our includes
19 #include <CD_AmrMesh.H>
20 #include <CD_NamespaceHeader.H>
21 
26 template <size_t N = 1>
28 {
29 public:
33  using RHSFunction = std::function<std::array<Real, N>(const std::array<Real, N>&, const Real)>;
34 
38  MeshODESolver();
39 
44  MeshODESolver(const RefCountedPtr<AmrMesh>& a_amr) noexcept;
45 
49  MeshODESolver(const MeshODESolver&) = delete;
50 
54  MeshODESolver(const MeshODESolver&&) = delete;
55 
59  virtual ~MeshODESolver();
60 
65  operator=(const MeshODESolver&) = delete;
66 
71  operator=(const MeshODESolver&&) = delete;
72 
77  virtual void
78  setAmr(const RefCountedPtr<AmrMesh>& a_amrMesh) noexcept;
79 
83  virtual void
84  parseOptions() noexcept;
85 
89  virtual void
90  parseRuntimeOptions() noexcept;
91 
95  virtual void
96  allocate() noexcept;
97 
103  virtual void
104  setPhi(const std::function<Real(const RealVect& a_pos)>& a_phiFunc, const size_t a_comp) noexcept;
105 
110  virtual void
111  setPhi(const std::function<std::array<Real, N>(const RealVect& a_pos)>& a_phiFunc) noexcept;
112 
118  virtual void
119  setRHS(const std::function<Real(const RealVect& a_pos)>& a_srcFunc, const size_t a_comp) noexcept;
120 
125  virtual void
126  computeRHS(const RHSFunction& a_rhsFunction) noexcept;
127 
133  virtual void
134  computeRHS(EBAMRCellData& rhs, const RHSFunction& a_rhsFunction) const noexcept;
135 
140  getPhi() noexcept;
141 
145  const EBAMRCellData&
146  getPhi() const noexcept;
147 
152  getRHS() noexcept;
153 
157  const EBAMRCellData&
158  getRHS() const noexcept;
159 
166  virtual void
167  preRegrid(const int a_lbase, const int a_oldFinestLevel) noexcept;
168 
176  virtual void
177  regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel) noexcept;
178 
183  virtual std::string
184  getRealm() const noexcept;
185 
190  virtual std::string
191  getName() const noexcept;
192 
197  virtual void
198  setName(const std::string& a_name) noexcept;
199 
204  virtual void
205  registerOperators() const noexcept;
206 
211  virtual void
212  setRealm(const std::string a_realm) noexcept;
213 
218  virtual void
219  setPhase(phase::which_phase a_phase) noexcept;
220 
225  virtual void
226  setVerbosity(const int a_verbosity) noexcept;
227 
235  virtual void
236  setTime(const int a_step, const Real a_time, const Real a_dt) noexcept;
237 
243  virtual void
244  writePlotFile() const noexcept;
245 
250  virtual int
251  getNumberOfPlotVariables() const noexcept;
252 
257  virtual Vector<std::string>
258  getPlotVariableNames() const noexcept;
259 
267  virtual void
268  writePlotData(LevelData<EBCellFAB>& a_output,
269  int& a_icomp,
270  const std::string a_outputRealm,
271  const int a_level) const noexcept;
272 
278 #ifdef CH_USE_HDF5
279  virtual void
280  writeCheckpointLevel(HDF5Handle& a_handle, const int a_level) const noexcept;
281 #endif
282 
288 #ifdef CH_USE_HDF5
289  virtual void
290  readCheckpointLevel(HDF5Handle& a_handle, const int a_level) noexcept;
291 #endif
292 
293 protected:
297  RefCountedPtr<AmrMesh> m_amr;
298 
303 
308 
312  Real m_time;
313 
317  Real m_dt;
318 
322  bool m_plotPhi;
323 
327  bool m_plotRHS;
328 
333 
337  std::string m_name;
338 
343  std::string m_className;
344 
348  std::string m_realm;
349 
353  phase::which_phase m_phase;
354 
359 
364 
369 
380  virtual void
381  writeData(LevelData<EBCellFAB>& a_output,
382  int& a_comp,
383  const EBAMRCellData& a_data,
384  const std::string a_outputRealm,
385  const int a_level,
386  const bool a_interpToCentroids,
387  const bool a_interpGhost) const noexcept;
388 
392  virtual void
393  parsePlotVariables() noexcept;
394 };
395 
396 #include <CD_NamespaceFooter.H>
397 
398 #include <CD_MeshODESolverImplem.H>
399 
400 #endif
Declaration of core class for handling AMR-related operations (with embedded boundaries)
Implementation of CD_MeshODESolver.H.
Class for solving dy/dt = f on an AMR hierarchy.
Definition: CD_MeshODESolver.H:28
MeshODESolver & operator=(const MeshODESolver &)=delete
Disallowed assignment operator.
MeshODESolver(const MeshODESolver &&)=delete
Disallowed move constructor.
virtual std::string getRealm() const noexcept
Get the realm where this solver is registered.
Definition: CD_MeshODESolverImplem.H:429
int m_verbosity
Chattiness.
Definition: CD_MeshODESolver.H:302
virtual void writePlotData(LevelData< EBCellFAB > &a_output, int &a_icomp, const std::string a_outputRealm, const int a_level) const noexcept
Write plot data to output holder.
Definition: CD_MeshODESolverImplem.H:628
virtual Vector< std::string > getPlotVariableNames() const noexcept
Get output plot names.
Definition: CD_MeshODESolverImplem.H:602
virtual void regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel) noexcept
Regrid this solver.
Definition: CD_MeshODESolverImplem.H:407
virtual void writePlotFile() const noexcept
Write plot file.
Definition: CD_MeshODESolverImplem.H:531
bool m_regridSlopes
Use slopes when regridding.
Definition: CD_MeshODESolver.H:332
std::function< std::array< Real, N >(const std::array< Real, N > &, const Real)> RHSFunction
Alias for right-hand side.
Definition: CD_MeshODESolver.H:33
bool m_plotPhi
Plot solution vector or not.
Definition: CD_MeshODESolver.H:322
virtual void setName(const std::string &a_name) noexcept
Set solver name.
Definition: CD_MeshODESolverImplem.H:453
MeshODESolver(const MeshODESolver &)=delete
Disallowed copy constructor.
virtual void preRegrid(const int a_lbase, const int a_oldFinestLevel) noexcept
Perform pre-regrid operations.
Definition: CD_MeshODESolverImplem.H:392
bool m_plotRHS
Plot source term or not.
Definition: CD_MeshODESolver.H:327
virtual void setPhi(const std::function< Real(const RealVect &a_pos)> &a_phiFunc, const size_t a_comp) noexcept
Set phi for a specific component.
Definition: CD_MeshODESolverImplem.H:182
virtual void parseRuntimeOptions() noexcept
Parse run-time configurable class options.
Definition: CD_MeshODESolverImplem.H:87
MeshODESolver()
Default constructor. Must subsequently set everything through public member functions.
Definition: CD_MeshODESolverImplem.H:27
EBAMRCellData m_cache
Cache storage when doing regrids.
Definition: CD_MeshODESolver.H:368
virtual void registerOperators() const noexcept
Register operators for AMR operations.
Definition: CD_MeshODESolverImplem.H:465
virtual void setVerbosity(const int a_verbosity) noexcept
Set verbosity.
Definition: CD_MeshODESolverImplem.H:505
std::string m_name
Solver name.
Definition: CD_MeshODESolver.H:337
virtual void setRHS(const std::function< Real(const RealVect &a_pos)> &a_srcFunc, const size_t a_comp) noexcept
Set right-hand side for specified component.
Definition: CD_MeshODESolverImplem.H:267
std::string m_className
Class name.
Definition: CD_MeshODESolver.H:343
Real m_dt
Last time step increment.
Definition: CD_MeshODESolver.H:317
RefCountedPtr< AmrMesh > m_amr
Write checkpoint data into HDF5 file. @paramo[out] a_handle HDF5 file.
Definition: CD_MeshODESolver.H:297
virtual void setRealm(const std::string a_realm) noexcept
Set the realm for this solver.
Definition: CD_MeshODESolverImplem.H:481
EBAMRCellData & getPhi() noexcept
Get the solution vector (left-hand side of equation).
Definition: CD_MeshODESolverImplem.H:134
EBAMRCellData m_rhs
Source term (right-hand side of equation).
Definition: CD_MeshODESolver.H:363
virtual ~MeshODESolver()
Destructor.
Definition: CD_MeshODESolverImplem.H:50
std::string m_realm
Realm where solver is registered.
Definition: CD_MeshODESolver.H:348
virtual int getNumberOfPlotVariables() const noexcept
Get number of output fields.
Definition: CD_MeshODESolverImplem.H:580
virtual void parseOptions() noexcept
Parse class options.
Definition: CD_MeshODESolverImplem.H:69
Real m_time
Current time.
Definition: CD_MeshODESolver.H:312
int m_timeStep
Time step.
Definition: CD_MeshODESolver.H:307
virtual void parsePlotVariables() noexcept
Parse plot variables.
Definition: CD_MeshODESolverImplem.H:104
EBAMRCellData & getRHS() noexcept
Get the solution vector (left-hand side of equation).
Definition: CD_MeshODESolverImplem.H:158
virtual void setAmr(const RefCountedPtr< AmrMesh > &a_amrMesh) noexcept
Set AmrMesh.
Definition: CD_MeshODESolverImplem.H:57
EBAMRCellData m_phi
Solution vector (left hand side of equation).
Definition: CD_MeshODESolver.H:358
virtual void setPhase(phase::which_phase a_phase) noexcept
Set phase.
Definition: CD_MeshODESolverImplem.H:493
virtual void allocate() noexcept
Allocate internal storage.
Definition: CD_MeshODESolverImplem.H:379
virtual void setTime(const int a_step, const Real a_time, const Real a_dt) noexcept
Set the time for this solver.
Definition: CD_MeshODESolverImplem.H:517
phase::which_phase m_phase
Phase where solver data lives.
Definition: CD_MeshODESolver.H:353
virtual std::string getName() const noexcept
Get solver name.
Definition: CD_MeshODESolverImplem.H:441
MeshODESolver & operator=(const MeshODESolver &&)=delete
Disallowed move assignement operator.
virtual void computeRHS(const RHSFunction &a_rhsFunction) noexcept
Compute right-hand side from left-hand side. I.e. compute f = f(y,t).
Definition: CD_MeshODESolverImplem.H:279
virtual void writeData(LevelData< EBCellFAB > &a_output, int &a_comp, const EBAMRCellData &a_data, const std::string a_outputRealm, const int a_level, const bool a_interpToCentroids, const bool a_interpGhost) const noexcept
Write data to output. Convenience function.
Definition: CD_MeshODESolverImplem.H:649
phase names
Definition: CD_MultiFluidIndexSpace.H:27