12 #ifndef CD_MeshODEStepperImplem_H
13 #define CD_MeshODEStepperImplem_H
18 #include <CD_NamespaceHeader.H>
20 using namespace Physics::MeshODE;
25 CH_TIME(
"MeshODEStepper::MeshODEStepper");
37 CH_TIME(
"MeshODEStepper::~MeshODEStepper");
38 if (m_verbosity > 5) {
39 pout() <<
"MeshODEStepper::~MeshODEStepper" << endl;
47 CH_TIME(
"MeshODEStepper::setupSolvers");
48 if (m_verbosity > 5) {
49 pout() <<
"MeshODEStepper::setupSolvers" << endl;
54 m_solver->setPhase(m_phase);
55 m_solver->setRealm(m_realm);
56 m_solver->parseOptions();
63 CH_TIME(
"MeshODEStepper::allocate()");
64 if (m_verbosity > 5) {
65 pout() <<
"MeshODEStepper::allocate()" << endl;
75 CH_TIME(
"MeshODEStepper::initialData()");
76 if (m_verbosity > 5) {
77 pout() <<
"MeshODEStepper::initialData()" << endl;
80 m_solver->setPhi(m_initialData);
81 m_solver->computeRHS(m_rhsFunction);
88 CH_TIME(
"MeshODEStepper::postInitialize()");
89 if (m_verbosity > 5) {
90 pout() <<
"MeshODEStepper::postInitialize()" << endl;
98 CH_TIME(
"MeshODEStepper::postCheckpointSetup()");
99 if (m_verbosity > 5) {
100 pout() <<
"MeshODEStepper::postCheckpointSetup()" << endl;
103 m_solver->computeRHS(m_rhsFunction);
110 CH_TIME(
"MeshODEStepper::registerRealms()");
111 if (m_verbosity > 5) {
112 pout() <<
"MeshODEStepper::registerRealms()" << endl;
122 CH_TIME(
"MeshODEStepper::registerOperators()");
123 if (m_verbosity > 5) {
124 pout() <<
"MeshODEStepper::registerOperators()" << endl;
127 m_solver->registerOperators();
134 CH_TIME(
"MeshODEStepper::parseOptions()");
135 if (m_verbosity > 5) {
136 pout() <<
"MeshODEStepper::parseOptions()" << endl;
139 this->parseIntegrator();
140 this->parseVerbosity();
141 this->parseProblem();
148 CH_TIME(
"MeshODEStepper::parseRuntimeOptions()");
149 if (m_verbosity > 5) {
150 pout() <<
"MeshODEStepper::parseRuntimeOptions()" << endl;
153 m_solver->parseRuntimeOptions();
155 this->parseIntegrator();
156 this->parseVerbosity();
163 CH_TIME(
"MeshODEStepper::parseProblem()");
164 if (m_verbosity > 5) {
165 pout() <<
"MeshODEStepper::parseProblem()" << endl;
168 ParmParse pp(
"MeshODEStepper");
171 Real frequency = 0.0;
173 pp.get(
"init_phi", initPhi);
174 pp.get(
"frequency", frequency);
177 m_initialData = [initPhi](
const RealVect& a_pos) -> std::array<Real, N> {
178 std::array<Real, N> Y;
187 m_rhsFunction = [frequency](
const std::array<Real, N> Y,
const Real t) -> std::array<Real, N> {
188 std::array<Real, N> rhs;
190 for (
auto& r : rhs) {
191 r = cos(2 * M_PI * frequency * t);
203 CH_TIME(
"MeshODEStepper::writeCheckpointData(HDF5Handle, int)");
204 if (m_verbosity > 5) {
205 pout() <<
"MeshODEStepper::writeCheckpointData(HDF5Handle, int)" << endl;
208 m_solver->writeCheckpointLevel(a_handle, a_lvl);
217 CH_TIME(
"MeshODEStepper::readCheckpointData(HDF5Handle, int)");
218 if (m_verbosity > 5) {
219 pout() <<
"MeshODEStepper::readCheckpointData(HDF5Handle, int)" << endl;
222 m_solver->readCheckpointLevel(a_handle, a_lvl);
230 CH_TIME(
"MeshODEStepper::getNumberOfPlotVariables()");
231 if (m_verbosity > 5) {
232 pout() <<
"MeshODEStepper::getNumberOfPlotVariables()" << endl;
235 return m_solver->getNumberOfPlotVariables();
242 CH_TIME(
"MeshODEStepper::getPlotVariableNames()");
243 if (m_verbosity > 5) {
244 pout() <<
"MeshODEStepper::getPlotVariableNames()" << endl;
247 return m_solver->getPlotVariableNames();
254 const std::string a_outputRealm,
255 const int a_level)
const
257 CH_TIME(
"MeshODEStepper::writePlotData");
258 if (m_verbosity > 5) {
259 pout() <<
"MeshODEStepper::writePlotData" << endl;
262 m_solver->writePlotData(a_output, a_icomp, a_outputRealm, a_level);
269 CH_TIME(
"MeshODEStepper::computeDt()");
270 if (m_verbosity > 5) {
271 pout() <<
"MeshODEStepper::computeDt()" << endl;
281 CH_TIME(
"MeshODEStepper::avdvance(Real)");
282 if (m_verbosity > 5) {
283 pout() <<
"MeshODEStepper::advance(Real)" << endl;
286 switch (m_algorithm) {
287 case IntegrationAlgorithm::Euler: {
288 this->advanceEuler(a_dt);
292 case IntegrationAlgorithm::RK2: {
293 this->advanceRK2(a_dt);
297 case IntegrationAlgorithm::RK4: {
298 this->advanceRK4(a_dt);
303 MayDay::Error(
"MeshODEStepper::advance -- logic bust");
310 m_solver->computeRHS(m_rhsFunction);
319 CH_TIME(
"MeshODEStepper::synchronizeSolverTimes(int, Real, Real)");
320 if (m_verbosity > 5) {
321 pout() <<
"MeshODEStepper::synchronizeSolverTimes(int, Real, Real)" << endl;
327 m_solver->setTime(a_step, a_time, a_dt);
334 CH_TIME(
"MeshODEStepper::preRegrid(int, int)");
335 if (m_verbosity > 5) {
336 pout() <<
"MeshODEStepper::preRegrid(int, int)" << endl;
339 m_solver->preRegrid(a_lmin, a_oldFinestLevel);
346 CH_TIME(
"MeshODEStepper::regrid(int, int, int)");
347 if (m_verbosity > 5) {
348 pout() <<
"MeshODEStepper::regrid(int, int, int)" << endl;
351 m_solver->regrid(a_lmin, a_oldFinestLevel, a_newFinestLevel);
358 CH_TIME(
"MeshODEStepper::postRegrid()");
359 if (m_verbosity > 5) {
360 pout() <<
"MeshODEStepper::postRegrid()" << endl;
364 m_solver->computeRHS(m_rhsFunction);
371 CH_TIME(
"MeshODEStepper::parseIntegrator()");
372 if (m_verbosity > 5) {
373 pout() <<
"MeshODEStepper::parseIntegrator()" << endl;
376 ParmParse pp(
"MeshODEStepper");
380 pp.get(
"integration", str);
381 if (str ==
"euler") {
382 m_algorithm = IntegrationAlgorithm::Euler;
384 else if (str ==
"rk2") {
385 m_algorithm = IntegrationAlgorithm::RK2;
387 else if (str ==
"rk4") {
388 m_algorithm = IntegrationAlgorithm::RK4;
391 MayDay::Error(
"MeshODEStepper::parseIntegrator -- logic bust");
399 CH_TIME(
"MeshODEStepper::parseVerbosity()");
400 if (m_verbosity > 5) {
401 pout() <<
"MeshODEStepper::parseVerbosity()" << endl;
404 ParmParse pp(
"MeshODEStepper");
406 pp.get(
"verbosity", m_verbosity);
413 CH_TIME(
"MeshODEStepper::advanceEuler()");
414 if (m_verbosity > 5) {
415 pout() <<
"MeshODEStepper::advanceEuler()" << endl;
422 m_solver->computeRHS(rhs, m_rhsFunction);
431 CH_TIME(
"MeshODEStepper::advanceRK2()");
432 if (m_verbosity > 5) {
433 pout() <<
"MeshODEStepper::advanceRK2()" << endl;
441 m_amr->allocate(k1, m_realm, m_phase, N);
442 m_amr->allocate(k2, m_realm, m_phase, N);
444 m_solver->computeRHS(k1, m_rhsFunction);
447 m_solver->computeRHS(k2, m_rhsFunction);
456 CH_TIME(
"MeshODEStepper::advanceRK4()");
457 if (m_verbosity > 5) {
458 pout() <<
"MeshODEStepper::advanceRK4()" << endl;
461 MayDay::Error(
"MeshODEStepper::advanceRK4 -- not implemented");
464 #include <CD_NamespaceFooter.H>
Encapsulation of an ODE solver on the mesh.
Declaration of main (abstract) time stepper class.
static void incr(MFAMRCellData &a_lhs, const MFAMRCellData &a_rhs, const Real a_scale) noexcept
Function which increments data in the form a_lhs = a_lhs + a_rhs*a_scale for all components.
Definition: CD_DataOps.cpp:787
Class for solving dy/dt = f on an AMR hierarchy.
Definition: CD_MeshODESolver.H:28
Implementation of TimeStepper for solving an ODE on a mesh. N is the number of variables.
Definition: CD_MeshODEStepper.H:41
virtual void advanceEuler(const Real a_dt)
Advance using the explicit Euler rule.
Definition: CD_MeshODEStepperImplem.H:411
virtual Real advance(const Real a_dt) override
Advancement method. Swaps between various kernels.
Definition: CD_MeshODEStepperImplem.H:279
void registerOperators() override
Register operators.
Definition: CD_MeshODEStepperImplem.H:120
virtual void writePlotData(LevelData< EBCellFAB > &a_output, int &a_icomp, const std::string a_outputRealm, const int a_level) const override
Write plot data to output holder.
Definition: CD_MeshODEStepperImplem.H:252
void parseRuntimeOptions() override
Parse runtime options.
Definition: CD_MeshODEStepperImplem.H:146
virtual Vector< std::string > getPlotVariableNames() const override
Get plot variable names.
Definition: CD_MeshODEStepperImplem.H:240
virtual void advanceRK2(const Real a_dt)
Advance using a second-order Runge-Kutta method.
Definition: CD_MeshODEStepperImplem.H:429
virtual void regrid(const int a_lmin, const int a_oldFinestLevel, const int a_newFinestLevel) override
Time stepper regrid method.
Definition: CD_MeshODEStepperImplem.H:344
virtual void parseIntegrator()
Parse integrator.
Definition: CD_MeshODEStepperImplem.H:369
void initialData() override
Fill problem with initial data.
Definition: CD_MeshODEStepperImplem.H:73
void allocate() override
Allocate storage for solvers and time stepper.
Definition: CD_MeshODEStepperImplem.H:61
virtual void synchronizeSolverTimes(const int a_step, const Real a_time, const Real a_dt) override
Synchronize solver times and time steps.
Definition: CD_MeshODEStepperImplem.H:317
virtual ~MeshODEStepper()
Destructor.
Definition: CD_MeshODEStepperImplem.H:35
virtual void parseVerbosity()
Parse chattiness.
Definition: CD_MeshODEStepperImplem.H:397
virtual void parseProblem()
Parse the problem type.
Definition: CD_MeshODEStepperImplem.H:161
void setupSolvers() override
Instantiate the ODE solver.
Definition: CD_MeshODEStepperImplem.H:45
virtual void advanceRK4(const Real a_dt)
Advance using a fourth order Runge-Kutta method.
Definition: CD_MeshODEStepperImplem.H:454
virtual void preRegrid(const int a_lmin, const int a_oldFinestLevel) override
Perform pre-regrid operations.
Definition: CD_MeshODEStepperImplem.H:332
void postCheckpointSetup() override
Post checkpoint operations.
Definition: CD_MeshODEStepperImplem.H:96
virtual int getNumberOfPlotVariables() const override
Get the number of plot variables for this time stepper.
Definition: CD_MeshODEStepperImplem.H:228
void registerRealms() override
Register realms. Primal is the only realm we need.
Definition: CD_MeshODEStepperImplem.H:108
void parseOptions()
Parse options.
Definition: CD_MeshODEStepperImplem.H:132
virtual void postRegrid() override
Perform post-regrid operations.
Definition: CD_MeshODEStepperImplem.H:356
void postInitialize() override
Perform any post-initialization steps.
Definition: CD_MeshODEStepperImplem.H:86
MeshODEStepper()
Constructor. Does nothing.
Definition: CD_MeshODEStepperImplem.H:23
virtual Real computeDt() override
Compute a time step to be used by Driver.
Definition: CD_MeshODEStepperImplem.H:267
static const std::string Primal
Identifier for perimal realm.
Definition: CD_Realm.H:47