From f52398a32e3d585cc6c56772be34c3e4ffd00a97 Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Fri, 7 May 2021 11:21:58 +0200 Subject: [PATCH] Use WellContainer to manage per well events --- .../wells/BlackoilWellModel_impl.hpp | 12 +++++------ .../wells/WellStateFullyImplicitBlackoil.hpp | 21 ++++++++++++++----- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index 55d268503..704b9bb6d 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -813,14 +813,14 @@ namespace Opm { if (this->wellTestState_.hasWellClosed(well_name)) { // TODO: more checking here, to make sure this standard more specific and complete // maybe there is some WCON keywords will not open the well - auto& events = this->wellState().events(); - if (events.hasEvent(well_name, WellStateFullyImplicitBlackoil::event_mask)) { + auto& events = this->wellState().events(w); + if (events.hasEvent(WellStateFullyImplicitBlackoil::event_mask)) { if (wellTestState_.lastTestTime(well_name) == ebosSimulator_.time()) { // The well was shut this timestep, we are most likely retrying // a timestep without the well in question, after it caused // repeated timestep cuts. It should therefore not be opened, // even if it was new or received new targets this report step. - events.clearEvent(well_name, WellStateFullyImplicitBlackoil::event_mask); + events.clearEvent(WellStateFullyImplicitBlackoil::event_mask); } else { wellTestState_.openWell(well_name); } @@ -1687,12 +1687,12 @@ namespace Opm { const int w = well->indexOfWell(); if (!well->isOperable() ) continue; - auto& events = this->wellState().events(); - if (events.hasEvent(well->name(), WellStateFullyImplicitBlackoil::event_mask)) { + auto& events = this->wellState().events(w); + if (events.hasEvent(WellStateFullyImplicitBlackoil::event_mask)) { well->updateWellStateWithTarget(ebosSimulator_, this->wellState(), deferred_logger); // There is no new well control change input within a report step, // so next time step, the well does not consider to have effective events anymore. - events.clearEvent(well->name(), WellStateFullyImplicitBlackoil::event_mask); + events.clearEvent(WellStateFullyImplicitBlackoil::event_mask); } } updatePrimaryVariables(deferred_logger); diff --git a/opm/simulators/wells/WellStateFullyImplicitBlackoil.hpp b/opm/simulators/wells/WellStateFullyImplicitBlackoil.hpp index 66fe3767a..34faff6dd 100644 --- a/opm/simulators/wells/WellStateFullyImplicitBlackoil.hpp +++ b/opm/simulators/wells/WellStateFullyImplicitBlackoil.hpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -115,7 +116,17 @@ namespace Opm well_dissolved_gas_rates_.resize(nw, 0.0); well_vaporized_oil_rates_.resize(nw, 0.0); - this->events_ = schedule[report_step].wellgroup_events(); + this->events_.clear(); + { + const auto& wg_events = schedule[report_step].wellgroup_events(); + for (const auto& ecl_well : wells_ecl) { + const auto& wname = ecl_well.name(); + if (wg_events.has(wname)) + this->events_.add( wname, wg_events.at(wname) ); + else + this->events_.add( wname, Events() ); + } + } // Ensure that we start out with zero rates by default. perfphaserates_.clear(); perfphaserates_.resize(nperf * this->numPhases(), 0.0); @@ -230,7 +241,7 @@ namespace Opm thp()[ newIndex ] = prevState->thp()[ oldIndex ]; // If new target is set using WCONPROD, WCONINJE etc. we use the new control - if (!this->events_.hasEvent(well.name(), WellStateFullyImplicitBlackoil::event_mask)) { + if (!this->events_[w].hasEvent(WellStateFullyImplicitBlackoil::event_mask)) { current_injection_controls_[ newIndex ] = prevState->currentInjectionControls()[ oldIndex ]; current_production_controls_[ newIndex ] = prevState->currentProductionControls()[ oldIndex ]; } @@ -789,8 +800,8 @@ namespace Opm } - WellGroupEvents& events() { - return this->events_; + Events& events(std::size_t well_index) { + return this->events_[well_index]; } const std::vector& firstPerfIndex() const @@ -1175,7 +1186,7 @@ namespace Opm // some events happens to the well, like this well is a new well // or new well control keywords happens // \Note: for now, only WCON* keywords, and well status change is considered - WellGroupEvents events_; + WellContainer events_; // MS well related // for StandardWell, the number of segments will be one