From 54e049620315ec5ac768b74b7e2b5c55302ff62e Mon Sep 17 00:00:00 2001 From: Tor Harald Sandve Date: Thu, 29 Sep 2022 09:22:56 +0200 Subject: [PATCH] check group constraints from top --- opm/simulators/wells/BlackoilWellModel.hpp | 5 ++ .../wells/BlackoilWellModelGeneric.cpp | 38 --------------- .../wells/BlackoilWellModelGeneric.hpp | 7 --- .../wells/BlackoilWellModel_impl.hpp | 48 ++++++++++++++----- 4 files changed, 40 insertions(+), 58 deletions(-) diff --git a/opm/simulators/wells/BlackoilWellModel.hpp b/opm/simulators/wells/BlackoilWellModel.hpp index 15bc0ab7d..cc0c4dc78 100644 --- a/opm/simulators/wells/BlackoilWellModel.hpp +++ b/opm/simulators/wells/BlackoilWellModel.hpp @@ -288,6 +288,11 @@ namespace Opm { const int iterationIdx, DeferredLogger& deferred_logger); + bool updateGroupControls(const Group& group, + DeferredLogger& deferred_logger, + const int reportStepIdx, + const int iterationIdx); + WellInterfacePtr getWell(const std::string& well_name) const; bool hasWell(const std::string& well_name) const; diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.cpp b/opm/simulators/wells/BlackoilWellModelGeneric.cpp index eefc88b1d..3ae39fc64 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.cpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.cpp @@ -1270,12 +1270,6 @@ checkGroupHigherConstraints(const Group& group, } - // call recursively down the group hiearchy - for (const std::string& groupName : group.groups()) { - bool changed_this = checkGroupHigherConstraints( schedule().getGroup(groupName, reportStepIdx), deferred_logger, reportStepIdx); - changed = changed || changed_this; - } - return changed; } @@ -1315,41 +1309,9 @@ updateGroupIndividualControl(const Group& group, } } - // call recursively down the group hiearchy - for (const std::string& groupName : group.groups()) { - bool changed_this = updateGroupIndividualControl( schedule().getGroup(groupName, reportStepIdx), deferred_logger, reportStepIdx); - changed = changed || changed_this; - } - return changed; } -bool -BlackoilWellModelGeneric:: -updateGroupIndividualControls(DeferredLogger& deferred_logger, - const int reportStepIdx, - const int iterationIdx) -{ - const int nupcol = schedule()[reportStepIdx].nupcol(); - // don't switch group control when iterationIdx > nupcol - // to avoid oscilations between group controls - if (iterationIdx > nupcol) - return false; - - const Group& fieldGroup = schedule().getGroup("FIELD", reportStepIdx); - return updateGroupIndividualControl(fieldGroup, deferred_logger, - reportStepIdx); -} - -bool -BlackoilWellModelGeneric:: -updateGroupHigherControls(DeferredLogger& deferred_logger, - const int reportStepIdx) -{ - const Group& fieldGroup = schedule().getGroup("FIELD", reportStepIdx); - return checkGroupHigherConstraints(fieldGroup, deferred_logger, reportStepIdx); -} - void BlackoilWellModelGeneric:: actionOnBrokenConstraints(const Group& group, diff --git a/opm/simulators/wells/BlackoilWellModelGeneric.hpp b/opm/simulators/wells/BlackoilWellModelGeneric.hpp index 56433b863..f9b3685a7 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.hpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.hpp @@ -343,13 +343,6 @@ protected: DeferredLogger& deferred_logger, const int reportStepIdx); - bool updateGroupIndividualControls(DeferredLogger& deferred_logger, - const int reportStepIdx, - const int iterationIdx); - - bool updateGroupHigherControls(DeferredLogger& deferred_logger, - const int reportStepIdx); - void actionOnBrokenConstraints(const Group& group, const Group::ExceedAction& exceed_action, const Group::ProductionCMode& newControl, diff --git a/opm/simulators/wells/BlackoilWellModel_impl.hpp b/opm/simulators/wells/BlackoilWellModel_impl.hpp index 5034b28eb..bdc78597e 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -1452,20 +1452,15 @@ namespace Opm { std::set switched_wells; if (checkGroupControls) { + // Check group individual constraints. - bool changed_individual = updateGroupIndividualControls(deferred_logger, - episodeIdx, iterationIdx); - - if (changed_individual) - updateAndCommunicate(episodeIdx, iterationIdx, deferred_logger); - - // Check group's constraints from higher levels. - bool changed_higher = updateGroupHigherControls(deferred_logger, - episodeIdx); - - if (changed_higher) - updateAndCommunicate(episodeIdx, iterationIdx, deferred_logger); - + const int nupcol = schedule()[episodeIdx].nupcol(); + // don't switch group control when iterationIdx > nupcol + // to avoid oscilations between group controls + if (iterationIdx <= nupcol) { + const Group& fieldGroup = schedule().getGroup("FIELD", episodeIdx); + updateGroupControls(fieldGroup, deferred_logger, episodeIdx, iterationIdx); + } // Check wells' group constraints and communicate. bool changed_well_group = false; for (const auto& well : well_container_) { @@ -1518,6 +1513,33 @@ namespace Opm { updateAndCommunicateGroupData(reportStepIdx, iterationIdx); } + template + bool + BlackoilWellModel:: + updateGroupControls(const Group& group, + DeferredLogger& deferred_logger, + const int reportStepIdx, + const int iterationIdx) + { + bool changed = false; + bool changed_hc = checkGroupHigherConstraints( group, deferred_logger, reportStepIdx); + if (changed_hc) { + changed = true; + updateAndCommunicate(reportStepIdx, iterationIdx, deferred_logger); + } + bool changed_individual = updateGroupIndividualControl( group, deferred_logger, reportStepIdx); + if (changed_individual) { + changed = true; + updateAndCommunicate(reportStepIdx, iterationIdx, deferred_logger); + } + // call recursively down the group hierarchy + for (const std::string& groupName : group.groups()) { + bool changed_this = updateGroupControls( schedule().getGroup(groupName, reportStepIdx), deferred_logger, reportStepIdx,iterationIdx); + changed = changed || changed_this; + } + return changed; + } + template void BlackoilWellModel::