mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
move getGroupProductionControl into WellGroupControls
This commit is contained in:
@@ -176,6 +176,108 @@ getGroupInjectionControl(const Group& group,
|
||||
control_eq = current_rate - target_rate;
|
||||
}
|
||||
|
||||
template<class EvalWell>
|
||||
void WellGroupControls::getGroupProductionControl(const Group& group,
|
||||
const WellState& well_state,
|
||||
const GroupState& group_state,
|
||||
const Schedule& schedule,
|
||||
const SummaryState& summaryState,
|
||||
const EvalWell& bhp,
|
||||
const std::vector<EvalWell>& rates,
|
||||
const RateConvFunc& rateConverter,
|
||||
double efficiencyFactor,
|
||||
EvalWell& control_eq) const
|
||||
{
|
||||
const Group::ProductionCMode& currentGroupControl = group_state.production_control(group.name());
|
||||
if (currentGroupControl == Group::ProductionCMode::FLD ||
|
||||
currentGroupControl == Group::ProductionCMode::NONE) {
|
||||
if (!group.productionGroupControlAvailable()) {
|
||||
// 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_.wellEcl().productionControls(summaryState);
|
||||
control_eq = bhp - controls.bhp_limit;
|
||||
return;
|
||||
} else {
|
||||
// Produce share of parents control
|
||||
const auto& parent = schedule.getGroup(group.parent(), well_.currentStep());
|
||||
efficiencyFactor *= group.getGroupEfficiencyFactor();
|
||||
getGroupProductionControl(parent, well_state, group_state,
|
||||
schedule, summaryState, bhp,
|
||||
rates, rateConverter,
|
||||
efficiencyFactor, control_eq);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const auto& well = well_.wellEcl();
|
||||
const auto pu = well_.phaseUsage();
|
||||
|
||||
if (!group.isProductionGroup()) {
|
||||
// use bhp as control eq and let the updateControl code find a valid control
|
||||
const auto& controls = well.productionControls(summaryState);
|
||||
control_eq = bhp - controls.bhp_limit;
|
||||
return;
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
||||
// Make conversion factors for RESV <-> surface rates.
|
||||
std::vector<double> resv_coeff(well_.phaseUsage().num_phases, 1.0);
|
||||
rateConverter(0, well_.pvtRegionIdx(), resv_coeff); // FIPNUM region 0 here, should use FIPNUM from WELSPECS.
|
||||
|
||||
// gconsale may adjust the grat target.
|
||||
// the adjusted rates is send to the targetCalculator
|
||||
double gratTargetFromSales = 0.0;
|
||||
if (group_state.has_grat_sales_target(group.name()))
|
||||
gratTargetFromSales = group_state.grat_sales_target(group.name());
|
||||
|
||||
WellGroupHelpers::TargetCalculator tcalc(currentGroupControl, pu, resv_coeff,
|
||||
gratTargetFromSales, group.name(),
|
||||
group_state,
|
||||
group.has_gpmaint_control(currentGroupControl));
|
||||
WellGroupHelpers::FractionCalculator fcalc(schedule, well_state, group_state,
|
||||
well_.currentStep(),
|
||||
well_.guideRate(),
|
||||
tcalc.guideTargetMode(),
|
||||
pu, true, Phase::OIL);
|
||||
|
||||
auto localFraction = [&](const std::string& child) {
|
||||
return fcalc.localFraction(child, child);
|
||||
};
|
||||
|
||||
auto localReduction = [&](const std::string& group_name) {
|
||||
const std::vector<double>& groupTargetReductions = group_state.production_reduction_rates(group_name);
|
||||
return tcalc.calcModeRateFromRates(groupTargetReductions);
|
||||
};
|
||||
|
||||
const double orig_target = tcalc.groupTarget(group.productionControls(summaryState));
|
||||
const auto chain = WellGroupHelpers::groupChainTopBot(well_.name(), group.name(),
|
||||
schedule, well_.currentStep());
|
||||
// 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) {
|
||||
if ((ii == 0) || well_.guideRate()->has(chain[ii])) {
|
||||
// Apply local reductions only at the control level
|
||||
// (top) and for levels where we have a specified
|
||||
// group guide rate.
|
||||
target -= localReduction(chain[ii]);
|
||||
}
|
||||
target *= localFraction(chain[ii+1]);
|
||||
}
|
||||
// Avoid negative target rates coming from too large local reductions.
|
||||
const double target_rate = std::max(0.0, target / efficiencyFactor);
|
||||
const auto current_rate = -tcalc.calcModeRateFromRates(rates); // Switch sign since 'rates' are negative for producers.
|
||||
control_eq = current_rate - target_rate;
|
||||
}
|
||||
|
||||
#define INSTANCE(...) \
|
||||
template void WellGroupControls:: \
|
||||
getGroupInjectionControl<__VA_ARGS__>(const Group&, \
|
||||
@@ -189,7 +291,18 @@ getGroupInjectionControl<__VA_ARGS__>(const Group&, \
|
||||
const RateConvFunc& rateConverter, \
|
||||
double efficiencyFactor, \
|
||||
__VA_ARGS__& control_eq, \
|
||||
DeferredLogger& deferred_logger) const;
|
||||
DeferredLogger& deferred_logger) const; \
|
||||
template void WellGroupControls:: \
|
||||
getGroupProductionControl<__VA_ARGS__>(const Group&, \
|
||||
const WellState&, \
|
||||
const GroupState&, \
|
||||
const Schedule&, \
|
||||
const SummaryState&, \
|
||||
const __VA_ARGS__& bhp, \
|
||||
const std::vector<__VA_ARGS__>&, \
|
||||
const RateConvFunc& rateConverter, \
|
||||
double efficiencyFactor, \
|
||||
__VA_ARGS__& control_eq) const;
|
||||
|
||||
INSTANCE(DenseAd::Evaluation<double,3,0u>)
|
||||
INSTANCE(DenseAd::Evaluation<double,4,0u>)
|
||||
|
||||
@@ -62,6 +62,18 @@ public:
|
||||
EvalWell& control_eq,
|
||||
DeferredLogger& deferred_logger) const;
|
||||
|
||||
template<class EvalWell>
|
||||
void getGroupProductionControl(const Group& group,
|
||||
const WellState& well_state,
|
||||
const GroupState& group_state,
|
||||
const Schedule& schedule,
|
||||
const SummaryState& summaryState,
|
||||
const EvalWell& bhp,
|
||||
const std::vector<EvalWell>& rates,
|
||||
const RateConvFunc& rateConverter,
|
||||
double efficiencyFactor,
|
||||
EvalWell& control_eq) const;
|
||||
|
||||
private:
|
||||
const WellInterfaceGeneric& well_; //!< Reference to well interface
|
||||
};
|
||||
|
||||
@@ -49,99 +49,6 @@ WellInterfaceEval(const WellInterfaceFluidSystem<FluidSystem>& baseif)
|
||||
: baseif_(baseif)
|
||||
{}
|
||||
|
||||
template<class FluidSystem>
|
||||
template<class EvalWell>
|
||||
void
|
||||
WellInterfaceEval<FluidSystem>::
|
||||
getGroupProductionControl(const Group& group,
|
||||
const WellState& well_state,
|
||||
const GroupState& group_state,
|
||||
const Schedule& schedule,
|
||||
const SummaryState& summaryState,
|
||||
const EvalWell& bhp,
|
||||
const std::vector<EvalWell>& rates,
|
||||
EvalWell& control_eq,
|
||||
double efficiencyFactor) const
|
||||
{
|
||||
const Group::ProductionCMode& currentGroupControl = group_state.production_control(group.name());
|
||||
if (currentGroupControl == Group::ProductionCMode::FLD ||
|
||||
currentGroupControl == Group::ProductionCMode::NONE) {
|
||||
if (!group.productionGroupControlAvailable()) {
|
||||
// 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 = baseif_.wellEcl().productionControls(summaryState);
|
||||
control_eq = bhp - controls.bhp_limit;
|
||||
return;
|
||||
} else {
|
||||
// Produce share of parents control
|
||||
const auto& parent = schedule.getGroup(group.parent(), baseif_.currentStep());
|
||||
efficiencyFactor *= group.getGroupEfficiencyFactor();
|
||||
getGroupProductionControl(parent, well_state, group_state, schedule, summaryState, bhp, rates, control_eq, efficiencyFactor);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const auto& well = baseif_.wellEcl();
|
||||
const auto pu = baseif_.phaseUsage();
|
||||
|
||||
if (!group.isProductionGroup()) {
|
||||
// use bhp as control eq and let the updateControl code find a valid control
|
||||
const auto& controls = well.productionControls(summaryState);
|
||||
control_eq = bhp - controls.bhp_limit;
|
||||
return;
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
||||
// Make conversion factors for RESV <-> surface rates.
|
||||
std::vector<double> resv_coeff(baseif_.phaseUsage().num_phases, 1.0);
|
||||
baseif_.rateConverter().calcCoeff(0, baseif_.pvtRegionIdx(), resv_coeff); // FIPNUM region 0 here, should use FIPNUM from WELSPECS.
|
||||
|
||||
// gconsale may adjust the grat target.
|
||||
// the adjusted rates is send to the targetCalculator
|
||||
double gratTargetFromSales = 0.0;
|
||||
if (group_state.has_grat_sales_target(group.name()))
|
||||
gratTargetFromSales = group_state.grat_sales_target(group.name());
|
||||
|
||||
WellGroupHelpers::TargetCalculator tcalc(currentGroupControl, pu, resv_coeff, gratTargetFromSales, group.name(), group_state, group.has_gpmaint_control(currentGroupControl));
|
||||
WellGroupHelpers::FractionCalculator fcalc(schedule, well_state, group_state, baseif_.currentStep(), baseif_.guideRate(), tcalc.guideTargetMode(), pu, true, Phase::OIL);
|
||||
|
||||
auto localFraction = [&](const std::string& child) {
|
||||
return fcalc.localFraction(child, child);
|
||||
};
|
||||
|
||||
auto localReduction = [&](const std::string& group_name) {
|
||||
const std::vector<double>& groupTargetReductions = group_state.production_reduction_rates(group_name);
|
||||
return tcalc.calcModeRateFromRates(groupTargetReductions);
|
||||
};
|
||||
|
||||
const double orig_target = tcalc.groupTarget(group.productionControls(summaryState));
|
||||
const auto chain = WellGroupHelpers::groupChainTopBot(baseif_.name(), group.name(), schedule, baseif_.currentStep());
|
||||
// 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) {
|
||||
if ((ii == 0) || baseif_.guideRate()->has(chain[ii])) {
|
||||
// Apply local reductions only at the control level
|
||||
// (top) and for levels where we have a specified
|
||||
// group guide rate.
|
||||
target -= localReduction(chain[ii]);
|
||||
}
|
||||
target *= localFraction(chain[ii+1]);
|
||||
}
|
||||
// Avoid negative target rates coming from too large local reductions.
|
||||
const double target_rate = std::max(0.0, target / efficiencyFactor);
|
||||
const auto current_rate = -tcalc.calcModeRateFromRates(rates); // Switch sign since 'rates' are negative for producers.
|
||||
control_eq = current_rate - target_rate;
|
||||
}
|
||||
|
||||
template<class FluidSystem>
|
||||
template<class EvalWell>
|
||||
void
|
||||
@@ -244,7 +151,18 @@ assembleControlEqProd_(const WellState& well_state,
|
||||
active_rates[pu.phase_pos[canonical_phase]] = rates[canonical_phase];
|
||||
}
|
||||
}
|
||||
getGroupProductionControl(group, well_state, group_state, schedule, summaryState, bhp, active_rates, control_eq, efficiencyFactor);
|
||||
auto rCoeff = [this](const RegionId id, const int region, std::vector<double>& coeff)
|
||||
{
|
||||
baseif_.rateConverter().calcCoeff(id, region, coeff);
|
||||
};
|
||||
WellGroupControls(baseif_).getGroupProductionControl(group, well_state,
|
||||
group_state,
|
||||
schedule,
|
||||
summaryState,
|
||||
bhp, active_rates,
|
||||
rCoeff,
|
||||
efficiencyFactor,
|
||||
control_eq);
|
||||
break;
|
||||
}
|
||||
case Well::ProducerCMode::CMODE_UNDEFINED: {
|
||||
|
||||
@@ -56,16 +56,6 @@ public:
|
||||
const SummaryState& summaryState,
|
||||
const double rho,
|
||||
DeferredLogger& deferred_logger) const;
|
||||
template<class EvalWell>
|
||||
void getGroupProductionControl(const Group& group,
|
||||
const WellState& well_state,
|
||||
const GroupState& group_state,
|
||||
const Schedule& schedule,
|
||||
const SummaryState& summaryState,
|
||||
const EvalWell& bhp,
|
||||
const std::vector<EvalWell>& rates,
|
||||
EvalWell& control_eq,
|
||||
double efficiencyFactor) const;
|
||||
|
||||
template<class EvalWell, class BhpFromThpFunc>
|
||||
void assembleControlEqProd(const WellState& well_state,
|
||||
|
||||
Reference in New Issue
Block a user