Skip to content

Commit

Permalink
Construct integrators via string name
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Mullen committed Nov 13, 2023
1 parent bd4c0b1 commit 809decb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
19 changes: 17 additions & 2 deletions src/time_integration/butcher_integrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ namespace parthenon {
* alpha_k = c_k
* c_k = b_k
*/
ButcherIntegrator::ButcherIntegrator(ParameterInput *pin)
: StagedIntegrator(pin->GetOrAddString("parthenon/time", "integrator", "rk2")) {

//----------------------------------------------------------------------------------------
//! \class ButcherIntegrator::ButcherIntegrator(const std::string &name)
//! \brief Constructs a ButcherIntegrator instance given a string (e.g., rk2, rk3..)

ButcherIntegrator::ButcherIntegrator(const std::string &name) : StagedIntegrator(name) {
if (name_ == "rk1") {
nstages = nbuffers = 1;
Resize_(nstages);
Expand Down Expand Up @@ -219,6 +223,17 @@ ButcherIntegrator::ButcherIntegrator(ParameterInput *pin)
}
}

//----------------------------------------------------------------------------------------
//! \class ButcherIntegrator::ButcherIntegrator(ParameterInput *pin)
//! \brief Constructs a ButcherIntegrator instance given ParameterInput *pin

ButcherIntegrator::ButcherIntegrator(ParameterInput *pin)
: ButcherIntegrator(pin->GetOrAddString("parthenon/time", "integrator", "rk2")) {}

//----------------------------------------------------------------------------------------
//! \fn void ButcherIntegrator::Resize_(int nstages)
//! \brief Resizes ButcherIntegrator registers given a supplied integer nstages

void ButcherIntegrator::Resize_(int nstages) {
a.resize(nstages);
for (int i = 0; i < a.size(); ++i) {
Expand Down
16 changes: 14 additions & 2 deletions src/time_integration/low_storage_integrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ namespace parthenon {
* Stone et al., ApJS (2020) 249:4
* See equations 11 through 15.
*/
LowStorageIntegrator::LowStorageIntegrator(ParameterInput *pin)
: StagedIntegrator(pin->GetOrAddString("parthenon/time", "integrator", "rk2")) {

//----------------------------------------------------------------------------------------
//! \class LowStorageIntegrator::LowStorageIntegrator(const std::string &name)
//! \brief Constructs a LowStorageIntegrator instance given a string (e.g., rk2, rk3..)

LowStorageIntegrator::LowStorageIntegrator(const std::string &name)
: StagedIntegrator(name) {
if (name_ == "rk1") {
nstages = 1;
nbuffers = 1;
Expand Down Expand Up @@ -155,4 +160,11 @@ LowStorageIntegrator::LowStorageIntegrator(ParameterInput *pin)
MakePeriodicNames_(stage_name, nstages);
}

//----------------------------------------------------------------------------------------
//! \class LowStorageIntegrator::LowStorageIntegrator(ParameterInput *pin)
//! \brief Constructs a LowStorageIntegrator instance given ParameterInput *pin

LowStorageIntegrator::LowStorageIntegrator(ParameterInput *pin)
: LowStorageIntegrator(pin->GetOrAddString("parthenon/time", "integrator", "rk2")) {}

} // namespace parthenon
2 changes: 2 additions & 0 deletions src/time_integration/staged_integrator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class StagedIntegrator {
class LowStorageIntegrator : public StagedIntegrator {
public:
LowStorageIntegrator() = default;
explicit LowStorageIntegrator(const std::string &name);
explicit LowStorageIntegrator(ParameterInput *pin);
std::vector<Real> delta;
std::vector<Real> beta;
Expand All @@ -60,6 +61,7 @@ class LowStorageIntegrator : public StagedIntegrator {
class ButcherIntegrator : public StagedIntegrator {
public:
ButcherIntegrator() = default;
explicit ButcherIntegrator(const std::string &name);
explicit ButcherIntegrator(ParameterInput *pin);
// TODO(JMM): Should I do a flat array with indexing instead?
std::vector<std::vector<Real>> a;
Expand Down

0 comments on commit 809decb

Please sign in to comment.