diff --git a/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp b/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp index 963f196a5d..00bd9c9b8b 100644 --- a/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp +++ b/opm/simulators/flow/SimulatorFullyImplicitBlackoil.hpp @@ -425,7 +425,9 @@ public: wmatcher, this->wellModel_().wellOpenTimes(), this->wellModel_().wellCloseTimes(), - [timeStep, &wg_events = schedule[reportStep].wellgroup_events()](const std::string& name) + [timeStep, + &wg_events = this->wellModel_().reportStepStartEvents()] + (const std::string& name) { if (timeStep != 0) { return false; diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.hpp b/opm/simulators/wells/BlackoilWellModelGeneric.hpp index 10eadc94be..761266d2e0 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.hpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.hpp @@ -226,6 +226,7 @@ public: const std::map& wellOpenTimes() const { return well_open_times_; } const std::map& wellCloseTimes() const { return well_close_times_; } + const WellGroupEvents& reportStepStartEvents() const { return report_step_start_events_; } std::vector getCellsForConnections(const Well& well) const; @@ -523,6 +524,7 @@ protected: WGState active_wgstate_; WGState last_valid_wgstate_; WGState nupcol_wgstate_; + WellGroupEvents report_step_start_events_; //!< Well group events at start of report step bool wellStructureChangedDynamically_{false}; diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index 7581950a04..9ecfa9d3fe 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -196,7 +196,7 @@ namespace Opm { DeferredLogger local_deferredLogger{}; this->report_step_starts_ = true; - + this->report_step_start_events_ = this->schedule()[timeStepIdx].wellgroup_events(); this->rateConverter_ = std::make_unique (this->phase_usage_, std::vector(this->local_num_cells_, 0)); @@ -790,12 +790,13 @@ namespace Opm { if (nw > 0) { well_container_.reserve(nw); - const auto& wg_events = this->schedule()[report_step].wellgroup_events(); + const auto& wmatcher = this->schedule().wellMatcher(report_step); + const auto& wcycle = this->schedule()[report_step].wcycle.get(); // First loop and check for status changes. This is necessary // as wcycle needs the updated open/close times. std::for_each(this->wells_ecl_.begin(), this->wells_ecl_.end(), - [this, &wg_events](const auto& well_ecl) + [this, &wg_events = this->report_step_start_events_](const auto& well_ecl) { if (!well_ecl.hasConnections()) { // No connections in this well. Nothing to do. @@ -820,9 +821,6 @@ namespace Opm { } }); - const auto& wmatcher = this->schedule().wellMatcher(report_step); - const auto& wcycle = this->schedule()[report_step].wcycle.get(); - // Grab wcycle states. This needs to run before the schedule gets processed const auto cycle_states = wcycle.wellStatus(this->simulator_.time(), wmatcher, @@ -947,10 +945,11 @@ namespace Opm { } if (!wcycle.empty()) { - auto schedule_open = [&wg_events](const std::string& name) - { - return wg_events.hasEvent(name, ScheduleEvents::REQUEST_OPEN_WELL); - }; + const auto schedule_open = + [&wg_events = this->report_step_start_events_](const std::string& name) + { + return wg_events.hasEvent(name, ScheduleEvents::REQUEST_OPEN_WELL); + }; for (const auto& [wname, wscale] : wcycle.efficiencyScale(this->simulator_.time(), this->simulator_.timeStepSize(), wmatcher,