From 0ef68b452a101f9b78c6b485e9c6fd71f4343b1d Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Mon, 7 Jun 2021 15:01:10 +0200 Subject: [PATCH] BlackoilWellModel: move runWellPIScaling to generic class --- opm/simulators/wells/BlackoilWellModel.hpp | 12 +-- .../wells/BlackoilWellModelGeneric.cpp | 76 +++++++++++++++++- .../wells/BlackoilWellModelGeneric.hpp | 16 +++- .../wells/BlackoilWellModel_impl.hpp | 79 ------------------- 4 files changed, 93 insertions(+), 90 deletions(-) diff --git a/opm/simulators/wells/BlackoilWellModel.hpp b/opm/simulators/wells/BlackoilWellModel.hpp index abe35ccf2..9432a568f 100644 --- a/opm/simulators/wells/BlackoilWellModel.hpp +++ b/opm/simulators/wells/BlackoilWellModel.hpp @@ -125,7 +125,7 @@ namespace Opm { BlackoilWellModel(Simulator& ebosSimulator); void init(); - void initWellContainer(); + void initWellContainer() override; ///////////// // @@ -279,7 +279,7 @@ namespace Opm { const SummaryState& summaryState); // create the well container - void createWellContainer(const int time_step); + void createWellContainer(const int time_step) override; WellInterfacePtr createWellPointer(const int wellID, @@ -301,8 +301,6 @@ namespace Opm { std::vector depth_{}; bool alternative_well_rate_init_{}; - std::optional last_run_wellpi_{}; - std::unique_ptr rateConverter_{}; SimulatorReportSingle last_report_{}; @@ -348,8 +346,8 @@ namespace Opm { const std::vector& wellPerfEfficiencyFactors() const; - void calculateProductivityIndexValuesShutWells(const int reportStepIdx, DeferredLogger& deferred_logger); - void calculateProductivityIndexValues(DeferredLogger& deferred_logger); + void calculateProductivityIndexValuesShutWells(const int reportStepIdx, DeferredLogger& deferred_logger) override; + void calculateProductivityIndexValues(DeferredLogger& deferred_logger) override; void calculateProductivityIndexValues(const WellInterface* wellPtr, DeferredLogger& deferred_logger); @@ -375,8 +373,6 @@ namespace Opm { const int pvtreg, std::vector& resv_coeff) override; - void runWellPIScaling(const int timeStepIdx, DeferredLogger& local_deferredLogger); - void computeWellTemperature(); private: diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.cpp b/opm/simulators/wells/BlackoilWellModelGeneric.cpp index 5fdb8f67a..9b7b970d2 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.cpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.cpp @@ -45,7 +45,7 @@ namespace Opm { BlackoilWellModelGeneric:: -BlackoilWellModelGeneric(const Schedule& schedule, +BlackoilWellModelGeneric(Schedule& schedule, const SummaryState& summaryState, const EclipseState& eclState, const PhaseUsage& phase_usage, @@ -1764,4 +1764,78 @@ updateWellPotentials(const int reportStepIdx, } +void +BlackoilWellModelGeneric:: +runWellPIScaling(const int timeStepIdx, + DeferredLogger& local_deferredLogger) +{ + if (this->last_run_wellpi_.has_value() && (*this->last_run_wellpi_ == timeStepIdx)) { + // We've already run WELPI scaling for this report step. Most + // common for the very first report step. Don't redo WELPI scaling. + return; + } + + auto hasWellPIEvent = [this, timeStepIdx](const int well_index) -> bool + { + return this->schedule()[timeStepIdx].wellgroup_events() + .hasEvent(this->wells_ecl_[well_index].name(), + ScheduleEvents::Events::WELL_PRODUCTIVITY_INDEX); + }; + + auto updateEclWell = [this, timeStepIdx](const int well_index) -> void + { + const auto& schedule = this->schedule(); + const auto& wname = this->wells_ecl_[well_index].name(); + this->wells_ecl_[well_index] = schedule.getWell(wname, timeStepIdx); + + 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().resetConnectionTransFactors(well_index, pd); + this->prod_index_calc_[well_index].reInit(well); + }; + + + auto rescaleWellPI = + [this, timeStepIdx](const int well_index, + const double newWellPI) -> void + { + const auto& wname = this->wells_ecl_[well_index].name(); + + schedule_.applyWellProdIndexScaling(wname, timeStepIdx, newWellPI); + }; + + // Minimal well setup to compute PI/II values + { + auto saved_previous_wgstate = this->prevWGState(); + this->commitWGState(); + + this->createWellContainer(timeStepIdx); + this->inferLocalShutWells(); + + this->initWellContainer(); + + this->calculateProductivityIndexValues(local_deferredLogger); + this->calculateProductivityIndexValuesShutWells(timeStepIdx, local_deferredLogger); + + this->commitWGState(std::move(saved_previous_wgstate)); + } + + const auto nw = this->numLocalWells(); + for (auto wellID = 0*nw; wellID < nw; ++wellID) { + if (hasWellPIEvent(wellID)) { + rescaleWellPI(wellID, this->wellPI(wellID)); + updateEclWell(wellID); + } + } + + this->last_run_wellpi_ = timeStepIdx; +} + } diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.hpp b/opm/simulators/wells/BlackoilWellModelGeneric.hpp index b2caf5576..a7d209044 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.hpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.hpp @@ -73,7 +73,7 @@ public: using GLiftProdWells = std::map; using GLiftWellStateMap = std::map>; - BlackoilWellModelGeneric(const Schedule& schedule, + BlackoilWellModelGeneric(Schedule& schedule, const SummaryState& summaryState, const EclipseState& eclState, const PhaseUsage& phase_usage, @@ -353,8 +353,18 @@ protected: const SummaryConfig& summaryConfig, DeferredLogger& deferred_logger); + // create the well container + virtual void createWellContainer(const int time_step) = 0; + virtual void initWellContainer() = 0; - const Schedule& schedule_; + virtual void calculateProductivityIndexValuesShutWells(const int reportStepIdx, + DeferredLogger& deferred_logger) = 0; + virtual void calculateProductivityIndexValues(DeferredLogger& deferred_logger) = 0; + + void runWellPIScaling(const int timeStepIdx, + DeferredLogger& local_deferredLogger); + + Schedule& schedule_; const SummaryState& summaryState_; const EclipseState& eclState_; const Comm& comm_; @@ -365,6 +375,8 @@ protected: bool initial_step_{}; bool report_step_starts_{}; + std::optional last_run_wellpi_{}; + std::vector wells_ecl_; std::vector> well_perf_data_; std::function not_on_process_{}; diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index 9aceda4a2..717a75c0a 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -1496,85 +1496,6 @@ namespace Opm { } - template - void - BlackoilWellModel:: - runWellPIScaling(const int timeStepIdx, DeferredLogger& local_deferredLogger) - { - if (this->last_run_wellpi_.has_value() && (*this->last_run_wellpi_ == timeStepIdx)) { - // We've already run WELPI scaling for this report step. Most - // common for the very first report step. Don't redo WELPI scaling. - return; - } - - auto hasWellPIEvent = [this, timeStepIdx](const int well_index) -> bool - { - return this->schedule()[timeStepIdx].wellgroup_events() - .hasEvent(this->wells_ecl_[well_index].name(), - ScheduleEvents::Events::WELL_PRODUCTIVITY_INDEX); - }; - - auto updateEclWell = [this, timeStepIdx](const int well_index) -> void - { - const auto& schedule = this->schedule(); - const auto& wname = this->wells_ecl_[well_index].name(); - this->wells_ecl_[well_index] = schedule.getWell(wname, timeStepIdx); - - 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().resetConnectionTransFactors(well_index, pd); - this->prod_index_calc_[well_index].reInit(well); - }; - - - auto rescaleWellPI = - [this, timeStepIdx](const int well_index, - const double newWellPI) -> void - { - const auto& wname = this->wells_ecl_[well_index].name(); - - auto& schedule = this->ebosSimulator_.vanguard().schedule(); // Mutable - schedule.applyWellProdIndexScaling(wname, timeStepIdx, newWellPI); - }; - - // Minimal well setup to compute PI/II values - { - auto saved_previous_wgstate = this->prevWGState(); - this->commitWGState(); - - this->createWellContainer(timeStepIdx); - this->inferLocalShutWells(); - - this->initWellContainer(); - - this->calculateProductivityIndexValues(local_deferredLogger); - this->calculateProductivityIndexValuesShutWells(timeStepIdx, local_deferredLogger); - - this->commitWGState(std::move(saved_previous_wgstate)); - } - - const auto nw = this->numLocalWells(); - for (auto wellID = 0*nw; wellID < nw; ++wellID) { - if (hasWellPIEvent(wellID)) { - rescaleWellPI(wellID, this->wellPI(wellID)); - updateEclWell(wellID); - } - } - - this->last_run_wellpi_ = timeStepIdx; - } - - - - - template void BlackoilWellModel::