Merge pull request #4033 from totto82/fix_grsw_output

cleanup group switching output to terminal
This commit is contained in:
Tor Harald Sandve 2022-09-13 12:25:40 +02:00 committed by GitHub
commit f8d1d040ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 99 additions and 75 deletions

View File

@ -1172,8 +1172,7 @@ bool
BlackoilWellModelGeneric:: BlackoilWellModelGeneric::
checkGroupHigherConstraints(const Group& group, checkGroupHigherConstraints(const Group& group,
DeferredLogger& deferred_logger, DeferredLogger& deferred_logger,
const int reportStepIdx, const int reportStepIdx)
std::set<std::string>& switched_groups)
{ {
// Set up coefficients for RESV <-> surface rate conversion. // Set up coefficients for RESV <-> surface rate conversion.
// Use the pvtRegionIdx from the top cell of the first well. // Use the pvtRegionIdx from the top cell of the first well.
@ -1203,9 +1202,8 @@ checkGroupHigherConstraints(const Group& group,
std::vector<double> rates(phase_usage_.num_phases, 0.0); std::vector<double> rates(phase_usage_.num_phases, 0.0);
const bool skip = switched_groups.count(group.name()) || group.name() == "FIELD"; bool isField = group.name() == "FIELD";
if (!isField && group.isInjectionGroup()) {
if (!skip && group.isInjectionGroup()) {
// Obtain rates for group. // Obtain rates for group.
std::vector<double> resv_coeff_inj(phase_usage_.num_phases, 0.0); std::vector<double> resv_coeff_inj(phase_usage_.num_phases, 0.0);
calcInjRates(fipnum, pvtreg, resv_coeff_inj); calcInjRates(fipnum, pvtreg, resv_coeff_inj);
@ -1221,33 +1219,33 @@ checkGroupHigherConstraints(const Group& group,
auto currentControl = this->groupState().injection_control(group.name(), phase); auto currentControl = this->groupState().injection_control(group.name(), phase);
if (currentControl != Group::InjectionCMode::FLD && group.injectionGroupControlAvailable(phase)) { if (currentControl != Group::InjectionCMode::FLD && group.injectionGroupControlAvailable(phase)) {
const Group& parentGroup = schedule().getGroup(group.parent(), reportStepIdx); const Group& parentGroup = schedule().getGroup(group.parent(), reportStepIdx);
const std::pair<bool, double> changed_this = WellGroupHelpers::checkGroupConstraintsInj( const auto [is_changed, scaling_factor] = WellGroupHelpers::checkGroupConstraintsInj(
group.name(), group.name(),
group.parent(), group.parent(),
parentGroup, parentGroup,
this->wellState(), this->wellState(),
this->groupState(), this->groupState(),
reportStepIdx, reportStepIdx,
&guideRate_, &guideRate_,
rates.data(), rates.data(),
phase, phase,
phase_usage_, phase_usage_,
group.getGroupEfficiencyFactor(), group.getGroupEfficiencyFactor(),
schedule(), schedule(),
summaryState_, summaryState_,
resv_coeff_inj, resv_coeff_inj,
deferred_logger); deferred_logger);
if (changed_this.first) { if (is_changed) {
switched_groups.insert(group.name()); switched_inj_groups_.insert({ {group.name(), phase}, Group::InjectionCMode2String(Group::InjectionCMode::FLD)});
actionOnBrokenConstraints(group, Group::InjectionCMode::FLD, phase, deferred_logger); actionOnBrokenConstraints(group, Group::InjectionCMode::FLD, phase, deferred_logger);
WellGroupHelpers::updateWellRatesFromGroupTargetScale(changed_this.second, group, schedule(), reportStepIdx, /* isInjector */ true, this->groupState(), this->wellState()); WellGroupHelpers::updateWellRatesFromGroupTargetScale(scaling_factor, group, schedule(), reportStepIdx, /* isInjector */ true, this->groupState(), this->wellState());
changed = true; changed = true;
} }
} }
} }
} }
if (!skip && group.isProductionGroup()) { if (!isField && group.isProductionGroup()) {
// Obtain rates for group. // Obtain rates for group.
for (int phasePos = 0; phasePos < phase_usage_.num_phases; ++phasePos) { for (int phasePos = 0; phasePos < phase_usage_.num_phases; ++phasePos) {
const double local_current_rate = WellGroupHelpers::sumWellSurfaceRates(group, schedule(), this->wellState(), reportStepIdx, phasePos, /* isInjector */ false); const double local_current_rate = WellGroupHelpers::sumWellSurfaceRates(group, schedule(), this->wellState(), reportStepIdx, phasePos, /* isInjector */ false);
@ -1258,36 +1256,37 @@ checkGroupHigherConstraints(const Group& group,
calcRates(fipnum, pvtreg, resv_coeff); calcRates(fipnum, pvtreg, resv_coeff);
// Check higher up only if under individual (not FLD) control. // Check higher up only if under individual (not FLD) control.
const Group::ProductionCMode& currentControl = this->groupState().production_control(group.name()); const Group::ProductionCMode& currentControl = this->groupState().production_control(group.name());
if (currentControl != Group::ProductionCMode::FLD && group.productionGroupControlAvailable()) { if (currentControl != Group::ProductionCMode::FLD && group.productionGroupControlAvailable()) {
const Group& parentGroup = schedule().getGroup(group.parent(), reportStepIdx); const Group& parentGroup = schedule().getGroup(group.parent(), reportStepIdx);
const std::pair<bool, double> changed_this = WellGroupHelpers::checkGroupConstraintsProd( const auto [is_changed, scaling_factor] = WellGroupHelpers::checkGroupConstraintsProd(
group.name(), group.name(),
group.parent(), group.parent(),
parentGroup, parentGroup,
this->wellState(), this->wellState(),
this->groupState(), this->groupState(),
reportStepIdx, reportStepIdx,
&guideRate_, &guideRate_,
rates.data(), rates.data(),
phase_usage_, phase_usage_,
group.getGroupEfficiencyFactor(), group.getGroupEfficiencyFactor(),
schedule(), schedule(),
summaryState_, summaryState_,
resv_coeff, resv_coeff,
deferred_logger); deferred_logger);
if (changed_this.first) { if (is_changed) {
switched_groups.insert(group.name()); switched_prod_groups_.insert({group.name(), Group::ProductionCMode2String(Group::ProductionCMode::FLD)});
const auto exceed_action = group.productionControls(summaryState_).exceed_action; const auto exceed_action = group.productionControls(summaryState_).exceed_action;
actionOnBrokenConstraints(group, exceed_action, Group::ProductionCMode::FLD, deferred_logger); actionOnBrokenConstraints(group, exceed_action, Group::ProductionCMode::FLD, deferred_logger);
WellGroupHelpers::updateWellRatesFromGroupTargetScale(changed_this.second, group, schedule(), reportStepIdx, /* isInjector */ false, this->groupState(), this->wellState()); WellGroupHelpers::updateWellRatesFromGroupTargetScale(scaling_factor, group, schedule(), reportStepIdx, /* isInjector */ false, this->groupState(), this->wellState());
changed = true; changed = true;
}
} }
}
} }
// call recursively down the group hiearchy // call recursively down the group hiearchy
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
bool changed_this = checkGroupHigherConstraints( schedule().getGroup(groupName, reportStepIdx), deferred_logger, reportStepIdx, switched_groups); bool changed_this = checkGroupHigherConstraints( schedule().getGroup(groupName, reportStepIdx), deferred_logger, reportStepIdx);
changed = changed || changed_this; changed = changed || changed_this;
} }
@ -1298,12 +1297,10 @@ bool
BlackoilWellModelGeneric:: BlackoilWellModelGeneric::
updateGroupIndividualControl(const Group& group, updateGroupIndividualControl(const Group& group,
DeferredLogger& deferred_logger, DeferredLogger& deferred_logger,
const int reportStepIdx, const int reportStepIdx)
std::set<std::string>& switched_groups)
{ {
bool changed = false; bool changed = false;
const bool skip = switched_groups.count(group.name()); if (group.isInjectionGroup())
if (!skip && group.isInjectionGroup())
{ {
const Phase all[] = {Phase::WATER, Phase::OIL, Phase::GAS}; const Phase all[] = {Phase::WATER, Phase::OIL, Phase::GAS};
for (Phase phase : all) { for (Phase phase : all) {
@ -1313,19 +1310,19 @@ updateGroupIndividualControl(const Group& group,
const auto& changed_this = checkGroupInjectionConstraints(group, reportStepIdx, phase); const auto& changed_this = checkGroupInjectionConstraints(group, reportStepIdx, phase);
if (changed_this.first != Group::InjectionCMode::NONE) if (changed_this.first != Group::InjectionCMode::NONE)
{ {
switched_groups.insert(group.name()); switched_inj_groups_.insert({{group.name(), phase}, Group::InjectionCMode2String(changed_this.first)});
actionOnBrokenConstraints(group, changed_this.first, phase, deferred_logger); actionOnBrokenConstraints(group, changed_this.first, phase, deferred_logger);
WellGroupHelpers::updateWellRatesFromGroupTargetScale(changed_this.second, group, schedule(), reportStepIdx, /* isInjector */ false, this->groupState(), this->wellState()); WellGroupHelpers::updateWellRatesFromGroupTargetScale(changed_this.second, group, schedule(), reportStepIdx, /* isInjector */ false, this->groupState(), this->wellState());
changed = true; changed = true;
} }
} }
} }
if (!skip && group.isProductionGroup()) { if (group.isProductionGroup()) {
const auto& changed_this = checkGroupProductionConstraints(group, reportStepIdx, deferred_logger); const auto& changed_this = checkGroupProductionConstraints(group, reportStepIdx, deferred_logger);
const auto controls = group.productionControls(summaryState_); const auto controls = group.productionControls(summaryState_);
if (changed_this.first != Group::ProductionCMode::NONE) if (changed_this.first != Group::ProductionCMode::NONE)
{ {
switched_groups.insert(group.name()); switched_prod_groups_.insert({group.name(), Group::ProductionCMode2String(changed_this.first)});
actionOnBrokenConstraints(group, controls.exceed_action, changed_this.first, deferred_logger); actionOnBrokenConstraints(group, controls.exceed_action, changed_this.first, deferred_logger);
WellGroupHelpers::updateWellRatesFromGroupTargetScale(changed_this.second, group, schedule(), reportStepIdx, /* isInjector */ false, this->groupState(), this->wellState()); WellGroupHelpers::updateWellRatesFromGroupTargetScale(changed_this.second, group, schedule(), reportStepIdx, /* isInjector */ false, this->groupState(), this->wellState());
changed = true; changed = true;
@ -1334,7 +1331,7 @@ updateGroupIndividualControl(const Group& group,
// call recursively down the group hiearchy // call recursively down the group hiearchy
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
bool changed_this = updateGroupIndividualControl( schedule().getGroup(groupName, reportStepIdx), deferred_logger, reportStepIdx, switched_groups); bool changed_this = updateGroupIndividualControl( schedule().getGroup(groupName, reportStepIdx), deferred_logger, reportStepIdx);
changed = changed || changed_this; changed = changed || changed_this;
} }
@ -1344,7 +1341,6 @@ updateGroupIndividualControl(const Group& group,
bool bool
BlackoilWellModelGeneric:: BlackoilWellModelGeneric::
updateGroupIndividualControls(DeferredLogger& deferred_logger, updateGroupIndividualControls(DeferredLogger& deferred_logger,
std::set<std::string>& switched_groups,
const int reportStepIdx, const int reportStepIdx,
const int iterationIdx) const int iterationIdx)
{ {
@ -1356,17 +1352,16 @@ updateGroupIndividualControls(DeferredLogger& deferred_logger,
const Group& fieldGroup = schedule().getGroup("FIELD", reportStepIdx); const Group& fieldGroup = schedule().getGroup("FIELD", reportStepIdx);
return updateGroupIndividualControl(fieldGroup, deferred_logger, return updateGroupIndividualControl(fieldGroup, deferred_logger,
reportStepIdx, switched_groups); reportStepIdx);
} }
bool bool
BlackoilWellModelGeneric:: BlackoilWellModelGeneric::
updateGroupHigherControls(DeferredLogger& deferred_logger, updateGroupHigherControls(DeferredLogger& deferred_logger,
const int reportStepIdx, const int reportStepIdx)
std::set<std::string>& switched_groups)
{ {
const Group& fieldGroup = schedule().getGroup("FIELD", reportStepIdx); const Group& fieldGroup = schedule().getGroup("FIELD", reportStepIdx);
return checkGroupHigherConstraints(fieldGroup, deferred_logger, reportStepIdx, switched_groups); return checkGroupHigherConstraints(fieldGroup, deferred_logger, reportStepIdx);
} }
void void
@ -1418,7 +1413,7 @@ actionOnBrokenConstraints(const Group& group,
Parallel::Communication cc = comm_; Parallel::Communication cc = comm_;
if (!ss.str().empty() && cc.rank() == 0) if (!ss.str().empty() && cc.rank() == 0)
deferred_logger.info(ss.str()); deferred_logger.debug(ss.str());
} }
void void

View File

@ -340,22 +340,18 @@ protected:
bool checkGroupHigherConstraints(const Group& group, bool checkGroupHigherConstraints(const Group& group,
DeferredLogger& deferred_logger, DeferredLogger& deferred_logger,
const int reportStepIdx, const int reportStepIdx);
std::set<std::string>& switched_groups);
bool updateGroupIndividualControl(const Group& group, bool updateGroupIndividualControl(const Group& group,
DeferredLogger& deferred_logger, DeferredLogger& deferred_logger,
const int reportStepIdx, const int reportStepIdx);
std::set<std::string>& switched_groups);
bool updateGroupIndividualControls(DeferredLogger& deferred_logger, bool updateGroupIndividualControls(DeferredLogger& deferred_logger,
std::set<std::string>& switched_groups,
const int reportStepIdx, const int reportStepIdx,
const int iterationIdx); const int iterationIdx);
bool updateGroupHigherControls(DeferredLogger& deferred_logger, bool updateGroupHigherControls(DeferredLogger& deferred_logger,
const int reportStepIdx, const int reportStepIdx);
std::set<std::string>& switched_groups);
void actionOnBrokenConstraints(const Group& group, void actionOnBrokenConstraints(const Group& group,
const Group::ExceedAction& exceed_action, const Group::ExceedAction& exceed_action,
@ -462,6 +458,10 @@ protected:
double last_glift_opt_time_ = -1.0; double last_glift_opt_time_ = -1.0;
std::map<std::string, std::string> switched_prod_groups_;
std::map<std::pair<std::string, Opm::Phase>, std::string> switched_inj_groups_;
private: private:
WellInterfaceGeneric* getGenWell(const std::string& well_name); WellInterfaceGeneric* getGenWell(const std::string& well_name);
}; };

View File

@ -250,6 +250,8 @@ namespace Opm {
updatePerforationIntensiveQuantities(); updatePerforationIntensiveQuantities();
updateAverageFormationFactor(); updateAverageFormationFactor();
DeferredLogger local_deferredLogger; DeferredLogger local_deferredLogger;
switched_prod_groups_.clear();
switched_inj_groups_.clear();
this->resetWGState(); this->resetWGState();
const int reportStepIdx = ebosSimulator_.episodeIndex(); const int reportStepIdx = ebosSimulator_.episodeIndex();
@ -463,6 +465,35 @@ namespace Opm {
for (const auto& well : well_container_) { for (const auto& well : well_container_) {
well->reportWellSwitching(this->wellState().well(well->indexOfWell()), local_deferredLogger); well->reportWellSwitching(this->wellState().well(well->indexOfWell()), local_deferredLogger);
} }
// report group switching
if (terminal_output_) {
for (const auto& [name, to] : switched_prod_groups_) {
const Group::ProductionCMode& oldControl = this->prevWGState().group_state.production_control(name);
std::string from = Group::ProductionCMode2String(oldControl);
if (to != from) {
std::string msg = " Production Group " + name
+ " control mode changed from ";
msg += from;
msg += " to " + to;
local_deferredLogger.info(msg);
}
}
for (const auto& [key, to] : switched_inj_groups_) {
const std::string& name = key.first;
const Opm::Phase& phase = key.second;
const Group::InjectionCMode& oldControl = this->prevWGState().group_state.injection_control(name, phase);
std::string from = Group::InjectionCMode2String(oldControl);
if (to != from) {
std::string msg = " Injection Group " + name
+ " control mode changed from ";
msg += from;
msg += " to " + to;
local_deferredLogger.info(msg);
}
}
}
// update the rate converter with current averages pressures etc in // update the rate converter with current averages pressures etc in
rateConverter_->template defineState<ElementContext>(ebosSimulator_); rateConverter_->template defineState<ElementContext>(ebosSimulator_);
@ -1424,11 +1455,10 @@ namespace Opm {
updateNetworkPressures(episodeIdx); updateNetworkPressures(episodeIdx);
std::set<std::string> switched_wells; std::set<std::string> switched_wells;
std::set<std::string> switched_groups;
if (checkGroupControls) { if (checkGroupControls) {
// Check group individual constraints. // Check group individual constraints.
bool changed_individual = updateGroupIndividualControls(deferred_logger, switched_groups, bool changed_individual = updateGroupIndividualControls(deferred_logger,
episodeIdx, iterationIdx); episodeIdx, iterationIdx);
if (changed_individual) if (changed_individual)
@ -1436,8 +1466,7 @@ namespace Opm {
// Check group's constraints from higher levels. // Check group's constraints from higher levels.
bool changed_higher = updateGroupHigherControls(deferred_logger, bool changed_higher = updateGroupHigherControls(deferred_logger,
episodeIdx, episodeIdx);
switched_groups);
if (changed_higher) if (changed_higher)
updateAndCommunicate(episodeIdx, iterationIdx, deferred_logger); updateAndCommunicate(episodeIdx, iterationIdx, deferred_logger);