move updateGroupIndividualControl into BlackoilWellModelConstraints

This commit is contained in:
Arne Morten Kvarving
2022-10-24 09:36:05 +02:00
parent e04f20af8e
commit cc306a45b4
5 changed files with 97 additions and 65 deletions

View File

@@ -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::pair<std::string,Opm::Phase>,std::string>& switched_inj,
std::map<std::string, std::string>& 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;
}
}

View File

@@ -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<Group::InjectionCMode, double>
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<Group::ProductionCMode, double>
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::pair<std::string,Opm::Phase>,std::string>& switched_inj,
std::map<std::string, std::string>& 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<Group::InjectionCMode, double>
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<Group::ProductionCMode, double>
checkGroupProductionConstraints(const Group& group,
const int reportStepIdx,
DeferredLogger& deferred_logger) const;
const BlackoilWellModelGeneric& wellModel_; //!< Reference to well model
};

View File

@@ -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,

View File

@@ -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);

View File

@@ -25,6 +25,7 @@
#include <opm/grid/utility/cartesianToCompressed.hpp>
#include <opm/input/eclipse/Units/UnitSystem.hpp>
#include <opm/simulators/wells/BlackoilWellModelConstraints.hpp>
#include <opm/simulators/wells/VFPProperties.hpp>
#include <opm/simulators/utils/MPIPacker.hpp>
#include <opm/simulators/linalg/bda/WellContributions.hpp>
@@ -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);