WellGroupHelpers: template Scalar type

This commit is contained in:
Arne Morten Kvarving 2024-02-19 13:47:25 +01:00
parent 522625aca8
commit aa03d06c4d
10 changed files with 683 additions and 462 deletions

View File

@ -74,7 +74,12 @@ checkGroupInjectionConstraints(const Group& group,
if (currentControl != Group::InjectionCMode::RATE) if (currentControl != Group::InjectionCMode::RATE)
{ {
double current_rate = 0.0; double current_rate = 0.0;
current_rate += WellGroupHelpers::sumWellSurfaceRates(group, wellModel_.schedule(), well_state, reportStepIdx, phasePos, /*isInjector*/true); current_rate += WellGroupHelpers<double>::sumWellSurfaceRates(group,
wellModel_.schedule(),
well_state,
reportStepIdx,
phasePos,
/*isInjector*/true);
// sum over all nodes // sum over all nodes
current_rate = wellModel_.comm().sum(current_rate); current_rate = wellModel_.comm().sum(current_rate);
@ -98,7 +103,12 @@ checkGroupInjectionConstraints(const Group& group,
if (currentControl != Group::InjectionCMode::RESV) if (currentControl != Group::InjectionCMode::RESV)
{ {
double current_rate = 0.0; double current_rate = 0.0;
current_rate += WellGroupHelpers::sumWellResRates(group, wellModel_.schedule(), well_state, reportStepIdx, phasePos, /*isInjector*/true); current_rate += WellGroupHelpers<double>::sumWellResRates(group,
wellModel_.schedule(),
well_state,
reportStepIdx,
phasePos,
/*isInjector*/true);
// sum over all nodes // sum over all nodes
current_rate = wellModel_.comm().sum(current_rate); current_rate = wellModel_.comm().sum(current_rate);
@ -123,17 +133,23 @@ checkGroupInjectionConstraints(const Group& group,
double production_Rate = 0.0; double production_Rate = 0.0;
const auto& controls = group.injectionControls(phase, wellModel_.summaryState()); const auto& controls = group.injectionControls(phase, wellModel_.summaryState());
const Group& groupRein = wellModel_.schedule().getGroup(controls.reinj_group, reportStepIdx); const Group& groupRein = wellModel_.schedule().getGroup(controls.reinj_group, reportStepIdx);
production_Rate += WellGroupHelpers::sumWellSurfaceRates(groupRein, wellModel_.schedule(), production_Rate += WellGroupHelpers<double>::sumWellSurfaceRates(groupRein,
well_state, reportStepIdx, wellModel_.schedule(),
phasePos, /*isInjector*/false); well_state,
reportStepIdx,
phasePos,
/*isInjector*/false);
// sum over all nodes // sum over all nodes
production_Rate = wellModel_.comm().sum(production_Rate); production_Rate = wellModel_.comm().sum(production_Rate);
double current_rate = 0.0; double current_rate = 0.0;
current_rate += WellGroupHelpers::sumWellSurfaceRates(group, wellModel_.schedule(), current_rate += WellGroupHelpers<double>::sumWellSurfaceRates(group,
well_state, reportStepIdx, wellModel_.schedule(),
phasePos, /*isInjector*/true); well_state,
reportStepIdx,
phasePos,
/*isInjector*/true);
// sum over all nodes // sum over all nodes
current_rate = wellModel_.comm().sum(current_rate); current_rate = wellModel_.comm().sum(current_rate);
@ -153,29 +169,46 @@ checkGroupInjectionConstraints(const Group& group,
double voidage_rate = 0.0; double voidage_rate = 0.0;
const auto& controls = group.injectionControls(phase, wellModel_.summaryState()); const auto& controls = group.injectionControls(phase, wellModel_.summaryState());
const Group& groupVoidage = wellModel_.schedule().getGroup(controls.voidage_group, reportStepIdx); const Group& groupVoidage = wellModel_.schedule().getGroup(controls.voidage_group, reportStepIdx);
voidage_rate += WellGroupHelpers::sumWellResRates(groupVoidage, wellModel_.schedule(), voidage_rate += WellGroupHelpers<double>::sumWellResRates(groupVoidage,
wellModel_.schedule(),
well_state,
reportStepIdx,
pu.phase_pos[BlackoilPhases::Aqua],
false);
voidage_rate += WellGroupHelpers<double>::sumWellResRates(groupVoidage,
wellModel_.schedule(),
well_state,
reportStepIdx,
pu.phase_pos[BlackoilPhases::Liquid],
false);
voidage_rate += WellGroupHelpers<double>::sumWellResRates(groupVoidage,
wellModel_.schedule(),
well_state, reportStepIdx, well_state, reportStepIdx,
pu.phase_pos[BlackoilPhases::Aqua], false); pu.phase_pos[BlackoilPhases::Vapour],
voidage_rate += WellGroupHelpers::sumWellResRates(groupVoidage, wellModel_.schedule(), false);
well_state, reportStepIdx,
pu.phase_pos[BlackoilPhases::Liquid], false);
voidage_rate += WellGroupHelpers::sumWellResRates(groupVoidage, wellModel_.schedule(),
well_state, reportStepIdx,
pu.phase_pos[BlackoilPhases::Vapour], false);
// sum over all nodes // sum over all nodes
voidage_rate = wellModel_.comm().sum(voidage_rate); voidage_rate = wellModel_.comm().sum(voidage_rate);
double total_rate = 0.0; double total_rate = 0.0;
total_rate += WellGroupHelpers::sumWellResRates(group, wellModel_.schedule(), total_rate += WellGroupHelpers<double>::sumWellResRates(group,
well_state, reportStepIdx, wellModel_.schedule(),
pu.phase_pos[BlackoilPhases::Aqua], true); well_state,
total_rate += WellGroupHelpers::sumWellResRates(group, wellModel_.schedule(), reportStepIdx,
well_state, reportStepIdx, pu.phase_pos[BlackoilPhases::Aqua],
pu.phase_pos[BlackoilPhases::Liquid], true); true);
total_rate += WellGroupHelpers::sumWellResRates(group, wellModel_.schedule(), total_rate += WellGroupHelpers<double>::sumWellResRates(group,
well_state, reportStepIdx, wellModel_.schedule(),
pu.phase_pos[BlackoilPhases::Vapour], true); well_state,
reportStepIdx,
pu.phase_pos[BlackoilPhases::Liquid],
true);
total_rate += WellGroupHelpers<double>::sumWellResRates(group,
wellModel_.schedule(),
well_state,
reportStepIdx,
pu.phase_pos[BlackoilPhases::Vapour],
true);
// sum over all nodes // sum over all nodes
total_rate = wellModel_.comm().sum(total_rate); total_rate = wellModel_.comm().sum(total_rate);
@ -208,9 +241,12 @@ checkGroupProductionConstraints(const Group& group,
if (currentControl != Group::ProductionCMode::ORAT) if (currentControl != Group::ProductionCMode::ORAT)
{ {
double current_rate = 0.0; double current_rate = 0.0;
current_rate += WellGroupHelpers::sumWellSurfaceRates(group, wellModel_.schedule(), current_rate += WellGroupHelpers<double>::sumWellSurfaceRates(group,
well_state, reportStepIdx, wellModel_.schedule(),
pu.phase_pos[BlackoilPhases::Liquid], false); well_state,
reportStepIdx,
pu.phase_pos[BlackoilPhases::Liquid],
false);
// sum over all nodes // sum over all nodes
current_rate = wellModel_.comm().sum(current_rate); current_rate = wellModel_.comm().sum(current_rate);
@ -228,11 +264,13 @@ checkGroupProductionConstraints(const Group& group,
{ {
if (currentControl != Group::ProductionCMode::WRAT) if (currentControl != Group::ProductionCMode::WRAT)
{ {
double current_rate = 0.0; double current_rate = 0.0;
current_rate += WellGroupHelpers::sumWellSurfaceRates(group, wellModel_.schedule(), current_rate += WellGroupHelpers<double>::sumWellSurfaceRates(group,
well_state, reportStepIdx, wellModel_.schedule(),
pu.phase_pos[BlackoilPhases::Aqua], false); well_state,
reportStepIdx,
pu.phase_pos[BlackoilPhases::Aqua],
false);
// sum over all nodes // sum over all nodes
current_rate = wellModel_.comm().sum(current_rate); current_rate = wellModel_.comm().sum(current_rate);
@ -250,9 +288,12 @@ checkGroupProductionConstraints(const Group& group,
if (currentControl != Group::ProductionCMode::GRAT) if (currentControl != Group::ProductionCMode::GRAT)
{ {
double current_rate = 0.0; double current_rate = 0.0;
current_rate += WellGroupHelpers::sumWellSurfaceRates(group, wellModel_.schedule(), current_rate += WellGroupHelpers<double>::sumWellSurfaceRates(group,
well_state, reportStepIdx, wellModel_.schedule(),
pu.phase_pos[BlackoilPhases::Vapour], false); well_state,
reportStepIdx,
pu.phase_pos[BlackoilPhases::Vapour],
false);
// sum over all nodes // sum over all nodes
current_rate = wellModel_.comm().sum(current_rate); current_rate = wellModel_.comm().sum(current_rate);
@ -269,21 +310,30 @@ checkGroupProductionConstraints(const Group& group,
if (currentControl != Group::ProductionCMode::LRAT) if (currentControl != Group::ProductionCMode::LRAT)
{ {
double current_rate = 0.0; double current_rate = 0.0;
current_rate += WellGroupHelpers::sumWellSurfaceRates(group, wellModel_.schedule(), current_rate += WellGroupHelpers<double>::sumWellSurfaceRates(group,
well_state, reportStepIdx, wellModel_.schedule(),
pu.phase_pos[BlackoilPhases::Liquid], false); well_state,
current_rate += WellGroupHelpers::sumWellSurfaceRates(group, wellModel_.schedule(), reportStepIdx,
well_state, reportStepIdx, pu.phase_pos[BlackoilPhases::Liquid],
pu.phase_pos[BlackoilPhases::Aqua], false); false);
current_rate += WellGroupHelpers<double>::sumWellSurfaceRates(group,
wellModel_.schedule(),
well_state,
reportStepIdx,
pu.phase_pos[BlackoilPhases::Aqua],
false);
// sum over all nodes // sum over all nodes
current_rate = wellModel_.comm().sum(current_rate); current_rate = wellModel_.comm().sum(current_rate);
bool skip = false; bool skip = false;
if (controls.liquid_target == controls.oil_target) { if (controls.liquid_target == controls.oil_target) {
double current_water_rate = WellGroupHelpers::sumWellSurfaceRates(group, wellModel_.schedule(), double current_water_rate = WellGroupHelpers<double>::sumWellSurfaceRates(group,
well_state, reportStepIdx, wellModel_.schedule(),
pu.phase_pos[BlackoilPhases::Aqua], false); well_state,
reportStepIdx,
pu.phase_pos[BlackoilPhases::Aqua],
false);
current_water_rate = wellModel_.comm().sum(current_water_rate); current_water_rate = wellModel_.comm().sum(current_water_rate);
if (std::abs(current_water_rate) < 1e-12) { if (std::abs(current_water_rate) < 1e-12) {
skip = true; skip = true;
@ -309,15 +359,24 @@ checkGroupProductionConstraints(const Group& group,
if (currentControl != Group::ProductionCMode::RESV) if (currentControl != Group::ProductionCMode::RESV)
{ {
double current_rate = 0.0; double current_rate = 0.0;
current_rate += WellGroupHelpers::sumWellResRates(group, wellModel_.schedule(), current_rate += WellGroupHelpers<double>::sumWellResRates(group,
well_state, reportStepIdx, wellModel_.schedule(),
pu.phase_pos[BlackoilPhases::Aqua], false); well_state,
current_rate += WellGroupHelpers::sumWellResRates(group, wellModel_.schedule(), reportStepIdx,
well_state, reportStepIdx, pu.phase_pos[BlackoilPhases::Aqua],
pu.phase_pos[BlackoilPhases::Liquid], false); false);
current_rate += WellGroupHelpers::sumWellResRates(group, wellModel_.schedule(), current_rate += WellGroupHelpers<double>::sumWellResRates(group,
well_state, reportStepIdx, wellModel_.schedule(),
pu.phase_pos[BlackoilPhases::Vapour], false); well_state,
reportStepIdx,
pu.phase_pos[BlackoilPhases::Liquid],
false);
current_rate += WellGroupHelpers<double>::sumWellResRates(group,
wellModel_.schedule(),
well_state,
reportStepIdx,
pu.phase_pos[BlackoilPhases::Vapour],
false);
// sum over all nodes // sum over all nodes
current_rate = wellModel_.comm().sum(current_rate); current_rate = wellModel_.comm().sum(current_rate);
@ -457,9 +516,8 @@ actionOnBrokenConstraints(const Group& group,
break; break;
} }
case Group::ExceedAction::WELL: { case Group::ExceedAction::WELL: {
std::tie(worst_offending_well, std::ignore) = std::tie(worst_offending_well, std::ignore) =
WellGroupHelpers::worstOffendingWell(group, wellModel_.schedule(), reportStepIdx, WellGroupHelpers<double>::worstOffendingWell(group, wellModel_.schedule(), reportStepIdx,
newControl, wellModel_.phaseUsage(), newControl, wellModel_.phaseUsage(),
wellModel_.comm(), well_state, deferred_logger); wellModel_.comm(), well_state, deferred_logger);
break; break;
@ -520,7 +578,7 @@ updateGroupIndividualControl(const Group& group,
Group::InjectionCMode2String(changed_this.first)); Group::InjectionCMode2String(changed_this.first));
this->actionOnBrokenConstraints(group, changed_this.first, phase, this->actionOnBrokenConstraints(group, changed_this.first, phase,
group_state, deferred_logger); group_state, deferred_logger);
WellGroupHelpers::updateWellRatesFromGroupTargetScale(changed_this.second, WellGroupHelpers<double>::updateWellRatesFromGroupTargetScale(changed_this.second,
group, group,
wellModel_.schedule(), wellModel_.schedule(),
reportStepIdx, reportStepIdx,
@ -549,7 +607,7 @@ updateGroupIndividualControl(const Group& group,
if(changed) { if(changed) {
switched_prod.insert_or_assign(group.name(), switched_prod.insert_or_assign(group.name(),
Group::ProductionCMode2String(changed_this.first)); Group::ProductionCMode2String(changed_this.first));
WellGroupHelpers::updateWellRatesFromGroupTargetScale(changed_this.second, WellGroupHelpers<double>::updateWellRatesFromGroupTargetScale(changed_this.second,
group, group,
wellModel_.schedule(), wellModel_.schedule(),
reportStepIdx, reportStepIdx,

View File

@ -450,8 +450,18 @@ checkGconsaleLimits(const Group& group,
const Group::ProductionCMode& oldProductionControl = this->groupState().production_control(group.name()); const Group::ProductionCMode& oldProductionControl = this->groupState().production_control(group.name());
int gasPos = phase_usage_.phase_pos[BlackoilPhases::Vapour]; int gasPos = phase_usage_.phase_pos[BlackoilPhases::Vapour];
double production_rate = WellGroupHelpers::sumWellSurfaceRates(group, schedule(), well_state, reportStepIdx, gasPos, /*isInjector*/false); double production_rate = WellGroupHelpers<double>::sumWellSurfaceRates(group,
double injection_rate = WellGroupHelpers::sumWellSurfaceRates(group, schedule(), well_state, reportStepIdx, gasPos, /*isInjector*/true); schedule(),
well_state,
reportStepIdx,
gasPos,
/*isInjector*/false);
double injection_rate = WellGroupHelpers<double>::sumWellSurfaceRates(group,
schedule(),
well_state,
reportStepIdx,
gasPos,
/*isInjector*/true);
// sum over all nodes // sum over all nodes
injection_rate = comm_.sum(injection_rate); injection_rate = comm_.sum(injection_rate);
@ -585,7 +595,12 @@ checkGroupHigherConstraints(const Group& group,
calcInjRates(fipnum, pvtreg, resv_coeff_inj); calcInjRates(fipnum, pvtreg, resv_coeff_inj);
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 */ true); const double local_current_rate = WellGroupHelpers<double>::sumWellSurfaceRates(group,
schedule(),
this->wellState(),
reportStepIdx,
phasePos,
/* isInjector */ true);
// Sum over all processes // Sum over all processes
rates[phasePos] = comm_.sum(local_current_rate); rates[phasePos] = comm_.sum(local_current_rate);
} }
@ -595,8 +610,8 @@ 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 auto [is_changed, scaling_factor] = WellGroupHelpers::checkGroupConstraintsInj( const auto [is_changed, scaling_factor] =
group.name(), WellGroupHelpers<double>::checkGroupConstraintsInj(group.name(),
group.parent(), group.parent(),
parentGroup, parentGroup,
this->wellState(), this->wellState(),
@ -617,7 +632,13 @@ checkGroupHigherConstraints(const Group& group,
actionOnBrokenConstraints(group, Group::InjectionCMode::FLD, actionOnBrokenConstraints(group, Group::InjectionCMode::FLD,
phase, this->groupState(), phase, this->groupState(),
deferred_logger); deferred_logger);
WellGroupHelpers::updateWellRatesFromGroupTargetScale(scaling_factor, group, schedule(), reportStepIdx, /* isInjector */ true, this->groupState(), this->wellState()); WellGroupHelpers<double>::updateWellRatesFromGroupTargetScale(scaling_factor,
group,
schedule(),
reportStepIdx,
/* isInjector */ true,
this->groupState(),
this->wellState());
changed = true; changed = true;
} }
} }
@ -627,7 +648,12 @@ checkGroupHigherConstraints(const Group& group,
if (!isField && 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<double>::sumWellSurfaceRates(group,
schedule(),
this->wellState(),
reportStepIdx,
phasePos,
/* isInjector */ false);
// Sum over all processes // Sum over all processes
rates[phasePos] = -comm_.sum(local_current_rate); rates[phasePos] = -comm_.sum(local_current_rate);
} }
@ -637,8 +663,8 @@ checkGroupHigherConstraints(const Group& group,
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 auto [is_changed, scaling_factor] = WellGroupHelpers::checkGroupConstraintsProd( const auto [is_changed, scaling_factor] =
group.name(), WellGroupHelpers<double>::checkGroupConstraintsProd(group.name(),
group.parent(), group.parent(),
parentGroup, parentGroup,
this->wellState(), this->wellState(),
@ -664,8 +690,15 @@ checkGroupHigherConstraints(const Group& group,
deferred_logger); deferred_logger);
if (changed) { if (changed) {
switched_prod_groups_.insert_or_assign(group.name(), Group::ProductionCMode2String(Group::ProductionCMode::FLD)); switched_prod_groups_.insert_or_assign(group.name(),
WellGroupHelpers::updateWellRatesFromGroupTargetScale(scaling_factor, group, schedule(), reportStepIdx, /* isInjector */ false, this->groupState(), this->wellState()); Group::ProductionCMode2String(Group::ProductionCMode::FLD));
WellGroupHelpers<double>::updateWellRatesFromGroupTargetScale(scaling_factor,
group,
schedule(),
reportStepIdx,
/* isInjector */ false,
this->groupState(),
this->wellState());
} }
} }
} }
@ -808,8 +841,17 @@ updateWsolvent(const Group& group,
int gasPos = phase_usage_.phase_pos[BlackoilPhases::Vapour]; int gasPos = phase_usage_.phase_pos[BlackoilPhases::Vapour];
const auto& controls = group.injectionControls(Phase::GAS, summaryState_); const auto& controls = group.injectionControls(Phase::GAS, summaryState_);
const Group& groupRein = schedule_.getGroup(controls.reinj_group, reportStepIdx); const Group& groupRein = schedule_.getGroup(controls.reinj_group, reportStepIdx);
double gasProductionRate = WellGroupHelpers::sumWellSurfaceRates(groupRein, schedule_, wellState, reportStepIdx, gasPos, /*isInjector*/false); double gasProductionRate = WellGroupHelpers<double>::sumWellSurfaceRates(groupRein,
double solventProductionRate = WellGroupHelpers::sumSolventRates(groupRein, schedule_, wellState, reportStepIdx, /*isInjector*/false); schedule_,
wellState,
reportStepIdx,
gasPos,
/*isInjector*/false);
double solventProductionRate = WellGroupHelpers<double>::sumSolventRates(groupRein,
schedule_,
wellState,
reportStepIdx,
/*isInjector*/false);
solventProductionRate = comm_.sum(solventProductionRate); solventProductionRate = comm_.sum(solventProductionRate);
gasProductionRate = comm_.sum(gasProductionRate); gasProductionRate = comm_.sum(gasProductionRate);
@ -956,7 +998,7 @@ assignNodeValues(std::map<std::string, data::NodeData>& nodevalues, const int re
const auto& network = schedule()[reportStepIdx].network(); const auto& network = schedule()[reportStepIdx].network();
if (!network.active()) return; if (!network.active()) return;
auto converged_pressures = WellGroupHelpers::computeNetworkPressures(network, auto converged_pressures = WellGroupHelpers<double>::computeNetworkPressures(network,
this->wellState(), this->wellState(),
this->groupState(), this->groupState(),
*(vfp_properties_->getProd()), *(vfp_properties_->getProd()),
@ -1011,20 +1053,63 @@ updateAndCommunicateGroupData(const int reportStepIdx,
// the group target reduction rates needs to be update since wells may have switched to/from GRUP control // the group target reduction rates needs to be update since wells may have switched to/from GRUP control
// The group target reduction does not honor NUPCOL. // The group target reduction does not honor NUPCOL.
std::vector<double> groupTargetReduction(numPhases(), 0.0); std::vector<double> groupTargetReduction(numPhases(), 0.0);
WellGroupHelpers::updateGroupTargetReduction(fieldGroup, schedule(), reportStepIdx, /*isInjector*/ false, phase_usage_, guideRate_, well_state, this->groupState(), groupTargetReduction); WellGroupHelpers<double>::updateGroupTargetReduction(fieldGroup,
schedule(),
reportStepIdx,
/*isInjector*/ false,
phase_usage_,
guideRate_,
well_state,
this->groupState(),
groupTargetReduction);
std::vector<double> groupTargetReductionInj(numPhases(), 0.0); std::vector<double> groupTargetReductionInj(numPhases(), 0.0);
WellGroupHelpers::updateGroupTargetReduction(fieldGroup, schedule(), reportStepIdx, /*isInjector*/ true, phase_usage_, guideRate_, well_state, this->groupState(), groupTargetReductionInj); WellGroupHelpers<double>::updateGroupTargetReduction(fieldGroup,
schedule(),
reportStepIdx,
/*isInjector*/ true,
phase_usage_,
guideRate_,
well_state,
this->groupState(),
groupTargetReductionInj);
WellGroupHelpers::updateREINForGroups(fieldGroup, schedule(), reportStepIdx, phase_usage_, summaryState_, well_state_nupcol, this->groupState(), comm_.rank()==0); WellGroupHelpers<double>::updateREINForGroups(fieldGroup,
WellGroupHelpers::updateVREPForGroups(fieldGroup, schedule(), reportStepIdx, well_state_nupcol, this->groupState()); schedule(),
reportStepIdx,
phase_usage_,
summaryState_,
well_state_nupcol,
this->groupState(),
comm_.rank() == 0);
WellGroupHelpers<double>::updateVREPForGroups(fieldGroup,
schedule(),
reportStepIdx,
well_state_nupcol,
this->groupState());
WellGroupHelpers::updateReservoirRatesInjectionGroups(fieldGroup, schedule(), reportStepIdx, well_state_nupcol, this->groupState()); WellGroupHelpers<double>::updateReservoirRatesInjectionGroups(fieldGroup,
WellGroupHelpers::updateSurfaceRatesInjectionGroups(fieldGroup, schedule(), reportStepIdx, well_state_nupcol, this->groupState()); schedule(),
reportStepIdx,
well_state_nupcol,
this->groupState());
WellGroupHelpers<double>::updateSurfaceRatesInjectionGroups(fieldGroup,
schedule(),
reportStepIdx,
well_state_nupcol,
this->groupState());
WellGroupHelpers::updateGroupProductionRates(fieldGroup, schedule(), reportStepIdx, well_state_nupcol, this->groupState()); WellGroupHelpers<double>::updateGroupProductionRates(fieldGroup,
schedule(),
reportStepIdx,
well_state_nupcol,
this->groupState());
// We use the rates from the previous time-step to reduce oscillations // We use the rates from the previous time-step to reduce oscillations
WellGroupHelpers::updateWellRates(fieldGroup, schedule(), reportStepIdx, this->prevWellState(), well_state); WellGroupHelpers<double>::updateWellRates(fieldGroup,
schedule(),
reportStepIdx,
this->prevWellState(),
well_state);
// Set ALQ for off-process wells to zero // Set ALQ for off-process wells to zero
for (const auto& wname : schedule().wellNames(reportStepIdx)) { for (const auto& wname : schedule().wellNames(reportStepIdx)) {
@ -1151,7 +1236,7 @@ updateNetworkPressures(const int reportStepIdx)
const auto previous_node_pressures = node_pressures_; const auto previous_node_pressures = node_pressures_;
node_pressures_ = WellGroupHelpers::computeNetworkPressures(network, node_pressures_ = WellGroupHelpers<double>::computeNetworkPressures(network,
this->wellState(), this->wellState(),
this->groupState(), this->groupState(),
*(vfp_properties_->getProd()), *(vfp_properties_->getProd()),
@ -1225,7 +1310,11 @@ calculateEfficiencyFactors(const int reportStepIdx)
for (auto& well : well_container_generic_) { for (auto& well : well_container_generic_) {
const Well& wellEcl = well->wellEcl(); const Well& wellEcl = well->wellEcl();
double well_efficiency_factor = wellEcl.getEfficiencyFactor(); double well_efficiency_factor = wellEcl.getEfficiencyFactor();
WellGroupHelpers::accumulateGroupEfficiencyFactor(schedule().getGroup(wellEcl.groupName(), reportStepIdx), schedule(), reportStepIdx, well_efficiency_factor); WellGroupHelpers<double>::accumulateGroupEfficiencyFactor(schedule().getGroup(wellEcl.groupName(),
reportStepIdx),
schedule(),
reportStepIdx,
well_efficiency_factor);
well->setWellEfficiencyFactor(well_efficiency_factor); well->setWellEfficiencyFactor(well_efficiency_factor);
} }
} }

View File

@ -328,7 +328,7 @@ getGuideRateValues(const Well& well) const
return grval; return grval;
} }
const auto qs = WellGroupHelpers:: const auto qs = WellGroupHelpers<double>::
getWellRateVector(wellModel_.wellState(), wellModel_.phaseUsage(), wname); getWellRateVector(wellModel_.wellState(), wellModel_.phaseUsage(), wname);
this->getGuideRateValues(qs, well.isInjector(), wname, grval); this->getGuideRateValues(qs, well.isInjector(), wname, grval);
@ -355,7 +355,7 @@ getGuideRateValues(const Group& group) const
return grval; return grval;
} }
const auto qs = WellGroupHelpers:: const auto qs = WellGroupHelpers<double>::
getProductionGroupRateVector(wellModel_.groupState(), wellModel_.phaseUsage(), gname); getProductionGroupRateVector(wellModel_.groupState(), wellModel_.phaseUsage(), gname);
const auto is_inj = false; // This procedure only applies to G*PGR. const auto is_inj = false; // This procedure only applies to G*PGR.
@ -433,7 +433,7 @@ assignWellGuideRates(data::Wells& wsrpt,
const auto get_gr = parent const auto get_gr = parent
|| RetrieveWellGuideRate{wellModel_.guideRate(), wname}; || RetrieveWellGuideRate{wellModel_.guideRate(), wname};
const auto qs = WellGroupHelpers:: const auto qs = WellGroupHelpers<double>::
getWellRateVector(wellModel_.wellState(), wellModel_.phaseUsage(), wname); getWellRateVector(wellModel_.wellState(), wellModel_.phaseUsage(), wname);
auto getGR = [this, &wname, &qs](const GuideRateModel::Target t) auto getGR = [this, &wname, &qs](const GuideRateModel::Target t)

View File

@ -343,7 +343,7 @@ namespace Opm {
const auto& fieldGroup = const auto& fieldGroup =
this->schedule().getGroup("FIELD", reportStepIdx); this->schedule().getGroup("FIELD", reportStepIdx);
WellGroupHelpers::setCmodeGroup(fieldGroup, WellGroupHelpers<Scalar>::setCmodeGroup(fieldGroup,
this->schedule(), this->schedule(),
this->summaryState(), this->summaryState(),
reportStepIdx, reportStepIdx,
@ -352,7 +352,7 @@ namespace Opm {
// Define per region average pressure calculators for use by // Define per region average pressure calculators for use by
// pressure maintenance groups (GPMAINT keyword). // pressure maintenance groups (GPMAINT keyword).
if (this->schedule()[reportStepIdx].has_gpmaint()) { if (this->schedule()[reportStepIdx].has_gpmaint()) {
WellGroupHelpers::setRegionAveragePressureCalculator WellGroupHelpers<Scalar>::setRegionAveragePressureCalculator
(fieldGroup, (fieldGroup,
this->schedule(), this->schedule(),
reportStepIdx, reportStepIdx,
@ -505,10 +505,20 @@ namespace Opm {
//update guide rates //update guide rates
const auto& comm = simulator_.vanguard().grid().comm(); const auto& comm = simulator_.vanguard().grid().comm();
std::vector<double> pot(numPhases(), 0.0); std::vector<double> pot(this->numPhases(), 0.0);
const Group& fieldGroup = schedule().getGroup("FIELD", reportStepIdx); const Group& fieldGroup = this->schedule().getGroup("FIELD", reportStepIdx);
WellGroupHelpers::updateGuideRates(fieldGroup, schedule(), summaryState, this->phase_usage_, reportStepIdx, simulationTime, WellGroupHelpers<double>::updateGuideRates(fieldGroup,
this->wellState(), this->groupState(), comm, &this->guideRate_, pot, local_deferredLogger); this->schedule(),
summaryState,
this->phase_usage_,
reportStepIdx,
simulationTime,
this->wellState(),
this->groupState(),
comm,
&this->guideRate_,
pot,
local_deferredLogger);
std::string exc_msg; std::string exc_msg;
auto exc_type = ExceptionType::NONE; auto exc_type = ExceptionType::NONE;
// update gpmaint targets // update gpmaint targets
@ -517,8 +527,13 @@ namespace Opm {
calculator.second->template defineState<ElementContext>(simulator_); calculator.second->template defineState<ElementContext>(simulator_);
} }
const double dt = simulator_.timeStepSize(); const double dt = simulator_.timeStepSize();
WellGroupHelpers::updateGpMaintTargetForGroups(fieldGroup, WellGroupHelpers<double>::updateGpMaintTargetForGroups(fieldGroup,
schedule_, regionalAveragePressureCalculator_, reportStepIdx, dt, this->wellState(), this->groupState()); this->schedule_,
regionalAveragePressureCalculator_,
reportStepIdx,
dt,
this->wellState(),
this->groupState());
} }
try { try {
// Compute initial well solution for new wells and injectors that change injection type i.e. WAG. // Compute initial well solution for new wells and injectors that change injection type i.e. WAG.
@ -574,8 +589,11 @@ namespace Opm {
well->init(&phase_usage_, depth_, gravity_, local_num_cells_, B_avg_, true); well->init(&phase_usage_, depth_, gravity_, local_num_cells_, B_avg_, true);
double well_efficiency_factor = wellEcl.getEfficiencyFactor(); double well_efficiency_factor = wellEcl.getEfficiencyFactor();
WellGroupHelpers::accumulateGroupEfficiencyFactor(schedule().getGroup(wellEcl.groupName(), timeStepIdx), WellGroupHelpers<double>::accumulateGroupEfficiencyFactor(this->schedule().getGroup(wellEcl.groupName(),
schedule(), timeStepIdx, well_efficiency_factor); timeStepIdx),
this->schedule(),
timeStepIdx,
well_efficiency_factor);
well->setWellEfficiencyFactor(well_efficiency_factor); well->setWellEfficiencyFactor(well_efficiency_factor);
well->setVFPProperties(vfp_properties_.get()); well->setVFPProperties(vfp_properties_.get());
@ -1191,13 +1209,22 @@ namespace Opm {
const double simulationTime = simulator_.time(); const double simulationTime = simulator_.time();
const auto& comm = simulator_.vanguard().grid().comm(); const auto& comm = simulator_.vanguard().grid().comm();
const auto& summaryState = simulator_.vanguard().summaryState(); const auto& summaryState = simulator_.vanguard().summaryState();
std::vector<double> pot(numPhases(), 0.0); std::vector<double> pot(this->numPhases(), 0.0);
const Group& fieldGroup = schedule().getGroup("FIELD", reportStepIdx); const Group& fieldGroup = this->schedule().getGroup("FIELD", reportStepIdx);
WellGroupHelpers::updateGuideRates(fieldGroup, schedule(), summaryState, this->phase_usage_, reportStepIdx, simulationTime, WellGroupHelpers<double>::updateGuideRates(fieldGroup,
this->wellState(), this->groupState(), comm, &this->guideRate_, pot, local_deferredLogger); this->schedule(),
summaryState,
this->phase_usage_,
reportStepIdx,
simulationTime,
this->wellState(),
this->groupState(),
comm,
&this->guideRate_,
pot,
local_deferredLogger);
} }
return {more_network_update, well_group_control_changed}; return {more_network_update, well_group_control_changed};
} }

View File

@ -144,7 +144,7 @@ guideRate(const std::string& name,
const std::string& always_included_child) const std::string& always_included_child)
{ {
if (schedule_.hasWell(name, report_step_)) { if (schedule_.hasWell(name, report_step_)) {
return WellGroupHelpers::getGuideRate(name, schedule_, well_state_, group_state_, return WellGroupHelpers<Scalar>::getGuideRate(name, schedule_, well_state_, group_state_,
report_step_, guide_rate_, target_, pu_); report_step_, guide_rate_, target_, pu_);
} else { } else {
if (groupControlledWells(name, always_included_child) > 0) { if (groupControlledWells(name, always_included_child) > 0) {
@ -171,7 +171,7 @@ int FractionCalculator<Scalar>::
groupControlledWells(const std::string& group_name, groupControlledWells(const std::string& group_name,
const std::string& always_included_child) const std::string& always_included_child)
{ {
return WellGroupHelpers::groupControlledWells(schedule_, return WellGroupHelpers<Scalar>::groupControlledWells(schedule_,
well_state_, well_state_,
this->group_state_, this->group_state_,
report_step_, report_step_,
@ -186,7 +186,7 @@ GuideRate::RateVector FractionCalculator<Scalar>::
getGroupRateVector(const std::string& group_name) getGroupRateVector(const std::string& group_name)
{ {
assert(is_producer_); assert(is_producer_);
return WellGroupHelpers::getProductionGroupRateVector(this->group_state_, return WellGroupHelpers<Scalar>::getProductionGroupRateVector(this->group_state_,
this->pu_, this->pu_,
group_name); group_name);
} }

View File

@ -77,9 +77,12 @@ GroupEconomicLimitsChecker(const BlackoilWellModelGeneric& well_model,
auto phase_idx = this->phase_idx_map_[i]; auto phase_idx = this->phase_idx_map_[i];
this->phase_idx_reverse_map_[phase_idx] = static_cast<int>(i); this->phase_idx_reverse_map_[phase_idx] = static_cast<int>(i);
auto phase_pos = this->well_model_.phaseUsage().phase_pos[phase_idx]; auto phase_pos = this->well_model_.phaseUsage().phase_pos[phase_idx];
Scalar production_rate = WellGroupHelpers::sumWellSurfaceRates( Scalar production_rate = WellGroupHelpers<Scalar>::sumWellSurfaceRates(this->group_,
this->group_, this->schedule_, this->well_state_, this->schedule_,
this->report_step_idx_, phase_pos, /*isInjector*/false); this->well_state_,
this->report_step_idx_,
phase_pos,
/*isInjector*/false);
this->production_rates_[i] = this->well_model_.comm().sum(production_rate); this->production_rates_[i] = this->well_model_.comm().sum(production_rate);
} }
} }

View File

@ -74,7 +74,7 @@ checkGroupConstraintsInj(const Group& group,
const auto& ws = well_state.well(well_.indexOfWell()); const auto& ws = well_state.well(well_.indexOfWell());
// Call check for the well's injection phase. // Call check for the well's injection phase.
return WellGroupHelpers::checkGroupConstraintsInj(well_.name(), return WellGroupHelpers<double>::checkGroupConstraintsInj(well_.name(),
well_.wellEcl().groupName(), well_.wellEcl().groupName(),
group, group,
well_state, well_state,
@ -107,7 +107,7 @@ checkGroupConstraintsProd(const Group& group,
rateConverter(0, well_.pvtRegionIdx(), group.name(), resv_coeff); // FIPNUM region 0 here, should use FIPNUM from WELSPECS. rateConverter(0, well_.pvtRegionIdx(), group.name(), resv_coeff); // FIPNUM region 0 here, should use FIPNUM from WELSPECS.
const auto& ws = well_state.well(well_.indexOfWell()); const auto& ws = well_state.well(well_.indexOfWell());
return WellGroupHelpers::checkGroupConstraintsProd(well_.name(), return WellGroupHelpers<double>::checkGroupConstraintsProd(well_.name(),
well_.wellEcl().groupName(), well_.wellEcl().groupName(),
group, group,
well_state, well_state,

View File

@ -173,7 +173,7 @@ getGroupInjectionControl(const Group& group,
const double orig_target = tcalc.groupTarget(ctrl, const double orig_target = tcalc.groupTarget(ctrl,
deferred_logger); deferred_logger);
const auto chain = WellGroupHelpers::groupChainTopBot(well_.name(), group.name(), const auto chain = WellGroupHelpers<double>::groupChainTopBot(well_.name(), group.name(),
schedule, well_.currentStep()); schedule, well_.currentStep());
// Because 'name' is the last of the elements, and not an ancestor, we subtract one below. // Because 'name' is the last of the elements, and not an ancestor, we subtract one below.
const std::size_t num_ancestors = chain.size() - 1; const std::size_t num_ancestors = chain.size() - 1;
@ -306,7 +306,10 @@ getGroupInjectionTargetRate(const Group& group,
const double orig_target = tcalc.groupTarget(ctrl, deferred_logger); const double orig_target = tcalc.groupTarget(ctrl, deferred_logger);
const auto chain = WellGroupHelpers::groupChainTopBot(well_.name(), group.name(), schedule, well_.currentStep()); const auto chain = WellGroupHelpers<double>::groupChainTopBot(well_.name(),
group.name(),
schedule,
well_.currentStep());
// Because 'name' is the last of the elements, and not an ancestor, we subtract one below. // Because 'name' is the last of the elements, and not an ancestor, we subtract one below.
const std::size_t num_ancestors = chain.size() - 1; const std::size_t num_ancestors = chain.size() - 1;
double target = orig_target; double target = orig_target;
@ -417,7 +420,7 @@ void WellGroupControls::getGroupProductionControl(const Group& group,
ctrl = group.productionControls(summaryState); ctrl = group.productionControls(summaryState);
const double orig_target = tcalc.groupTarget(ctrl, deferred_logger); const double orig_target = tcalc.groupTarget(ctrl, deferred_logger);
const auto chain = WellGroupHelpers::groupChainTopBot(well_.name(), group.name(), const auto chain = WellGroupHelpers<double>::groupChainTopBot(well_.name(), group.name(),
schedule, well_.currentStep()); schedule, well_.currentStep());
// Because 'name' is the last of the elements, and not an ancestor, we subtract one below. // Because 'name' is the last of the elements, and not an ancestor, we subtract one below.
const std::size_t num_ancestors = chain.size() - 1; const std::size_t num_ancestors = chain.size() - 1;
@ -514,7 +517,7 @@ getGroupProductionTargetRate(const Group& group,
ctrl = group.productionControls(summaryState); ctrl = group.productionControls(summaryState);
const double orig_target = tcalc.groupTarget(ctrl, deferred_logger); const double orig_target = tcalc.groupTarget(ctrl, deferred_logger);
const auto chain = WellGroupHelpers::groupChainTopBot(well_.name(), group.name(), const auto chain = WellGroupHelpers<double>::groupChainTopBot(well_.name(), group.name(),
schedule, well_.currentStep()); schedule, well_.currentStep());
// Because 'name' is the last of the elements, and not an ancestor, we subtract one below. // Because 'name' is the last of the elements, and not an ancestor, we subtract one below.
const std::size_t num_ancestors = chain.size() - 1; const std::size_t num_ancestors = chain.size() - 1;

View File

@ -50,36 +50,41 @@
#include <stdexcept> #include <stdexcept>
namespace { namespace {
template<class Scalar>
Opm::GuideRate::RateVector Opm::GuideRate::RateVector
getGuideRateVector(const std::vector<double>& rates, const Opm::PhaseUsage& pu) getGuideRateVector(const std::vector<Scalar>& rates, const Opm::PhaseUsage& pu)
{ {
using Opm::BlackoilPhases; using Opm::BlackoilPhases;
double oilRate = 0.0; Scalar oilRate = 0.0;
if (pu.phase_used[BlackoilPhases::Liquid]) if (pu.phase_used[BlackoilPhases::Liquid]) {
oilRate = rates[pu.phase_pos[BlackoilPhases::Liquid]]; oilRate = rates[pu.phase_pos[BlackoilPhases::Liquid]];
}
double gasRate = 0.0; Scalar gasRate = 0.0;
if (pu.phase_used[BlackoilPhases::Vapour]) if (pu.phase_used[BlackoilPhases::Vapour]) {
gasRate = rates[pu.phase_pos[BlackoilPhases::Vapour]]; gasRate = rates[pu.phase_pos[BlackoilPhases::Vapour]];
}
double waterRate = 0.0; Scalar waterRate = 0.0;
if (pu.phase_used[BlackoilPhases::Aqua]) if (pu.phase_used[BlackoilPhases::Aqua]) {
waterRate = rates[pu.phase_pos[BlackoilPhases::Aqua]]; waterRate = rates[pu.phase_pos[BlackoilPhases::Aqua]];
}
return {oilRate, gasRate, waterRate}; return {oilRate, gasRate, waterRate};
} }
double sumWellPhaseRates(bool res_rates, template<class Scalar>
Scalar sumWellPhaseRates(bool res_rates,
const Opm::Group& group, const Opm::Group& group,
const Opm::Schedule& schedule, const Opm::Schedule& schedule,
const Opm::WellState<double>& wellState, const Opm::WellState<Scalar>& wellState,
const int reportStepIdx, const int reportStepIdx,
const int phasePos, const int phasePos,
const bool injector) const bool injector)
{ {
double rate = 0.0; Scalar rate = 0.0;
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
const auto& groupTmp = schedule.getGroup(groupName, reportStepIdx); const auto& groupTmp = schedule.getGroup(groupName, reportStepIdx);
const auto& gefac = groupTmp.getGroupEfficiencyFactor(); const auto& gefac = groupTmp.getGroupEfficiencyFactor();
@ -104,7 +109,7 @@ namespace {
if (wellEcl.getStatus() == Opm::Well::Status::SHUT) if (wellEcl.getStatus() == Opm::Well::Status::SHUT)
continue; continue;
double factor = wellEcl.getEfficiencyFactor(); Scalar factor = wellEcl.getEfficiencyFactor();
const auto& ws = wellState.well(well_index.value()); const auto& ws = wellState.well(well_index.value());
if (res_rates) { if (res_rates) {
const auto& well_rates = ws.reservoir_rates; const auto& well_rates = ws.reservoir_rates;
@ -126,12 +131,13 @@ namespace {
namespace Opm { namespace Opm {
void WellGroupHelpers:: template<class Scalar>
void WellGroupHelpers<Scalar>::
setCmodeGroup(const Group& group, 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<Scalar>& group_state)
{ {
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
@ -185,11 +191,12 @@ setCmodeGroup(const Group& group,
} }
} }
void WellGroupHelpers:: template<class Scalar>
void WellGroupHelpers<Scalar>::
accumulateGroupEfficiencyFactor(const Group& group, accumulateGroupEfficiencyFactor(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
double& factor) Scalar& factor)
{ {
factor *= group.getGroupEfficiencyFactor(); factor *= group.getGroupEfficiencyFactor();
if (group.parent() != "FIELD" && !group.parent().empty()) if (group.parent() != "FIELD" && !group.parent().empty())
@ -197,10 +204,11 @@ accumulateGroupEfficiencyFactor(const Group& group,
schedule.getGroup(group.parent(), reportStepIdx), schedule, reportStepIdx, factor); schedule.getGroup(group.parent(), reportStepIdx), schedule, reportStepIdx, factor);
} }
double WellGroupHelpers:: template<class Scalar>
Scalar WellGroupHelpers<Scalar>::
sumWellSurfaceRates(const Group& group, sumWellSurfaceRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
const int reportStepIdx, const int reportStepIdx,
const int phasePos, const int phasePos,
const bool injector) const bool injector)
@ -208,10 +216,11 @@ sumWellSurfaceRates(const Group& group,
return sumWellPhaseRates(false, group, schedule, wellState, reportStepIdx, phasePos, injector); return sumWellPhaseRates(false, group, schedule, wellState, reportStepIdx, phasePos, injector);
} }
double WellGroupHelpers:: template<class Scalar>
Scalar WellGroupHelpers<Scalar>::
sumWellResRates(const Group& group, sumWellResRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
const int reportStepIdx, const int reportStepIdx,
const int phasePos, const int phasePos,
const bool injector) const bool injector)
@ -219,15 +228,15 @@ sumWellResRates(const Group& group,
return sumWellPhaseRates(true, group, schedule, wellState, reportStepIdx, phasePos, injector); return sumWellPhaseRates(true, group, schedule, wellState, reportStepIdx, phasePos, injector);
} }
double WellGroupHelpers:: template<class Scalar>
Scalar WellGroupHelpers<Scalar>::
sumSolventRates(const Group& group, sumSolventRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
const int reportStepIdx, const int reportStepIdx,
const bool injector) const bool injector)
{ {
Scalar rate = 0.0;
double rate = 0.0;
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);
const auto& gefac = groupTmp.getGroupEfficiencyFactor(); const auto& gefac = groupTmp.getGroupEfficiencyFactor();
@ -253,7 +262,7 @@ sumSolventRates(const Group& group,
continue; continue;
const auto& ws = wellState.well(well_index.value()); const auto& ws = wellState.well(well_index.value());
double factor = wellEcl.getEfficiencyFactor(); const Scalar factor = wellEcl.getEfficiencyFactor();
if (injector) if (injector)
rate += factor * ws.sum_solvent_rates(); rate += factor * ws.sum_solvent_rates();
else else
@ -262,14 +271,15 @@ sumSolventRates(const Group& group,
return rate; return rate;
} }
void WellGroupHelpers:: template<class Scalar>
void WellGroupHelpers<Scalar>::
updateGuideRatesForInjectionGroups(const Group& group, updateGuideRatesForInjectionGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const SummaryState& summaryState, const SummaryState& summaryState,
const PhaseUsage& pu, const PhaseUsage& pu,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
const GroupState<double>& group_state, const GroupState<Scalar>& group_state,
GuideRate* guideRate, GuideRate* guideRate,
DeferredLogger& deferred_logger) DeferredLogger& deferred_logger)
{ {
@ -283,7 +293,7 @@ updateGuideRatesForInjectionGroups(const Group& group,
if(!group.hasInjectionControl(phase)) if(!group.hasInjectionControl(phase))
continue; continue;
double guideRateValue = 0.0; Scalar guideRateValue = 0.0;
const auto& controls = group.injectionControls(phase, summaryState); const auto& controls = group.injectionControls(phase, summaryState);
switch (controls.guide_rate_def){ switch (controls.guide_rate_def){
case Group::GuideRateInjTarget::RATE: case Group::GuideRateInjTarget::RATE:
@ -296,7 +306,7 @@ updateGuideRatesForInjectionGroups(const Group& group,
case Group::GuideRateInjTarget::NETV: case Group::GuideRateInjTarget::NETV:
{ {
guideRateValue = group_state.injection_vrep_rate(group.name()); guideRateValue = group_state.injection_vrep_rate(group.name());
const std::vector<double>& injRES = group_state.injection_reservoir_rates(group.name()); const std::vector<Scalar>& injRES = group_state.injection_reservoir_rates(group.name());
if (phase != Phase::OIL && pu.phase_used[BlackoilPhases::Liquid]) if (phase != Phase::OIL && pu.phase_used[BlackoilPhases::Liquid])
guideRateValue -= injRES[pu.phase_pos[BlackoilPhases::Liquid]]; guideRateValue -= injRES[pu.phase_pos[BlackoilPhases::Liquid]];
if (phase != Phase::GAS && pu.phase_used[BlackoilPhases::Vapour]) if (phase != Phase::GAS && pu.phase_used[BlackoilPhases::Vapour])
@ -323,20 +333,21 @@ updateGuideRatesForInjectionGroups(const Group& group,
} }
} }
void WellGroupHelpers:: template<class Scalar>
void WellGroupHelpers<Scalar>::
updateGroupTargetReduction(const Group& group, updateGroupTargetReduction(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const bool isInjector, const bool isInjector,
const PhaseUsage& pu, const PhaseUsage& pu,
const GuideRate& guide_rate, const GuideRate& guide_rate,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
GroupState<double>& group_state, GroupState<Scalar>& group_state,
std::vector<double>& groupTargetReduction) std::vector<Scalar>& 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<Scalar> subGroupTargetReduction(np, 0.0);
const Group& subGroup = schedule.getGroup(subGroupName, reportStepIdx); const Group& subGroup = schedule.getGroup(subGroupName, reportStepIdx);
updateGroupTargetReduction(subGroup, updateGroupTargetReduction(subGroup,
schedule, schedule,
@ -348,7 +359,7 @@ updateGroupTargetReduction(const Group& group,
group_state, group_state,
subGroupTargetReduction); subGroupTargetReduction);
const double subGroupEfficiency = subGroup.getGroupEfficiencyFactor(); const Scalar subGroupEfficiency = subGroup.getGroupEfficiencyFactor();
// accumulate group contribution from sub group // accumulate group contribution from sub group
if (isInjector) { if (isInjector) {
@ -441,7 +452,7 @@ updateGroupTargetReduction(const Group& group,
continue; continue;
} }
const double efficiency = wellTmp.getEfficiencyFactor(); const Scalar efficiency = wellTmp.getEfficiencyFactor();
// add contributino from wells not under group control // add contributino from wells not under group control
const auto& ws = wellState.well(well_index.value()); const auto& ws = wellState.well(well_index.value());
if (isInjector) { if (isInjector) {
@ -462,14 +473,15 @@ updateGroupTargetReduction(const Group& group,
group_state.update_production_reduction_rates(group.name(), groupTargetReduction); group_state.update_production_reduction_rates(group.name(), groupTargetReduction);
} }
void WellGroupHelpers:: template<class Scalar>
updateWellRatesFromGroupTargetScale(const double scale, void WellGroupHelpers<Scalar>::
updateWellRatesFromGroupTargetScale(const Scalar scale,
const Group& group, const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
bool isInjector, bool isInjector,
const GroupState<double>& group_state, const GroupState<Scalar>& group_state,
WellState<double>& wellState) WellState<Scalar>& wellState)
{ {
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
bool individual_control = false; bool individual_control = false;
@ -522,29 +534,31 @@ updateWellRatesFromGroupTargetScale(const double scale,
ws.surface_rates[phase] *= scale; ws.surface_rates[phase] *= scale;
} }
} else { } else {
if (ws.production_cmode == Well::ProducerCMode::GRUP) if (ws.production_cmode == Well::ProducerCMode::GRUP) {
for (int phase = 0; phase < np; phase++) { for (int phase = 0; phase < np; phase++) {
ws.surface_rates[phase] *= scale; ws.surface_rates[phase] *= scale;
} }
} }
} }
}
} }
void WellGroupHelpers:: template<class Scalar>
void WellGroupHelpers<Scalar>::
updateVREPForGroups(const Group& group, updateVREPForGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
GroupState<double>& group_state) GroupState<Scalar>& 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);
} }
const int np = wellState.numPhases(); const int np = wellState.numPhases();
double resv = 0.0; Scalar resv = 0.0;
for (int phase = 0; phase < np; ++phase) { for (int phase = 0; phase < np; ++phase) {
resv += sumWellPhaseRates(true, resv += sumWellPhaseRates(true,
group, group,
@ -557,19 +571,20 @@ updateVREPForGroups(const Group& group,
group_state.update_injection_vrep_rate(group.name(), resv); group_state.update_injection_vrep_rate(group.name(), resv);
} }
void WellGroupHelpers:: template<class Scalar>
void WellGroupHelpers<Scalar>::
updateReservoirRatesInjectionGroups(const Group& group, updateReservoirRatesInjectionGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
GroupState<double>& group_state) GroupState<Scalar>& 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);
} }
const int np = wellState.numPhases(); const int np = wellState.numPhases();
std::vector<double> resv(np, 0.0); std::vector<Scalar> resv(np, 0.0);
for (int phase = 0; phase < np; ++phase) { for (int phase = 0; phase < np; ++phase) {
resv[phase] = sumWellPhaseRates(true, resv[phase] = sumWellPhaseRates(true,
group, group,
@ -582,19 +597,20 @@ updateReservoirRatesInjectionGroups(const Group& group,
group_state.update_injection_reservoir_rates(group.name(), resv); group_state.update_injection_reservoir_rates(group.name(), resv);
} }
void WellGroupHelpers:: template<class Scalar>
void WellGroupHelpers<Scalar>::
updateSurfaceRatesInjectionGroups(const Group& group, updateSurfaceRatesInjectionGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
GroupState<double>& group_state) GroupState<Scalar>& 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);
} }
const int np = wellState.numPhases(); const int np = wellState.numPhases();
std::vector<double> rates(np, 0.0); std::vector<Scalar> rates(np, 0.0);
for (int phase = 0; phase < np; ++phase) { for (int phase = 0; phase < np; ++phase) {
rates[phase] = sumWellPhaseRates(false, rates[phase] = sumWellPhaseRates(false,
group, group,
@ -607,12 +623,13 @@ updateSurfaceRatesInjectionGroups(const Group& group,
group_state.update_injection_surface_rates(group.name(), rates); group_state.update_injection_surface_rates(group.name(), rates);
} }
void WellGroupHelpers:: template<class Scalar>
void WellGroupHelpers<Scalar>::
updateWellRates(const Group& group, updateWellRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellStateNupcol, const WellState<Scalar>& wellStateNupcol,
WellState<double>& wellState) WellState<Scalar>& 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);
@ -620,7 +637,7 @@ updateWellRates(const Group& group,
} }
const int np = wellState.numPhases(); const int np = wellState.numPhases();
for (const std::string& wellName : group.wells()) { for (const std::string& wellName : group.wells()) {
std::vector<double> rates(np, 0.0); std::vector<Scalar> rates(np, 0.0);
const auto& well_index = wellState.index(wellName); const auto& well_index = wellState.index(wellName);
if (well_index.has_value()) { // the well is found on this node if (well_index.has_value()) { // the well is found on this node
const auto& wellTmp = schedule.getWell(wellName, reportStepIdx); const auto& wellTmp = schedule.getWell(wellName, reportStepIdx);
@ -638,33 +655,35 @@ updateWellRates(const Group& group,
} }
} }
void WellGroupHelpers:: template<class Scalar>
void WellGroupHelpers<Scalar>::
updateGroupProductionRates(const Group& group, updateGroupProductionRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
GroupState<double>& group_state) GroupState<Scalar>& 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);
} }
const int np = wellState.numPhases(); const int np = wellState.numPhases();
std::vector<double> rates(np, 0.0); std::vector<Scalar> rates(np, 0.0);
for (int phase = 0; phase < np; ++phase) { for (int phase = 0; phase < np; ++phase) {
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 WellGroupHelpers:: template<class Scalar>
void WellGroupHelpers<Scalar>::
updateREINForGroups(const Group& group, updateREINForGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const PhaseUsage& pu, const PhaseUsage& pu,
const SummaryState& st, const SummaryState& st,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
GroupState<double>& group_state, GroupState<Scalar>& group_state,
bool sum_rank) bool sum_rank)
{ {
const int np = wellState.numPhases(); const int np = wellState.numPhases();
@ -673,7 +692,7 @@ updateREINForGroups(const Group& group,
updateREINForGroups(groupTmp, schedule, reportStepIdx, pu, st, wellState, group_state, sum_rank); updateREINForGroups(groupTmp, schedule, reportStepIdx, pu, st, wellState, group_state, sum_rank);
} }
std::vector<double> rein(np, 0.0); std::vector<Scalar> rein(np, 0.0);
for (int phase = 0; phase < np; ++phase) { for (int phase = 0; phase < np; ++phase) {
rein[phase] = sumWellPhaseRates(false, group, schedule, wellState, reportStepIdx, phase, /*isInjector*/ false); rein[phase] = sumWellPhaseRates(false, group, schedule, wellState, reportStepIdx, phase, /*isInjector*/ false);
} }
@ -692,16 +711,16 @@ updateREINForGroups(const Group& group,
group_state.update_injection_rein_rates(group.name(), rein); group_state.update_injection_rein_rates(group.name(), rein);
} }
template<class Scalar>
template <class RegionalValues> template <class RegionalValues>
void WellGroupHelpers:: void WellGroupHelpers<Scalar>::
updateGpMaintTargetForGroups(const Group& group, 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<Scalar>& well_state,
GroupState<double>& group_state) GroupState<Scalar>& 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);
@ -716,11 +735,11 @@ updateGpMaintTargetForGroups(const Group& group,
return; return;
const auto [name, number] = *region; const auto [name, number] = *region;
const double error = gpm->pressure_target() - regional_values.at(name)->pressure(number); const Scalar error = gpm->pressure_target() - regional_values.at(name)->pressure(number);
double current_rate = 0.0; Scalar current_rate = 0.0;
const auto& pu = well_state.phaseUsage(); const auto& pu = well_state.phaseUsage();
bool injection = true; bool injection = true;
double sign = 1.0; Scalar sign = 1.0;
switch (gpm->flow_target()) { switch (gpm->flow_target()) {
case GPMaint::FlowTarget::RESV_PROD: case GPMaint::FlowTarget::RESV_PROD:
{ {
@ -777,18 +796,16 @@ updateGpMaintTargetForGroups(const Group& group,
// we only activate gpmaint if pressure is lower than the target regional pressure for injectors // we only activate gpmaint if pressure is lower than the target regional pressure for injectors
// (i.e. error > 0) and higher for producers. // (i.e. error > 0) and higher for producers.
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; const Scalar 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));
} }
template<class Scalar>
std::map<std::string, Scalar>
WellGroupHelpers<Scalar>::
std::map<std::string, double> computeNetworkPressures(const Network::ExtNetwork& network,
WellGroupHelpers:: const WellState<Scalar>& well_state,
computeNetworkPressures(const Opm::Network::ExtNetwork& network, const GroupState<Scalar>& group_state,
const WellState<double>& well_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)
@ -799,7 +816,7 @@ computeNetworkPressures(const Opm::Network::ExtNetwork& network,
return {}; return {};
} }
std::map<std::string, double> node_pressures; std::map<std::string, Scalar> node_pressures;
auto roots = network.roots(); auto roots = network.roots();
for (const auto& root : roots) { for (const auto& root : roots) {
// Fixed pressure nodes of the network are the roots of trees. // Fixed pressure nodes of the network are the roots of trees.
@ -828,7 +845,7 @@ computeNetworkPressures(const Opm::Network::ExtNetwork& network,
// Starting with the leaf nodes of the network, get the flow rates // Starting with the leaf nodes of the network, get the flow rates
// from the corresponding groups. // from the corresponding groups.
std::map<std::string, std::vector<double>> node_inflows; std::map<std::string, std::vector<Scalar>> node_inflows;
for (const auto& node : leaf_nodes) { for (const auto& node : leaf_nodes) {
node_inflows[node] = group_state.production_rates(node); node_inflows[node] = group_state.production_rates(node);
// Add the ALQ amounts to the gas rates if requested. // Add the ALQ amounts to the gas rates if requested.
@ -845,7 +862,7 @@ computeNetworkPressures(const Opm::Network::ExtNetwork& network,
// - Making the wells' maximum flows (i.e. not time-averaged by using a efficiency factor) // - Making the wells' maximum flows (i.e. not time-averaged by using a efficiency factor)
// available and using those (for wells with WEFAC(3) true only) when accumulating group // available and using those (for wells with WEFAC(3) true only) when accumulating group
// rates, but ONLY for network calculations. // rates, but ONLY for network calculations.
const double efficiency = well.getEfficiencyFactor(); const Scalar efficiency = well.getEfficiencyFactor();
node_inflows[node][BlackoilPhases::Vapour] += well_state.getALQ(wellname) * efficiency; node_inflows[node][BlackoilPhases::Vapour] += well_state.getALQ(wellname) * efficiency;
} }
} }
@ -861,8 +878,8 @@ computeNetworkPressures(const Opm::Network::ExtNetwork& network,
const auto upbranch = network.uptree_branch(node); const auto upbranch = network.uptree_branch(node);
if (upbranch) { if (upbranch) {
// Add downbranch rates to upbranch. // Add downbranch rates to upbranch.
std::vector<double>& up = node_inflows[(*upbranch).uptree_node()]; std::vector<Scalar>& up = node_inflows[(*upbranch).uptree_node()];
const std::vector<double>& down = node_inflows[node]; const std::vector<Scalar>& down = node_inflows[node];
if (up.empty()) { if (up.empty()) {
up = down; up = down;
} else { } else {
@ -884,7 +901,7 @@ computeNetworkPressures(const Opm::Network::ExtNetwork& network,
} else { } else {
const auto upbranch = network.uptree_branch(node); const auto upbranch = network.uptree_branch(node);
assert(upbranch); assert(upbranch);
const double up_press = node_pressures[(*upbranch).uptree_node()]; const Scalar up_press = node_pressures[(*upbranch).uptree_node()];
const auto vfp_table = (*upbranch).vfp_table(); const auto vfp_table = (*upbranch).vfp_table();
if (vfp_table) { if (vfp_table) {
// The rates are here positive, but the VFP code expects the // The rates are here positive, but the VFP code expects the
@ -893,7 +910,7 @@ computeNetworkPressures(const Opm::Network::ExtNetwork& network,
auto rates = node_inflows[node]; auto rates = node_inflows[node];
for (auto& r : rates) { r *= -1.0; } for (auto& r : rates) { r *= -1.0; }
assert(rates.size() == 3); assert(rates.size() == 3);
const double alq = 0.0; // TODO: Do not ignore ALQ const Scalar alq = 0.0; // TODO: Do not ignore ALQ
node_pressures[node] = vfp_prod_props.bhp(*vfp_table, node_pressures[node] = vfp_prod_props.bhp(*vfp_table,
rates[BlackoilPhases::Aqua], rates[BlackoilPhases::Aqua],
rates[BlackoilPhases::Liquid], rates[BlackoilPhases::Liquid],
@ -921,32 +938,32 @@ computeNetworkPressures(const Opm::Network::ExtNetwork& network,
return node_pressures; return node_pressures;
} }
template<class Scalar>
GuideRate::RateVector GuideRate::RateVector
WellGroupHelpers:: WellGroupHelpers<Scalar>::
getWellRateVector(const WellState<double>& well_state, getWellRateVector(const WellState<Scalar>& 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);
} }
template<class Scalar>
GuideRate::RateVector GuideRate::RateVector
WellGroupHelpers:: WellGroupHelpers<Scalar>::
getProductionGroupRateVector(const GroupState<double>& group_state, getProductionGroupRateVector(const GroupState<Scalar>& 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 WellGroupHelpers:: template<class Scalar>
Scalar WellGroupHelpers<Scalar>::
getGuideRate(const std::string& name, getGuideRate(const std::string& name,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
const GroupState<double>& group_state, const GroupState<Scalar>& group_state,
const int reportStepIdx, const int reportStepIdx,
const GuideRate* guideRate, const GuideRate* guideRate,
const GuideRateModel::Target target, const GuideRateModel::Target target,
@ -964,7 +981,7 @@ getGuideRate(const std::string& name,
return guideRate->get(name, target, getProductionGroupRateVector(group_state, pu, name)); return guideRate->get(name, target, getProductionGroupRateVector(group_state, pu, name));
} }
double totalGuideRate = 0.0; Scalar totalGuideRate = 0.0;
const Group& group = schedule.getGroup(name, reportStepIdx); const Group& group = schedule.getGroup(name, reportStepIdx);
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
@ -996,11 +1013,12 @@ getGuideRate(const std::string& name,
return totalGuideRate; return totalGuideRate;
} }
double WellGroupHelpers:: template<class Scalar>
Scalar WellGroupHelpers<Scalar>::
getGuideRateInj(const std::string& name, getGuideRateInj(const std::string& name,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
const GroupState<double>& group_state, const GroupState<Scalar>& group_state,
const int reportStepIdx, const int reportStepIdx,
const GuideRate* guideRate, const GuideRate* guideRate,
const GuideRateModel::Target target, const GuideRateModel::Target target,
@ -1016,7 +1034,7 @@ getGuideRateInj(const std::string& name,
return guideRate->get(name, injectionPhase); return guideRate->get(name, injectionPhase);
} }
double totalGuideRate = 0.0; Scalar totalGuideRate = 0.0;
const Group& group = schedule.getGroup(name, reportStepIdx); const Group& group = schedule.getGroup(name, reportStepIdx);
for (const std::string& groupName : group.groups()) { for (const std::string& groupName : group.groups()) {
@ -1047,10 +1065,11 @@ getGuideRateInj(const std::string& name,
return totalGuideRate; return totalGuideRate;
} }
int WellGroupHelpers:: template<class Scalar>
int WellGroupHelpers<Scalar>::
groupControlledWells(const Schedule& schedule, groupControlledWells(const Schedule& schedule,
const WellState<double>& well_state, const WellState<Scalar>& well_state,
const GroupState<double>& group_state, const GroupState<Scalar>& group_state,
const int report_step, const int report_step,
const std::string& group_name, const std::string& group_name,
const std::string& always_included_child, const std::string& always_included_child,
@ -1089,8 +1108,9 @@ groupControlledWells(const Schedule& schedule,
return num_wells; return num_wells;
} }
template<class Scalar>
std::vector<std::string> std::vector<std::string>
WellGroupHelpers:: WellGroupHelpers<Scalar>::
groupChainTopBot(const std::string& bottom, groupChainTopBot(const std::string& bottom,
const std::string& top, const std::string& top,
const Schedule& schedule, const Schedule& schedule,
@ -1119,21 +1139,22 @@ groupChainTopBot(const std::string& bottom,
return chain; return chain;
} }
std::pair<bool, double> template<class Scalar>
WellGroupHelpers:: std::pair<bool, Scalar>
WellGroupHelpers<Scalar>::
checkGroupConstraintsProd(const std::string& name, 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<Scalar>& wellState,
const GroupState<double>& group_state, const GroupState<Scalar>& group_state,
const int reportStepIdx, const int reportStepIdx,
const GuideRate* guideRate, const GuideRate* guideRate,
const double* rates, const Scalar* rates,
const PhaseUsage& pu, const PhaseUsage& pu,
const double efficiencyFactor, const Scalar efficiencyFactor,
const Schedule& schedule, const Schedule& schedule,
const SummaryState& summaryState, const SummaryState& summaryState,
const std::vector<double>& resv_coeff, const std::vector<Scalar>& 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'
@ -1172,7 +1193,7 @@ checkGroupConstraintsProd(const std::string& name,
// This can be false for FLD-controlled groups, we must therefore // This can be false for FLD-controlled groups, we must therefore
// check for FLD first (done above). // check for FLD first (done above).
if (!group.isProductionGroup()) { if (!group.isProductionGroup()) {
return std::make_pair(false, 1.0); return std::make_pair(false, Scalar(1.0));
} }
// If we are here, we are at the topmost group to be visited in the recursion. // If we are here, we are at the topmost group to be visited in the recursion.
@ -1180,7 +1201,7 @@ checkGroupConstraintsProd(const std::string& name,
// gconsale may adjust the grat target. // gconsale may adjust the grat target.
// the adjusted rates is send to the targetCalculator // the adjusted rates is send to the targetCalculator
double gratTargetFromSales = 0.0; Scalar gratTargetFromSales = 0.0;
if (group_state.has_grat_sales_target(group.name())) if (group_state.has_grat_sales_target(group.name()))
gratTargetFromSales = group_state.grat_sales_target(group.name()); gratTargetFromSales = group_state.grat_sales_target(group.name());
@ -1204,13 +1225,17 @@ checkGroupConstraintsProd(const std::string& name,
auto localFraction = [&](const std::string& child) { return fcalc.localFraction(child, name); }; auto localFraction = [&](const std::string& child) { return fcalc.localFraction(child, name); };
auto localReduction = [&](const std::string& group_name) { auto localReduction = [&](const std::string& group_name)
const std::vector<double>& groupTargetReductions = group_state.production_reduction_rates(group_name); {
const std::vector<Scalar>& groupTargetReductions =
group_state.production_reduction_rates(group_name);
return tcalc.calcModeRateFromRates(groupTargetReductions); return tcalc.calcModeRateFromRates(groupTargetReductions);
}; };
auto localCurrentRate = [&](const std::string& group_name) { auto localCurrentRate = [&](const std::string& group_name)
const std::vector<double>& groupSurfaceRates = group_state.production_rates(group_name); {
const std::vector<Scalar>& groupSurfaceRates =
group_state.production_rates(group_name);
return tcalc.calcModeRateFromRates(groupSurfaceRates); return tcalc.calcModeRateFromRates(groupSurfaceRates);
}; };
@ -1218,11 +1243,11 @@ checkGroupConstraintsProd(const std::string& name,
if (!group.has_gpmaint_control(currentGroupControl)) if (!group.has_gpmaint_control(currentGroupControl))
ctrl = group.productionControls(summaryState); ctrl = group.productionControls(summaryState);
const double orig_target = tcalc.groupTarget(ctrl, deferred_logger); const Scalar orig_target = tcalc.groupTarget(ctrl, deferred_logger);
// Assume we have a chain of groups as follows: BOTTOM -> MIDDLE -> TOP. // Assume we have a chain of groups as follows: BOTTOM -> MIDDLE -> TOP.
// Then ... // Then ...
// TODO finish explanation. // TODO finish explanation.
const double current_rate const Scalar current_rate
= -tcalc.calcModeRateFromRates(rates); // Switch sign since 'rates' are negative for producers. = -tcalc.calcModeRateFromRates(rates); // Switch sign since 'rates' are negative for producers.
const auto chain = groupChainTopBot(name, group.name(), schedule, reportStepIdx); const auto chain = groupChainTopBot(name, group.name(), schedule, reportStepIdx);
// Because 'name' is the last of the elements, and not an ancestor, we subtract one below. // Because 'name' is the last of the elements, and not an ancestor, we subtract one below.
@ -1246,18 +1271,18 @@ checkGroupConstraintsProd(const std::string& name,
for (std::size_t ii = 1; ii < num_ancestors; ++ii) { for (std::size_t ii = 1; ii < num_ancestors; ++ii) {
if (guideRate->has(chain[ii])) { if (guideRate->has(chain[ii])) {
const auto& guided_group = chain[ii]; const auto& guided_group = chain[ii];
const double grefficiency const Scalar grefficiency
= schedule.getGroup(guided_group, reportStepIdx).getGroupEfficiencyFactor(); = schedule.getGroup(guided_group, reportStepIdx).getGroupEfficiencyFactor();
const double currentRateFraction = grefficiency * localCurrentRate(guided_group) / (localCurrentRate(chain[ii-1])); const Scalar currentRateFraction = grefficiency * localCurrentRate(guided_group) / (localCurrentRate(chain[ii-1]));
const double guiderateFraction = localFraction(guided_group); const Scalar guiderateFraction = localFraction(guided_group);
// we add a factor here to avoid switching due to numerical instability // we add a factor here to avoid switching due to numerical instability
const double factor = 1.01; const Scalar factor = 1.01;
if (currentRateFraction > (guiderateFraction * factor)) { if (currentRateFraction > (guiderateFraction * factor)) {
return std::make_pair(true, guiderateFraction / currentRateFraction); return std::make_pair(true, guiderateFraction / currentRateFraction);
} }
} }
} }
double target = orig_target; Scalar target = orig_target;
for (std::size_t ii = 0; ii < num_ancestors; ++ii) { for (std::size_t ii = 0; ii < num_ancestors; ++ii) {
if ((ii == 0) || guideRate->has(chain[ii])) { if ((ii == 0) || guideRate->has(chain[ii])) {
// Apply local reductions only at the control level // Apply local reductions only at the control level
@ -1274,30 +1299,31 @@ checkGroupConstraintsProd(const std::string& name,
target *= localFraction(chain[ii + 1]); target *= localFraction(chain[ii + 1]);
} }
// Avoid negative target rates comming from too large local reductions. // Avoid negative target rates comming from too large local reductions.
const double target_rate = std::max(1e-12, target / efficiencyFactor); const Scalar target_rate = std::max(Scalar(1e-12), target / efficiencyFactor);
double scale = 1.0; Scalar scale = 1.0;
if (current_rate > 1e-12) if (current_rate > 1e-12)
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> template<class Scalar>
WellGroupHelpers:: std::pair<bool, Scalar>
WellGroupHelpers<Scalar>::
checkGroupConstraintsInj(const std::string& name, 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<Scalar>& wellState,
const GroupState<double>& group_state, const GroupState<Scalar>& group_state,
const int reportStepIdx, const int reportStepIdx,
const GuideRate* guideRate, const GuideRate* guideRate,
const double* rates, const Scalar* rates,
Phase injectionPhase, Phase injectionPhase,
const PhaseUsage& pu, const PhaseUsage& pu,
const double efficiencyFactor, const Scalar efficiencyFactor,
const Schedule& schedule, const Schedule& schedule,
const SummaryState& summaryState, const SummaryState& summaryState,
const std::vector<double>& resv_coeff, const std::vector<Scalar>& 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'
@ -1313,7 +1339,7 @@ checkGroupConstraintsInj(const std::string& name,
if (currentGroupControl == Group::InjectionCMode::FLD || currentGroupControl == Group::InjectionCMode::NONE) { if (currentGroupControl == Group::InjectionCMode::FLD || currentGroupControl == Group::InjectionCMode::NONE) {
// Return if we are not available for parent group. // Return if we are not available for parent group.
if (!group.injectionGroupControlAvailable(injectionPhase)) { if (!group.injectionGroupControlAvailable(injectionPhase)) {
return std::make_pair(false, 1); return std::make_pair(false, Scalar(1));
} }
// Otherwise: check production share of parent's control. // Otherwise: check production share of parent's control.
const auto& parentGroup = schedule.getGroup(group.parent(), reportStepIdx); const auto& parentGroup = schedule.getGroup(group.parent(), reportStepIdx);
@ -1337,12 +1363,12 @@ checkGroupConstraintsInj(const std::string& name,
// This can be false for FLD-controlled groups, we must therefore // This can be false for FLD-controlled groups, we must therefore
// check for FLD first (done above). // check for FLD first (done above).
if (!group.isInjectionGroup()) { if (!group.isInjectionGroup()) {
return std::make_pair(false, 1.0); return std::make_pair(false, Scalar(1.0));
} }
// If we are here, we are at the topmost group to be visited in the recursion. // If we are here, we are at the topmost group to be visited in the recursion.
// This is the group containing the control we will check against. // This is the group containing the control we will check against.
double sales_target = 0; Scalar sales_target = 0;
if (schedule[reportStepIdx].gconsale().has(group.name())) { if (schedule[reportStepIdx].gconsale().has(group.name())) {
const auto& gconsale = schedule[reportStepIdx].gconsale().get(group.name(), summaryState); const auto& gconsale = schedule[reportStepIdx].gconsale().get(group.name(), summaryState);
sales_target = gconsale.sales_target; sales_target = gconsale.sales_target;
@ -1370,13 +1396,17 @@ checkGroupConstraintsInj(const std::string& name,
auto localFraction = [&](const std::string& child) { return fcalc.localFraction(child, name); }; auto localFraction = [&](const std::string& child) { return fcalc.localFraction(child, name); };
auto localReduction = [&](const std::string& group_name) { auto localReduction = [&](const std::string& group_name)
const std::vector<double>& groupTargetReductions = group_state.injection_reduction_rates(group_name); {
const std::vector<Scalar>& groupTargetReductions =
group_state.injection_reduction_rates(group_name);
return tcalc.calcModeRateFromRates(groupTargetReductions); return tcalc.calcModeRateFromRates(groupTargetReductions);
}; };
auto localCurrentRate = [&](const std::string& group_name) { auto localCurrentRate = [&](const std::string& group_name)
const std::vector<double>& groupSurfaceRates = group_state.injection_surface_rates(group_name); {
const std::vector<Scalar>& groupSurfaceRates =
group_state.injection_surface_rates(group_name);
return tcalc.calcModeRateFromRates(groupSurfaceRates); return tcalc.calcModeRateFromRates(groupSurfaceRates);
}; };
@ -1385,11 +1415,11 @@ checkGroupConstraintsInj(const std::string& name,
ctrl = group.injectionControls(injectionPhase, summaryState); ctrl = group.injectionControls(injectionPhase, summaryState);
const double orig_target = tcalc.groupTarget(ctrl, deferred_logger); const Scalar orig_target = tcalc.groupTarget(ctrl, deferred_logger);
// Assume we have a chain of groups as follows: BOTTOM -> MIDDLE -> TOP. // Assume we have a chain of groups as follows: BOTTOM -> MIDDLE -> TOP.
// Then ... // Then ...
// TODO finish explanation. // TODO finish explanation.
const double current_rate const Scalar current_rate
= tcalc.calcModeRateFromRates(rates); // Switch sign since 'rates' are negative for producers. = tcalc.calcModeRateFromRates(rates); // Switch sign since 'rates' are negative for producers.
const auto chain = groupChainTopBot(name, group.name(), schedule, reportStepIdx); const auto chain = groupChainTopBot(name, group.name(), schedule, reportStepIdx);
// Because 'name' is the last of the elements, and not an ancestor, we subtract one below. // Because 'name' is the last of the elements, and not an ancestor, we subtract one below.
@ -1414,19 +1444,20 @@ checkGroupConstraintsInj(const std::string& name,
for (std::size_t ii = 1; ii < num_ancestors; ++ii) { for (std::size_t ii = 1; ii < num_ancestors; ++ii) {
if (guideRate->has(chain[ii], injectionPhase)) { if (guideRate->has(chain[ii], injectionPhase)) {
const auto& guided_group = chain[ii]; const auto& guided_group = chain[ii];
const double grefficiency const Scalar grefficiency
= schedule.getGroup(guided_group, reportStepIdx).getGroupEfficiencyFactor(); = schedule.getGroup(guided_group, reportStepIdx).getGroupEfficiencyFactor();
const double currentRateFraction = grefficiency * localCurrentRate(guided_group) / (localCurrentRate(chain[ii-1])); const Scalar currentRateFraction = grefficiency * localCurrentRate(guided_group) /
const double guiderateFraction = localFraction(guided_group); localCurrentRate(chain[ii-1]);
const Scalar guiderateFraction = localFraction(guided_group);
// we add a factor here to avoid switching due to numerical instability // we add a factor here to avoid switching due to numerical instability
const double factor = 1.01; const Scalar factor = 1.01;
if (currentRateFraction > (guiderateFraction * factor)) { if (currentRateFraction > (guiderateFraction * factor)) {
return std::make_pair(true, guiderateFraction / currentRateFraction); return std::make_pair(true, guiderateFraction / currentRateFraction);
} }
} }
} }
double target = orig_target; Scalar target = orig_target;
for (std::size_t ii = 0; ii < num_ancestors; ++ii) { for (std::size_t ii = 0; ii < num_ancestors; ++ii) {
if ((ii == 0) || guideRate->has(chain[ii], injectionPhase)) { if ((ii == 0) || guideRate->has(chain[ii], injectionPhase)) {
// Apply local reductions only at the control level // Apply local reductions only at the control level
@ -1444,26 +1475,27 @@ checkGroupConstraintsInj(const std::string& name,
target *= localFraction(chain[ii + 1]); target *= localFraction(chain[ii + 1]);
} }
// Avoid negative target rates comming from too large local reductions. // Avoid negative target rates comming from too large local reductions.
const double target_rate = std::max(1e-12, target / efficiencyFactor); const Scalar target_rate = std::max(Scalar(1e-12), target / efficiencyFactor);
double scale = 1.0; Scalar scale = 1.0;
if (current_rate > 1e-12) if (current_rate > 1e-12)
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> template<class Scalar>
WellGroupHelpers:: std::pair<std::optional<std::string>, Scalar>
WellGroupHelpers<Scalar>::
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,
const PhaseUsage& pu, const PhaseUsage& pu,
const Parallel::Communication& comm, const Parallel::Communication& comm,
const WellState<double>& wellState, const WellState<Scalar>& 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>, Scalar> 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);
const auto & offending_well_this = worstOffendingWell(this_group, const auto & offending_well_this = worstOffendingWell(this_group,
@ -1482,8 +1514,8 @@ worstOffendingWell(const Group& group,
for (const std::string& child_well : group.wells()) { for (const std::string& child_well : group.wells()) {
const auto& well_index = wellState.index(child_well); const auto& well_index = wellState.index(child_well);
double violating_rate = 0.0; Scalar violating_rate = 0.0;
double prefered_rate = 0.0; Scalar prefered_rate = 0.0;
if (well_index.has_value() && wellState.wellIsOwned(well_index.value(), child_well)) if (well_index.has_value() && wellState.wellIsOwned(well_index.value(), child_well))
{ {
const auto& ws = wellState.well(child_well); const auto& ws = wellState.well(child_well);
@ -1542,7 +1574,7 @@ worstOffendingWell(const Group& group,
violating_rate = comm.sum(violating_rate); violating_rate = comm.sum(violating_rate);
if (violating_rate < 0 ) { // only check producing wells if (violating_rate < 0 ) { // only check producing wells
prefered_rate = comm.sum(prefered_rate); prefered_rate = comm.sum(prefered_rate);
double fraction = prefered_rate < -1e-16 ? violating_rate / prefered_rate : 1.0; Scalar fraction = prefered_rate < -1e-16 ? violating_rate / prefered_rate : 1.0;
if ( fraction > offending_well.second) { if ( fraction > offending_well.second) {
offending_well = {child_well, fraction}; offending_well = {child_well, fraction};
} }
@ -1551,8 +1583,9 @@ worstOffendingWell(const Group& group,
return offending_well; return offending_well;
} }
template<class Scalar>
template <class AverageRegionalPressureType> template <class AverageRegionalPressureType>
void WellGroupHelpers:: void WellGroupHelpers<Scalar>::
setRegionAveragePressureCalculator(const Group& group, setRegionAveragePressureCalculator(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
@ -1579,18 +1612,19 @@ setRegionAveragePressureCalculator(const Group& group,
} }
} }
void WellGroupHelpers:: template<class Scalar>
void WellGroupHelpers<Scalar>::
updateGuideRates(const Group& group, updateGuideRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const SummaryState& summary_state, const SummaryState& summary_state,
const PhaseUsage& pu, const PhaseUsage& pu,
const int report_step, const int report_step,
const double sim_time, const double sim_time,
WellState<double>& well_state, WellState<Scalar>& well_state,
const GroupState<double>& group_state, const GroupState<Scalar>& group_state,
const Parallel::Communication& comm, const Parallel::Communication& comm,
GuideRate* guide_rate, GuideRate* guide_rate,
std::vector<double>& pot, std::vector<Scalar>& pot,
DeferredLogger& deferred_logger) DeferredLogger& deferred_logger)
{ {
guide_rate->updateGuideRateExpiration(sim_time, report_step); guide_rate->updateGuideRateExpiration(sim_time, report_step);
@ -1599,21 +1633,22 @@ updateGuideRates(const Group& group,
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 WellGroupHelpers:: template<class Scalar>
void WellGroupHelpers<Scalar>::
updateGuideRateForProductionGroups(const Group& group, updateGuideRateForProductionGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const PhaseUsage& pu, const PhaseUsage& pu,
const int reportStepIdx, const int reportStepIdx,
const double& simTime, const double& simTime,
WellState<double>& wellState, WellState<Scalar>& wellState,
const GroupState<double>& group_state, const GroupState<Scalar>& group_state,
const Parallel::Communication& comm, const Parallel::Communication& comm,
GuideRate* guideRate, GuideRate* guideRate,
std::vector<double>& pot) std::vector<Scalar>& 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<Scalar> thisPot(np, 0.0);
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx); const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
// Note that group effiency factors for groupTmp are applied in updateGuideRateForGroups // Note that group effiency factors for groupTmp are applied in updateGuideRateForGroups
@ -1659,7 +1694,7 @@ updateGuideRateForProductionGroups(const Group& group,
} }
} }
std::array<double,3> potentials{}; std::array<Scalar,3> potentials{};
auto& [oilPot, gasPot, waterPot] = potentials; auto& [oilPot, gasPot, waterPot] = potentials;
if (pu.phase_used[BlackoilPhases::Liquid]) if (pu.phase_used[BlackoilPhases::Liquid])
oilPot = pot[pu.phase_pos[BlackoilPhases::Liquid]]; oilPot = pot[pu.phase_pos[BlackoilPhases::Liquid]];
@ -1678,17 +1713,18 @@ updateGuideRateForProductionGroups(const Group& group,
guideRate->compute(group.name(), reportStepIdx, simTime, oilPot, gasPot, waterPot); guideRate->compute(group.name(), reportStepIdx, simTime, oilPot, gasPot, waterPot);
} }
void WellGroupHelpers:: template<class Scalar>
void WellGroupHelpers<Scalar>::
updateGuideRatesForWells(const Schedule& schedule, 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<Scalar>& 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<Scalar,3> potentials{};
auto& [oilpot, gaspot, waterpot] = potentials; auto& [oilpot, gaspot, waterpot] = potentials;
const auto& well_index = wellState.index(well.name()); const auto& well_index = wellState.index(well.name());
@ -1715,9 +1751,12 @@ updateGuideRatesForWells(const Schedule& schedule,
} }
} }
template class WellGroupHelpers<double>;
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::
template void WellGroupHelpers<double>::
updateGpMaintTargetForGroups<AvgPMap>(const Group&, updateGpMaintTargetForGroups<AvgPMap>(const Group&,
const Schedule&, const Schedule&,
const AvgPMap&, const AvgPMap&,
@ -1725,7 +1764,7 @@ template void WellGroupHelpers::
double, double,
const WellState<double>&, const WellState<double>&,
GroupState<double>&); GroupState<double>&);
template void WellGroupHelpers:: template void WellGroupHelpers<double>::
setRegionAveragePressureCalculator<AvgP>(const Group&, setRegionAveragePressureCalculator<AvgP>(const Group&,
const Schedule&, const Schedule&,
const int, const int,

View File

@ -43,6 +43,7 @@ class FieldPropsManager;
namespace Network { class ExtNetwork; } namespace Network { class ExtNetwork; }
template<class Scalar>
class WellGroupHelpers class WellGroupHelpers
{ {
public: public:
@ -50,41 +51,41 @@ public:
const Schedule& schedule, const Schedule& schedule,
const SummaryState& summaryState, const SummaryState& summaryState,
const int reportStepIdx, const int reportStepIdx,
GroupState<double>& group_state); GroupState<Scalar>& group_state);
static void accumulateGroupEfficiencyFactor(const Group& group, static void accumulateGroupEfficiencyFactor(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
double& factor); Scalar& factor);
static double sumWellSurfaceRates(const Group& group, static Scalar sumWellSurfaceRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
const int reportStepIdx, const int reportStepIdx,
const int phasePos, const int phasePos,
const bool injector); const bool injector);
/// Returns the name of the worst offending well and its fraction (i.e. violated_phase / preferred_phase) /// Returns the name of the worst offending well and its fraction (i.e. violated_phase / preferred_phase)
static std::pair<std::optional<std::string>, double> static std::pair<std::optional<std::string>, Scalar>
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,
const PhaseUsage& pu, const PhaseUsage& pu,
const Parallel::Communication& comm, const Parallel::Communication& comm,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
DeferredLogger& deferred_logger); DeferredLogger& deferred_logger);
static double sumWellResRates(const Group& group, static Scalar sumWellResRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
const int reportStepIdx, const int reportStepIdx,
const int phasePos, const int phasePos,
const bool injector); const bool injector);
static double sumSolventRates(const Group& group, static Scalar sumSolventRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
const int reportStepIdx, const int reportStepIdx,
const bool injector); const bool injector);
@ -94,9 +95,9 @@ public:
const bool isInjector, const bool isInjector,
const PhaseUsage& pu, const PhaseUsage& pu,
const GuideRate& guide_rate, const GuideRate& guide_rate,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
GroupState<double>& group_state, GroupState<Scalar>& group_state,
std::vector<double>& groupTargetReduction); std::vector<Scalar>& groupTargetReduction);
static void updateGuideRates(const Group& group, static void updateGuideRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
@ -104,29 +105,29 @@ public:
const PhaseUsage& pu, const PhaseUsage& pu,
int report_step, int report_step,
double sim_time, double sim_time,
WellState<double>& well_state, WellState<Scalar>& well_state,
const GroupState<double>& group_state, const GroupState<Scalar>& group_state,
const Parallel::Communication& comm, const Parallel::Communication& comm,
GuideRate* guide_rate, GuideRate* guide_rate,
std::vector<double>& pot, std::vector<Scalar>& pot,
DeferredLogger& deferred_logge); DeferredLogger& deferred_logger);
static void updateGuideRateForProductionGroups(const Group& group, static void updateGuideRateForProductionGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const PhaseUsage& pu, const PhaseUsage& pu,
const int reportStepIdx, const int reportStepIdx,
const double& simTime, const double& simTime,
WellState<double>& wellState, WellState<Scalar>& wellState,
const GroupState<double>& group_state, const GroupState<Scalar>& group_state,
const Parallel::Communication& comm, const Parallel::Communication& comm,
GuideRate* guideRate, GuideRate* guideRate,
std::vector<double>& pot); std::vector<Scalar>& pot);
static void updateGuideRatesForWells(const Schedule& schedule, static 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<Scalar>& wellState,
const Parallel::Communication& comm, const Parallel::Communication& comm,
GuideRate* guideRate); GuideRate* guideRate);
@ -135,16 +136,16 @@ public:
const SummaryState& summaryState, const SummaryState& summaryState,
const PhaseUsage& pu, const PhaseUsage& pu,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
const GroupState<double>& group_state, const GroupState<Scalar>& group_state,
GuideRate* guideRate, GuideRate* guideRate,
DeferredLogger& deferred_logger); DeferredLogger& deferred_logger);
static void updateVREPForGroups(const Group& group, static void updateVREPForGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
GroupState<double>& group_state); GroupState<Scalar>& group_state);
template <class RegionalValues> template <class RegionalValues>
static void updateGpMaintTargetForGroups(const Group& group, static void updateGpMaintTargetForGroups(const Group& group,
@ -152,81 +153,82 @@ public:
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<Scalar>& well_state,
GroupState<double>& group_state); GroupState<Scalar>& group_state);
static void updateReservoirRatesInjectionGroups(const Group& group, static void updateReservoirRatesInjectionGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
GroupState<double>& group_state); GroupState<Scalar>& group_state);
static void updateSurfaceRatesInjectionGroups(const Group& group, static void updateSurfaceRatesInjectionGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
GroupState<double>& group_state); GroupState<Scalar>& group_state);
static void updateWellRates(const Group& group, static void updateWellRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellStateNupcol, const WellState<Scalar>& wellStateNupcol,
WellState<double>& wellState); WellState<Scalar>& wellState);
static void updateGroupProductionRates(const Group& group, static void updateGroupProductionRates(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
GroupState<double>& group_state); GroupState<Scalar>& group_state);
static void updateWellRatesFromGroupTargetScale(const double scale, static void updateWellRatesFromGroupTargetScale(const Scalar scale,
const Group& group, const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
bool isInjector, bool isInjector,
const GroupState<double>& group_state, const GroupState<Scalar>& group_state,
WellState<double>& wellState); WellState<Scalar>& wellState);
static void updateREINForGroups(const Group& group, static void updateREINForGroups(const Group& group,
const Schedule& schedule, const Schedule& schedule,
const int reportStepIdx, const int reportStepIdx,
const PhaseUsage& pu, const PhaseUsage& pu,
const SummaryState& st, const SummaryState& st,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
GroupState<double>& group_state, GroupState<Scalar>& group_state,
bool sum_rank); bool sum_rank);
static std::map<std::string, double>
static std::map<std::string, Scalar>
computeNetworkPressures(const Network::ExtNetwork& network, computeNetworkPressures(const Network::ExtNetwork& network,
const WellState<double>& well_state, const WellState<Scalar>& well_state,
const GroupState<double>& group_state, const GroupState<Scalar>& 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);
static GuideRate::RateVector static GuideRate::RateVector
getWellRateVector(const WellState<double>& well_state, getWellRateVector(const WellState<Scalar>& well_state,
const PhaseUsage& pu, const PhaseUsage& pu,
const std::string& name); const std::string& name);
static GuideRate::RateVector static GuideRate::RateVector
getProductionGroupRateVector(const GroupState<double>& group_state, getProductionGroupRateVector(const GroupState<Scalar>& group_state,
const PhaseUsage& pu, const PhaseUsage& pu,
const std::string& group_name); const std::string& group_name);
static double getGuideRate(const std::string& name, static Scalar getGuideRate(const std::string& name,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
const GroupState<double>& group_state, const GroupState<Scalar>& group_state,
const int reportStepIdx, const int reportStepIdx,
const GuideRate* guideRate, const GuideRate* guideRate,
const GuideRateModel::Target target, const GuideRateModel::Target target,
const PhaseUsage& pu); const PhaseUsage& pu);
static double getGuideRateInj(const std::string& name, static Scalar getGuideRateInj(const std::string& name,
const Schedule& schedule, const Schedule& schedule,
const WellState<double>& wellState, const WellState<Scalar>& wellState,
const GroupState<double>& group_state, const GroupState<Scalar>& group_state,
const int reportStepIdx, const int reportStepIdx,
const GuideRate* guideRate, const GuideRate* guideRate,
const GuideRateModel::Target target, const GuideRateModel::Target target,
@ -234,29 +236,29 @@ public:
const PhaseUsage& pu); const PhaseUsage& pu);
static int groupControlledWells(const Schedule& schedule, static int groupControlledWells(const Schedule& schedule,
const WellState<double>& well_state, const WellState<Scalar>& well_state,
const GroupState<double>& group_state, const GroupState<Scalar>& group_state,
const int report_step, const int report_step,
const std::string& group_name, const std::string& group_name,
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);
static std::pair<bool, double> static std::pair<bool, Scalar>
checkGroupConstraintsInj(const std::string& name, 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<Scalar>& wellState,
const GroupState<double>& group_state, const GroupState<Scalar>& group_state,
const int reportStepIdx, const int reportStepIdx,
const GuideRate* guideRate, const GuideRate* guideRate,
const double* rates, const Scalar* rates,
Phase injectionPhase, Phase injectionPhase,
const PhaseUsage& pu, const PhaseUsage& pu,
const double efficiencyFactor, const Scalar efficiencyFactor,
const Schedule& schedule, const Schedule& schedule,
const SummaryState& summaryState, const SummaryState& summaryState,
const std::vector<double>& resv_coeff, const std::vector<Scalar>& resv_coeff,
DeferredLogger& deferred_logger); DeferredLogger& deferred_logger);
static std::vector<std::string> static std::vector<std::string>
@ -265,20 +267,20 @@ public:
const Schedule& schedule, const Schedule& schedule,
const int report_step); const int report_step);
static std::pair<bool, double> static std::pair<bool, Scalar>
checkGroupConstraintsProd(const std::string& name, 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<Scalar>& wellState,
const GroupState<double>& group_state, const GroupState<Scalar>& group_state,
const int reportStepIdx, const int reportStepIdx,
const GuideRate* guideRate, const GuideRate* guideRate,
const double* rates, const Scalar* rates,
const PhaseUsage& pu, const PhaseUsage& pu,
const double efficiencyFactor, const Scalar efficiencyFactor,
const Schedule& schedule, const Schedule& schedule,
const SummaryState& summaryState, const SummaryState& summaryState,
const std::vector<double>& resv_coeff, const std::vector<Scalar>& resv_coeff,
DeferredLogger& deferred_logger); DeferredLogger& deferred_logger);
template <class AverageRegionalPressureType> template <class AverageRegionalPressureType>