Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions flowexperimental/comp/wells/CompWellModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ class CompWellModel : WellConnectionAuxiliaryModule<TypeTag, CompWellModel<TypeT
void beginTimeStep();
void beginIteration();

// FlowProblem calls these lifecycle hooks for well models.
// Compositional wells currently keep no extra timestep snapshot state.
void updateFailed() {}
void advanceTimeLevel() {}

void init();
void endIteration() const {}
void endTimeStep() {}
Expand Down
4 changes: 2 additions & 2 deletions opm/simulators/flow/BlackoilModel_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ 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();
simulator_.problem().advanceTimeLevel();
}

// Set the timestep size and episode index for the model explicitly.
Expand Down
12 changes: 12 additions & 0 deletions opm/simulators/flow/FlowProblem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,18 @@ class FlowProblem : public GetPropType<TypeTag, Properties::BaseProblem>

}

void updateFailed()
{
wellModel_.updateFailed();
this->model().updateFailed();
}

void advanceTimeLevel()
{
this->model().advanceTimeLevel();
wellModel_.advanceTimeLevel();
}

/*!
* \brief Called by the simulator before each Newton-Raphson iteration.
*/
Expand Down
4 changes: 4 additions & 0 deletions opm/simulators/wells/BlackoilWellModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ template<class Scalar> class WellContributions;

void beginTimeStep();

void updateFailed();

void advanceTimeLevel();

void beginIteration()
{
OPM_TIMEBLOCK(beginIteration);
Expand Down
3 changes: 3 additions & 0 deletions opm/simulators/wells/BlackoilWellModelGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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_
Expand Down
21 changes: 21 additions & 0 deletions opm/simulators/wells/BlackoilWellModelGeneric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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_);
Expand Down Expand Up @@ -550,6 +569,7 @@ class BlackoilWellModelGeneric
std::vector<int> pvt_region_idx_;

mutable std::unordered_set<std::string> closed_this_step_;
std::unordered_set<std::string> prev_timestep_closed_this_step_;

GuideRate guideRate_;
std::unique_ptr<VFPProperties<Scalar, IndexTraits>> vfp_properties_{};
Expand All @@ -568,6 +588,7 @@ class BlackoilWellModelGeneric
*/
WGState<Scalar, IndexTraits> active_wgstate_;
WGState<Scalar, IndexTraits> last_valid_wgstate_;
WGState<Scalar, IndexTraits> prev_timestep_wgstate_;
WGState<Scalar, IndexTraits> nupcol_wgstate_;
GroupStateHelperType group_state_helper_;
WellGroupEvents report_step_start_events_; //!< Well group events at start of report step
Expand Down
16 changes: 16 additions & 0 deletions opm/simulators/wells/BlackoilWellModel_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,22 @@ namespace Opm {

}

template<typename TypeTag>
void
BlackoilWellModel<TypeTag>::
updateFailed()
{
this->BlackoilWellModelGeneric<Scalar, IndexTraits>::updateFailed();
}

template<typename TypeTag>
void
BlackoilWellModel<TypeTag>::
advanceTimeLevel()
{
this->BlackoilWellModelGeneric<Scalar, IndexTraits>::advanceTimeLevel();
}

#ifdef RESERVOIR_COUPLING_ENABLED
// Automatically manages the lifecycle of the DeferredLogger pointer
// in the reservoir coupling logger. Ensures the logger is properly
Expand Down