WellGroupHelpers: drop indent for namespace

This commit is contained in:
Arne Morten Kvarving 2024-04-19 10:59:53 +02:00
parent cff4e4b514
commit d6fc7cc4f6
2 changed files with 1656 additions and 1666 deletions

View File

@ -124,20 +124,14 @@ namespace {
} }
} // namespace Anonymous } // namespace Anonymous
namespace Opm namespace Opm::WellGroupHelpers {
{
void setCmodeGroup(const Group& group,
namespace WellGroupHelpers
{
void setCmodeGroup(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const SummaryState& summaryState, const SummaryState& summaryState,
const int reportStepIdx, const int reportStepIdx,
GroupState<double>& group_state) GroupState<double>& group_state)
{ {
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
setCmodeGroup(schedule.getGroup(groupName, reportStepIdx), setCmodeGroup(schedule.getGroup(groupName, reportStepIdx),
@ -188,46 +182,46 @@ namespace WellGroupHelpers
if (schedule[reportStepIdx].gconsale().has(group.name())) { if (schedule[reportStepIdx].gconsale().has(group.name())) {
group_state.injection_control(group.name(), Phase::GAS, Group::InjectionCMode::SALE); group_state.injection_control(group.name(), Phase::GAS, Group::InjectionCMode::SALE);
} }
} }
void accumulateGroupEfficiencyFactor(const Group& group, void accumulateGroupEfficiencyFactor(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
double& factor) double& factor)
{ {
factor *= group.getGroupEfficiencyFactor(); factor *= group.getGroupEfficiencyFactor();
if (group.parent() != "FIELD" && !group.parent().empty()) if (group.parent() != "FIELD" && !group.parent().empty())
accumulateGroupEfficiencyFactor( accumulateGroupEfficiencyFactor(
schedule.getGroup(group.parent(), reportStepIdx), schedule, reportStepIdx, factor); schedule.getGroup(group.parent(), reportStepIdx), schedule, reportStepIdx, factor);
} }
double sumWellSurfaceRates(const Group& group, double sumWellSurfaceRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<double>& wellState,
const int reportStepIdx, const int reportStepIdx,
const int phasePos, const int phasePos,
const bool injector) const bool injector)
{ {
return sumWellPhaseRates(false, group, schedule, wellState, reportStepIdx, phasePos, injector); return sumWellPhaseRates(false, group, schedule, wellState, reportStepIdx, phasePos, injector);
} }
double sumWellResRates(const Group& group, double sumWellResRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<double>& wellState,
const int reportStepIdx, const int reportStepIdx,
const int phasePos, const int phasePos,
const bool injector) const bool injector)
{ {
return sumWellPhaseRates(true, group, schedule, wellState, reportStepIdx, phasePos, injector); return sumWellPhaseRates(true, group, schedule, wellState, reportStepIdx, phasePos, injector);
} }
double sumSolventRates(const Group& group, double sumSolventRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<double>& wellState,
const int reportStepIdx, const int reportStepIdx,
const bool injector) const bool injector)
{ {
double rate = 0.0; double rate = 0.0;
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
@ -262,9 +256,9 @@ namespace WellGroupHelpers
rate -= factor * ws.sum_solvent_rates(); rate -= factor * ws.sum_solvent_rates();
} }
return rate; return rate;
} }
void updateGuideRatesForInjectionGroups(const Group& group, void updateGuideRatesForInjectionGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const SummaryState& summaryState, const SummaryState& summaryState,
const Opm::PhaseUsage& pu, const Opm::PhaseUsage& pu,
@ -273,7 +267,7 @@ namespace WellGroupHelpers
const GroupState<double>& group_state, const GroupState<double>& group_state,
GuideRate* guideRate, GuideRate* guideRate,
Opm::DeferredLogger& deferred_logger) Opm::DeferredLogger& deferred_logger)
{ {
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx); const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
updateGuideRatesForInjectionGroups(groupTmp, schedule, summaryState, pu, reportStepIdx, wellState, group_state, guideRate, deferred_logger); updateGuideRatesForInjectionGroups(groupTmp, schedule, summaryState, pu, reportStepIdx, wellState, group_state, guideRate, deferred_logger);
@ -322,9 +316,9 @@ namespace WellGroupHelpers
guideRateValue = unit_system.from_si(UnitSystem::measure::rate, guideRateValue); guideRateValue = unit_system.from_si(UnitSystem::measure::rate, guideRateValue);
guideRate->compute(group.name(), phase, reportStepIdx, guideRateValue); guideRate->compute(group.name(), phase, reportStepIdx, guideRateValue);
} }
} }
void updateGroupTargetReduction(const Group& group, void updateGroupTargetReduction(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const bool isInjector, const bool isInjector,
@ -333,7 +327,7 @@ namespace WellGroupHelpers
const WellState<double>& wellState, const WellState<double>& wellState,
GroupState<double>& group_state, GroupState<double>& group_state,
std::vector<double>& groupTargetReduction) std::vector<double>& groupTargetReduction)
{ {
const int np = wellState.numPhases(); const int np = wellState.numPhases();
for (const std::string& subGroupName : group.groups()) { for (const std::string& subGroupName : group.groups()) {
std::vector<double> subGroupTargetReduction(np, 0.0); std::vector<double> subGroupTargetReduction(np, 0.0);
@ -460,9 +454,9 @@ namespace WellGroupHelpers
group_state.update_injection_reduction_rates(group.name(), groupTargetReduction); group_state.update_injection_reduction_rates(group.name(), groupTargetReduction);
else else
group_state.update_production_reduction_rates(group.name(), groupTargetReduction); group_state.update_production_reduction_rates(group.name(), groupTargetReduction);
} }
void updateWellRatesFromGroupTargetScale(const double scale, void updateWellRatesFromGroupTargetScale(const double scale,
const Group& group, const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
@ -528,15 +522,15 @@ namespace WellGroupHelpers
} }
} }
void updateVREPForGroups(const Group& group, void updateVREPForGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellState, const WellState<double>& wellState,
GroupState<double>& group_state) GroupState<double>& group_state)
{ {
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx); const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
updateVREPForGroups(groupTmp, schedule, reportStepIdx, wellState, group_state); updateVREPForGroups(groupTmp, schedule, reportStepIdx, wellState, group_state);
@ -553,14 +547,14 @@ namespace WellGroupHelpers
/*isInjector*/ false); /*isInjector*/ false);
} }
group_state.update_injection_vrep_rate(group.name(), resv); group_state.update_injection_vrep_rate(group.name(), resv);
} }
void updateReservoirRatesInjectionGroups(const Group& group, void updateReservoirRatesInjectionGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellState, const WellState<double>& wellState,
GroupState<double>& group_state) GroupState<double>& group_state)
{ {
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx); const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
updateReservoirRatesInjectionGroups(groupTmp, schedule, reportStepIdx, wellState, group_state); updateReservoirRatesInjectionGroups(groupTmp, schedule, reportStepIdx, wellState, group_state);
@ -577,14 +571,14 @@ namespace WellGroupHelpers
/*isInjector*/ true); /*isInjector*/ true);
} }
group_state.update_injection_reservoir_rates(group.name(), resv); group_state.update_injection_reservoir_rates(group.name(), resv);
} }
void updateSurfaceRatesInjectionGroups(const Group& group, void updateSurfaceRatesInjectionGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellState, const WellState<double>& wellState,
GroupState<double>& group_state) GroupState<double>& group_state)
{ {
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx); const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
updateSurfaceRatesInjectionGroups(groupTmp, schedule, reportStepIdx, wellState, group_state); updateSurfaceRatesInjectionGroups(groupTmp, schedule, reportStepIdx, wellState, group_state);
@ -601,14 +595,14 @@ namespace WellGroupHelpers
/*isInjector*/ true); /*isInjector*/ true);
} }
group_state.update_injection_surface_rates(group.name(), rates); group_state.update_injection_surface_rates(group.name(), rates);
} }
void updateWellRates(const Group& group, void updateWellRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellStateNupcol, const WellState<double>& wellStateNupcol,
WellState<double>& wellState) WellState<double>& wellState)
{ {
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx); const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
updateWellRates(groupTmp, schedule, reportStepIdx, wellStateNupcol, wellState); updateWellRates(groupTmp, schedule, reportStepIdx, wellStateNupcol, wellState);
@ -631,14 +625,14 @@ namespace WellGroupHelpers
} }
wellState.setCurrentWellRates(wellName, rates); wellState.setCurrentWellRates(wellName, rates);
} }
} }
void updateGroupProductionRates(const Group& group, void updateGroupProductionRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellState, const WellState<double>& wellState,
GroupState<double>& group_state) GroupState<double>& group_state)
{ {
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx); const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
updateGroupProductionRates(groupTmp, schedule, reportStepIdx, wellState, group_state); updateGroupProductionRates(groupTmp, schedule, reportStepIdx, wellState, group_state);
@ -649,10 +643,10 @@ namespace WellGroupHelpers
rates[phase] = sumWellPhaseRates(false, group, schedule, wellState, reportStepIdx, phase, /*isInjector*/ false); rates[phase] = sumWellPhaseRates(false, group, schedule, wellState, reportStepIdx, phase, /*isInjector*/ false);
} }
group_state.update_production_rates(group.name(), rates); group_state.update_production_rates(group.name(), rates);
} }
void updateREINForGroups(const Group& group, void updateREINForGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const PhaseUsage& pu, const PhaseUsage& pu,
@ -660,7 +654,7 @@ namespace WellGroupHelpers
const WellState<double>& wellState, const WellState<double>& wellState,
GroupState<double>& group_state, GroupState<double>& group_state,
bool sum_rank) bool sum_rank)
{ {
const int np = wellState.numPhases(); const int np = wellState.numPhases();
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx); const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
@ -684,18 +678,18 @@ namespace WellGroupHelpers
} }
group_state.update_injection_rein_rates(group.name(), rein); group_state.update_injection_rein_rates(group.name(), rein);
} }
template <class RegionalValues> template <class RegionalValues>
void updateGpMaintTargetForGroups(const Group& group, void updateGpMaintTargetForGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const RegionalValues& regional_values, const RegionalValues& regional_values,
const int reportStepIdx, const int reportStepIdx,
const double dt, const double dt,
const WellState<double>& well_state, const WellState<double>& well_state,
GroupState<double>& group_state) GroupState<double>& group_state)
{ {
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx); const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
updateGpMaintTargetForGroups(groupTmp, schedule, regional_values, reportStepIdx, dt, well_state, group_state); updateGpMaintTargetForGroups(groupTmp, schedule, regional_values, reportStepIdx, dt, well_state, group_state);
@ -772,19 +766,19 @@ namespace WellGroupHelpers
bool activate = (injection && error > 0) || (!injection && error < 0); bool activate = (injection && error > 0) || (!injection && error < 0);
double rate = activate? gpm->rate(gpmaint_state, current_rate, error, dt) : 0.0; double rate = activate? gpm->rate(gpmaint_state, current_rate, error, dt) : 0.0;
group_state.update_gpmaint_target(group.name(), std::max(0.0, sign * rate)); group_state.update_gpmaint_target(group.name(), std::max(0.0, sign * rate));
} }
std::map<std::string, double> std::map<std::string, double>
computeNetworkPressures(const Opm::Network::ExtNetwork& network, computeNetworkPressures(const Opm::Network::ExtNetwork& network,
const WellState<double>& well_state, const WellState<double>& well_state,
const GroupState<double>& group_state, const GroupState<double>& group_state,
const VFPProdProperties& vfp_prod_props, const VFPProdProperties& vfp_prod_props,
const Schedule& schedule, const Schedule& schedule,
const int report_time_step) const int report_time_step)
{ {
// TODO: Only dealing with production networks for now. // TODO: Only dealing with production networks for now.
if (!network.active()) { if (!network.active()) {
@ -895,14 +889,14 @@ namespace WellGroupHelpers
0.0, //explicit_wfr 0.0, //explicit_wfr
0.0, //explicit_gfr 0.0, //explicit_gfr
false); //use_expvfp we dont support explicit lookup false); //use_expvfp we dont support explicit lookup
#define EXTRA_DEBUG_NETWORK 0 #define EXTRA_DEBUG_NETWORK 0
#if EXTRA_DEBUG_NETWORK #if EXTRA_DEBUG_NETWORK
std::ostringstream oss; std::ostringstream oss;
oss << "parent: " << (*upbranch).uptree_node() << " child: " << node oss << "parent: " << (*upbranch).uptree_node() << " child: " << node
<< " rates = [ " << rates[0]*86400 << ", " << rates[1]*86400 << ", " << rates[2]*86400 << " ]" << " rates = [ " << rates[0]*86400 << ", " << rates[1]*86400 << ", " << rates[2]*86400 << " ]"
<< " p(parent) = " << up_press/1e5 << " p(child) = " << node_pressures[node]/1e5 << std::endl; << " p(parent) = " << up_press/1e5 << " p(child) = " << node_pressures[node]/1e5 << std::endl;
OpmLog::debug(oss.str()); OpmLog::debug(oss.str());
#endif #endif
} else { } else {
// Table number specified as 9999 in the deck, no pressure loss. // Table number specified as 9999 in the deck, no pressure loss.
node_pressures[node] = up_press; node_pressures[node] = up_press;
@ -911,28 +905,28 @@ namespace WellGroupHelpers
} }
} }
return node_pressures; return node_pressures;
} }
GuideRate::RateVector GuideRate::RateVector
getWellRateVector(const WellState<double>& well_state, getWellRateVector(const WellState<double>& well_state,
const PhaseUsage& pu, const PhaseUsage& pu,
const std::string& name) const std::string& name)
{ {
return getGuideRateVector(well_state.currentWellRates(name), pu); return getGuideRateVector(well_state.currentWellRates(name), pu);
} }
GuideRate::RateVector GuideRate::RateVector
getProductionGroupRateVector(const GroupState<double>& group_state, getProductionGroupRateVector(const GroupState<double>& group_state,
const PhaseUsage& pu, const PhaseUsage& pu,
const std::string& group_name) const std::string& group_name)
{ {
return getGuideRateVector(group_state.production_rates(group_name), pu); return getGuideRateVector(group_state.production_rates(group_name), pu);
} }
double getGuideRate(const std::string& name, double getGuideRate(const std::string& name,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<double>& wellState,
const GroupState<double>& group_state, const GroupState<double>& group_state,
@ -940,7 +934,7 @@ namespace WellGroupHelpers
const GuideRate* guideRate, const GuideRate* guideRate,
const GuideRateModel::Target target, const GuideRateModel::Target target,
const PhaseUsage& pu) const PhaseUsage& pu)
{ {
if (schedule.hasWell(name, reportStepIdx)) { if (schedule.hasWell(name, reportStepIdx)) {
if (guideRate->has(name) || guideRate->hasPotentials(name)) { if (guideRate->has(name) || guideRate->hasPotentials(name)) {
return guideRate->get(name, target, getWellRateVector(wellState, pu, name)); return guideRate->get(name, target, getWellRateVector(wellState, pu, name));
@ -983,10 +977,10 @@ namespace WellGroupHelpers
} }
return totalGuideRate; return totalGuideRate;
} }
double getGuideRateInj(const std::string& name, double getGuideRateInj(const std::string& name,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<double>& wellState,
const GroupState<double>& group_state, const GroupState<double>& group_state,
@ -995,7 +989,7 @@ namespace WellGroupHelpers
const GuideRateModel::Target target, const GuideRateModel::Target target,
const Phase& injectionPhase, const Phase& injectionPhase,
const PhaseUsage& pu) const PhaseUsage& pu)
{ {
if (schedule.hasWell(name, reportStepIdx)) { if (schedule.hasWell(name, reportStepIdx)) {
return getGuideRate(name, schedule, wellState, group_state, return getGuideRate(name, schedule, wellState, group_state,
reportStepIdx, guideRate, target, pu); reportStepIdx, guideRate, target, pu);
@ -1034,11 +1028,11 @@ namespace WellGroupHelpers
totalGuideRate += guideRate->get(wellName, target, getWellRateVector(wellState, pu, wellName)); totalGuideRate += guideRate->get(wellName, target, getWellRateVector(wellState, pu, wellName));
} }
return totalGuideRate; return totalGuideRate;
} }
int groupControlledWells(const Schedule& schedule, int groupControlledWells(const Schedule& schedule,
const WellState<double>& well_state, const WellState<double>& well_state,
const GroupState<double>& group_state, const GroupState<double>& group_state,
const int report_step, const int report_step,
@ -1046,7 +1040,7 @@ namespace WellGroupHelpers
const std::string& always_included_child, const std::string& always_included_child,
const bool is_production_group, const bool is_production_group,
const Phase injection_phase) const Phase injection_phase)
{ {
const Group& group = schedule.getGroup(group_name, report_step); const Group& group = schedule.getGroup(group_name, report_step);
int num_wells = 0; int num_wells = 0;
for (const std::string& child_group : group.groups()) { for (const std::string& child_group : group.groups()) {
@ -1077,11 +1071,11 @@ namespace WellGroupHelpers
} }
} }
return num_wells; return num_wells;
} }
std::vector<std::string> std::vector<std::string>
groupChainTopBot(const std::string& bottom, const std::string& top, const Schedule& schedule, const int report_step) groupChainTopBot(const std::string& bottom, const std::string& top, const Schedule& schedule, const int report_step)
{ {
// Get initial parent, 'bottom' can be a well or a group. // Get initial parent, 'bottom' can be a well or a group.
std::string parent; std::string parent;
if (schedule.hasWell(bottom, report_step)) { if (schedule.hasWell(bottom, report_step)) {
@ -1103,12 +1097,12 @@ namespace WellGroupHelpers
// Reverse order and return. // Reverse order and return.
std::reverse(chain.begin(), chain.end()); std::reverse(chain.begin(), chain.end());
return chain; return chain;
} }
std::pair<bool, double> checkGroupConstraintsProd(const std::string& name, std::pair<bool, double> checkGroupConstraintsProd(const std::string& name,
const std::string& parent, const std::string& parent,
const Group& group, const Group& group,
const WellState<double>& wellState, const WellState<double>& wellState,
@ -1122,7 +1116,7 @@ namespace WellGroupHelpers
const SummaryState& summaryState, const SummaryState& summaryState,
const std::vector<double>& resv_coeff, const std::vector<double>& resv_coeff,
DeferredLogger& deferred_logger) DeferredLogger& deferred_logger)
{ {
// When called for a well ('name' is a well name), 'parent' // When called for a well ('name' is a well name), 'parent'
// will be the name of 'group'. But if we recurse, 'name' and // will be the name of 'group'. But if we recurse, 'name' and
// 'parent' will stay fixed while 'group' will be higher up // 'parent' will stay fixed while 'group' will be higher up
@ -1252,9 +1246,9 @@ namespace WellGroupHelpers
scale = target_rate / current_rate; scale = target_rate / current_rate;
return std::make_pair(current_rate > target_rate, scale); return std::make_pair(current_rate > target_rate, scale);
} }
std::pair<bool, double> checkGroupConstraintsInj(const std::string& name, std::pair<bool, double> checkGroupConstraintsInj(const std::string& name,
const std::string& parent, const std::string& parent,
const Group& group, const Group& group,
const WellState<double>& wellState, const WellState<double>& wellState,
@ -1269,7 +1263,7 @@ namespace WellGroupHelpers
const SummaryState& summaryState, const SummaryState& summaryState,
const std::vector<double>& resv_coeff, const std::vector<double>& resv_coeff,
DeferredLogger& deferred_logger) DeferredLogger& deferred_logger)
{ {
// When called for a well ('name' is a well name), 'parent' // When called for a well ('name' is a well name), 'parent'
// will be the name of 'group'. But if we recurse, 'name' and // will be the name of 'group'. But if we recurse, 'name' and
// 'parent' will stay fixed while 'group' will be higher up // 'parent' will stay fixed while 'group' will be higher up
@ -1402,10 +1396,10 @@ namespace WellGroupHelpers
scale = target_rate / current_rate; scale = target_rate / current_rate;
return std::make_pair(current_rate > target_rate, scale); return std::make_pair(current_rate > target_rate, scale);
} }
std::pair<std::optional<std::string>, double> std::pair<std::optional<std::string>, double>
worstOffendingWell(const Group& group, worstOffendingWell(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const Group::ProductionCMode& offendedControl, const Group::ProductionCMode& offendedControl,
@ -1413,7 +1407,7 @@ namespace WellGroupHelpers
const Parallel::Communication& comm, const Parallel::Communication& comm,
const WellState<double>& wellState, const WellState<double>& wellState,
DeferredLogger& deferred_logger) DeferredLogger& deferred_logger)
{ {
std::pair<std::optional<std::string>, double> offending_well {std::nullopt, 0.0}; std::pair<std::optional<std::string>, double> offending_well {std::nullopt, 0.0};
for (const std::string& child_group : group.groups()) { for (const std::string& child_group : group.groups()) {
const auto& this_group = schedule.getGroup(child_group, reportStepIdx); const auto& this_group = schedule.getGroup(child_group, reportStepIdx);
@ -1500,16 +1494,16 @@ namespace WellGroupHelpers
} }
} }
return offending_well; return offending_well;
} }
template <class AverageRegionalPressureType> template <class AverageRegionalPressureType>
void setRegionAveragePressureCalculator(const Group& group, void setRegionAveragePressureCalculator(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const FieldPropsManager& fp, const FieldPropsManager& fp,
const PhaseUsage& pu, const PhaseUsage& pu,
std::map<std::string, std::unique_ptr<AverageRegionalPressureType>>& regionalAveragePressureCalculator) std::map<std::string, std::unique_ptr<AverageRegionalPressureType>>& regionalAveragePressureCalculator)
{ {
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
setRegionAveragePressureCalculator( schedule.getGroup(groupName, reportStepIdx), schedule, setRegionAveragePressureCalculator( schedule.getGroup(groupName, reportStepIdx), schedule,
reportStepIdx, fp, pu, regionalAveragePressureCalculator); reportStepIdx, fp, pu, regionalAveragePressureCalculator);
@ -1527,9 +1521,9 @@ namespace WellGroupHelpers
const auto& fipnum = fp.get_int(name); const auto& fipnum = fp.get_int(name);
regionalAveragePressureCalculator[reg->first] = std::make_unique<AverageRegionalPressureType>(pu,fipnum); regionalAveragePressureCalculator[reg->first] = std::make_unique<AverageRegionalPressureType>(pu,fipnum);
} }
} }
void updateGuideRates(const Group& group, void updateGuideRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const SummaryState& summary_state, const SummaryState& summary_state,
const PhaseUsage& pu, const PhaseUsage& pu,
@ -1541,14 +1535,14 @@ namespace WellGroupHelpers
GuideRate* guide_rate, GuideRate* guide_rate,
std::vector<double>& pot, std::vector<double>& pot,
Opm::DeferredLogger& deferred_logger) Opm::DeferredLogger& deferred_logger)
{ {
guide_rate->updateGuideRateExpiration(sim_time, report_step); guide_rate->updateGuideRateExpiration(sim_time, report_step);
updateGuideRateForProductionGroups(group, schedule, pu, report_step, sim_time, well_state, group_state, comm, guide_rate, pot); updateGuideRateForProductionGroups(group, schedule, pu, report_step, sim_time, well_state, group_state, comm, guide_rate, pot);
updateGuideRatesForInjectionGroups(group, schedule, summary_state, pu, report_step, well_state, group_state, guide_rate, deferred_logger); updateGuideRatesForInjectionGroups(group, schedule, summary_state, pu, report_step, well_state, group_state, guide_rate, deferred_logger);
updateGuideRatesForWells(schedule, pu, report_step, sim_time, well_state, comm, guide_rate); updateGuideRatesForWells(schedule, pu, report_step, sim_time, well_state, comm, guide_rate);
} }
void updateGuideRateForProductionGroups(const Group& group, void updateGuideRateForProductionGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const PhaseUsage& pu, const PhaseUsage& pu,
const int reportStepIdx, const int reportStepIdx,
@ -1558,7 +1552,7 @@ namespace WellGroupHelpers
const Parallel::Communication& comm, const Parallel::Communication& comm,
GuideRate* guideRate, GuideRate* guideRate,
std::vector<double>& pot) std::vector<double>& pot)
{ {
const int np = pu.num_phases; const int np = pu.num_phases;
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
std::vector<double> thisPot(np, 0.0); std::vector<double> thisPot(np, 0.0);
@ -1624,16 +1618,16 @@ namespace WellGroupHelpers
waterPot = unit_system.from_si(UnitSystem::measure::liquid_surface_rate, waterPot); waterPot = unit_system.from_si(UnitSystem::measure::liquid_surface_rate, waterPot);
gasPot = unit_system.from_si(UnitSystem::measure::gas_surface_rate, gasPot); gasPot = unit_system.from_si(UnitSystem::measure::gas_surface_rate, gasPot);
guideRate->compute(group.name(), reportStepIdx, simTime, oilPot, gasPot, waterPot); guideRate->compute(group.name(), reportStepIdx, simTime, oilPot, gasPot, waterPot);
} }
void updateGuideRatesForWells(const Schedule& schedule, void updateGuideRatesForWells(const Schedule& schedule,
const PhaseUsage& pu, const PhaseUsage& pu,
const int reportStepIdx, const int reportStepIdx,
const double& simTime, const double& simTime,
const WellState<double>& wellState, const WellState<double>& wellState,
const Parallel::Communication& comm, const Parallel::Communication& comm,
GuideRate* guideRate) GuideRate* guideRate)
{ {
for (const auto& well : schedule.getWells(reportStepIdx)) { for (const auto& well : schedule.getWells(reportStepIdx)) {
std::array<double,3> potentials{}; std::array<double,3> potentials{};
auto& [oilpot, gaspot, waterpot] = potentials; auto& [oilpot, gaspot, waterpot] = potentials;
@ -1660,23 +1654,23 @@ namespace WellGroupHelpers
gaspot = unit_system.from_si(UnitSystem::measure::gas_surface_rate, gaspot); gaspot = unit_system.from_si(UnitSystem::measure::gas_surface_rate, gaspot);
guideRate->compute(well.name(), reportStepIdx, simTime, oilpot, gaspot, waterpot); guideRate->compute(well.name(), reportStepIdx, simTime, oilpot, gaspot, waterpot);
} }
} }
using AvgP = RegionAverageCalculator::AverageRegionalPressure<BlackOilFluidSystem<double>,std::vector<int>>; using AvgP = RegionAverageCalculator::AverageRegionalPressure<BlackOilFluidSystem<double>,std::vector<int>>;
using AvgPMap = std::map<std::string, std::unique_ptr<AvgP>>; using AvgPMap = std::map<std::string, std::unique_ptr<AvgP>>;
template void WellGroupHelpers::updateGpMaintTargetForGroups<AvgPMap>(const Group&, template void WellGroupHelpers::
updateGpMaintTargetForGroups<AvgPMap>(const Group&,
const Schedule&, const Schedule&,
const AvgPMap&, const AvgPMap&,
int, int,
double, double,
const WellState<double>&, const WellState<double>&,
GroupState<double>&); GroupState<double>&);
template void WellGroupHelpers::setRegionAveragePressureCalculator<AvgP>(const Group&, template void WellGroupHelpers::
setRegionAveragePressureCalculator<AvgP>(const Group&,
const Schedule&, const Schedule&,
const int, const int,
const FieldPropsManager&, const FieldPropsManager&,
const PhaseUsage&, const PhaseUsage&,
AvgPMap&); AvgPMap&);
} // namespace WellGroupHelpers } // namespace Opm::WellGroupHelpers
} // namespace Opm

