From e2b8715b42680c23b457e9f02d6088810da541cd Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Sat, 6 Jul 2024 10:22:47 +0200 Subject: [PATCH] move EclTimeStepping parameters to TypeTag-free parameter system --- flowexperimental/flowexp.hpp | 2 +- flowexperimental/flowexp_blackoil.cpp | 2 +- opm/simulators/flow/FlowProblem.hpp | 6 +- opm/simulators/flow/FlowProblemProperties.hpp | 2 +- opm/simulators/flow/OutputBlackoilModule.hpp | 30 ++---- .../flow/SimulatorFullyImplicitBlackoil.hpp | 4 +- .../timestepping/AdaptiveTimeStepping.hpp | 19 ++-- .../timestepping/EclTimeSteppingParams.hpp | 97 ++++--------------- tests/TestTypeTag.hpp | 4 +- tests/test_glift1.cpp | 2 +- 10 files changed, 47 insertions(+), 121 deletions(-) diff --git a/flowexperimental/flowexp.hpp b/flowexperimental/flowexp.hpp index 21a6d29a0..6efef55fd 100644 --- a/flowexperimental/flowexp.hpp +++ b/flowexperimental/flowexp.hpp @@ -57,7 +57,7 @@ namespace TTag { struct FlowExpTypeTag { - using InheritsFrom = std::tuple; + using InheritsFrom = std::tuple; }; } diff --git a/flowexperimental/flowexp_blackoil.cpp b/flowexperimental/flowexp_blackoil.cpp index 616e4956c..8f9025b96 100644 --- a/flowexperimental/flowexp_blackoil.cpp +++ b/flowexperimental/flowexp_blackoil.cpp @@ -78,6 +78,6 @@ struct Simulator int main(int argc, char** argv) { using TypeTag = Opm::Properties::TTag::FlowExpProblemBlackOil; - Opm::registerEclTimeSteppingParameters(); + Opm::registerEclTimeSteppingParameters(); return Opm::start(argc, argv); } diff --git a/opm/simulators/flow/FlowProblem.hpp b/opm/simulators/flow/FlowProblem.hpp index 379a94383..1ab0fd1f2 100644 --- a/opm/simulators/flow/FlowProblem.hpp +++ b/opm/simulators/flow/FlowProblem.hpp @@ -338,9 +338,9 @@ public: enableEclOutput_ = Parameters::Get(); enableVtkOutput_ = Parameters::Get(); - this->enableTuning_ = Parameters::get(); + this->enableTuning_ = Parameters::Get(); this->initialTimeStepSize_ = Parameters::Get>(); - this->maxTimeStepAfterWellEvent_ = Parameters::get() * 24 * 60 * 60; + this->maxTimeStepAfterWellEvent_ = Parameters::Get>() * 24 * 60 * 60; // The value N for this parameter is defined in the following order of presedence: // 1. Command line value (--num-pressure-points-equil=N) @@ -2723,7 +2723,7 @@ private: int episodeIdx = simulator.episodeIndex(); // first thing in the morning, limit the time step size to the maximum size - Scalar maxTimeStepSize = Parameters::get() * 24 * 60 * 60; + Scalar maxTimeStepSize = Parameters::Get>() * 24 * 60 * 60; int reportStepIdx = std::max(episodeIdx, 0); if (this->enableTuning_) { const auto& tuning = schedule[reportStepIdx].tuning(); diff --git a/opm/simulators/flow/FlowProblemProperties.hpp b/opm/simulators/flow/FlowProblemProperties.hpp index 859d92ea5..391c787e5 100644 --- a/opm/simulators/flow/FlowProblemProperties.hpp +++ b/opm/simulators/flow/FlowProblemProperties.hpp @@ -60,7 +60,7 @@ namespace Opm::Properties { namespace TTag { struct FlowBaseProblem { - using InheritsFrom = std::tuple; + using InheritsFrom = std::tuple; }; } diff --git a/opm/simulators/flow/OutputBlackoilModule.hpp b/opm/simulators/flow/OutputBlackoilModule.hpp index 57829ab8b..555540a8d 100644 --- a/opm/simulators/flow/OutputBlackoilModule.hpp +++ b/opm/simulators/flow/OutputBlackoilModule.hpp @@ -65,28 +65,10 @@ #include #include -namespace Opm::Properties::TTag { - -// create new type tag for the Ecl-output -struct OutputBlackOil {}; - -} // namespace Opm::Properties::TTag - namespace Opm::Parameters { -template -struct ForceDisableFluidInPlaceOutput { using type = Properties::UndefinedProperty; }; - -template -struct ForceDisableResvFluidInPlaceOutput { using type = Properties::UndefinedProperty; }; - -template -struct ForceDisableFluidInPlaceOutput -{ static constexpr bool value = false; }; - -template -struct ForceDisableResvFluidInPlaceOutput -{ static constexpr bool value = false; }; +struct ForceDisableFluidInPlaceOutput { static constexpr bool value = false; }; +struct ForceDisableResvFluidInPlaceOutput { static constexpr bool value = false; }; } // namespace Opm::Parameters @@ -165,10 +147,10 @@ public: this->setupBlockData(isCartIdxOnThisRank); this->forceDisableFipOutput_ = - Parameters::get(); + Parameters::Get(); this->forceDisableFipresvOutput_ = - Parameters::get(); + Parameters::Get(); if (! Parameters::Get()) { const std::string msg = "The output code does not support --owner-cells-first=false."; @@ -199,10 +181,10 @@ public: */ static void registerParameters() { - Parameters::registerParam + Parameters::Register ("Do not print fluid-in-place values after each report step " "even if requested by the deck."); - Parameters::registerParam + Parameters::Register ("Do not print reservoir volumes values after each report step " "even if requested by the deck."); } diff --git a/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp b/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp index f25ce2584..7a9b7a5c9 100644 --- a/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp +++ b/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp @@ -215,7 +215,7 @@ public: // adaptive time stepping bool enableAdaptive = Parameters::Get(); - bool enableTUNING = Parameters::get(); + bool enableTUNING = Parameters::Get(); if (enableAdaptive) { const UnitSystem& unitSystem = this->simulator_.vanguard().eclState().getUnits(); const auto& sched_state = schedule()[timer.currentStepNum()]; @@ -305,7 +305,7 @@ public: this->solver_->model().beginReportStep(); - const bool enableTUNING = Parameters::get(); + const bool enableTUNING = Parameters::Get(); // If sub stepping is enabled allow the solver to sub cycle // in case the report steps are too large for the solver to converge diff --git a/opm/simulators/timestepping/AdaptiveTimeStepping.hpp b/opm/simulators/timestepping/AdaptiveTimeStepping.hpp index 0a24d3019..2d08b398b 100644 --- a/opm/simulators/timestepping/AdaptiveTimeStepping.hpp +++ b/opm/simulators/timestepping/AdaptiveTimeStepping.hpp @@ -49,9 +49,7 @@ namespace Opm::Properties::TTag { -struct FlowTimeSteppingParameters { - using InheritsFrom = std::tuple; -}; +struct FlowTimeSteppingParameters {}; } @@ -219,6 +217,7 @@ std::set consistentlyFailingWells(const std::vector& sr template class AdaptiveTimeStepping { + using Scalar = GetPropType; template class SolutionTimeErrorSolverWrapper : public RelativeChangeInterface { @@ -252,18 +251,18 @@ std::set consistentlyFailingWells(const std::vector& sr const double max_next_tstep = -1.0, const bool terminalOutput = true) : timeStepControl_() - , restartFactor_(Parameters::get()) // 0.33 - , growthFactor_(Parameters::get()) // 2.0 - , maxGrowth_(Parameters::get()) // 3.0 - , maxTimeStep_(Parameters::get() * 24 * 60 * 60) // 365.25 - , minTimeStep_(unitSystem.to_si(UnitSystem::measure::time, Parameters::get())) // 1e-12; + , restartFactor_(Parameters::Get>()) // 0.33 + , growthFactor_(Parameters::Get>()) // 2.0 + , maxGrowth_(Parameters::Get>()) // 3.0 + , maxTimeStep_(Parameters::Get>() * 24 * 60 * 60) // 365.25 + , minTimeStep_(unitSystem.to_si(UnitSystem::measure::time, Parameters::Get>())) // 1e-12; , ignoreConvergenceFailure_(Parameters::get()) // false; , solverRestartMax_(Parameters::get()) // 10 , solverVerbose_(Parameters::get() > 0 && terminalOutput) // 2 , timestepVerbose_(Parameters::get() > 0 && terminalOutput) // 2 , suggestedNextTimestep_((max_next_tstep <= 0 ? Parameters::get() : max_next_tstep) * 24 * 60 * 60) // 1.0 , fullTimestepInitially_(Parameters::get()) // false - , timestepAfterEvent_(Parameters::get() * 24 * 60 * 60) // 1e30 + , timestepAfterEvent_(Parameters::Get>() * 24 * 60 * 60) // 1e30 , useNewtonIteration_(false) , minTimeStepBeforeShuttingProblematicWells_(Parameters::get() * unit::day) @@ -301,7 +300,7 @@ std::set consistentlyFailingWells(const std::vector& sr static void registerParameters() { - registerEclTimeSteppingParameters(); + registerEclTimeSteppingParameters(); // TODO: make sure the help messages are correct (and useful) Parameters::registerParam ("Continue instead of stop when minimum solver time step is reached"); diff --git a/opm/simulators/timestepping/EclTimeSteppingParams.hpp b/opm/simulators/timestepping/EclTimeSteppingParams.hpp index 41bd9efc1..136207644 100644 --- a/opm/simulators/timestepping/EclTimeSteppingParams.hpp +++ b/opm/simulators/timestepping/EclTimeSteppingParams.hpp @@ -26,104 +26,49 @@ #include #include - -namespace Opm::Properties::TTag { - -struct EclTimeSteppingParameters {}; - -} - namespace Opm::Parameters { -template -struct EnableTuning { using type = Properties::UndefinedProperty; }; +struct EnableTuning { static constexpr bool value = false; }; +template +struct SolverGrowthFactor { static constexpr Scalar value = 2.0; }; -template -struct SolverGrowthFactor { using type = Properties::UndefinedProperty; }; +template +struct SolverMaxGrowth { static constexpr Scalar value = 3.0; }; -template -struct SolverMaxGrowth { using type = Properties::UndefinedProperty; }; +template +struct SolverMinTimeStep { static constexpr Scalar value = 1e-12; }; -template -struct SolverMaxTimeStepInDays { using type = Properties::UndefinedProperty; }; +template +struct SolverMaxTimeStepInDays { static constexpr Scalar value = 365.0; }; -template -struct SolverMinTimeStep { using type = Properties::UndefinedProperty; }; +template +struct SolverRestartFactor { static constexpr Scalar value = 0.33; }; -template -struct SolverRestartFactor { using type = Properties::UndefinedProperty; }; - -template -struct TimeStepAfterEventInDays { using type = Properties::UndefinedProperty; }; - -template -struct EnableTuning -{ static constexpr bool value = false; }; - -template -struct SolverGrowthFactor -{ - using type = GetPropType; - static constexpr type value = 2.0; -}; - -template -struct SolverMaxGrowth -{ - using type = GetPropType; - static constexpr type value = 3.0; -}; - -template -struct SolverMinTimeStep -{ - using type = GetPropType; - static constexpr type value = 1.0e-12; -}; - -template -struct SolverMaxTimeStepInDays -{ - using type = GetPropType; - static constexpr type value = 365.0; -}; - -template -struct SolverRestartFactor -{ - using type = GetPropType; - static constexpr type value = 0.33; -}; - -template -struct TimeStepAfterEventInDays -{ - using type = GetPropType; - static constexpr type value = -1.0; -}; +template +struct TimeStepAfterEventInDays { static constexpr Scalar value = -1.0; }; } // namespace Opm::Properties namespace Opm { -template +template void registerEclTimeSteppingParameters() { - Parameters::registerParam + Parameters::Register ("Honor some aspects of the TUNING keyword."); - Parameters::registerParam + Parameters::Register> ("The factor time steps are elongated after a successful substep"); - Parameters::registerParam + Parameters::Register> ("The maximum factor time steps are elongated after a report step"); - Parameters::registerParam + Parameters::Register> ("The maximum size of a time step in days"); - Parameters::registerParam + Parameters::Register> ("The minimum size of a time step in days for field and " "metric and hours for lab. If a step cannot converge without " "getting cut below this step size the simulator will stop"); - Parameters::registerParam + Parameters::Register> ("The factor time steps are elongated after restarts"); - Parameters::registerParam + Parameters::Register> ("Time step size of the first time step after an event " "occurs during the simulation in days"); } diff --git a/tests/TestTypeTag.hpp b/tests/TestTypeTag.hpp index 5bd026043..4fb69fc84 100644 --- a/tests/TestTypeTag.hpp +++ b/tests/TestTypeTag.hpp @@ -43,9 +43,9 @@ namespace TTag { struct TestTypeTag { using InheritsFrom = std::tuple; + BlackOilModel>; }; + } // Set the problem class diff --git a/tests/test_glift1.cpp b/tests/test_glift1.cpp index ae11d5932..08d4454f6 100644 --- a/tests/test_glift1.cpp +++ b/tests/test_glift1.cpp @@ -87,7 +87,7 @@ initSimulator(const char *filename) Parameters::reset(); registerAllParameters_(false); - registerEclTimeSteppingParameters(); + registerEclTimeSteppingParameters(); BlackoilModelParameters::registerParameters(); Parameters::Register("Do *NOT* use!"); Opm::Parameters::SetDefault(2);