mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Handle guide-rate based well constraints from groups.
This commit is contained in:
@@ -981,6 +981,20 @@ namespace Opm
|
||||
StandardWell<TypeTag>::
|
||||
assembleGroupInjectionControl(const Group& group, const WellState& well_state, const Opm::Schedule& schedule, const SummaryState& summaryState, const InjectorType& injectorType, EvalWell& control_eq, double efficiencyFactor, Opm::DeferredLogger& deferred_logger)
|
||||
{
|
||||
if (!group.isAvailableForGroupControl()) {
|
||||
// We cannot go any further up the hierarchy. This could
|
||||
// be the FIELD group, or any group for which this has
|
||||
// been set in GCONINJE or GCONPROD. If we are here
|
||||
// anyway, it is likely that the deck set inconsistent
|
||||
// requirements, such as GRUP control mode on a well with
|
||||
// no appropriate controls defined on any of its
|
||||
// containing groups. We will therefore use the wells' bhp
|
||||
// limit equation as a fallback.
|
||||
const auto& controls = well_ecl_.injectionControls(summaryState);
|
||||
control_eq = getBhp() - controls.bhp_limit;
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& well = well_ecl_;
|
||||
const auto pu = phaseUsage();
|
||||
|
||||
@@ -1015,31 +1029,21 @@ namespace Opm
|
||||
}
|
||||
const Group::InjectionCMode& currentGroupControl = well_state.currentInjectionGroupControl(injectionPhase, group.name());
|
||||
|
||||
if (currentGroupControl == Group::InjectionCMode::FLD) {
|
||||
if (currentGroupControl == Group::InjectionCMode::FLD ||
|
||||
currentGroupControl == Group::InjectionCMode::NONE) {
|
||||
// Inject share of parents control
|
||||
const auto& parent = schedule.getGroup( group.parent(), current_step_ );
|
||||
if (group.getTransferGroupEfficiencyFactor())
|
||||
efficiencyFactor *= group.getGroupEfficiencyFactor();
|
||||
|
||||
efficiencyFactor *= group.getGroupEfficiencyFactor();
|
||||
assembleGroupInjectionControl(parent, well_state, schedule, summaryState, injectorType, control_eq, efficiencyFactor, deferred_logger);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!group.isInjectionGroup() || currentGroupControl == Group::InjectionCMode::NONE) {
|
||||
// use bhp as control eq and let the updateControl code find a valid control
|
||||
const auto& controls = well.injectionControls(summaryState);
|
||||
control_eq = getBhp() - controls.bhp_limit;
|
||||
return;
|
||||
}
|
||||
|
||||
assert(group.hasInjectionControl(injectionPhase));
|
||||
const auto& groupcontrols = group.injectionControls(injectionPhase, summaryState);
|
||||
|
||||
|
||||
const std::vector<double>& groupInjectionReductions = well_state.currentInjectionGroupReductionRates(group.name());
|
||||
double groupTargetReduction = groupInjectionReductions[phasePos];
|
||||
double fraction = wellGroupHelpers::wellFractionFromGuideRates(well, schedule, well_state, current_step_, Base::guide_rate_, wellTarget, /*isInjector*/true);
|
||||
wellGroupHelpers::accumulateGroupInjectionPotentialFractions(well.groupName(), group.name(), schedule, well_state, pu, current_step_, injectionPhase, fraction);
|
||||
double fraction = wellGroupHelpers::fractionFromInjectionPotentials(well.name(), group.name(), schedule, well_state, current_step_, Base::guide_rate_, GuideRateModel::convert_target(wellTarget), pu, injectionPhase,false);
|
||||
switch(currentGroupControl) {
|
||||
case Group::InjectionCMode::NONE:
|
||||
{
|
||||
@@ -1049,7 +1053,7 @@ namespace Opm
|
||||
}
|
||||
case Group::InjectionCMode::RATE:
|
||||
{
|
||||
double target = std::max(0.0, (groupcontrols.surface_max_rate / efficiencyFactor - groupTargetReduction) );
|
||||
double target = std::max(0.0, (groupcontrols.surface_max_rate - groupTargetReduction)) / efficiencyFactor;
|
||||
control_eq = getWQTotal() - fraction * target;
|
||||
break;
|
||||
}
|
||||
@@ -1058,15 +1062,14 @@ namespace Opm
|
||||
std::vector<double> convert_coeff(number_of_phases_, 1.0);
|
||||
Base::rateConverter_.calcCoeff(/*fipreg*/ 0, Base::pvtRegionIdx_, convert_coeff);
|
||||
double coeff = convert_coeff[phasePos];
|
||||
double target = std::max(0.0, (groupcontrols.resv_max_rate/coeff/efficiencyFactor - groupTargetReduction));
|
||||
double target = std::max(0.0, (groupcontrols.resv_max_rate/coeff - groupTargetReduction)) / efficiencyFactor;
|
||||
control_eq = getWQTotal() - fraction * target;
|
||||
break;
|
||||
}
|
||||
case Group::InjectionCMode::REIN:
|
||||
{
|
||||
double productionRate = well_state.currentInjectionREINRates(groupcontrols.reinj_group)[phasePos];
|
||||
productionRate /= efficiencyFactor;
|
||||
double target = std::max(0.0, (groupcontrols.target_reinj_fraction*productionRate - groupTargetReduction));
|
||||
double target = std::max(0.0, (groupcontrols.target_reinj_fraction*productionRate - groupTargetReduction)) / efficiencyFactor;
|
||||
control_eq = getWQTotal() - fraction * target;
|
||||
break;
|
||||
}
|
||||
@@ -1090,9 +1093,7 @@ namespace Opm
|
||||
|
||||
voidageRate -= injReduction;
|
||||
|
||||
voidageRate /= efficiencyFactor;
|
||||
|
||||
double target = std::max(0.0, ( voidageRate/coeff - groupTargetReduction));
|
||||
double target = std::max(0.0, ( voidageRate/coeff - groupTargetReduction)) / efficiencyFactor;
|
||||
control_eq = getWQTotal() - fraction * target;
|
||||
break;
|
||||
}
|
||||
@@ -1119,8 +1120,7 @@ namespace Opm
|
||||
const auto& gconsale = schedule.gConSale(current_step_).get(group.name(), summaryState);
|
||||
inj_rate -= gconsale.sales_target;
|
||||
|
||||
inj_rate /= efficiencyFactor;
|
||||
double target = std::max(0.0, (inj_rate - groupTargetReduction));
|
||||
double target = std::max(0.0, (inj_rate - groupTargetReduction)) / efficiencyFactor;
|
||||
control_eq = getWQTotal() - fraction * target;
|
||||
break;
|
||||
}
|
||||
@@ -1139,30 +1139,94 @@ namespace Opm
|
||||
StandardWell<TypeTag>::
|
||||
assembleGroupProductionControl(const Group& group, const WellState& well_state, const Opm::Schedule& schedule, const SummaryState& summaryState, EvalWell& control_eq, double efficiencyFactor, Opm::DeferredLogger& deferred_logger)
|
||||
{
|
||||
|
||||
const auto& well = well_ecl_;
|
||||
const auto pu = phaseUsage();
|
||||
|
||||
const Group::ProductionCMode& currentGroupControl = well_state.currentProductionGroupControl(group.name());
|
||||
if (currentGroupControl == Group::ProductionCMode::FLD) {
|
||||
// Produce share of parents control
|
||||
const auto& parent = schedule.getGroup( group.parent(), current_step_ );
|
||||
if (group.getTransferGroupEfficiencyFactor())
|
||||
if (currentGroupControl == Group::ProductionCMode::FLD ||
|
||||
currentGroupControl == Group::ProductionCMode::NONE) {
|
||||
if (!group.isAvailableForGroupControl()) {
|
||||
// We cannot go any further up the hierarchy. This could
|
||||
// be the FIELD group, or any group for which this has
|
||||
// been set in GCONINJE or GCONPROD. If we are here
|
||||
// anyway, it is likely that the deck set inconsistent
|
||||
// requirements, such as GRUP control mode on a well with
|
||||
// no appropriate controls defined on any of its
|
||||
// containing groups. We will therefore use the wells' bhp
|
||||
// limit equation as a fallback.
|
||||
const auto& controls = well_ecl_.productionControls(summaryState);
|
||||
control_eq = getBhp() - controls.bhp_limit;
|
||||
return;
|
||||
} else {
|
||||
// Produce share of parents control
|
||||
const auto& parent = schedule.getGroup( group.parent(), current_step_ );
|
||||
efficiencyFactor *= group.getGroupEfficiencyFactor();
|
||||
|
||||
assembleGroupProductionControl(parent, well_state, schedule, summaryState, control_eq, efficiencyFactor, deferred_logger);
|
||||
return;
|
||||
assembleGroupProductionControl(parent, well_state, schedule, summaryState, control_eq, efficiencyFactor, deferred_logger);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!group.isProductionGroup() || currentGroupControl == Group::ProductionCMode::NONE) {
|
||||
if (!group.isProductionGroup()) {
|
||||
// use bhp as control eq and let the updateControl code find a vallied control
|
||||
const auto& controls = well.productionControls(summaryState);
|
||||
control_eq = getBhp() - controls.bhp_limit;
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& groupcontrols = group.productionControls(summaryState);
|
||||
// ------------------------------- New code start --------------------------------
|
||||
|
||||
// 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.
|
||||
wellGroupHelpers::TargetCalculator tcalc(currentGroupControl, pu, Base::rateConverter_, Base::pvtRegionIdx_);
|
||||
wellGroupHelpers::FractionCalculator fcalc(schedule, well_state, current_step_, Base::guide_rate_, tcalc.guideTargetMode());
|
||||
|
||||
auto localFraction = [&](const std::string& child) {
|
||||
return fcalc.localFraction(child, "");
|
||||
};
|
||||
|
||||
auto localReduction = [&](const std::string& group_name) {
|
||||
const std::vector<double>& groupTargetReductions = well_state.currentProductionGroupReductionRates(group_name);
|
||||
return tcalc.calcModeRateFromRates(groupTargetReductions);
|
||||
};
|
||||
|
||||
const double orig_target = tcalc.groupTarget(group.productionControls(summaryState));
|
||||
// Assume we have a chain of groups as follows: BOTTOM -> MIDDLE -> TOP.
|
||||
// Then ...
|
||||
// TODO finish explanation.
|
||||
const auto chain = wellGroupHelpers::groupChainTopBot(name(), group.name(), schedule, current_step_);
|
||||
// Because 'name' is the last of the elements, and not an ancestor, we subtract one below.
|
||||
const size_t num_ancestors = chain.size() - 1;
|
||||
double target = orig_target;
|
||||
for (size_t ii = 0; ii < num_ancestors; ++ii) {
|
||||
target -= localReduction(chain[ii]);
|
||||
// Next lines: different from in WellGroupHelpers.hpp
|
||||
// if (ii == num_ancestors - 1) {
|
||||
// // Final level. Add my reduction back.
|
||||
// target += current_rate*efficiencyFactor;
|
||||
// }
|
||||
target *= localFraction(chain[ii+1]);
|
||||
}
|
||||
const double target_rate = target / efficiencyFactor;
|
||||
|
||||
std::vector<EvalWell> rates(pu.num_phases);
|
||||
const int compIndices[3] = { FluidSystem::waterCompIdx, FluidSystem::oilCompIdx, FluidSystem::gasCompIdx };
|
||||
const BlackoilPhases::PhaseIndex phases[3] = { BlackoilPhases::Aqua, BlackoilPhases::Liquid, BlackoilPhases::Vapour };
|
||||
for (int canonical_phase = 0; canonical_phase < 3; ++canonical_phase) {
|
||||
const auto phase = phases[canonical_phase];
|
||||
if (pu.phase_used[phase]) {
|
||||
const auto compIdx = compIndices[canonical_phase];
|
||||
rates[pu.phase_pos[phase]] = getQs(Indices::canonicalToActiveComponentIndex(compIdx));
|
||||
}
|
||||
}
|
||||
const auto current_rate = -tcalc.calcModeRateFromRates(rates); // Switch sign since 'rates' are negative for producers.
|
||||
|
||||
control_eq = current_rate - target_rate;
|
||||
|
||||
// ------------------------------- New code end --------------------------------
|
||||
|
||||
|
||||
#if 0
|
||||
const auto& groupcontrols = group.productionControls(summaryState);
|
||||
const std::vector<double>& groupTargetReductions = well_state.currentProductionGroupReductionRates(group.name());
|
||||
|
||||
switch(currentGroupControl) {
|
||||
@@ -1174,10 +1238,9 @@ namespace Opm
|
||||
case Group::ProductionCMode::ORAT:
|
||||
{
|
||||
double groupTargetReduction = groupTargetReductions[pu.phase_pos[Oil]];
|
||||
double fraction = wellGroupHelpers::wellFractionFromGuideRates(well, schedule, well_state, current_step_, Base::guide_rate_, Well::GuideRateTarget::OIL, /*isInjector*/false);
|
||||
wellGroupHelpers::accumulateGroupFractionsFromGuideRates(well.groupName(), group.name(), schedule, well_state, current_step_, Base::guide_rate_, Group::GuideRateTarget::OIL, fraction);
|
||||
double fraction = wellGroupHelpers::fractionFromGuideRates(well.name(), group.name(), schedule, well_state, current_step_, Base::guide_rate_, GuideRateModel::convert_target(Well::GuideRateTarget::OIL));
|
||||
|
||||
const double rate_target = std::max(0.0, groupcontrols.oil_target / efficiencyFactor - groupTargetReduction);
|
||||
const double rate_target = std::max(0.0, groupcontrols.oil_target - groupTargetReduction) / efficiencyFactor;
|
||||
assert(FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx));
|
||||
EvalWell rate = -getQs(Indices::canonicalToActiveComponentIndex(FluidSystem::oilCompIdx));
|
||||
control_eq = rate - fraction * rate_target;
|
||||
@@ -1186,10 +1249,9 @@ namespace Opm
|
||||
case Group::ProductionCMode::WRAT:
|
||||
{
|
||||
double groupTargetReduction = groupTargetReductions[pu.phase_pos[Water]];
|
||||
double fraction = wellGroupHelpers::wellFractionFromGuideRates(well, schedule, well_state, current_step_, Base::guide_rate_, Well::GuideRateTarget::WAT, /*isInjector*/false);
|
||||
wellGroupHelpers::accumulateGroupFractionsFromGuideRates(well.groupName(), group.name(), schedule, well_state, current_step_, Base::guide_rate_, Group::GuideRateTarget::WAT, fraction);
|
||||
double fraction = wellGroupHelpers::fractionFromGuideRates(well.name(), group.name(), schedule, well_state, current_step_, Base::guide_rate_, GuideRateModel::convert_target(Well::GuideRateTarget::WAT));
|
||||
|
||||
const double rate_target = std::max(0.0, groupcontrols.water_target / efficiencyFactor - groupTargetReduction);
|
||||
const double rate_target = std::max(0.0, groupcontrols.water_target - groupTargetReduction) / efficiencyFactor;
|
||||
assert(FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx));
|
||||
EvalWell rate = -getQs(Indices::canonicalToActiveComponentIndex(FluidSystem::waterCompIdx));
|
||||
control_eq = rate - fraction * rate_target;
|
||||
@@ -1198,10 +1260,9 @@ namespace Opm
|
||||
case Group::ProductionCMode::GRAT:
|
||||
{
|
||||
double groupTargetReduction = groupTargetReductions[pu.phase_pos[Gas]];
|
||||
double fraction = wellGroupHelpers::wellFractionFromGuideRates(well, schedule, well_state, current_step_, Base::guide_rate_, Well::GuideRateTarget::GAS, /*isInjector*/false);
|
||||
wellGroupHelpers::accumulateGroupFractionsFromGuideRates(well.groupName(), group.name(), schedule, well_state, current_step_, Base::guide_rate_, Group::GuideRateTarget::GAS, fraction);
|
||||
double fraction = wellGroupHelpers::fractionFromGuideRates(well.name(), group.name(), schedule, well_state, current_step_, Base::guide_rate_, GuideRateModel::convert_target(Well::GuideRateTarget::GAS));
|
||||
|
||||
const double rate_target = std::max(0.0, groupcontrols.gas_target / efficiencyFactor - groupTargetReduction);
|
||||
const double rate_target = std::max(0.0, groupcontrols.gas_target - groupTargetReduction) / efficiencyFactor;
|
||||
assert(FluidSystem::phaseIsActive(FluidSystem::gasCompIdx));
|
||||
EvalWell rate = -getQs(Indices::canonicalToActiveComponentIndex(FluidSystem::gasCompIdx));
|
||||
control_eq = rate - fraction * rate_target;
|
||||
@@ -1210,10 +1271,9 @@ namespace Opm
|
||||
case Group::ProductionCMode::LRAT:
|
||||
{
|
||||
double groupTargetReduction = groupTargetReductions[pu.phase_pos[Oil]] + groupTargetReductions[pu.phase_pos[Water]];
|
||||
double fraction = wellGroupHelpers::wellFractionFromGuideRates(well, schedule, well_state, current_step_, Base::guide_rate_, Well::GuideRateTarget::LIQ, /*isInjector*/false);
|
||||
wellGroupHelpers::accumulateGroupFractionsFromGuideRates(well.groupName(), group.name(), schedule, well_state, current_step_, Base::guide_rate_, Group::GuideRateTarget::LIQ, fraction);
|
||||
double fraction = wellGroupHelpers::fractionFromGuideRates(well.name(), group.name(), schedule, well_state, current_step_, Base::guide_rate_, GuideRateModel::convert_target(Well::GuideRateTarget::LIQ));
|
||||
|
||||
const double rate_target = std::max(0.0, groupcontrols.liquid_target / efficiencyFactor - groupTargetReduction);
|
||||
const double rate_target = std::max(0.0, groupcontrols.liquid_target - groupTargetReduction) / efficiencyFactor;
|
||||
assert(FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx));
|
||||
|
||||
EvalWell rate = -getQs(Indices::canonicalToActiveComponentIndex(FluidSystem::waterCompIdx))
|
||||
@@ -1232,8 +1292,7 @@ namespace Opm
|
||||
+ groupTargetReductions[pu.phase_pos[Gas]]
|
||||
+ groupTargetReductions[pu.phase_pos[Water]];
|
||||
|
||||
double fraction = wellGroupHelpers::wellFractionFromGuideRates(well, schedule, well_state, current_step_, Base::guide_rate_, Well::GuideRateTarget::RES, /*isInjector*/false);
|
||||
wellGroupHelpers::accumulateGroupFractionsFromGuideRates(well.groupName(), group.name(), schedule, well_state, current_step_, Base::guide_rate_, Group::GuideRateTarget::RES, fraction);
|
||||
double fraction = wellGroupHelpers::fractionFromGuideRates(well.name(), group.name(), schedule, well_state, current_step_, Base::guide_rate_, GuideRateModel::convert_target(Well::GuideRateTarget::RES));
|
||||
|
||||
EvalWell total_rate(numWellEq_ + numEq, 0.); // reservoir rate
|
||||
std::vector<double> convert_coeff(number_of_phases_, 1.0);
|
||||
@@ -1242,7 +1301,7 @@ namespace Opm
|
||||
total_rate -= getQs( flowPhaseToEbosCompIdx(phase) ) * convert_coeff[phase];
|
||||
}
|
||||
|
||||
const double rate_target = std::max(0.0, groupcontrols.resv_target/ efficiencyFactor - groupTargetReduction);
|
||||
const double rate_target = std::max(0.0, groupcontrols.resv_target - groupTargetReduction) / efficiencyFactor;
|
||||
assert(FluidSystem::phaseIsActive(FluidSystem::gasCompIdx));
|
||||
control_eq = total_rate - fraction * rate_target;
|
||||
break;
|
||||
@@ -1262,6 +1321,7 @@ namespace Opm
|
||||
default:
|
||||
OPM_DEFLOG_THROW(std::runtime_error, "Unvallied group control specified for group " + well.groupName(), deferred_logger );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user