diff --git a/ebos/eclpeacemanwell.hh b/ebos/eclpeacemanwell.hh index 4a2b1dcb8..7248eb356 100644 --- a/ebos/eclpeacemanwell.hh +++ b/ebos/eclpeacemanwell.hh @@ -45,6 +45,7 @@ #include #include +#include namespace Opm { @@ -1449,8 +1450,8 @@ protected: void - updateEclWell(int, const std::string&) { - throw std::logic_error("updateEclWell() method not implemented for class eclpeacemanwell"); + updateEclWells(int, const std::unordered_set&) { + throw std::logic_error("updateEclWells() method not implemented for class eclpeacemanwell"); } diff --git a/ebos/eclproblem.hh b/ebos/eclproblem.hh index 45a2a0b78..07d298127 100644 --- a/ebos/eclproblem.hh +++ b/ebos/eclproblem.hh @@ -1393,14 +1393,10 @@ public: const auto& wellpi = this->fetchWellPI(reportStep, *action, schedule, matching_wells); - schedule.applyAction(reportStep, Opm::TimeService::from_time_t(simTime), *action, actionResult, wellpi); + auto affected_wells = schedule.applyAction(reportStep, Opm::TimeService::from_time_t(simTime), *action, actionResult, wellpi); actionState.add_run(*action, simTime); + this->wellModel_.updateEclWells(reportStep, affected_wells); - for ( const auto& [wname, _] : wellpi) { - (void)_; - if (this->wellModel_.hasWell(wname)) - this->wellModel_.updateEclWell(reportStep, wname); - } } else { std::string msg = "The action: " + action->name() + " evaluated to false at " + ts; Opm::OpmLog::info(msg); diff --git a/ebos/eclwellmanager.hh b/ebos/eclwellmanager.hh index cd7706646..d7999e4ac 100644 --- a/ebos/eclwellmanager.hh +++ b/ebos/eclwellmanager.hh @@ -51,6 +51,7 @@ #include #include +#include #include #include @@ -658,7 +659,7 @@ public: void - updateEclWell(int, const std::string&) { + updateEclWells(int, const std::unordered_set&) { throw std::logic_error("wellPI() method not implemented for class eclwellmanager"); } diff --git a/opm/simulators/wells/BlackoilWellModel.hpp b/opm/simulators/wells/BlackoilWellModel.hpp index 6e05f2779..8ec4adc42 100644 --- a/opm/simulators/wells/BlackoilWellModel.hpp +++ b/opm/simulators/wells/BlackoilWellModel.hpp @@ -365,7 +365,7 @@ namespace Opm { /// Returns true if the well was actually found and shut. bool forceShutWellByNameIfPredictionMode(const std::string& wellname, const double simulation_time); - void updateEclWell(const int timeStepIdx, const std::string& wname); + void updateEclWells(const int timeStepIdx, const std::unordered_set& wells); bool hasWell(const std::string& wname); double wellPI(const int well_index) const; double wellPI(const std::string& well_name) const; diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index 69994bb9c..416d5b65e 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -2628,25 +2628,32 @@ namespace Opm { template void BlackoilWellModel:: - updateEclWell(const int timeStepIdx, const std::string& wname) - { - auto well_iter = std::find_if(this->wells_ecl_.begin(), this->wells_ecl_.end(), - [&wname](const auto& well) -> bool - { - return well.name() == wname; - }); + updateEclWells(const int timeStepIdx, const std::unordered_set& wells) { + const auto& schedule = this->ebosSimulator_.vanguard().schedule(); + for (const auto& wname : wells) { + auto well_iter = std::find_if( this->wells_ecl_.begin(), this->wells_ecl_.end(), [wname] (const auto& well) -> bool { return well.name() == wname;}); + if (well_iter != this->wells_ecl_.end()) { + auto well_index = std::distance( this->wells_ecl_.begin(), well_iter ); + this->wells_ecl_[well_index] = schedule.getWell(wname, timeStepIdx); - if (well_iter == this->wells_ecl_.end()) { - throw std::logic_error { "Could not find well: " + wname }; + const auto& well = this->wells_ecl_[well_index]; + auto& pd = this->well_perf_data_[well_index]; + auto pdIter = pd.begin(); + for (const auto& conn : well.getConnections()) { + if (conn.state() != Connection::State::SHUT) { + pdIter->connection_transmissibility_factor = conn.CF(); + ++pdIter; + } + } + this->wellState().updateStatus(well_index, well.getStatus()); + this->wellState().resetConnectionTransFactors(well_index, pd); + this->prod_index_calc_[well_index].reInit(well); + } } - - auto well_index = std::distance(this->wells_ecl_.begin(), well_iter); - this->updateEclWell(timeStepIdx, well_index); } - template double BlackoilWellModel:: @@ -2753,7 +2760,7 @@ namespace Opm { ++pdIter; } } - this->well_state_.resetConnectionTransFactors(well_index, pd); + this->wellState().resetConnectionTransFactors(well_index, pd); this->prod_index_calc_[well_index].reInit(well); };