From b8b9a3810de92cd4a8cdc4a9f70d33b1679234c5 Mon Sep 17 00:00:00 2001 From: Vegard Kippe Date: Mon, 19 Feb 2024 19:14:13 +0100 Subject: [PATCH] Ensure NEXTSTEP is respected also withouth --enbale-tuning=true --- ebos/eclgenericproblem_impl.hh | 2 +- .../flow/SimulatorFullyImplicitBlackoil.hpp | 17 ++++++++++------- .../timestepping/AdaptiveTimeStepping.hpp | 12 +++++++++--- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/ebos/eclgenericproblem_impl.hh b/ebos/eclgenericproblem_impl.hh index ad94efcb9..dae2a52d1 100644 --- a/ebos/eclgenericproblem_impl.hh +++ b/ebos/eclgenericproblem_impl.hh @@ -473,7 +473,7 @@ beginEpisode_(bool enableExperiments, { const auto& sched_state = schedule_[episodeIdx]; const auto& tuning = sched_state.tuning(); - initialTimeStepSize_ = sched_state.max_next_tstep(); + initialTimeStepSize_ = sched_state.max_next_tstep(enableTuning_); maxTimeStepAfterWellEvent_ = tuning.TMAXWC; return true; } diff --git a/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp b/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp index e0fb33ec6..a9142a1a3 100644 --- a/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp +++ b/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp @@ -286,15 +286,15 @@ public: bool enableTUNING = EWOMS_GET_PARAM(TypeTag, bool, EnableTuning); if (enableAdaptive) { const UnitSystem& unitSystem = this->ebosSimulator_.vanguard().eclState().getUnits(); + const auto& sched_state = schedule()[timer.currentStepNum()]; + auto max_next_tstep = sched_state.max_next_tstep(enableTUNING); if (enableTUNING) { - const auto& sched_state = schedule()[timer.currentStepNum()]; - auto max_next_tstep = sched_state.max_next_tstep(); adaptiveTimeStepping_ = std::make_unique(max_next_tstep, sched_state.tuning(), unitSystem, terminalOutput_); } else { - adaptiveTimeStepping_ = std::make_unique(unitSystem, terminalOutput_); + adaptiveTimeStepping_ = std::make_unique(unitSystem, max_next_tstep, terminalOutput_); } if (isRestart()) { @@ -379,18 +379,21 @@ public: // \Note: The sub stepping will require a copy of the state variables if (adaptiveTimeStepping_) { const auto& events = schedule()[timer.currentStepNum()].events(); - if (enableTUNING) { - if (events.hasEvent(ScheduleEvents::TUNING_CHANGE)) { - const auto& sched_state = schedule()[timer.currentStepNum()]; + if (events.hasEvent(ScheduleEvents::TUNING_CHANGE)) { + const auto& sched_state = schedule()[timer.currentStepNum()]; + const auto& max_next_tstep = sched_state.max_next_tstep(enableTUNING); + if (enableTUNING) { const auto& tuning = sched_state.tuning(); - const auto& max_next_tstep = sched_state.max_next_tstep(); adaptiveTimeStepping_->updateTUNING(max_next_tstep, tuning); // \Note: Assumes TUNING is only used with adaptive time-stepping // \Note: Need to update both solver (model) and simulator since solver is re-created each report step. solver_->model().updateTUNING(tuning); this->updateTUNING(tuning); + } else { + adaptiveTimeStepping_->updateNEXTSTEP(max_next_tstep); } } + bool event = events.hasEvent(ScheduleEvents::NEW_WELL) || events.hasEvent(ScheduleEvents::INJECTION_TYPE_CHANGED) || events.hasEvent(ScheduleEvents::WELL_SWITCHED_INJECTOR_PRODUCER) || diff --git a/opm/simulators/timestepping/AdaptiveTimeStepping.hpp b/opm/simulators/timestepping/AdaptiveTimeStepping.hpp index 4d9adc332..8c7b80bbb 100644 --- a/opm/simulators/timestepping/AdaptiveTimeStepping.hpp +++ b/opm/simulators/timestepping/AdaptiveTimeStepping.hpp @@ -249,6 +249,7 @@ std::set consistentlyFailingWells(const std::vector& sr //! \brief contructor taking parameter object AdaptiveTimeStepping(const UnitSystem& unitSystem, + const double max_next_tstep = -1.0, const bool terminalOutput = true) : timeStepControl_() , restartFactor_(EWOMS_GET_PARAM(TypeTag, double, SolverRestartFactor)) // 0.33 @@ -260,7 +261,7 @@ std::set consistentlyFailingWells(const std::vector& sr , solverRestartMax_(EWOMS_GET_PARAM(TypeTag, int, SolverMaxRestarts)) // 10 , solverVerbose_(EWOMS_GET_PARAM(TypeTag, int, SolverVerbosity) > 0 && terminalOutput) // 2 , timestepVerbose_(EWOMS_GET_PARAM(TypeTag, int, TimeStepVerbosity) > 0 && terminalOutput) // 2 - , suggestedNextTimestep_(EWOMS_GET_PARAM(TypeTag, double, InitialTimeStepInDays)*24*60*60) // 1.0 + , suggestedNextTimestep_((max_next_tstep <= 0 ? EWOMS_GET_PARAM(TypeTag, double, InitialTimeStepInDays) : max_next_tstep)*24*60*60) // 1.0 , fullTimestepInitially_(EWOMS_GET_PARAM(TypeTag, bool, FullTimeStepInitially)) // false , timestepAfterEvent_(EWOMS_GET_PARAM(TypeTag, double, TimeStepAfterEventInDays)*24*60*60) // 1e30 , useNewtonIteration_(false) @@ -289,7 +290,7 @@ std::set consistentlyFailingWells(const std::vector& sr , solverRestartMax_(EWOMS_GET_PARAM(TypeTag, int, SolverMaxRestarts)) // 10 , solverVerbose_(EWOMS_GET_PARAM(TypeTag, int, SolverVerbosity) > 0 && terminalOutput) // 2 , timestepVerbose_(EWOMS_GET_PARAM(TypeTag, int, TimeStepVerbosity) > 0 && terminalOutput) // 2 - , suggestedNextTimestep_(max_next_tstep <= 0 ? EWOMS_GET_PARAM(TypeTag, double, InitialTimeStepInDays)*86400 : max_next_tstep) // 1.0 + , suggestedNextTimestep_(max_next_tstep <= 0 ? EWOMS_GET_PARAM(TypeTag, double, InitialTimeStepInDays)*24*60*60 : max_next_tstep) // 1.0 , fullTimestepInitially_(EWOMS_GET_PARAM(TypeTag, bool, FullTimeStepInitially)) // false , timestepAfterEvent_(tuning.TMAXWC) // 1e30 , useNewtonIteration_(false) @@ -625,11 +626,16 @@ std::set consistentlyFailingWells(const std::vector& sr growthFactor_ = tuning.TFDIFF; maxGrowth_ = tuning.TSFMAX; maxTimeStep_ = tuning.TSMAXZ; + updateNEXTSTEP(max_next_tstep); + timestepAfterEvent_ = tuning.TMAXWC; + } + + void updateNEXTSTEP(double max_next_tstep) + { // \Note Only update next suggested step if TSINIT was explicitly set in TUNING or NEXTSTEP is active. if (max_next_tstep > 0) { suggestedNextTimestep_ = max_next_tstep; } - timestepAfterEvent_ = tuning.TMAXWC; } template