mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
move getGroupInjectionTargetRate into WellGroupControls
This commit is contained in:
parent
cdbeef0a3e
commit
2d4c522082
@ -34,6 +34,7 @@
|
||||
#include <opm/simulators/wells/WellGroupHelpers.hpp>
|
||||
#include <opm/simulators/wells/WellInterfaceGeneric.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
namespace Opm
|
||||
@ -176,6 +177,118 @@ getGroupInjectionControl(const Group& group,
|
||||
control_eq = current_rate - target_rate;
|
||||
}
|
||||
|
||||
std::optional<double>
|
||||
WellGroupControls::
|
||||
getGroupInjectionTargetRate(const Group& group,
|
||||
const WellState& well_state,
|
||||
const GroupState& group_state,
|
||||
const Schedule& schedule,
|
||||
const SummaryState& summaryState,
|
||||
const InjectorType& injectorType,
|
||||
const RateConvFunc& rateConverter,
|
||||
double efficiencyFactor,
|
||||
DeferredLogger& deferred_logger) const
|
||||
{
|
||||
// Setting some defaults to silence warnings below.
|
||||
// Will be overwritten in the switch statement.
|
||||
Phase injectionPhase = Phase::WATER;
|
||||
switch (injectorType) {
|
||||
case InjectorType::WATER:
|
||||
{
|
||||
injectionPhase = Phase::WATER;
|
||||
break;
|
||||
}
|
||||
case InjectorType::OIL:
|
||||
{
|
||||
injectionPhase = Phase::OIL;
|
||||
break;
|
||||
}
|
||||
case InjectorType::GAS:
|
||||
{
|
||||
injectionPhase = Phase::GAS;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// Should not be here.
|
||||
assert(false);
|
||||
}
|
||||
|
||||
auto currentGroupControl = group_state.injection_control(group.name(), injectionPhase);
|
||||
if (currentGroupControl == Group::InjectionCMode::FLD ||
|
||||
currentGroupControl == Group::InjectionCMode::NONE) {
|
||||
if (!group.injectionGroupControlAvailable(injectionPhase)) {
|
||||
// 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.
|
||||
return std::nullopt;
|
||||
} else {
|
||||
// Inject share of parents control
|
||||
const auto& parent = schedule.getGroup( group.parent(), well_.currentStep());
|
||||
efficiencyFactor *= group.getGroupEfficiencyFactor();
|
||||
return getGroupInjectionTargetRate(parent, well_state, group_state,
|
||||
schedule, summaryState, injectorType,
|
||||
rateConverter, efficiencyFactor, deferred_logger);
|
||||
}
|
||||
}
|
||||
|
||||
const auto pu = well_.phaseUsage();
|
||||
|
||||
if (!group.isInjectionGroup()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// 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(pu.num_phases, 1.0);
|
||||
rateConverter(0, well_.pvtRegionIdx(), resv_coeff); // FIPNUM region 0 here, should use FIPNUM from WELSPECS.
|
||||
|
||||
double sales_target = 0;
|
||||
if (schedule[well_.currentStep()].gconsale().has(group.name())) {
|
||||
const auto& gconsale = schedule[well_.currentStep()].gconsale().get(group.name(), summaryState);
|
||||
sales_target = gconsale.sales_target;
|
||||
}
|
||||
WellGroupHelpers::InjectionTargetCalculator tcalc(currentGroupControl, pu, resv_coeff,
|
||||
group.name(), sales_target, group_state,
|
||||
injectionPhase,
|
||||
group.has_gpmaint_control(injectionPhase, currentGroupControl),
|
||||
deferred_logger);
|
||||
WellGroupHelpers::FractionCalculator fcalc(schedule, well_state, group_state,
|
||||
well_.currentStep(), well_.guideRate(),
|
||||
tcalc.guideTargetMode(), pu, false, injectionPhase);
|
||||
|
||||
auto localFraction = [&](const std::string& child) {
|
||||
return fcalc.localFraction(child, child); //Note child needs to be passed to always include since the global isGrup map is not updated yet.
|
||||
};
|
||||
|
||||
auto localReduction = [&](const std::string& group_name) {
|
||||
const std::vector<double>& groupTargetReductions = group_state.injection_reduction_rates(group_name);
|
||||
return tcalc.calcModeRateFromRates(groupTargetReductions);
|
||||
};
|
||||
|
||||
const double orig_target = tcalc.groupTarget(group.injectionControls(injectionPhase, summaryState), deferred_logger);
|
||||
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], injectionPhase)) {
|
||||
// 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]);
|
||||
}
|
||||
return std::max(0.0, target / efficiencyFactor);
|
||||
}
|
||||
|
||||
template<class EvalWell>
|
||||
void WellGroupControls::getGroupProductionControl(const Group& group,
|
||||
const WellState& well_state,
|
||||
|
@ -25,6 +25,7 @@
|
||||
#define OPM_WELL_GROUP_CONTROLS_HEADER_INCLUDED
|
||||
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
namespace Opm
|
||||
@ -62,6 +63,17 @@ public:
|
||||
EvalWell& control_eq,
|
||||
DeferredLogger& deferred_logger) const;
|
||||
|
||||
std::optional<double>
|
||||
getGroupInjectionTargetRate(const Group& group,
|
||||
const WellState& well_state,
|
||||
const GroupState& group_state,
|
||||
const Schedule& schedule,
|
||||
const SummaryState& summaryState,
|
||||
const InjectorType& injectorType,
|
||||
const RateConvFunc& rateConverter,
|
||||
double efficiencyFactor,
|
||||
DeferredLogger& deferred_logger) const;
|
||||
|
||||
template<class EvalWell>
|
||||
void getGroupProductionControl(const Group& group,
|
||||
const WellState& well_state,
|
||||
|
@ -531,96 +531,16 @@ getGroupInjectionTargetRate(const Group& group,
|
||||
double efficiencyFactor,
|
||||
DeferredLogger& deferred_logger) const
|
||||
{
|
||||
// Setting some defaults to silence warnings below.
|
||||
// Will be overwritten in the switch statement.
|
||||
Phase injectionPhase = Phase::WATER;
|
||||
switch (injectorType) {
|
||||
case InjectorType::WATER:
|
||||
auto rCoeff = [this](const int id, const int region, std::vector<double>& coeff)
|
||||
{
|
||||
injectionPhase = Phase::WATER;
|
||||
break;
|
||||
}
|
||||
case InjectorType::OIL:
|
||||
{
|
||||
injectionPhase = Phase::OIL;
|
||||
break;
|
||||
}
|
||||
case InjectorType::GAS:
|
||||
{
|
||||
injectionPhase = Phase::GAS;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// Should not be here.
|
||||
assert(false);
|
||||
}
|
||||
|
||||
auto currentGroupControl = group_state.injection_control(group.name(), injectionPhase);
|
||||
if (currentGroupControl == Group::InjectionCMode::FLD ||
|
||||
currentGroupControl == Group::InjectionCMode::NONE) {
|
||||
if (!group.injectionGroupControlAvailable(injectionPhase)) {
|
||||
// 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.
|
||||
return std::nullopt;
|
||||
} else {
|
||||
// Inject share of parents control
|
||||
const auto& parent = schedule.getGroup( group.parent(), currentStep());
|
||||
efficiencyFactor *= group.getGroupEfficiencyFactor();
|
||||
return getGroupInjectionTargetRate(parent, well_state, group_state, schedule, summaryState, injectorType, efficiencyFactor, deferred_logger);
|
||||
}
|
||||
}
|
||||
|
||||
const auto pu = phaseUsage();
|
||||
|
||||
if (!group.isInjectionGroup()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
// 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(pu.num_phases, 1.0);
|
||||
rateConverter_.calcCoeff(0, pvtRegionIdx(), resv_coeff); // FIPNUM region 0 here, should use FIPNUM from WELSPECS.
|
||||
|
||||
double sales_target = 0;
|
||||
if (schedule[currentStep()].gconsale().has(group.name())) {
|
||||
const auto& gconsale = schedule[currentStep()].gconsale().get(group.name(), summaryState);
|
||||
sales_target = gconsale.sales_target;
|
||||
}
|
||||
WellGroupHelpers::InjectionTargetCalculator tcalc(currentGroupControl, pu, resv_coeff, group.name(), sales_target, group_state, injectionPhase, group.has_gpmaint_control(injectionPhase, currentGroupControl), deferred_logger);
|
||||
WellGroupHelpers::FractionCalculator fcalc(schedule, well_state, group_state, currentStep(), guideRate(), tcalc.guideTargetMode(), pu, false, injectionPhase);
|
||||
|
||||
auto localFraction = [&](const std::string& child) {
|
||||
return fcalc.localFraction(child, child); //Note child needs to be passed to always include since the global isGrup map is not updated yet.
|
||||
this->rateConverter().calcCoeff(id, region, coeff);
|
||||
};
|
||||
|
||||
auto localReduction = [&](const std::string& group_name) {
|
||||
const std::vector<double>& groupTargetReductions = group_state.injection_reduction_rates(group_name);
|
||||
return tcalc.calcModeRateFromRates(groupTargetReductions);
|
||||
};
|
||||
|
||||
const double orig_target = tcalc.groupTarget(group.injectionControls(injectionPhase, summaryState), deferred_logger);
|
||||
const auto chain = WellGroupHelpers::groupChainTopBot(name(), group.name(), schedule, 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) || guideRate()->has(chain[ii], injectionPhase)) {
|
||||
// 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]);
|
||||
}
|
||||
return std::max(0.0, target / efficiencyFactor);
|
||||
return WellGroupControls(*this).getGroupInjectionTargetRate(group, well_state,
|
||||
group_state, schedule,
|
||||
summaryState, injectorType,
|
||||
rCoeff, efficiencyFactor,
|
||||
deferred_logger);
|
||||
}
|
||||
template<typename FluidSystem>
|
||||
double
|
||||
|
Loading…
Reference in New Issue
Block a user