View File

@ -29,8 +29,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
namespace Opm namespace Opm {
{
class DeferredLogger; class DeferredLogger;
class Group; class Group;
@ -44,43 +43,40 @@ class FieldPropsManager;
namespace Network { class ExtNetwork; } namespace Network { class ExtNetwork; }
namespace WellGroupHelpers namespace WellGroupHelpers {
{
void setCmodeGroup(const Group& group,
void setCmodeGroup(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const SummaryState& summaryState, const SummaryState& summaryState,
const int reportStepIdx, const int reportStepIdx,
GroupState<double>& group_state); GroupState<double>& group_state);
void accumulateGroupEfficiencyFactor(const Group& group, void accumulateGroupEfficiencyFactor(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
double& factor); double& factor);
double sumWellSurfaceRates(const Group& group, double sumWellSurfaceRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<double>& wellState,
const int reportStepIdx, const int reportStepIdx,
const int phasePos, const int phasePos,
const bool injector); const bool injector);
double sumWellResRates(const Group& group, double sumWellResRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<double>& wellState,
const int reportStepIdx, const int reportStepIdx,
const int phasePos, const int phasePos,
const bool injector); const bool injector);
double sumSolventRates(const Group& group, double sumSolventRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<double>& wellState,
const int reportStepIdx, const int reportStepIdx,
const bool injector); const bool injector);
void updateGroupTargetReduction(const Group& group, void updateGroupTargetReduction(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const bool isInjector, const bool isInjector,
@ -90,7 +86,7 @@ namespace WellGroupHelpers
GroupState<double>& group_state, GroupState<double>& group_state,
std::vector<double>& groupTargetReduction); std::vector<double>& groupTargetReduction);
void updateGuideRates(const Group& group, void updateGuideRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const SummaryState& summary_state, const SummaryState& summary_state,
const PhaseUsage& pu, const PhaseUsage& pu,
@ -103,7 +99,7 @@ namespace WellGroupHelpers
std::vector<double>& pot, std::vector<double>& pot,
Opm::DeferredLogger& deferred_logge); Opm::DeferredLogger& deferred_logge);
void updateGuideRateForProductionGroups(const Group& group, void updateGuideRateForProductionGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const PhaseUsage& pu, const PhaseUsage& pu,
const int reportStepIdx, const int reportStepIdx,
@ -114,7 +110,7 @@ namespace WellGroupHelpers
GuideRate* guideRate, GuideRate* guideRate,
std::vector<double>& pot); std::vector<double>& pot);
void updateGuideRatesForWells(const Schedule& schedule, void updateGuideRatesForWells(const Schedule& schedule,
const PhaseUsage& pu, const PhaseUsage& pu,
const int reportStepIdx, const int reportStepIdx,
const double& simTime, const double& simTime,
@ -122,7 +118,7 @@ namespace WellGroupHelpers
const Parallel::Communication& comm, const Parallel::Communication& comm,
GuideRate* guideRate); GuideRate* guideRate);
void updateGuideRatesForInjectionGroups(const Group& group, void updateGuideRatesForInjectionGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const SummaryState& summaryState, const SummaryState& summaryState,
const Opm::PhaseUsage& pu, const Opm::PhaseUsage& pu,
@ -132,37 +128,37 @@ namespace WellGroupHelpers
GuideRate* guideRate, GuideRate* guideRate,
Opm::DeferredLogger& deferred_logger); Opm::DeferredLogger& deferred_logger);
void updateVREPForGroups(const Group& group, void updateVREPForGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellState, const WellState<double>& wellState,
GroupState<double>& group_state); GroupState<double>& group_state);
void updateReservoirRatesInjectionGroups(const Group& group, void updateReservoirRatesInjectionGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellState, const WellState<double>& wellState,
GroupState<double>& group_state); GroupState<double>& group_state);
void updateSurfaceRatesInjectionGroups(const Group& group, void updateSurfaceRatesInjectionGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellState, const WellState<double>& wellState,
GroupState<double>& group_state); GroupState<double>& group_state);
void updateWellRates(const Group& group, void updateWellRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellStateNupcol, const WellState<double>& wellStateNupcol,
WellState<double>& wellState); WellState<double>& wellState);
void updateGroupProductionRates(const Group& group, void updateGroupProductionRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellState, const WellState<double>& wellState,
GroupState<double>& group_state); GroupState<double>& group_state);
void updateWellRatesFromGroupTargetScale(const double scale, void updateWellRatesFromGroupTargetScale(const double scale,
const Group& group, const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
@ -170,7 +166,7 @@ namespace WellGroupHelpers
const GroupState<double>& group_state, const GroupState<double>& group_state,
WellState<double>& wellState); WellState<double>& wellState);
void updateREINForGroups(const Group& group, void updateREINForGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const PhaseUsage& pu, const PhaseUsage& pu,
@ -180,10 +176,10 @@ namespace WellGroupHelpers
bool sum_rank); bool sum_rank);
/// Returns the name of the worst offending well and its fraction /// Returns the name of the worst offending well and its fraction
/// (i.e. violated_phase / preferred_phase) /// (i.e. violated_phase / preferred_phase)
std::pair<std::optional<std::string>, double> std::pair<std::optional<std::string>, double>
worstOffendingWell(const Group& group, worstOffendingWell(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const Group::ProductionCMode& offendedControl, const Group::ProductionCMode& offendedControl,
@ -192,8 +188,8 @@ namespace WellGroupHelpers
const WellState<double>& wellState, const WellState<double>& wellState,
DeferredLogger& deferred_logger); DeferredLogger& deferred_logger);
template <class RegionalValues> template <class RegionalValues>
void updateGpMaintTargetForGroups(const Group& group, void updateGpMaintTargetForGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const RegionalValues& regional_values, const RegionalValues& regional_values,
const int reportStepIdx, const int reportStepIdx,
@ -201,25 +197,25 @@ namespace WellGroupHelpers
const WellState<double>& well_state, const WellState<double>& well_state,
GroupState<double>& group_state); GroupState<double>& group_state);
std::map<std::string, double> std::map<std::string, double>
computeNetworkPressures(const Opm::Network::ExtNetwork& network, computeNetworkPressures(const Opm::Network::ExtNetwork& network,
const WellState<double>& well_state, const WellState<double>& well_state,
const GroupState<double>& group_state, const GroupState<double>& group_state,
const VFPProdProperties& vfp_prod_props, const VFPProdProperties& vfp_prod_props,
const Schedule& schedule, const Schedule& schedule,
const int report_time_step); const int report_time_step);
GuideRate::RateVector GuideRate::RateVector
getWellRateVector(const WellState<double>& well_state, getWellRateVector(const WellState<double>& well_state,
const PhaseUsage& pu, const PhaseUsage& pu,
const std::string& name); const std::string& name);
GuideRate::RateVector GuideRate::RateVector
getProductionGroupRateVector(const GroupState<double>& group_state, getProductionGroupRateVector(const GroupState<double>& group_state,
const PhaseUsage& pu, const PhaseUsage& pu,
const std::string& group_name); const std::string& group_name);
double getGuideRate(const std::string& name, double getGuideRate(const std::string& name,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<double>& wellState,
const GroupState<double>& group_state, const GroupState<double>& group_state,
@ -229,7 +225,7 @@ namespace WellGroupHelpers
const PhaseUsage& pu); const PhaseUsage& pu);
double getGuideRateInj(const std::string& name, double getGuideRateInj(const std::string& name,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<double>& wellState,
const GroupState<double>& group_state, const GroupState<double>& group_state,
@ -239,7 +235,7 @@ namespace WellGroupHelpers
const Phase& injectionPhase, const Phase& injectionPhase,
const PhaseUsage& pu); const PhaseUsage& pu);
int groupControlledWells(const Schedule& schedule, int groupControlledWells(const Schedule& schedule,
const WellState<double>& well_state, const WellState<double>& well_state,
const GroupState<double>& group_state, const GroupState<double>& group_state,
const int report_step, const int report_step,
@ -249,7 +245,7 @@ namespace WellGroupHelpers
const Phase injection_phase); const Phase injection_phase);
std::pair<bool, double> checkGroupConstraintsInj(const std::string& name, std::pair<bool, double> checkGroupConstraintsInj(const std::string& name,
const std::string& parent, const std::string& parent,
const Group& group, const Group& group,
const WellState<double>& wellState, const WellState<double>& wellState,
@ -270,7 +266,7 @@ namespace WellGroupHelpers
std::vector<std::string> groupChainTopBot(const std::string& bottom, std::vector<std::string> groupChainTopBot(const std::string& bottom,
const std::string& top, const std::string& top,
const Schedule& schedule, const Schedule& schedule,
const int report_step); const int report_step);
@ -278,7 +274,7 @@ namespace WellGroupHelpers
std::pair<bool, double> checkGroupConstraintsProd(const std::string& name, std::pair<bool, double> checkGroupConstraintsProd(const std::string& name,
const std::string& parent, const std::string& parent,
const Group& group, const Group& group,
const WellState<double>& wellState, const WellState<double>& wellState,
@ -293,8 +289,8 @@ namespace WellGroupHelpers
const std::vector<double>& resv_coeff, const std::vector<double>& resv_coeff,
DeferredLogger& deferred_logger); DeferredLogger& deferred_logger);
template <class AverageRegionalPressureType> template <class AverageRegionalPressureType>
void setRegionAveragePressureCalculator(const Group& group, void setRegionAveragePressureCalculator(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const FieldPropsManager& fp, const FieldPropsManager& fp,