diff --git a/opm/simulators/wells/BlackoilWellModel.hpp b/opm/simulators/wells/BlackoilWellModel.hpp index 88c842474..d418a5db8 100644 --- a/opm/simulators/wells/BlackoilWellModel.hpp +++ b/opm/simulators/wells/BlackoilWellModel.hpp @@ -289,6 +289,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 19766a1c4..c86615726 100644 --- a/opm/simulators/wells/BlackoilWellModelGeneric.cpp +++ b/opm/simulators/wells/BlackoilWellModelGeneric.cpp @@ -1280,12 +1280,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; } @@ -1325,41 +1319,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 e7cc7e0cf..f1967d5df 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 5c8ad9972..27e7c682f 100644 --- a/opm/simulators/wells/BlackoilWellModel_impl.hpp +++ b/opm/simulators/wells/BlackoilWellModel_impl.hpp @@ -1512,20 +1512,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_) { @@ -1580,6 +1575,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::