From 2b356c0742c5b864bb13315bda8d10619a6f5715 Mon Sep 17 00:00:00 2001 From: hnil Date: Mon, 27 Apr 2026 11:59:37 +0200 Subject: [PATCH 1/4] moving updateFailed to problem --- opm/simulators/flow/BlackoilModel_impl.hpp | 2 +- opm/simulators/flow/FlowProblem.hpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/opm/simulators/flow/BlackoilModel_impl.hpp b/opm/simulators/flow/BlackoilModel_impl.hpp index bf0945a09a0..2e72b367d57 100644 --- a/opm/simulators/flow/BlackoilModel_impl.hpp +++ b/opm/simulators/flow/BlackoilModel_impl.hpp @@ -122,7 +122,7 @@ prepareStep(const SimulatorTimerInterface& timer) "- the previous step succeeded on some ranks but failed on others."); } if (lastStepFailed) { - simulator_.model().updateFailed(); + simulator_.problem().updateFailed(); } else { simulator_.model().advanceTimeLevel(); diff --git a/opm/simulators/flow/FlowProblem.hpp b/opm/simulators/flow/FlowProblem.hpp index 73ff334ffd9..5192c4f07e4 100644 --- a/opm/simulators/flow/FlowProblem.hpp +++ b/opm/simulators/flow/FlowProblem.hpp @@ -392,6 +392,11 @@ class FlowProblem : public GetPropType } + void updateFailed() + { + this->model().updateFailed(); + } + /*! * \brief Called by the simulator before each Newton-Raphson iteration. */ From f089db5a4bbe31fc4ebdb91c52e1a2c2a6850fe6 Mon Sep 17 00:00:00 2001 From: hnil Date: Mon, 27 Apr 2026 12:09:52 +0200 Subject: [PATCH 2/4] also moved advanceTimelevel --- opm/simulators/flow/BlackoilModel_impl.hpp | 2 +- opm/simulators/flow/FlowProblem.hpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/opm/simulators/flow/BlackoilModel_impl.hpp b/opm/simulators/flow/BlackoilModel_impl.hpp index 2e72b367d57..dd0c5680ca4 100644 --- a/opm/simulators/flow/BlackoilModel_impl.hpp +++ b/opm/simulators/flow/BlackoilModel_impl.hpp @@ -125,7 +125,7 @@ prepareStep(const SimulatorTimerInterface& timer) simulator_.problem().updateFailed(); } else { - simulator_.model().advanceTimeLevel(); + simulator_.problem().advanceTimeLevel(); } // Set the timestep size and episode index for the model explicitly. diff --git a/opm/simulators/flow/FlowProblem.hpp b/opm/simulators/flow/FlowProblem.hpp index 5192c4f07e4..2850a0a07f7 100644 --- a/opm/simulators/flow/FlowProblem.hpp +++ b/opm/simulators/flow/FlowProblem.hpp @@ -397,6 +397,11 @@ class FlowProblem : public GetPropType this->model().updateFailed(); } + void advanceTimeLevel() + { + this->model().advanceTimeLevel(); + } + /*! * \brief Called by the simulator before each Newton-Raphson iteration. */ From d3327c5e8f7645bca39f9518e236bbb39213c132 Mon Sep 17 00:00:00 2001 From: hnil Date: Mon, 27 Apr 2026 12:34:16 +0200 Subject: [PATCH 3/4] added start on proper update functions --- opm/simulators/flow/FlowProblem.hpp | 2 ++ opm/simulators/wells/BlackoilWellModel.hpp | 4 ++++ .../wells/BlackoilWellModelGeneric.cpp | 3 +++ .../wells/BlackoilWellModelGeneric.hpp | 21 +++++++++++++++++++ .../wells/BlackoilWellModel_impl.hpp | 16 ++++++++++++++ 5 files changed, 46 insertions(+) diff --git a/opm/simulators/flow/FlowProblem.hpp b/opm/simulators/flow/FlowProblem.hpp index 2850a0a07f7..566ac17e0dc 100644 --- a/opm/simulators/flow/FlowProblem.hpp +++ b/opm/simulators/flow/FlowProblem.hpp @@ -394,12 +394,14 @@ class FlowProblem : public GetPropType void updateFailed() { + wellModel_.updateFailed(); this->model().updateFailed(); } void advanceTimeLevel() { this->model().advanceTimeLevel(); + wellModel_.advanceTimeLevel(); } /*! diff --git a/opm/simulators/wells/BlackoilWellModel.hpp b/opm/simulators/wells/BlackoilWellModel.hpp index f4792403ef7..481f9b4ec51 100644 --- a/opm/simulators/wells/BlackoilWellModel.hpp +++ b/opm/simulators/wells/BlackoilWellModel.hpp @@ -154,6 +154,10 @@ template class WellContributions; void beginTimeStep(); + void updateFailed(); + + void advanceTimeLevel(); + void beginIteration() { OPM_TIMEBLOCK(beginIteration); diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.cpp b/opm/simulators/wells/BlackoilWellModelGeneric.cpp index e4969aad544..5d7d2ccba56 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.cpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.cpp @@ -110,6 +110,7 @@ BlackoilWellModelGeneric(Schedule& schedule, , guideRate_(schedule) , active_wgstate_(pu) , last_valid_wgstate_(pu) + , prev_timestep_wgstate_(pu) , nupcol_wgstate_(pu) , group_state_helper_(this->wellState(), this->groupState(), @@ -1964,10 +1965,12 @@ operator==(const BlackoilWellModelGeneric& rhs) const && this->last_run_wellpi_ == rhs.last_run_wellpi_ && this->local_shut_wells_ == rhs.local_shut_wells_ && this->closed_this_step_ == rhs.closed_this_step_ + && this->prev_timestep_closed_this_step_ == rhs.prev_timestep_closed_this_step_ && this->genNetwork_ == rhs.genNetwork_ && this->prev_inj_multipliers_ == rhs.prev_inj_multipliers_ && this->active_wgstate_ == rhs.active_wgstate_ && this->last_valid_wgstate_ == rhs.last_valid_wgstate_ + && this->prev_timestep_wgstate_ == rhs.prev_timestep_wgstate_ && this->nupcol_wgstate_ == rhs.nupcol_wgstate_ && this->switched_prod_groups_ == rhs.switched_prod_groups_ && this->switched_inj_groups_ == rhs.switched_inj_groups_ diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.hpp b/opm/simulators/wells/BlackoilWellModelGeneric.hpp index b8a0e08c195..a111676ac20 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.hpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.hpp @@ -212,6 +212,23 @@ class BlackoilWellModelGeneric data::GroupAndNetworkValues groupAndNetworkData(const int reportStepIdx) const; + // Snapshot dynamic state at start of timestep for failure recovery. + void advanceTimeLevel() + { + this->prev_timestep_wgstate_ = this->active_wgstate_; + this->prev_timestep_closed_this_step_ = this->closed_this_step_; + this->genNetwork_.commitState(); + } + + // Restore dynamic state captured at the start of the failing timestep. + void updateFailed() + { + this->active_wgstate_ = this->prev_timestep_wgstate_; + this->closed_this_step_ = this->prev_timestep_closed_this_step_; + this->genNetwork_.resetState(); + this->group_state_helper_.updateState(this->wellState(), this->groupState()); + } + /// Shut down any single well /// Returns true if the well was actually found and shut. bool forceShutWellByName(const std::string& wellname, @@ -254,11 +271,13 @@ class BlackoilWellModelGeneric serializer(last_run_wellpi_); serializer(local_shut_wells_); serializer(closed_this_step_); + serializer(prev_timestep_closed_this_step_); serializer(guideRate_); serializer(genNetwork_); serializer(prev_inj_multipliers_); serializer(active_wgstate_); serializer(last_valid_wgstate_); + serializer(prev_timestep_wgstate_); serializer(nupcol_wgstate_); serializer(switched_prod_groups_); serializer(switched_inj_groups_); @@ -550,6 +569,7 @@ class BlackoilWellModelGeneric std::vector pvt_region_idx_; mutable std::unordered_set closed_this_step_; + std::unordered_set prev_timestep_closed_this_step_; GuideRate guideRate_; std::unique_ptr> vfp_properties_{}; @@ -568,6 +588,7 @@ class BlackoilWellModelGeneric */ WGState active_wgstate_; WGState last_valid_wgstate_; + WGState prev_timestep_wgstate_; WGState nupcol_wgstate_; GroupStateHelperType group_state_helper_; WellGroupEvents report_step_start_events_; //!< Well group events at start of report step diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index 46dfdd352cf..bfc77f9cc78 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -569,6 +569,22 @@ namespace Opm { } + template + void + BlackoilWellModel:: + updateFailed() + { + this->BlackoilWellModelGeneric::updateFailed(); + } + + template + void + BlackoilWellModel:: + advanceTimeLevel() + { + this->BlackoilWellModelGeneric::advanceTimeLevel(); + } + #ifdef RESERVOIR_COUPLING_ENABLED // Automatically manages the lifecycle of the DeferredLogger pointer // in the reservoir coupling logger. Ensures the logger is properly From 40dbaf5dd79eacae6ca1d021febc470281c9d0cf Mon Sep 17 00:00:00 2001 From: hnil Date: Mon, 27 Apr 2026 12:36:39 +0200 Subject: [PATCH 4/4] made dummy updates for compositional wells --- flowexperimental/comp/wells/CompWellModel.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/flowexperimental/comp/wells/CompWellModel.hpp b/flowexperimental/comp/wells/CompWellModel.hpp index 52daa76fb5f..dabec5a4866 100644 --- a/flowexperimental/comp/wells/CompWellModel.hpp +++ b/flowexperimental/comp/wells/CompWellModel.hpp @@ -96,6 +96,11 @@ class CompWellModel : WellConnectionAuxiliaryModule