From cc306a45b4adcefef20b5434be5fffceb4d671d0 Mon Sep 17 00:00:00 2001 From: Arne Morten Kvarving Date: Mon, 24 Oct 2022 09:36:05 +0200 Subject: [PATCH] move updateGroupIndividualControl into BlackoilWellModelConstraints --- .../wells/BlackoilWellModelConstraints.cpp | 65 +++++++++++++++++++ .../wells/BlackoilWellModelConstraints.hpp | 34 ++++++---- .../wells/BlackoilWellModelGeneric.cpp | 48 -------------- .../wells/BlackoilWellModelGeneric.hpp | 4 -- .../wells/BlackoilWellModel_impl.hpp | 11 +++- 5 files changed, 97 insertions(+), 65 deletions(-) diff --git a/opm/simulators/wells/BlackoilWellModelConstraints.cpp b/opm/simulators/wells/BlackoilWellModelConstraints.cpp index f13fe3a84..27c00115c 100644 --- a/opm/simulators/wells/BlackoilWellModelConstraints.cpp +++ b/opm/simulators/wells/BlackoilWellModelConstraints.cpp @@ -448,4 +448,69 @@ actionOnBrokenConstraints(const Group& group, deferred_logger.debug(ss.str()); } +bool BlackoilWellModelConstraints:: +updateGroupIndividualControl(const Group& group, + const int reportStepIdx, + std::map,std::string>& switched_inj, + std::map& switched_prod, + GroupState& group_state, + WellState& well_state, + DeferredLogger& deferred_logger) const +{ + bool changed = false; + if (group.isInjectionGroup()) + { + const Phase all[] = {Phase::WATER, Phase::OIL, Phase::GAS}; + for (Phase phase : all) { + if (!group.hasInjectionControl(phase)) { + continue; + } + const auto& changed_this = this->checkGroupInjectionConstraints(group, + reportStepIdx, + phase); + if (changed_this.first != Group::InjectionCMode::NONE) + { + switched_inj.insert({{group.name(), phase}, + Group::InjectionCMode2String(changed_this.first)}); + this->actionOnBrokenConstraints(group, changed_this.first, phase, + group_state, deferred_logger); + WellGroupHelpers::updateWellRatesFromGroupTargetScale(changed_this.second, + group, + wellModel_.schedule(), + reportStepIdx, + /* isInjector */ false, + wellModel_.groupState(), + well_state); + changed = true; + } + } + } + if (group.isProductionGroup()) { + const auto& changed_this = this->checkGroupProductionConstraints(group, + reportStepIdx, + deferred_logger); + const auto controls = group.productionControls(wellModel_.summaryState()); + if (changed_this.first != Group::ProductionCMode::NONE) + { + switched_prod.insert({group.name(), + Group::ProductionCMode2String(changed_this.first)}); + + this->actionOnBrokenConstraints(group, + controls.exceed_action, + changed_this.first, + group_state, deferred_logger); + WellGroupHelpers::updateWellRatesFromGroupTargetScale(changed_this.second, + group, + wellModel_.schedule(), + reportStepIdx, + /* isInjector */ false, + wellModel_.groupState(), + well_state); + changed = true; + } + } + + return changed; +} + } diff --git a/opm/simulators/wells/BlackoilWellModelConstraints.hpp b/opm/simulators/wells/BlackoilWellModelConstraints.hpp index 90b1eb45a..f84948fc0 100644 --- a/opm/simulators/wells/BlackoilWellModelConstraints.hpp +++ b/opm/simulators/wells/BlackoilWellModelConstraints.hpp @@ -33,6 +33,7 @@ class BlackoilWellModelGeneric; class DeferredLogger; class GroupState; class SummaryState; +class WellState; /// Class for handling constraints for the blackoil well model. class BlackoilWellModelConstraints @@ -46,18 +47,6 @@ public: /// Return true if any well has a THP constraint. bool hasTHPConstraints() const; - //! \brief Check and return value and type of constraints for an injection well group. - std::pair - checkGroupInjectionConstraints(const Group& group, - const int reportStepIdx, - const Phase& phase) const; - - //! \brief Check and return value and type of constraints for a production well group. - std::pair - checkGroupProductionConstraints(const Group& group, - const int reportStepIdx, - DeferredLogger& deferred_logger) const; - //! \brief Check the constraints of a well group. bool checkGroupConstraints(const Group& group, const int reportStepIdx, @@ -77,7 +66,28 @@ public: GroupState& group_state, DeferredLogger& deferred_logger) const; + //! \brief Update the individual controls for wells in a group. + bool updateGroupIndividualControl(const Group& group, + const int reportStepIdx, + std::map,std::string>& switched_inj, + std::map& switched_prod, + GroupState& group_state, + WellState& well_state, + DeferredLogger& deferred_logger) const; + private: + //! \brief Check and return value and type of constraints for an injection well group. + std::pair + checkGroupInjectionConstraints(const Group& group, + const int reportStepIdx, + const Phase& phase) const; + + //! \brief Check and return value and type of constraints for a production well group. + std::pair + checkGroupProductionConstraints(const Group& group, + const int reportStepIdx, + DeferredLogger& deferred_logger) const; + const BlackoilWellModelGeneric& wellModel_; //!< Reference to well model }; diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.cpp b/opm/simulators/wells/BlackoilWellModelGeneric.cpp index 12ac3a420..0e588f975 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.cpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.cpp @@ -779,54 +779,6 @@ checkGroupHigherConstraints(const Group& group, return changed; } -bool -BlackoilWellModelGeneric:: -updateGroupIndividualControl(const Group& group, - DeferredLogger& deferred_logger, - const int reportStepIdx) -{ - bool changed = false; - if (group.isInjectionGroup()) - { - const Phase all[] = {Phase::WATER, Phase::OIL, Phase::GAS}; - for (Phase phase : all) { - if (!group.hasInjectionControl(phase)) { - continue; - } - const auto& changed_this = - BlackoilWellModelConstraints(*this). - checkGroupInjectionConstraints(group, reportStepIdx, phase); - if (changed_this.first != Group::InjectionCMode::NONE) - { - switched_inj_groups_.insert({{group.name(), phase}, Group::InjectionCMode2String(changed_this.first)}); - BlackoilWellModelConstraints(*this). - actionOnBrokenConstraints(group, changed_this.first, phase, - this->groupState(), deferred_logger); - WellGroupHelpers::updateWellRatesFromGroupTargetScale(changed_this.second, group, schedule(), reportStepIdx, /* isInjector */ false, this->groupState(), this->wellState()); - changed = true; - } - } - } - if (group.isProductionGroup()) { - const auto& changed_this = - BlackoilWellModelConstraints(*this). - checkGroupProductionConstraints(group, reportStepIdx, deferred_logger); - const auto controls = group.productionControls(summaryState_); - if (changed_this.first != Group::ProductionCMode::NONE) - { - switched_prod_groups_.insert({group.name(), Group::ProductionCMode2String(changed_this.first)}); - BlackoilWellModelConstraints(*this). - actionOnBrokenConstraints(group, controls.exceed_action, - changed_this.first, - this->groupState(), deferred_logger); - WellGroupHelpers::updateWellRatesFromGroupTargetScale(changed_this.second, group, schedule(), reportStepIdx, /* isInjector */ false, this->groupState(), this->wellState()); - changed = true; - } - } - - return changed; -} - void BlackoilWellModelGeneric:: updateEclWells(const int timeStepIdx, diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.hpp b/opm/simulators/wells/BlackoilWellModelGeneric.hpp index b389776bc..e225e33e2 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.hpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.hpp @@ -302,10 +302,6 @@ protected: DeferredLogger& deferred_logger, const int reportStepIdx); - bool updateGroupIndividualControl(const Group& group, - DeferredLogger& deferred_logger, - const int reportStepIdx); - void updateAndCommunicateGroupData(const int reportStepIdx, const int iterationIdx); diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index cf06ab035..1a4ed8feb 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -1576,7 +1577,15 @@ namespace Opm { changed = true; updateAndCommunicate(reportStepIdx, iterationIdx, deferred_logger); } - bool changed_individual = updateGroupIndividualControl( group, deferred_logger, reportStepIdx); + bool changed_individual = + BlackoilWellModelConstraints(*this). + updateGroupIndividualControl(group, + reportStepIdx, + this->switched_inj_groups_, + this->switched_prod_groups_, + this->groupState(), + this->wellState(), + deferred_logger); if (changed_individual) { changed = true; updateAndCommunicate(reportStepIdx, iterationIdx, deferred_logger);