From 809decbc563eab07f05f0fbe478683390f514daa Mon Sep 17 00:00:00 2001 From: Patrick Mullen Date: Mon, 13 Nov 2023 15:28:24 -0700 Subject: [PATCH] Construct integrators via string name --- src/time_integration/butcher_integrator.cpp | 19 +++++++++++++++++-- .../low_storage_integrator.cpp | 16 ++++++++++++++-- src/time_integration/staged_integrator.hpp | 2 ++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/time_integration/butcher_integrator.cpp b/src/time_integration/butcher_integrator.cpp index d90de479ec68..40096dd1eeba 100644 --- a/src/time_integration/butcher_integrator.cpp +++ b/src/time_integration/butcher_integrator.cpp @@ -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); @@ -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) { diff --git a/src/time_integration/low_storage_integrator.cpp b/src/time_integration/low_storage_integrator.cpp index ab874d98e050..d833ddd8ad20 100644 --- a/src/time_integration/low_storage_integrator.cpp +++ b/src/time_integration/low_storage_integrator.cpp @@ -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; @@ -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 diff --git a/src/time_integration/staged_integrator.hpp b/src/time_integration/staged_integrator.hpp index 0d22d7d85600..329f69bc294b 100644 --- a/src/time_integration/staged_integrator.hpp +++ b/src/time_integration/staged_integrator.hpp @@ -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 delta; std::vector beta; @@ -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> a;