2020-03-27 07:27:45 -05:00
|
|
|
/*
|
|
|
|
Copyright 2019 Norce.
|
|
|
|
Copyright 2020 Equinor ASA.
|
|
|
|
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-12-08 14:17:58 -06:00
|
|
|
#include <config.h>
|
2020-03-27 07:27:45 -05:00
|
|
|
#include <opm/simulators/wells/WellGroupHelpers.hpp>
|
2021-04-30 04:33:40 -05:00
|
|
|
|
2022-09-01 07:43:47 -05:00
|
|
|
#include <opm/input/eclipse/Schedule/Schedule.hpp>
|
2021-12-14 01:30:15 -06:00
|
|
|
#include <opm/input/eclipse/Schedule/Group/GConSump.hpp>
|
|
|
|
#include <opm/input/eclipse/Schedule/Group/GConSale.hpp>
|
2022-09-01 07:43:47 -05:00
|
|
|
#include <opm/input/eclipse/Schedule/Group/GPMaint.hpp>
|
|
|
|
#include <opm/input/eclipse/Schedule/Group/Group.hpp>
|
2023-01-10 05:37:34 -06:00
|
|
|
#include <opm/input/eclipse/Schedule/Network/ExtNetwork.hpp>
|
2023-01-18 02:58:45 -06:00
|
|
|
#include <opm/input/eclipse/Schedule/Well/Well.hpp>
|
2022-09-01 07:43:47 -05:00
|
|
|
|
|
|
|
#include <opm/material/fluidsystems/BlackOilFluidSystem.hpp>
|
|
|
|
|
2021-04-30 04:33:40 -05:00
|
|
|
#include <opm/simulators/utils/DeferredLogger.hpp>
|
2021-04-29 02:01:03 -05:00
|
|
|
#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
|
2022-09-01 07:47:18 -05:00
|
|
|
#include <opm/simulators/utils/ParallelCommunication.hpp>
|
2022-09-01 07:43:47 -05:00
|
|
|
|
|
|
|
#include <opm/simulators/wells/GroupState.hpp>
|
|
|
|
#include <opm/simulators/wells/RegionAverageCalculator.hpp>
|
2021-04-30 04:33:40 -05:00
|
|
|
#include <opm/simulators/wells/TargetCalculator.hpp>
|
|
|
|
#include <opm/simulators/wells/VFPProdProperties.hpp>
|
2021-05-20 06:32:18 -05:00
|
|
|
#include <opm/simulators/wells/WellState.hpp>
|
2021-04-30 02:48:15 -05:00
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
#include <algorithm>
|
2021-04-30 02:48:15 -05:00
|
|
|
#include <cassert>
|
|
|
|
#include <set>
|
2020-05-15 04:21:32 -05:00
|
|
|
#include <stack>
|
2022-09-01 07:43:47 -05:00
|
|
|
#include <stdexcept>
|
2020-03-27 07:27:45 -05:00
|
|
|
|
2020-07-20 10:00:00 -05:00
|
|
|
namespace {
|
|
|
|
Opm::GuideRate::RateVector
|
|
|
|
getGuideRateVector(const std::vector<double>& rates, const Opm::PhaseUsage& pu)
|
|
|
|
{
|
|
|
|
using Opm::BlackoilPhases;
|
|
|
|
|
|
|
|
double oilRate = 0.0;
|
|
|
|
if (pu.phase_used[BlackoilPhases::Liquid])
|
|
|
|
oilRate = rates[pu.phase_pos[BlackoilPhases::Liquid]];
|
|
|
|
|
|
|
|
double gasRate = 0.0;
|
|
|
|
if (pu.phase_used[BlackoilPhases::Vapour])
|
|
|
|
gasRate = rates[pu.phase_pos[BlackoilPhases::Vapour]];
|
|
|
|
|
|
|
|
double waterRate = 0.0;
|
|
|
|
if (pu.phase_used[BlackoilPhases::Aqua])
|
|
|
|
waterRate = rates[pu.phase_pos[BlackoilPhases::Aqua]];
|
|
|
|
|
|
|
|
return {oilRate, gasRate, waterRate};
|
|
|
|
}
|
2021-08-23 10:49:21 -05:00
|
|
|
|
|
|
|
double sumWellPhaseRates(bool res_rates,
|
|
|
|
const Opm::Group& group,
|
|
|
|
const Opm::Schedule& schedule,
|
|
|
|
const Opm::WellState& wellState,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const int phasePos,
|
|
|
|
const bool injector)
|
|
|
|
{
|
|
|
|
|
|
|
|
double rate = 0.0;
|
|
|
|
for (const std::string& groupName : group.groups()) {
|
|
|
|
const auto& groupTmp = schedule.getGroup(groupName, reportStepIdx);
|
|
|
|
const auto& gefac = groupTmp.getGroupEfficiencyFactor();
|
|
|
|
rate += gefac * sumWellPhaseRates(res_rates, groupTmp, schedule, wellState, reportStepIdx, phasePos, injector);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const std::string& wellName : group.wells()) {
|
2021-08-06 06:18:18 -05:00
|
|
|
const auto& well_index = wellState.index(wellName);
|
|
|
|
if (!well_index.has_value())
|
2021-08-23 10:49:21 -05:00
|
|
|
continue;
|
|
|
|
|
2021-08-06 06:18:18 -05:00
|
|
|
if (! wellState.wellIsOwned(well_index.value(), wellName) ) // Only sum once
|
2021-08-23 10:49:21 -05:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& wellEcl = schedule.getWell(wellName, reportStepIdx);
|
|
|
|
// only count producers or injectors
|
|
|
|
if ((wellEcl.isProducer() && injector) || (wellEcl.isInjector() && !injector))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (wellEcl.getStatus() == Opm::Well::Status::SHUT)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
double factor = wellEcl.getEfficiencyFactor();
|
2021-08-06 06:18:18 -05:00
|
|
|
const auto& ws = wellState.well(well_index.value());
|
2021-08-23 10:49:21 -05:00
|
|
|
if (res_rates) {
|
2021-08-06 03:45:13 -05:00
|
|
|
const auto& well_rates = ws.reservoir_rates;
|
2021-08-23 10:49:21 -05:00
|
|
|
if (injector)
|
|
|
|
rate += factor * well_rates[phasePos];
|
|
|
|
else
|
|
|
|
rate -= factor * well_rates[phasePos];
|
|
|
|
} else {
|
2021-08-24 04:49:03 -05:00
|
|
|
const auto& well_rates = ws.surface_rates;
|
2021-08-23 10:49:21 -05:00
|
|
|
if (injector)
|
|
|
|
rate += factor * well_rates[phasePos];
|
|
|
|
else
|
|
|
|
rate -= factor * well_rates[phasePos];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rate;
|
|
|
|
}
|
2020-07-20 10:00:00 -05:00
|
|
|
} // namespace Anonymous
|
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
namespace Opm
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
namespace WellGroupHelpers
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
void setCmodeGroup(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const SummaryState& summaryState,
|
|
|
|
const int reportStepIdx,
|
2021-05-20 06:32:18 -05:00
|
|
|
WellState& wellState,
|
2021-04-22 10:31:21 -05:00
|
|
|
GroupState& group_state)
|
2020-03-27 07:27:45 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
for (const std::string& groupName : group.groups()) {
|
2021-04-22 10:31:21 -05:00
|
|
|
setCmodeGroup(schedule.getGroup(groupName, reportStepIdx), schedule, summaryState, reportStepIdx, wellState, group_state);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// use NONE as default control
|
|
|
|
const Phase all[] = {Phase::WATER, Phase::OIL, Phase::GAS};
|
|
|
|
for (Phase phase : all) {
|
2021-04-22 10:31:21 -05:00
|
|
|
if (!group_state.has_injection_control(group.name(), phase)) {
|
|
|
|
group_state.injection_control(group.name(), phase, Group::InjectionCMode::NONE);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
}
|
2021-04-22 10:31:21 -05:00
|
|
|
if (!group_state.has_production_control(group.name())) {
|
|
|
|
group_state.production_control(group.name(), Group::ProductionCMode::NONE);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
2021-01-10 14:46:45 -06:00
|
|
|
const auto& events = schedule[reportStepIdx].wellgroup_events();
|
2020-03-27 07:27:45 -05:00
|
|
|
if (group.isInjectionGroup()
|
2021-01-10 14:46:45 -06:00
|
|
|
&& events.hasEvent(group.name(), ScheduleEvents::GROUP_INJECTION_UPDATE)) {
|
2020-03-27 07:27:45 -05:00
|
|
|
|
|
|
|
for (Phase phase : all) {
|
|
|
|
if (!group.hasInjectionControl(phase))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const auto& controls = group.injectionControls(phase, summaryState);
|
2021-04-22 10:31:21 -05:00
|
|
|
group_state.injection_control(group.name(), phase, controls.cmode);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (group.isProductionGroup()
|
2021-01-10 14:46:45 -06:00
|
|
|
&& events.hasEvent(group.name(), ScheduleEvents::GROUP_PRODUCTION_UPDATE)) {
|
2020-03-27 07:27:45 -05:00
|
|
|
const auto controls = group.productionControls(summaryState);
|
2021-04-22 10:31:21 -05:00
|
|
|
group_state.production_control(group.name(), controls.cmode);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
2021-09-01 08:04:54 -05:00
|
|
|
if (group.has_gpmaint_control(Group::ProductionCMode::RESV)) {
|
|
|
|
group_state.production_control(group.name(), Group::ProductionCMode::RESV);
|
|
|
|
}
|
|
|
|
for (Phase phase : all) {
|
|
|
|
if (group.has_gpmaint_control(phase, Group::InjectionCMode::RATE)) {
|
|
|
|
group_state.injection_control(group.name(), phase, Group::InjectionCMode::RATE);
|
|
|
|
} else if (group.has_gpmaint_control(phase, Group::InjectionCMode::RESV)) {
|
|
|
|
group_state.injection_control(group.name(), phase, Group::InjectionCMode::RESV);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-12 11:29:59 -06:00
|
|
|
if (schedule[reportStepIdx].gconsale().has(group.name())) {
|
2021-04-22 10:31:21 -05:00
|
|
|
group_state.injection_control(group.name(), Phase::GAS, Group::InjectionCMode::SALE);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void accumulateGroupEfficiencyFactor(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const int reportStepIdx,
|
|
|
|
double& factor)
|
|
|
|
{
|
|
|
|
factor *= group.getGroupEfficiencyFactor();
|
2023-04-26 04:51:57 -05:00
|
|
|
if (group.parent() != "FIELD" && !group.parent().empty())
|
2020-03-27 07:27:45 -05:00
|
|
|
accumulateGroupEfficiencyFactor(
|
|
|
|
schedule.getGroup(group.parent(), reportStepIdx), schedule, reportStepIdx, factor);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-23 10:49:21 -05:00
|
|
|
double sumWellSurfaceRates(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const WellState& wellState,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const int phasePos,
|
|
|
|
const bool injector)
|
2020-03-27 07:27:45 -05:00
|
|
|
{
|
2021-08-23 10:49:21 -05:00
|
|
|
return sumWellPhaseRates(false, group, schedule, wellState, reportStepIdx, phasePos, injector);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
double sumWellResRates(const Group& group,
|
|
|
|
const Schedule& schedule,
|
2021-05-20 06:32:18 -05:00
|
|
|
const WellState& wellState,
|
2020-03-27 07:27:45 -05:00
|
|
|
const int reportStepIdx,
|
|
|
|
const int phasePos,
|
|
|
|
const bool injector)
|
|
|
|
{
|
2021-08-23 10:49:21 -05:00
|
|
|
return sumWellPhaseRates(true, group, schedule, wellState, reportStepIdx, phasePos, injector);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
double sumSolventRates(const Group& group,
|
|
|
|
const Schedule& schedule,
|
2021-05-20 06:32:18 -05:00
|
|
|
const WellState& wellState,
|
2020-03-27 07:27:45 -05:00
|
|
|
const int reportStepIdx,
|
|
|
|
const bool injector)
|
|
|
|
{
|
|
|
|
|
|
|
|
double rate = 0.0;
|
|
|
|
for (const std::string& groupName : group.groups()) {
|
|
|
|
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
|
2021-08-06 04:47:30 -05:00
|
|
|
const auto& gefac = groupTmp.getGroupEfficiencyFactor();
|
|
|
|
rate += gefac * sumSolventRates(groupTmp, schedule, wellState, reportStepIdx, injector);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
2021-08-06 06:18:18 -05:00
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
for (const std::string& wellName : group.wells()) {
|
2021-08-06 06:18:18 -05:00
|
|
|
const auto& well_index = wellState.index(wellName);
|
|
|
|
if (!well_index.has_value())
|
2020-03-27 07:27:45 -05:00
|
|
|
continue;
|
|
|
|
|
2021-08-06 06:18:18 -05:00
|
|
|
if (! wellState.wellIsOwned(well_index.value(), wellName) ) // Only sum once
|
2020-11-17 12:45:29 -06:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
const auto& wellEcl = schedule.getWell(wellName, reportStepIdx);
|
|
|
|
// only count producers or injectors
|
|
|
|
if ((wellEcl.isProducer() && injector) || (wellEcl.isInjector() && !injector))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (wellEcl.getStatus() == Well::Status::SHUT)
|
|
|
|
continue;
|
|
|
|
|
2021-09-27 05:06:54 -05:00
|
|
|
const auto& ws = wellState.well(well_index.value());
|
2020-03-27 07:27:45 -05:00
|
|
|
double factor = wellEcl.getEfficiencyFactor();
|
|
|
|
if (injector)
|
2021-09-27 05:06:54 -05:00
|
|
|
rate += factor * ws.sum_solvent_rates();
|
2020-03-27 07:27:45 -05:00
|
|
|
else
|
2021-09-27 05:06:54 -05:00
|
|
|
rate -= factor * ws.sum_solvent_rates();
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
2021-08-06 04:47:30 -05:00
|
|
|
return rate;
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
2021-03-10 07:26:04 -06:00
|
|
|
void updateGuideRatesForInjectionGroups(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const SummaryState& summaryState,
|
|
|
|
const Opm::PhaseUsage& pu,
|
|
|
|
const int reportStepIdx,
|
2021-05-20 06:32:18 -05:00
|
|
|
const WellState& wellState,
|
2021-04-22 10:31:21 -05:00
|
|
|
const GroupState& group_state,
|
2021-03-18 05:58:05 -05:00
|
|
|
GuideRate* guideRate,
|
|
|
|
Opm::DeferredLogger& deferred_logger)
|
2021-03-10 07:26:04 -06:00
|
|
|
{
|
|
|
|
for (const std::string& groupName : group.groups()) {
|
|
|
|
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
|
2021-04-22 10:31:21 -05:00
|
|
|
updateGuideRatesForInjectionGroups(groupTmp, schedule, summaryState, pu, reportStepIdx, wellState, group_state, guideRate, deferred_logger);
|
2021-03-10 07:26:04 -06:00
|
|
|
}
|
|
|
|
const Phase all[] = {Phase::WATER, Phase::OIL, Phase::GAS};
|
|
|
|
for (Phase phase : all) {
|
|
|
|
|
|
|
|
if(!group.hasInjectionControl(phase))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
double guideRateValue = 0.0;
|
|
|
|
const auto& controls = group.injectionControls(phase, summaryState);
|
|
|
|
switch (controls.guide_rate_def){
|
|
|
|
case Group::GuideRateInjTarget::RATE:
|
|
|
|
break;
|
|
|
|
case Group::GuideRateInjTarget::VOID:
|
|
|
|
{
|
2021-04-22 10:31:21 -05:00
|
|
|
guideRateValue = group_state.injection_vrep_rate(group.name());
|
2021-03-10 07:26:04 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Group::GuideRateInjTarget::NETV:
|
|
|
|
{
|
2021-04-22 10:31:21 -05:00
|
|
|
guideRateValue = group_state.injection_vrep_rate(group.name());
|
|
|
|
const std::vector<double>& injRES = group_state.injection_reservoir_rates(group.name());
|
2021-03-10 07:26:04 -06:00
|
|
|
if (phase != Phase::OIL && pu.phase_used[BlackoilPhases::Liquid])
|
|
|
|
guideRateValue -= injRES[pu.phase_pos[BlackoilPhases::Liquid]];
|
|
|
|
if (phase != Phase::GAS && pu.phase_used[BlackoilPhases::Vapour])
|
|
|
|
guideRateValue -= injRES[pu.phase_pos[BlackoilPhases::Vapour]];
|
|
|
|
if (phase != Phase::WATER && pu.phase_used[BlackoilPhases::Aqua])
|
|
|
|
guideRateValue -= injRES[pu.phase_pos[BlackoilPhases::Aqua]];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Group::GuideRateInjTarget::RESV:
|
2021-03-18 05:58:05 -05:00
|
|
|
OPM_DEFLOG_THROW(std::runtime_error, "GUIDE PHASE RESV not implemented. Group " + group.name(), deferred_logger);
|
2021-03-10 07:26:04 -06:00
|
|
|
case Group::GuideRateInjTarget::POTN:
|
|
|
|
break;
|
|
|
|
case Group::GuideRateInjTarget::NO_GUIDE_RATE:
|
|
|
|
break;
|
|
|
|
default:
|
2021-03-18 05:58:05 -05:00
|
|
|
OPM_DEFLOG_THROW(std::logic_error,
|
|
|
|
"Invalid GuideRateInjTarget in updateGuideRatesForInjectionGroups",
|
|
|
|
deferred_logger);
|
2021-03-10 07:26:04 -06:00
|
|
|
}
|
2021-06-17 16:56:02 -05:00
|
|
|
|
|
|
|
const UnitSystem& unit_system = schedule.getUnits();
|
|
|
|
guideRateValue = unit_system.from_si(UnitSystem::measure::rate, guideRateValue);
|
2021-03-16 09:56:03 -05:00
|
|
|
guideRate->compute(group.name(), phase, reportStepIdx, guideRateValue);
|
2021-03-10 07:26:04 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
void updateGroupTargetReduction(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const bool isInjector,
|
|
|
|
const PhaseUsage& pu,
|
2020-04-22 04:16:20 -05:00
|
|
|
const GuideRate& guide_rate,
|
2021-09-15 02:47:31 -05:00
|
|
|
const WellState& wellState,
|
2021-04-22 10:31:21 -05:00
|
|
|
GroupState& group_state,
|
2020-03-27 07:27:45 -05:00
|
|
|
std::vector<double>& groupTargetReduction)
|
|
|
|
{
|
|
|
|
const int np = wellState.numPhases();
|
|
|
|
for (const std::string& subGroupName : group.groups()) {
|
|
|
|
std::vector<double> subGroupTargetReduction(np, 0.0);
|
|
|
|
const Group& subGroup = schedule.getGroup(subGroupName, reportStepIdx);
|
2020-04-22 04:16:20 -05:00
|
|
|
updateGroupTargetReduction(subGroup,
|
|
|
|
schedule,
|
|
|
|
reportStepIdx,
|
|
|
|
isInjector,
|
|
|
|
pu,
|
|
|
|
guide_rate,
|
|
|
|
wellState,
|
2021-04-22 10:31:21 -05:00
|
|
|
group_state,
|
2020-04-22 04:16:20 -05:00
|
|
|
subGroupTargetReduction);
|
2020-03-27 07:27:45 -05:00
|
|
|
|
2021-08-06 04:47:30 -05:00
|
|
|
const double subGroupEfficiency = subGroup.getGroupEfficiencyFactor();
|
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
// accumulate group contribution from sub group
|
|
|
|
if (isInjector) {
|
|
|
|
const Phase all[] = {Phase::WATER, Phase::OIL, Phase::GAS};
|
|
|
|
for (Phase phase : all) {
|
2023-02-15 01:51:28 -06:00
|
|
|
|
|
|
|
int phase_pos = -1;
|
|
|
|
switch (phase) {
|
|
|
|
case Phase::GAS:
|
|
|
|
if (pu.phase_used[BlackoilPhases::Vapour]) {
|
|
|
|
phase_pos = pu.phase_pos[BlackoilPhases::Vapour];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Phase::OIL:
|
|
|
|
if (pu.phase_used[BlackoilPhases::Liquid]) {
|
|
|
|
phase_pos = pu.phase_pos[BlackoilPhases::Liquid];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Phase::WATER:
|
|
|
|
if (pu.phase_used[BlackoilPhases::Aqua]) {
|
|
|
|
phase_pos = pu.phase_pos[BlackoilPhases::Aqua];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// just to avoid warning
|
|
|
|
throw std::invalid_argument("unhandled phase enum");
|
|
|
|
}
|
|
|
|
|
|
|
|
// the phase is not present
|
|
|
|
if (phase_pos == -1)
|
|
|
|
continue;
|
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
const Group::InjectionCMode& currentGroupControl
|
2021-05-27 06:16:28 -05:00
|
|
|
= group_state.injection_control(subGroup.name(), phase);
|
2023-02-15 01:51:28 -06:00
|
|
|
const bool individual_control = (currentGroupControl != Group::InjectionCMode::FLD
|
2021-05-27 06:16:28 -05:00
|
|
|
&& currentGroupControl != Group::InjectionCMode::NONE);
|
2023-02-15 01:51:28 -06:00
|
|
|
const int num_group_controlled_wells
|
|
|
|
= groupControlledWells(schedule, wellState, group_state, reportStepIdx, subGroupName, "", !isInjector, phase);
|
|
|
|
if (individual_control || num_group_controlled_wells == 0) {
|
|
|
|
groupTargetReduction[phase_pos]
|
|
|
|
+= subGroupEfficiency * sumWellSurfaceRates(subGroup, schedule, wellState, reportStepIdx, phase_pos, isInjector);
|
|
|
|
} else {
|
2021-05-27 06:16:28 -05:00
|
|
|
// Accumulate from this subgroup only if no group guide rate is set for it.
|
2023-02-15 01:51:28 -06:00
|
|
|
if (!guide_rate.has(subGroupName, phase)) {
|
|
|
|
groupTargetReduction[phase_pos] += subGroupEfficiency * subGroupTargetReduction[phase_pos];
|
2021-05-27 06:16:28 -05:00
|
|
|
}
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2021-04-22 10:31:21 -05:00
|
|
|
const Group::ProductionCMode& currentGroupControl = group_state.production_control(subGroupName);
|
2020-03-27 07:27:45 -05:00
|
|
|
const bool individual_control = (currentGroupControl != Group::ProductionCMode::FLD
|
|
|
|
&& currentGroupControl != Group::ProductionCMode::NONE);
|
|
|
|
const int num_group_controlled_wells
|
2021-09-15 02:47:31 -05:00
|
|
|
= groupControlledWells(schedule, wellState, group_state, reportStepIdx, subGroupName, "", !isInjector, /*injectionPhaseNotUsed*/Phase::OIL);
|
2020-03-27 07:27:45 -05:00
|
|
|
if (individual_control || num_group_controlled_wells == 0) {
|
|
|
|
for (int phase = 0; phase < np; phase++) {
|
|
|
|
groupTargetReduction[phase]
|
2021-09-15 02:47:31 -05:00
|
|
|
+= subGroupEfficiency * sumWellSurfaceRates(subGroup, schedule, wellState, reportStepIdx, phase, isInjector);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
} else {
|
2020-04-22 04:16:20 -05:00
|
|
|
// The subgroup may participate in group control.
|
2021-03-16 09:56:03 -05:00
|
|
|
if (!guide_rate.has(subGroupName)) {
|
2020-04-22 04:16:20 -05:00
|
|
|
// Accumulate from this subgroup only if no group guide rate is set for it.
|
|
|
|
for (int phase = 0; phase < np; phase++) {
|
2021-08-06 04:47:30 -05:00
|
|
|
groupTargetReduction[phase] += subGroupEfficiency * subGroupTargetReduction[phase];
|
2020-04-22 04:16:20 -05:00
|
|
|
}
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-22 04:16:20 -05:00
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
for (const std::string& wellName : group.wells()) {
|
|
|
|
const auto& wellTmp = schedule.getWell(wellName, reportStepIdx);
|
|
|
|
|
|
|
|
if (wellTmp.isProducer() && isInjector)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (wellTmp.isInjector() && !isInjector)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (wellTmp.getStatus() == Well::Status::SHUT)
|
|
|
|
continue;
|
|
|
|
|
2021-08-06 06:18:18 -05:00
|
|
|
const auto& well_index = wellState.index(wellName);
|
|
|
|
if (!well_index.has_value())
|
2020-03-27 07:27:45 -05:00
|
|
|
continue;
|
|
|
|
|
2021-08-06 06:18:18 -05:00
|
|
|
if (! wellState.wellIsOwned(well_index.value(), wellName) ) // Only sum once
|
2020-11-17 12:45:29 -06:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
const double efficiency = wellTmp.getEfficiencyFactor();
|
|
|
|
// add contributino from wells not under group control
|
2021-08-06 06:18:18 -05:00
|
|
|
const auto& ws = wellState.well(well_index.value());
|
2020-03-27 07:27:45 -05:00
|
|
|
if (isInjector) {
|
2021-08-04 05:03:36 -05:00
|
|
|
if (ws.injection_cmode != Well::InjectorCMode::GRUP)
|
2020-03-27 07:27:45 -05:00
|
|
|
for (int phase = 0; phase < np; phase++) {
|
2021-09-15 02:47:31 -05:00
|
|
|
groupTargetReduction[phase] += ws.surface_rates[phase] * efficiency;
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
} else {
|
2021-08-04 05:03:36 -05:00
|
|
|
if (ws.production_cmode != Well::ProducerCMode::GRUP)
|
2020-03-27 07:27:45 -05:00
|
|
|
for (int phase = 0; phase < np; phase++) {
|
2021-09-15 02:47:31 -05:00
|
|
|
groupTargetReduction[phase] -= ws.surface_rates[phase] * efficiency;
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isInjector)
|
2021-04-22 10:31:21 -05:00
|
|
|
group_state.update_injection_reduction_rates(group.name(), groupTargetReduction);
|
2020-03-27 07:27:45 -05:00
|
|
|
else
|
2021-04-22 10:31:21 -05:00
|
|
|
group_state.update_production_reduction_rates(group.name(), groupTargetReduction);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
2021-06-09 08:15:12 -05:00
|
|
|
void updateWellRatesFromGroupTargetScale(const double scale,
|
|
|
|
const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const int reportStepIdx,
|
|
|
|
bool isInjector,
|
|
|
|
const GroupState& group_state,
|
|
|
|
WellState& wellState) {
|
|
|
|
for (const std::string& groupName : group.groups()) {
|
|
|
|
bool individual_control = false;
|
|
|
|
if (isInjector) {
|
|
|
|
const Phase all[] = {Phase::WATER, Phase::OIL, Phase::GAS};
|
|
|
|
for (Phase phase : all) {
|
|
|
|
const Group::InjectionCMode& currentGroupControl
|
|
|
|
= group_state.injection_control(groupName, phase);
|
|
|
|
individual_control = individual_control || (currentGroupControl != Group::InjectionCMode::FLD
|
|
|
|
&& currentGroupControl != Group::InjectionCMode::NONE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const Group::ProductionCMode& currentGroupControl = group_state.production_control(groupName);
|
|
|
|
individual_control = (currentGroupControl != Group::ProductionCMode::FLD
|
|
|
|
&& currentGroupControl != Group::ProductionCMode::NONE);
|
|
|
|
}
|
|
|
|
if (!individual_control) {
|
|
|
|
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
|
|
|
|
updateWellRatesFromGroupTargetScale(scale, groupTmp, schedule, reportStepIdx, isInjector, group_state, wellState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const int np = wellState.numPhases();
|
|
|
|
for (const std::string& wellName : group.wells()) {
|
|
|
|
const auto& wellTmp = schedule.getWell(wellName, reportStepIdx);
|
|
|
|
|
|
|
|
if (wellTmp.isProducer() && isInjector)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (wellTmp.isInjector() && !isInjector)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (wellTmp.getStatus() == Well::Status::SHUT)
|
|
|
|
continue;
|
|
|
|
|
2021-08-06 06:18:18 -05:00
|
|
|
const auto& well_index = wellState.index(wellName);
|
|
|
|
if (!well_index.has_value())
|
2021-06-09 08:15:12 -05:00
|
|
|
continue;
|
|
|
|
|
2021-08-06 06:18:18 -05:00
|
|
|
if (! wellState.wellIsOwned(well_index.value(), wellName) ) // Only sum once
|
2021-06-09 08:15:12 -05:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// scale rates
|
2021-08-06 06:18:18 -05:00
|
|
|
auto& ws = wellState.well(well_index.value());
|
2021-06-09 08:15:12 -05:00
|
|
|
if (isInjector) {
|
2021-08-04 05:03:36 -05:00
|
|
|
if (ws.injection_cmode == Well::InjectorCMode::GRUP)
|
2021-06-09 08:15:12 -05:00
|
|
|
for (int phase = 0; phase < np; phase++) {
|
2021-08-24 04:49:03 -05:00
|
|
|
ws.surface_rates[phase] *= scale;
|
2021-06-09 08:15:12 -05:00
|
|
|
}
|
|
|
|
} else {
|
2021-08-04 05:03:36 -05:00
|
|
|
if (ws.production_cmode == Well::ProducerCMode::GRUP)
|
2021-06-09 08:15:12 -05:00
|
|
|
for (int phase = 0; phase < np; phase++) {
|
2021-08-24 04:49:03 -05:00
|
|
|
ws.surface_rates[phase] *= scale;
|
2021-06-09 08:15:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
|
|
|
|
void updateVREPForGroups(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const int reportStepIdx,
|
2021-09-15 02:47:31 -05:00
|
|
|
const WellState& wellState,
|
2021-04-22 10:31:21 -05:00
|
|
|
GroupState& group_state)
|
2020-03-27 07:27:45 -05:00
|
|
|
{
|
|
|
|
for (const std::string& groupName : group.groups()) {
|
|
|
|
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
|
2021-09-15 02:47:31 -05:00
|
|
|
updateVREPForGroups(groupTmp, schedule, reportStepIdx, wellState, group_state);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
const int np = wellState.numPhases();
|
|
|
|
double resv = 0.0;
|
|
|
|
for (int phase = 0; phase < np; ++phase) {
|
2021-08-23 10:49:21 -05:00
|
|
|
resv += sumWellPhaseRates(true,
|
2020-03-27 07:27:45 -05:00
|
|
|
group,
|
|
|
|
schedule,
|
2021-09-15 02:47:31 -05:00
|
|
|
wellState,
|
2020-03-27 07:27:45 -05:00
|
|
|
reportStepIdx,
|
|
|
|
phase,
|
|
|
|
/*isInjector*/ false);
|
|
|
|
}
|
2021-04-22 10:31:21 -05:00
|
|
|
group_state.update_injection_vrep_rate(group.name(), resv);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void updateReservoirRatesInjectionGroups(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const int reportStepIdx,
|
2021-09-15 02:47:31 -05:00
|
|
|
const WellState& wellState,
|
2021-04-22 10:31:21 -05:00
|
|
|
GroupState& group_state)
|
2020-03-27 07:27:45 -05:00
|
|
|
{
|
|
|
|
for (const std::string& groupName : group.groups()) {
|
|
|
|
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
|
2021-09-15 02:47:31 -05:00
|
|
|
updateReservoirRatesInjectionGroups(groupTmp, schedule, reportStepIdx, wellState, group_state);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
const int np = wellState.numPhases();
|
|
|
|
std::vector<double> resv(np, 0.0);
|
|
|
|
for (int phase = 0; phase < np; ++phase) {
|
2021-08-23 10:49:21 -05:00
|
|
|
resv[phase] = sumWellPhaseRates(true,
|
2020-03-27 07:27:45 -05:00
|
|
|
group,
|
|
|
|
schedule,
|
2021-09-15 02:47:31 -05:00
|
|
|
wellState,
|
2020-03-27 07:27:45 -05:00
|
|
|
reportStepIdx,
|
|
|
|
phase,
|
|
|
|
/*isInjector*/ true);
|
|
|
|
}
|
2021-04-22 10:31:21 -05:00
|
|
|
group_state.update_injection_reservoir_rates(group.name(), resv);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
2021-09-01 08:04:54 -05:00
|
|
|
void updateSurfaceRatesInjectionGroups(const Group& group,
|
2021-09-06 08:02:20 -05:00
|
|
|
const Schedule& schedule,
|
|
|
|
const int reportStepIdx,
|
2021-09-15 02:47:31 -05:00
|
|
|
const WellState& wellState,
|
2021-09-06 08:02:20 -05:00
|
|
|
GroupState& group_state)
|
2021-09-01 08:04:54 -05:00
|
|
|
{
|
|
|
|
for (const std::string& groupName : group.groups()) {
|
|
|
|
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
|
2021-09-15 02:47:31 -05:00
|
|
|
updateSurfaceRatesInjectionGroups(groupTmp, schedule, reportStepIdx, wellState, group_state);
|
2021-09-01 08:04:54 -05:00
|
|
|
}
|
2021-09-15 02:47:31 -05:00
|
|
|
const int np = wellState.numPhases();
|
2021-09-01 08:04:54 -05:00
|
|
|
std::vector<double> rates(np, 0.0);
|
|
|
|
for (int phase = 0; phase < np; ++phase) {
|
|
|
|
rates[phase] = sumWellPhaseRates(false,
|
|
|
|
group,
|
|
|
|
schedule,
|
2021-09-15 02:47:31 -05:00
|
|
|
wellState,
|
2021-09-01 08:04:54 -05:00
|
|
|
reportStepIdx,
|
|
|
|
phase,
|
|
|
|
/*isInjector*/ true);
|
|
|
|
}
|
|
|
|
group_state.update_injection_surface_rates(group.name(), rates);
|
|
|
|
}
|
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
void updateWellRates(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const int reportStepIdx,
|
2021-05-20 06:32:18 -05:00
|
|
|
const WellState& wellStateNupcol,
|
|
|
|
WellState& wellState)
|
2020-03-27 07:27:45 -05:00
|
|
|
{
|
|
|
|
for (const std::string& groupName : group.groups()) {
|
|
|
|
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
|
|
|
|
updateWellRates(groupTmp, schedule, reportStepIdx, wellStateNupcol, wellState);
|
|
|
|
}
|
|
|
|
const int np = wellState.numPhases();
|
|
|
|
for (const std::string& wellName : group.wells()) {
|
|
|
|
std::vector<double> rates(np, 0.0);
|
2021-08-06 06:18:18 -05:00
|
|
|
const auto& well_index = wellState.index(wellName);
|
|
|
|
if (well_index.has_value()) { // the well is found on this node
|
2020-03-27 07:27:45 -05:00
|
|
|
const auto& wellTmp = schedule.getWell(wellName, reportStepIdx);
|
|
|
|
int sign = 1;
|
|
|
|
// production wellRates are negative. The users of currentWellRates uses the convention in
|
|
|
|
// opm-common that production and injection rates are positive.
|
|
|
|
if (!wellTmp.isInjector())
|
|
|
|
sign = -1;
|
2021-08-06 06:18:18 -05:00
|
|
|
const auto& ws = wellStateNupcol.well(well_index.value());
|
2020-03-27 07:27:45 -05:00
|
|
|
for (int phase = 0; phase < np; ++phase) {
|
2021-08-24 04:49:03 -05:00
|
|
|
rates[phase] = sign * ws.surface_rates[phase];
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
wellState.setCurrentWellRates(wellName, rates);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateGroupProductionRates(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const int reportStepIdx,
|
2021-09-15 02:47:31 -05:00
|
|
|
const WellState& wellState,
|
2021-04-22 10:31:21 -05:00
|
|
|
GroupState& group_state)
|
2020-03-27 07:27:45 -05:00
|
|
|
{
|
|
|
|
for (const std::string& groupName : group.groups()) {
|
|
|
|
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
|
2021-09-15 02:47:31 -05:00
|
|
|
updateGroupProductionRates(groupTmp, schedule, reportStepIdx, wellState, group_state);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
const int np = wellState.numPhases();
|
|
|
|
std::vector<double> rates(np, 0.0);
|
|
|
|
for (int phase = 0; phase < np; ++phase) {
|
2021-09-15 02:47:31 -05:00
|
|
|
rates[phase] = sumWellPhaseRates(false, group, schedule, wellState, reportStepIdx, phase, /*isInjector*/ false);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
2021-04-22 10:31:21 -05:00
|
|
|
group_state.update_production_rates(group.name(), rates);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
2021-03-10 07:26:04 -06:00
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
void updateREINForGroups(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const PhaseUsage& pu,
|
|
|
|
const SummaryState& st,
|
2021-09-15 02:47:31 -05:00
|
|
|
const WellState& wellState,
|
2021-04-22 10:31:21 -05:00
|
|
|
GroupState& group_state)
|
2020-03-27 07:27:45 -05:00
|
|
|
{
|
|
|
|
const int np = wellState.numPhases();
|
|
|
|
for (const std::string& groupName : group.groups()) {
|
|
|
|
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
|
2021-09-15 02:47:31 -05:00
|
|
|
updateREINForGroups(groupTmp, schedule, reportStepIdx, pu, st, wellState, group_state);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<double> rein(np, 0.0);
|
|
|
|
for (int phase = 0; phase < np; ++phase) {
|
2021-09-15 02:47:31 -05:00
|
|
|
rein[phase] = sumWellPhaseRates(false, group, schedule, wellState, reportStepIdx, phase, /*isInjector*/ false);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
2021-07-02 07:56:19 -05:00
|
|
|
// add import rate and subtract consumption rate for group for gas
|
2021-01-12 11:29:59 -06:00
|
|
|
if (schedule[reportStepIdx].gconsump().has(group.name())) {
|
|
|
|
const auto& gconsump = schedule[reportStepIdx].gconsump().get(group.name(), st);
|
2020-03-27 07:27:45 -05:00
|
|
|
if (pu.phase_used[BlackoilPhases::Vapour]) {
|
|
|
|
rein[pu.phase_pos[BlackoilPhases::Vapour]] += gconsump.import_rate;
|
|
|
|
rein[pu.phase_pos[BlackoilPhases::Vapour]] -= gconsump.consumption_rate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-22 10:31:21 -05:00
|
|
|
group_state.update_injection_rein_rates(group.name(), rein);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
2020-05-15 04:21:32 -05:00
|
|
|
|
2022-09-01 07:43:47 -05:00
|
|
|
template <class RegionalValues>
|
|
|
|
void updateGpMaintTargetForGroups(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const RegionalValues& regional_values,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const double dt,
|
|
|
|
const WellState& well_state,
|
|
|
|
GroupState& group_state)
|
|
|
|
{
|
|
|
|
for (const std::string& groupName : group.groups()) {
|
|
|
|
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
|
|
|
|
updateGpMaintTargetForGroups(groupTmp, schedule, regional_values, reportStepIdx, dt, well_state, group_state);
|
|
|
|
}
|
|
|
|
const auto& gpm = group.gpmaint();
|
|
|
|
if (!gpm)
|
|
|
|
return;
|
|
|
|
|
2022-11-09 09:49:07 -06:00
|
|
|
const auto& region = gpm->region();
|
|
|
|
if (!region)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto [name, number] = *region;
|
2023-01-11 03:49:51 -06:00
|
|
|
const double error = gpm->pressure_target() - regional_values.at(name)->pressure(number);
|
2022-09-01 07:43:47 -05:00
|
|
|
double current_rate = 0.0;
|
|
|
|
const auto& pu = well_state.phaseUsage();
|
|
|
|
double sign = 1.0;
|
|
|
|
switch (gpm->flow_target()) {
|
|
|
|
case GPMaint::FlowTarget::RESV_PROD:
|
|
|
|
{
|
|
|
|
current_rate = -group_state.injection_vrep_rate(group.name());
|
|
|
|
sign = -1.0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GPMaint::FlowTarget::RESV_OINJ:
|
|
|
|
{
|
|
|
|
if (pu.phase_used[BlackoilPhases::Liquid])
|
|
|
|
current_rate = group_state.injection_reservoir_rates(group.name())[pu.phase_pos[BlackoilPhases::Liquid]];
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GPMaint::FlowTarget::RESV_WINJ:
|
|
|
|
{
|
|
|
|
if (pu.phase_used[BlackoilPhases::Aqua])
|
|
|
|
current_rate = group_state.injection_reservoir_rates(group.name())[pu.phase_pos[BlackoilPhases::Aqua]];
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GPMaint::FlowTarget::RESV_GINJ:
|
|
|
|
{
|
|
|
|
if (pu.phase_used[BlackoilPhases::Vapour])
|
|
|
|
current_rate = group_state.injection_reservoir_rates(group.name())[pu.phase_pos[BlackoilPhases::Vapour]];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GPMaint::FlowTarget::SURF_OINJ:
|
|
|
|
{
|
|
|
|
if (pu.phase_used[BlackoilPhases::Liquid])
|
|
|
|
current_rate = group_state.injection_surface_rates(group.name())[pu.phase_pos[BlackoilPhases::Liquid]];
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GPMaint::FlowTarget::SURF_WINJ:
|
|
|
|
{
|
|
|
|
if (pu.phase_used[BlackoilPhases::Aqua])
|
|
|
|
current_rate = group_state.injection_surface_rates(group.name())[pu.phase_pos[BlackoilPhases::Aqua]];
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GPMaint::FlowTarget::SURF_GINJ:
|
|
|
|
{
|
|
|
|
if (pu.phase_used[BlackoilPhases::Vapour])
|
|
|
|
current_rate = group_state.injection_surface_rates(group.name())[pu.phase_pos[BlackoilPhases::Vapour]];
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
throw std::invalid_argument("Invalid Flow target type in GPMAINT");
|
|
|
|
}
|
|
|
|
auto& gpmaint_state = group_state.gpmaint(group.name());
|
|
|
|
double rate = gpm->rate(gpmaint_state, current_rate, error, dt);
|
|
|
|
group_state.update_gpmaint_target(group.name(), std::max(0.0, sign * rate));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-15 04:21:32 -05:00
|
|
|
|
|
|
|
|
|
|
|
std::map<std::string, double>
|
|
|
|
computeNetworkPressures(const Opm::Network::ExtNetwork& network,
|
2021-05-20 06:32:18 -05:00
|
|
|
const WellState& well_state,
|
2021-04-22 10:31:21 -05:00
|
|
|
const GroupState& group_state,
|
2020-11-09 08:04:45 -06:00
|
|
|
const VFPProdProperties& vfp_prod_props,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const int report_time_step)
|
2020-05-15 04:21:32 -05:00
|
|
|
{
|
|
|
|
// TODO: Only dealing with production networks for now.
|
|
|
|
|
|
|
|
if (!network.active()) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fixed pressure nodes of the network are the roots of trees.
|
|
|
|
// Leaf nodes must correspond to groups in the group structure.
|
|
|
|
// Let us first find all leaf nodes of the network. We also
|
|
|
|
// create a vector of all nodes, ordered so that a child is
|
|
|
|
// always after its parent.
|
|
|
|
std::stack<std::string> children;
|
|
|
|
std::set<std::string> leaf_nodes;
|
|
|
|
std::vector<std::string> root_to_child_nodes;
|
|
|
|
children.push(network.root().name());
|
|
|
|
while (!children.empty()) {
|
|
|
|
const auto node = children.top();
|
|
|
|
children.pop();
|
|
|
|
root_to_child_nodes.push_back(node);
|
|
|
|
auto branches = network.downtree_branches(node);
|
|
|
|
if (branches.empty()) {
|
|
|
|
leaf_nodes.insert(node);
|
|
|
|
}
|
|
|
|
for (const auto& branch : branches) {
|
|
|
|
children.push(branch.downtree_node());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(children.empty());
|
|
|
|
|
|
|
|
// Starting with the leaf nodes of the network, get the flow rates
|
|
|
|
// from the corresponding groups.
|
|
|
|
std::map<std::string, std::vector<double>> node_inflows;
|
|
|
|
for (const auto& node : leaf_nodes) {
|
2021-04-22 10:31:21 -05:00
|
|
|
node_inflows[node] = group_state.production_rates(node);
|
2020-11-09 08:04:45 -06:00
|
|
|
// Add the ALQ amounts to the gas rates if requested.
|
|
|
|
if (network.node(node).add_gas_lift_gas()) {
|
|
|
|
const auto& group = schedule.getGroup(node, report_time_step);
|
|
|
|
for (const std::string& wellname : group.wells()) {
|
2021-12-08 08:54:12 -06:00
|
|
|
const Well& well = schedule.getWell(wellname, report_time_step);
|
|
|
|
// Here we use the efficiency unconditionally, but if WEFAC item 3
|
|
|
|
// for the well is false (it defaults to true) then we should NOT use
|
|
|
|
// the efficiency factor. Fixing this requires not only changing the
|
|
|
|
// code here, but also:
|
|
|
|
// - Adding a member to the well for this flag, and setting it in Schedule::handleWEFAC().
|
|
|
|
// - 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
|
|
|
|
// rates, but ONLY for network calculations.
|
|
|
|
const double efficiency = well.getEfficiencyFactor();
|
|
|
|
node_inflows[node][BlackoilPhases::Vapour] += well_state.getALQ(wellname) * efficiency;
|
2020-11-09 08:04:45 -06:00
|
|
|
}
|
|
|
|
}
|
2020-05-15 04:21:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Accumulate in the network, towards the roots. Note that a
|
|
|
|
// root (i.e. fixed pressure node) can still be contributing
|
|
|
|
// flow towards other nodes in the network, i.e. a node is
|
|
|
|
// the root of a subtree.
|
|
|
|
auto child_to_root_nodes = root_to_child_nodes;
|
|
|
|
std::reverse(child_to_root_nodes.begin(), child_to_root_nodes.end());
|
|
|
|
for (const auto& node : child_to_root_nodes) {
|
|
|
|
const auto upbranch = network.uptree_branch(node);
|
|
|
|
if (upbranch) {
|
|
|
|
// Add downbranch rates to upbranch.
|
|
|
|
std::vector<double>& up = node_inflows[(*upbranch).uptree_node()];
|
|
|
|
const std::vector<double>& down = node_inflows[node];
|
|
|
|
if (up.empty()) {
|
|
|
|
up = down;
|
|
|
|
} else {
|
|
|
|
assert (up.size() == down.size());
|
|
|
|
for (size_t ii = 0; ii < up.size(); ++ii) {
|
|
|
|
up[ii] += down[ii];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Going the other way (from roots to leafs), calculate the pressure
|
|
|
|
// at each node using VFP tables and rates.
|
|
|
|
std::map<std::string, double> node_pressures;
|
|
|
|
for (const auto& node : root_to_child_nodes) {
|
|
|
|
auto press = network.node(node).terminal_pressure();
|
|
|
|
if (press) {
|
|
|
|
node_pressures[node] = *press;
|
|
|
|
} else {
|
|
|
|
const auto upbranch = network.uptree_branch(node);
|
|
|
|
assert(upbranch);
|
|
|
|
const double up_press = node_pressures[(*upbranch).uptree_node()];
|
|
|
|
const auto vfp_table = (*upbranch).vfp_table();
|
|
|
|
if (vfp_table) {
|
|
|
|
// The rates are here positive, but the VFP code expects the
|
|
|
|
// convention that production rates are negative, so we must
|
|
|
|
// take a copy and flip signs.
|
|
|
|
auto rates = node_inflows[node];
|
|
|
|
for (auto& r : rates) { r *= -1.0; }
|
|
|
|
assert(rates.size() == 3);
|
|
|
|
const double alq = 0.0; // TODO: Do not ignore ALQ
|
|
|
|
node_pressures[node] = vfp_prod_props.bhp(*vfp_table,
|
|
|
|
rates[BlackoilPhases::Aqua],
|
|
|
|
rates[BlackoilPhases::Liquid],
|
|
|
|
rates[BlackoilPhases::Vapour],
|
|
|
|
up_press,
|
2022-02-22 08:25:10 -06:00
|
|
|
alq,
|
|
|
|
0.0, //explicit_wfr
|
|
|
|
0.0, //explicit_gfr
|
2022-04-08 03:15:13 -05:00
|
|
|
false); //use_expvfp we dont support explicit lookup
|
2020-10-15 07:15:05 -05:00
|
|
|
#define EXTRA_DEBUG_NETWORK 0
|
2020-05-15 04:21:32 -05:00
|
|
|
#if EXTRA_DEBUG_NETWORK
|
|
|
|
std::ostringstream oss;
|
|
|
|
oss << "parent: " << (*upbranch).uptree_node() << " child: " << node
|
|
|
|
<< " rates = [ " << rates[0]*86400 << ", " << rates[1]*86400 << ", " << rates[2]*86400 << " ]"
|
|
|
|
<< " p(parent) = " << up_press/1e5 << " p(child) = " << node_pressures[node]/1e5 << std::endl;
|
|
|
|
OpmLog::debug(oss.str());
|
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
// Table number specified as 9999 in the deck, no pressure loss.
|
|
|
|
node_pressures[node] = up_press;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return node_pressures;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
GuideRate::RateVector
|
2021-05-20 06:32:18 -05:00
|
|
|
getWellRateVector(const WellState& well_state, const PhaseUsage& pu, const std::string& name)
|
2020-03-27 07:27:45 -05:00
|
|
|
{
|
2020-07-20 10:00:00 -05:00
|
|
|
return getGuideRateVector(well_state.currentWellRates(name), pu);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
2020-07-20 10:00:00 -05:00
|
|
|
GuideRate::RateVector
|
2021-04-22 10:31:21 -05:00
|
|
|
getProductionGroupRateVector(const GroupState& group_state, const PhaseUsage& pu, const std::string& group_name)
|
2020-07-20 10:00:00 -05:00
|
|
|
{
|
2021-04-22 10:31:21 -05:00
|
|
|
return getGuideRateVector(group_state.production_rates(group_name), pu);
|
2020-07-20 10:00:00 -05:00
|
|
|
}
|
2020-03-27 07:27:45 -05:00
|
|
|
|
|
|
|
double getGuideRate(const std::string& name,
|
|
|
|
const Schedule& schedule,
|
2021-05-20 06:32:18 -05:00
|
|
|
const WellState& wellState,
|
2021-04-22 10:31:21 -05:00
|
|
|
const GroupState& group_state,
|
2020-03-27 07:27:45 -05:00
|
|
|
const int reportStepIdx,
|
|
|
|
const GuideRate* guideRate,
|
|
|
|
const GuideRateModel::Target target,
|
|
|
|
const PhaseUsage& pu)
|
|
|
|
{
|
2021-03-10 07:26:04 -06:00
|
|
|
if (schedule.hasWell(name, reportStepIdx)) {
|
2023-04-26 07:23:42 -05:00
|
|
|
if (guideRate->has(name) || guideRate->hasPotentials(name)) {
|
|
|
|
return guideRate->get(name, target, getWellRateVector(wellState, pu, name));
|
|
|
|
} else {
|
|
|
|
return 0.0;
|
|
|
|
}
|
2021-03-10 07:26:04 -06:00
|
|
|
}
|
|
|
|
|
2021-03-16 09:56:03 -05:00
|
|
|
if (guideRate->has(name)) {
|
2021-04-22 10:31:21 -05:00
|
|
|
return guideRate->get(name, target, getProductionGroupRateVector(group_state, pu, name));
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
double totalGuideRate = 0.0;
|
|
|
|
const Group& group = schedule.getGroup(name, reportStepIdx);
|
|
|
|
|
|
|
|
for (const std::string& groupName : group.groups()) {
|
2021-04-22 10:31:21 -05:00
|
|
|
const Group::ProductionCMode& currentGroupControl = group_state.production_control(groupName);
|
2020-03-27 07:27:45 -05:00
|
|
|
if (currentGroupControl == Group::ProductionCMode::FLD
|
|
|
|
|| currentGroupControl == Group::ProductionCMode::NONE) {
|
|
|
|
// accumulate from sub wells/groups
|
2021-04-22 10:31:21 -05:00
|
|
|
totalGuideRate += getGuideRate(groupName, schedule, wellState, group_state, reportStepIdx, guideRate, target, pu);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const std::string& wellName : group.wells()) {
|
|
|
|
const auto& wellTmp = schedule.getWell(wellName, reportStepIdx);
|
|
|
|
|
|
|
|
if (wellTmp.isInjector())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (wellTmp.getStatus() == Well::Status::SHUT)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Only count wells under group control or the ru
|
|
|
|
if (!wellState.isProductionGrup(wellName))
|
|
|
|
continue;
|
|
|
|
|
2023-04-26 07:23:42 -05:00
|
|
|
totalGuideRate += getGuideRate(wellName, schedule, wellState, group_state,
|
|
|
|
reportStepIdx, guideRate, target, pu);
|
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
return totalGuideRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double getGuideRateInj(const std::string& name,
|
|
|
|
const Schedule& schedule,
|
2021-05-20 06:32:18 -05:00
|
|
|
const WellState& wellState,
|
2021-04-22 10:31:21 -05:00
|
|
|
const GroupState& group_state,
|
2020-03-27 07:27:45 -05:00
|
|
|
const int reportStepIdx,
|
|
|
|
const GuideRate* guideRate,
|
|
|
|
const GuideRateModel::Target target,
|
|
|
|
const Phase& injectionPhase,
|
|
|
|
const PhaseUsage& pu)
|
|
|
|
{
|
|
|
|
if (schedule.hasWell(name, reportStepIdx)) {
|
2023-04-26 07:23:42 -05:00
|
|
|
return getGuideRate(name, schedule, wellState, group_state,
|
|
|
|
reportStepIdx, guideRate, target, pu);
|
2021-03-10 07:26:04 -06:00
|
|
|
}
|
|
|
|
|
2021-03-16 09:56:03 -05:00
|
|
|
if (guideRate->has(name, injectionPhase)) {
|
|
|
|
return guideRate->get(name, injectionPhase);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
double totalGuideRate = 0.0;
|
|
|
|
const Group& group = schedule.getGroup(name, reportStepIdx);
|
|
|
|
|
|
|
|
for (const std::string& groupName : group.groups()) {
|
|
|
|
const Group::InjectionCMode& currentGroupControl
|
2021-04-22 10:31:21 -05:00
|
|
|
= group_state.injection_control(groupName, injectionPhase);
|
2020-03-27 07:27:45 -05:00
|
|
|
if (currentGroupControl == Group::InjectionCMode::FLD
|
|
|
|
|| currentGroupControl == Group::InjectionCMode::NONE) {
|
|
|
|
// accumulate from sub wells/groups
|
2021-04-22 10:31:21 -05:00
|
|
|
totalGuideRate += getGuideRateInj(groupName, schedule, wellState, group_state, reportStepIdx, guideRate, target, injectionPhase, pu);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const std::string& wellName : group.wells()) {
|
|
|
|
const auto& wellTmp = schedule.getWell(wellName, reportStepIdx);
|
|
|
|
|
|
|
|
if (!wellTmp.isInjector())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (wellTmp.getStatus() == Well::Status::SHUT)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Only count wells under group control or the ru
|
|
|
|
if (!wellState.isInjectionGrup(wellName))
|
|
|
|
continue;
|
|
|
|
|
2021-03-16 09:56:03 -05:00
|
|
|
totalGuideRate += guideRate->get(wellName, target, getWellRateVector(wellState, pu, wellName));
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
return totalGuideRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int groupControlledWells(const Schedule& schedule,
|
2021-05-20 06:32:18 -05:00
|
|
|
const WellState& well_state,
|
2021-04-22 10:31:21 -05:00
|
|
|
const GroupState& group_state,
|
2020-03-27 07:27:45 -05:00
|
|
|
const int report_step,
|
|
|
|
const std::string& group_name,
|
2021-03-10 07:26:04 -06:00
|
|
|
const std::string& always_included_child,
|
|
|
|
const bool is_production_group,
|
|
|
|
const Phase injection_phase)
|
2020-03-27 07:27:45 -05:00
|
|
|
{
|
|
|
|
const Group& group = schedule.getGroup(group_name, report_step);
|
|
|
|
int num_wells = 0;
|
|
|
|
for (const std::string& child_group : group.groups()) {
|
2021-03-10 07:26:04 -06:00
|
|
|
|
|
|
|
bool included = (child_group == always_included_child);
|
|
|
|
if (is_production_group) {
|
2021-04-22 10:31:21 -05:00
|
|
|
const auto ctrl = group_state.production_control(child_group);
|
2021-03-10 07:26:04 -06:00
|
|
|
included = included || (ctrl == Group::ProductionCMode::FLD) || (ctrl == Group::ProductionCMode::NONE);
|
|
|
|
} else {
|
2021-04-22 10:31:21 -05:00
|
|
|
const auto ctrl = group_state.injection_control(child_group, injection_phase);
|
2021-03-10 07:26:04 -06:00
|
|
|
included = included || (ctrl == Group::InjectionCMode::FLD) || (ctrl == Group::InjectionCMode::NONE);
|
|
|
|
}
|
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
if (included) {
|
|
|
|
num_wells
|
2021-04-22 10:31:21 -05:00
|
|
|
+= groupControlledWells(schedule, well_state, group_state, report_step, child_group, always_included_child, is_production_group, injection_phase);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const std::string& child_well : group.wells()) {
|
2021-03-10 07:26:04 -06:00
|
|
|
bool included = (child_well == always_included_child);
|
|
|
|
if (is_production_group) {
|
|
|
|
included = included || well_state.isProductionGrup(child_well);
|
|
|
|
} else {
|
|
|
|
included = included || well_state.isInjectionGrup(child_well);
|
|
|
|
}
|
2020-03-27 07:27:45 -05:00
|
|
|
if (included) {
|
|
|
|
++num_wells;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return num_wells;
|
|
|
|
}
|
|
|
|
|
|
|
|
FractionCalculator::FractionCalculator(const Schedule& schedule,
|
2021-05-20 06:32:18 -05:00
|
|
|
const WellState& well_state,
|
2021-04-22 10:31:21 -05:00
|
|
|
const GroupState& group_state,
|
2020-03-27 07:27:45 -05:00
|
|
|
const int report_step,
|
|
|
|
const GuideRate* guide_rate,
|
|
|
|
const GuideRateModel::Target target,
|
2021-03-10 07:26:04 -06:00
|
|
|
const PhaseUsage& pu,
|
|
|
|
const bool is_producer,
|
|
|
|
const Phase injection_phase)
|
2020-03-27 07:27:45 -05:00
|
|
|
: schedule_(schedule)
|
|
|
|
, well_state_(well_state)
|
2021-04-22 10:31:21 -05:00
|
|
|
, group_state_(group_state)
|
2020-03-27 07:27:45 -05:00
|
|
|
, report_step_(report_step)
|
|
|
|
, guide_rate_(guide_rate)
|
|
|
|
, target_(target)
|
|
|
|
, pu_(pu)
|
2021-03-10 07:26:04 -06:00
|
|
|
, is_producer_(is_producer)
|
|
|
|
, injection_phase_(injection_phase)
|
2020-03-27 07:27:45 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
double FractionCalculator::fraction(const std::string& name,
|
|
|
|
const std::string& control_group_name,
|
|
|
|
const bool always_include_this)
|
|
|
|
{
|
|
|
|
double fraction = 1.0;
|
|
|
|
std::string current = name;
|
|
|
|
while (current != control_group_name) {
|
|
|
|
fraction *= localFraction(current, always_include_this ? name : "");
|
|
|
|
current = parent(current);
|
|
|
|
}
|
|
|
|
return fraction;
|
|
|
|
}
|
|
|
|
double FractionCalculator::localFraction(const std::string& name, const std::string& always_included_child)
|
|
|
|
{
|
|
|
|
const double my_guide_rate = guideRate(name, always_included_child);
|
|
|
|
const Group& parent_group = schedule_.getGroup(parent(name), report_step_);
|
2020-04-23 02:39:28 -05:00
|
|
|
const double total_guide_rate = guideRateSum(parent_group, always_included_child);
|
2021-08-23 07:30:54 -05:00
|
|
|
|
|
|
|
// the total guide gate is the same as my_guide rate
|
|
|
|
// the well/group is probably on its own, i.e. return 1
|
|
|
|
// even is its guide_rate is zero
|
2020-03-27 07:27:45 -05:00
|
|
|
const double guide_rate_epsilon = 1e-12;
|
2021-08-23 07:30:54 -05:00
|
|
|
if ( std::abs(my_guide_rate - total_guide_rate) < guide_rate_epsilon )
|
|
|
|
return 1.0;
|
|
|
|
|
|
|
|
assert(total_guide_rate > my_guide_rate);
|
|
|
|
return my_guide_rate / total_guide_rate;
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
std::string FractionCalculator::parent(const std::string& name)
|
|
|
|
{
|
|
|
|
if (schedule_.hasWell(name)) {
|
|
|
|
return schedule_.getWell(name, report_step_).groupName();
|
|
|
|
} else {
|
|
|
|
return schedule_.getGroup(name, report_step_).parent();
|
|
|
|
}
|
|
|
|
}
|
2020-04-23 02:39:28 -05:00
|
|
|
double FractionCalculator::guideRateSum(const Group& group, const std::string& always_included_child)
|
2020-03-27 07:27:45 -05:00
|
|
|
{
|
|
|
|
double total_guide_rate = 0.0;
|
|
|
|
for (const std::string& child_group : group.groups()) {
|
2021-03-10 07:26:04 -06:00
|
|
|
bool included = (child_group == always_included_child);
|
|
|
|
if (is_producer_) {
|
2021-04-22 10:31:21 -05:00
|
|
|
const auto ctrl = this->group_state_.production_control(child_group);
|
2021-03-10 07:26:04 -06:00
|
|
|
included = included || (ctrl == Group::ProductionCMode::FLD) || (ctrl == Group::ProductionCMode::NONE);
|
|
|
|
} else {
|
2021-04-22 10:31:21 -05:00
|
|
|
const auto ctrl = this->group_state_.injection_control(child_group, this->injection_phase_);
|
2021-03-10 07:26:04 -06:00
|
|
|
included = included || (ctrl == Group::InjectionCMode::FLD) || (ctrl == Group::InjectionCMode::NONE);
|
|
|
|
}
|
2020-04-23 02:39:28 -05:00
|
|
|
if (included) {
|
2020-03-27 07:27:45 -05:00
|
|
|
total_guide_rate += guideRate(child_group, always_included_child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const std::string& child_well : group.wells()) {
|
2021-03-10 07:26:04 -06:00
|
|
|
bool included = (child_well == always_included_child);
|
|
|
|
if (is_producer_) {
|
|
|
|
included = included || well_state_.isProductionGrup(child_well);
|
|
|
|
} else {
|
|
|
|
included = included || well_state_.isInjectionGrup(child_well);
|
|
|
|
}
|
|
|
|
|
2020-04-23 02:39:28 -05:00
|
|
|
if (included) {
|
2020-03-27 07:27:45 -05:00
|
|
|
total_guide_rate += guideRate(child_well, always_included_child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return total_guide_rate;
|
|
|
|
}
|
|
|
|
double FractionCalculator::guideRate(const std::string& name, const std::string& always_included_child)
|
|
|
|
{
|
|
|
|
if (schedule_.hasWell(name, report_step_)) {
|
2023-04-26 07:23:42 -05:00
|
|
|
return getGuideRate(name, schedule_, well_state_, group_state_,
|
|
|
|
report_step_, guide_rate_, target_, pu_);
|
2020-03-27 07:27:45 -05:00
|
|
|
} else {
|
|
|
|
if (groupControlledWells(name, always_included_child) > 0) {
|
2021-03-16 09:56:03 -05:00
|
|
|
if (is_producer_ && guide_rate_->has(name)) {
|
|
|
|
return guide_rate_->get(name, target_, getGroupRateVector(name));
|
|
|
|
} else if (!is_producer_ && guide_rate_->has(name, injection_phase_)) {
|
|
|
|
return guide_rate_->get(name, injection_phase_);
|
2020-03-27 07:27:45 -05:00
|
|
|
} else {
|
|
|
|
// We are a group, with default guide rate.
|
|
|
|
// Compute guide rate by accumulating our children's guide rates.
|
|
|
|
const Group& group = schedule_.getGroup(name, report_step_);
|
2022-02-15 01:53:59 -06:00
|
|
|
const double eff = group.getGroupEfficiencyFactor();
|
|
|
|
return eff * guideRateSum(group, always_included_child);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// No group-controlled subordinate wells.
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int FractionCalculator::groupControlledWells(const std::string& group_name,
|
|
|
|
const std::string& always_included_child)
|
|
|
|
{
|
|
|
|
return ::Opm::WellGroupHelpers::groupControlledWells(
|
2021-04-22 10:31:21 -05:00
|
|
|
schedule_, well_state_, this->group_state_, report_step_, group_name, always_included_child, is_producer_, injection_phase_);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
GuideRate::RateVector FractionCalculator::getGroupRateVector(const std::string& group_name)
|
|
|
|
{
|
2021-03-10 07:26:04 -06:00
|
|
|
assert(is_producer_);
|
2021-04-22 10:31:21 -05:00
|
|
|
return getProductionGroupRateVector(this->group_state_, this->pu_, group_name);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string>
|
|
|
|
groupChainTopBot(const std::string& bottom, const std::string& top, const Schedule& schedule, const int report_step)
|
|
|
|
{
|
|
|
|
// Get initial parent, 'bottom' can be a well or a group.
|
|
|
|
std::string parent;
|
|
|
|
if (schedule.hasWell(bottom, report_step)) {
|
|
|
|
parent = schedule.getWell(bottom, report_step).groupName();
|
|
|
|
} else {
|
|
|
|
parent = schedule.getGroup(bottom, report_step).parent();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the chain from bottom to top.
|
|
|
|
std::vector<std::string> chain;
|
|
|
|
chain.push_back(bottom);
|
|
|
|
chain.push_back(parent);
|
|
|
|
while (parent != top) {
|
|
|
|
parent = schedule.getGroup(parent, report_step).parent();
|
|
|
|
chain.push_back(parent);
|
|
|
|
}
|
|
|
|
assert(chain.back() == top);
|
|
|
|
|
|
|
|
// Reverse order and return.
|
|
|
|
std::reverse(chain.begin(), chain.end());
|
|
|
|
return chain;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::pair<bool, double> checkGroupConstraintsProd(const std::string& name,
|
|
|
|
const std::string& parent,
|
|
|
|
const Group& group,
|
2021-05-20 06:32:18 -05:00
|
|
|
const WellState& wellState,
|
2021-04-22 10:31:21 -05:00
|
|
|
const GroupState& group_state,
|
2020-03-27 07:27:45 -05:00
|
|
|
const int reportStepIdx,
|
|
|
|
const GuideRate* guideRate,
|
|
|
|
const double* rates,
|
|
|
|
const PhaseUsage& pu,
|
|
|
|
const double efficiencyFactor,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const SummaryState& summaryState,
|
|
|
|
const std::vector<double>& resv_coeff,
|
|
|
|
DeferredLogger& deferred_logger)
|
|
|
|
{
|
|
|
|
// When called for a well ('name' is a well name), 'parent'
|
|
|
|
// will be the name of 'group'. But if we recurse, 'name' and
|
|
|
|
// 'parent' will stay fixed while 'group' will be higher up
|
|
|
|
// in the group tree.
|
2021-03-02 04:31:04 -06:00
|
|
|
// efficiencyfactor is the well efficiency factor for the first group the well is
|
|
|
|
// part of. Later it is the accumulated factor including the group efficiency factor
|
|
|
|
// of the child of group.
|
2020-03-27 07:27:45 -05:00
|
|
|
|
2021-04-22 10:31:21 -05:00
|
|
|
const Group::ProductionCMode& currentGroupControl = group_state.production_control(group.name());
|
2020-03-27 07:27:45 -05:00
|
|
|
|
|
|
|
if (currentGroupControl == Group::ProductionCMode::FLD || currentGroupControl == Group::ProductionCMode::NONE) {
|
|
|
|
// Return if we are not available for parent group.
|
2020-04-17 04:36:28 -05:00
|
|
|
if (!group.productionGroupControlAvailable()) {
|
2020-03-27 07:27:45 -05:00
|
|
|
return std::make_pair(false, 1);
|
|
|
|
}
|
|
|
|
// Otherwise: check production share of parent's control.
|
|
|
|
const auto& parentGroup = schedule.getGroup(group.parent(), reportStepIdx);
|
|
|
|
return checkGroupConstraintsProd(name,
|
|
|
|
parent,
|
|
|
|
parentGroup,
|
|
|
|
wellState,
|
2021-04-22 10:31:21 -05:00
|
|
|
group_state,
|
2020-03-27 07:27:45 -05:00
|
|
|
reportStepIdx,
|
|
|
|
guideRate,
|
|
|
|
rates,
|
|
|
|
pu,
|
|
|
|
efficiencyFactor * group.getGroupEfficiencyFactor(),
|
|
|
|
schedule,
|
|
|
|
summaryState,
|
|
|
|
resv_coeff,
|
|
|
|
deferred_logger);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This can be false for FLD-controlled groups, we must therefore
|
|
|
|
// check for FLD first (done above).
|
|
|
|
if (!group.isProductionGroup()) {
|
|
|
|
return std::make_pair(false, 1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2020-05-04 08:56:34 -05:00
|
|
|
|
|
|
|
// gconsale may adjust the grat target.
|
|
|
|
// the adjusted rates is send to the targetCalculator
|
|
|
|
double gratTargetFromSales = 0.0;
|
2021-04-22 10:31:21 -05:00
|
|
|
if (group_state.has_grat_sales_target(group.name()))
|
|
|
|
gratTargetFromSales = group_state.grat_sales_target(group.name());
|
2020-05-04 08:56:34 -05:00
|
|
|
|
2021-09-01 08:04:54 -05:00
|
|
|
TargetCalculator tcalc(currentGroupControl, pu, resv_coeff, gratTargetFromSales, group.name(), group_state, group.has_gpmaint_control(currentGroupControl));
|
2021-04-30 04:01:52 -05:00
|
|
|
FractionCalculator fcalc(schedule, wellState, group_state, reportStepIdx, guideRate, tcalc.guideTargetMode(), pu, true, Phase::OIL);
|
2020-03-27 07:27:45 -05:00
|
|
|
|
|
|
|
auto localFraction = [&](const std::string& child) { return fcalc.localFraction(child, name); };
|
|
|
|
|
|
|
|
auto localReduction = [&](const std::string& group_name) {
|
2021-04-22 10:31:21 -05:00
|
|
|
const std::vector<double>& groupTargetReductions = group_state.production_reduction_rates(group_name);
|
2020-03-27 07:27:45 -05:00
|
|
|
return tcalc.calcModeRateFromRates(groupTargetReductions);
|
|
|
|
};
|
|
|
|
|
2022-02-15 01:53:59 -06:00
|
|
|
auto localCurrentRate = [&](const std::string& group_name) {
|
|
|
|
const std::vector<double>& groupSurfaceRates = group_state.production_rates(group_name);
|
|
|
|
return tcalc.calcModeRateFromRates(groupSurfaceRates);
|
|
|
|
};
|
2023-01-10 08:32:08 -06:00
|
|
|
|
|
|
|
std::optional<Group::ProductionControls> ctrl;
|
|
|
|
if (!group.has_gpmaint_control(currentGroupControl))
|
|
|
|
ctrl = group.productionControls(summaryState);
|
|
|
|
|
|
|
|
const double orig_target = tcalc.groupTarget(ctrl, deferred_logger);
|
2020-03-27 07:27:45 -05:00
|
|
|
// Assume we have a chain of groups as follows: BOTTOM -> MIDDLE -> TOP.
|
|
|
|
// Then ...
|
|
|
|
// TODO finish explanation.
|
|
|
|
const double current_rate
|
|
|
|
= -tcalc.calcModeRateFromRates(rates); // Switch sign since 'rates' are negative for producers.
|
|
|
|
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.
|
|
|
|
const size_t num_ancestors = chain.size() - 1;
|
2020-04-23 13:54:59 -05:00
|
|
|
// we need to find out the level where the current well is applied to the local reduction
|
|
|
|
size_t local_reduction_level = 0;
|
2022-08-25 01:27:53 -05:00
|
|
|
for (size_t ii = 1; ii < num_ancestors; ++ii) {
|
|
|
|
const int num_gr_ctrl = groupControlledWells(schedule,
|
|
|
|
wellState,
|
|
|
|
group_state,
|
|
|
|
reportStepIdx,
|
|
|
|
chain[ii],
|
|
|
|
"",
|
|
|
|
/*is_producer*/ true,
|
|
|
|
/*injectionPhaseNotUsed*/ Phase::OIL);
|
|
|
|
if (guideRate->has(chain[ii]) && num_gr_ctrl > 0) {
|
2020-04-23 13:54:59 -05:00
|
|
|
local_reduction_level = ii;
|
|
|
|
}
|
|
|
|
}
|
2022-02-15 01:53:59 -06:00
|
|
|
// check whether guide rate is violated
|
2022-08-25 01:27:53 -05:00
|
|
|
for (size_t ii = 1; ii < num_ancestors; ++ii) {
|
|
|
|
if (guideRate->has(chain[ii])) {
|
|
|
|
const auto& guided_group = chain[ii];
|
|
|
|
const double grefficiency
|
2022-02-15 01:53:59 -06:00
|
|
|
= schedule.getGroup(guided_group, reportStepIdx).getGroupEfficiencyFactor();
|
2022-08-25 01:27:53 -05:00
|
|
|
const double currentRateFraction = grefficiency * localCurrentRate(guided_group) / (localCurrentRate(chain[ii-1]));
|
|
|
|
const double guiderateFraction = localFraction(guided_group);
|
|
|
|
// we add a factor here to avoid switching due to numerical instability
|
|
|
|
const double factor = 1.01;
|
|
|
|
if (currentRateFraction > (guiderateFraction * factor)) {
|
|
|
|
return std::make_pair(true, guiderateFraction/currentRateFraction);
|
|
|
|
}
|
2022-02-15 01:53:59 -06:00
|
|
|
}
|
|
|
|
}
|
2020-03-27 07:27:45 -05:00
|
|
|
double target = orig_target;
|
|
|
|
for (size_t ii = 0; ii < num_ancestors; ++ii) {
|
2021-03-16 09:56:03 -05:00
|
|
|
if ((ii == 0) || guideRate->has(chain[ii])) {
|
2020-04-22 04:16:20 -05:00
|
|
|
// Apply local reductions only at the control level
|
|
|
|
// (top) and for levels where we have a specified
|
|
|
|
// group guide rate.
|
2022-08-25 01:27:53 -05:00
|
|
|
if (local_reduction_level >= ii ) {
|
|
|
|
target -= localReduction(chain[ii]);
|
|
|
|
}
|
2020-04-23 13:54:59 -05:00
|
|
|
// Add my reduction back at the level where it is included in the local reduction
|
2022-08-25 01:27:53 -05:00
|
|
|
if (local_reduction_level == ii ) {
|
2021-08-06 04:47:30 -05:00
|
|
|
target += current_rate * efficiencyFactor;
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
target *= localFraction(chain[ii + 1]);
|
|
|
|
}
|
|
|
|
// Avoid negative target rates comming from too large local reductions.
|
2021-08-06 04:47:30 -05:00
|
|
|
const double target_rate = std::max(1e-12, target / efficiencyFactor);
|
2021-06-09 08:15:12 -05:00
|
|
|
double scale = 1.0;
|
|
|
|
if (current_rate > 1e-12)
|
|
|
|
scale = target_rate / current_rate;
|
2021-08-06 04:47:30 -05:00
|
|
|
|
2021-06-09 08:15:12 -05:00
|
|
|
return std::make_pair(current_rate > target_rate, scale);
|
2020-03-27 07:27:45 -05:00
|
|
|
}
|
|
|
|
|
2021-03-10 07:26:04 -06:00
|
|
|
std::pair<bool, double> checkGroupConstraintsInj(const std::string& name,
|
|
|
|
const std::string& parent,
|
|
|
|
const Group& group,
|
2021-05-20 06:32:18 -05:00
|
|
|
const WellState& wellState,
|
2021-04-22 10:31:21 -05:00
|
|
|
const GroupState& group_state,
|
2021-03-10 07:26:04 -06:00
|
|
|
const int reportStepIdx,
|
|
|
|
const GuideRate* guideRate,
|
|
|
|
const double* rates,
|
|
|
|
Phase injectionPhase,
|
|
|
|
const PhaseUsage& pu,
|
|
|
|
const double efficiencyFactor,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const SummaryState& summaryState,
|
|
|
|
const std::vector<double>& resv_coeff,
|
|
|
|
DeferredLogger& deferred_logger)
|
|
|
|
{
|
|
|
|
// When called for a well ('name' is a well name), 'parent'
|
|
|
|
// will be the name of 'group'. But if we recurse, 'name' and
|
|
|
|
// 'parent' will stay fixed while 'group' will be higher up
|
|
|
|
// in the group tree.
|
|
|
|
// efficiencyfactor is the well efficiency factor for the first group the well is
|
|
|
|
// part of. Later it is the accumulated factor including the group efficiency factor
|
|
|
|
// of the child of group.
|
|
|
|
|
2021-04-22 10:31:21 -05:00
|
|
|
auto currentGroupControl = group_state.injection_control(group.name(), injectionPhase);
|
2021-03-10 07:26:04 -06:00
|
|
|
|
|
|
|
if (currentGroupControl == Group::InjectionCMode::FLD || currentGroupControl == Group::InjectionCMode::NONE) {
|
|
|
|
// Return if we are not available for parent group.
|
|
|
|
if (!group.injectionGroupControlAvailable(injectionPhase)) {
|
|
|
|
return std::make_pair(false, 1);
|
|
|
|
}
|
|
|
|
// Otherwise: check production share of parent's control.
|
|
|
|
const auto& parentGroup = schedule.getGroup(group.parent(), reportStepIdx);
|
|
|
|
return checkGroupConstraintsInj(name,
|
|
|
|
parent,
|
|
|
|
parentGroup,
|
|
|
|
wellState,
|
2021-04-22 10:31:21 -05:00
|
|
|
group_state,
|
2021-03-10 07:26:04 -06:00
|
|
|
reportStepIdx,
|
|
|
|
guideRate,
|
|
|
|
rates,
|
|
|
|
injectionPhase,
|
|
|
|
pu,
|
|
|
|
efficiencyFactor * group.getGroupEfficiencyFactor(),
|
|
|
|
schedule,
|
|
|
|
summaryState,
|
|
|
|
resv_coeff,
|
|
|
|
deferred_logger);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This can be false for FLD-controlled groups, we must therefore
|
|
|
|
// check for FLD first (done above).
|
|
|
|
if (!group.isInjectionGroup()) {
|
|
|
|
return std::make_pair(false, 1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
double sales_target = 0;
|
|
|
|
if (schedule[reportStepIdx].gconsale().has(group.name())) {
|
|
|
|
const auto& gconsale = schedule[reportStepIdx].gconsale().get(group.name(), summaryState);
|
|
|
|
sales_target = gconsale.sales_target;
|
|
|
|
}
|
2021-09-01 08:04:54 -05:00
|
|
|
InjectionTargetCalculator tcalc(currentGroupControl, pu, resv_coeff, group.name(), sales_target, group_state, injectionPhase, group.has_gpmaint_control(injectionPhase, currentGroupControl), deferred_logger);
|
2021-04-30 04:01:52 -05:00
|
|
|
FractionCalculator fcalc(schedule, wellState, group_state, reportStepIdx, guideRate, tcalc.guideTargetMode(), pu, false, injectionPhase);
|
2021-03-10 07:26:04 -06:00
|
|
|
|
|
|
|
auto localFraction = [&](const std::string& child) { return fcalc.localFraction(child, name); };
|
|
|
|
|
|
|
|
auto localReduction = [&](const std::string& group_name) {
|
2021-04-22 10:31:21 -05:00
|
|
|
const std::vector<double>& groupTargetReductions = group_state.injection_reduction_rates(group_name);
|
2021-03-10 07:26:04 -06:00
|
|
|
return tcalc.calcModeRateFromRates(groupTargetReductions);
|
|
|
|
};
|
|
|
|
|
2022-02-15 01:53:59 -06:00
|
|
|
auto localCurrentRate = [&](const std::string& group_name) {
|
|
|
|
const std::vector<double>& groupSurfaceRates = group_state.injection_surface_rates(group_name);
|
|
|
|
return tcalc.calcModeRateFromRates(groupSurfaceRates);
|
|
|
|
};
|
|
|
|
|
2023-01-10 08:32:08 -06:00
|
|
|
std::optional<Group::InjectionControls> ctrl;
|
|
|
|
if (!group.has_gpmaint_control(injectionPhase, currentGroupControl))
|
|
|
|
ctrl = group.injectionControls(injectionPhase, summaryState);
|
|
|
|
|
|
|
|
|
|
|
|
const double orig_target = tcalc.groupTarget(ctrl, deferred_logger);
|
2021-03-10 07:26:04 -06:00
|
|
|
// Assume we have a chain of groups as follows: BOTTOM -> MIDDLE -> TOP.
|
|
|
|
// Then ...
|
|
|
|
// TODO finish explanation.
|
|
|
|
const double current_rate
|
|
|
|
= tcalc.calcModeRateFromRates(rates); // Switch sign since 'rates' are negative for producers.
|
|
|
|
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.
|
|
|
|
const size_t num_ancestors = chain.size() - 1;
|
|
|
|
// we need to find out the level where the current well is applied to the local reduction
|
|
|
|
size_t local_reduction_level = 0;
|
2022-08-25 01:27:53 -05:00
|
|
|
for (size_t ii = 1; ii < num_ancestors; ++ii) {
|
|
|
|
const int num_gr_ctrl = groupControlledWells(schedule,
|
|
|
|
wellState,
|
|
|
|
group_state,
|
|
|
|
reportStepIdx,
|
|
|
|
chain[ii],
|
|
|
|
"",
|
|
|
|
/*is_producer*/ false,
|
|
|
|
injectionPhase);
|
|
|
|
if (guideRate->has(chain[ii], injectionPhase) && num_gr_ctrl > 0) {
|
2021-03-10 07:26:04 -06:00
|
|
|
local_reduction_level = ii;
|
|
|
|
}
|
|
|
|
}
|
2022-02-15 01:53:59 -06:00
|
|
|
|
|
|
|
// check whether guide rate is violated
|
2022-08-25 01:27:53 -05:00
|
|
|
for (size_t ii = 1; ii < num_ancestors; ++ii) {
|
|
|
|
if (guideRate->has(chain[ii], injectionPhase)) {
|
|
|
|
const auto& guided_group = chain[ii];
|
|
|
|
const double grefficiency
|
2022-02-15 01:53:59 -06:00
|
|
|
= schedule.getGroup(guided_group, reportStepIdx).getGroupEfficiencyFactor();
|
2022-08-25 01:27:53 -05:00
|
|
|
const double currentRateFraction = grefficiency * localCurrentRate(guided_group) / (localCurrentRate(chain[ii-1]));
|
|
|
|
const double guiderateFraction = localFraction(guided_group);
|
|
|
|
// we add a factor here to avoid switching due to numerical instability
|
|
|
|
const double factor = 1.01;
|
|
|
|
if (currentRateFraction > (guiderateFraction * factor)) {
|
|
|
|
return std::make_pair(true, guiderateFraction/currentRateFraction);
|
|
|
|
}
|
2022-02-15 01:53:59 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-10 07:26:04 -06:00
|
|
|
double target = orig_target;
|
|
|
|
for (size_t ii = 0; ii < num_ancestors; ++ii) {
|
2021-03-16 09:56:03 -05:00
|
|
|
if ((ii == 0) || guideRate->has(chain[ii], injectionPhase)) {
|
2021-03-10 07:26:04 -06:00
|
|
|
// Apply local reductions only at the control level
|
|
|
|
// (top) and for levels where we have a specified
|
|
|
|
// group guide rate.
|
2022-08-25 01:27:53 -05:00
|
|
|
if (local_reduction_level >= ii ) {
|
|
|
|
target -= localReduction(chain[ii]);
|
|
|
|
}
|
2021-03-10 07:26:04 -06:00
|
|
|
|
|
|
|
// Add my reduction back at the level where it is included in the local reduction
|
2022-08-25 01:27:53 -05:00
|
|
|
if (local_reduction_level == ii ) {
|
2021-08-06 04:47:30 -05:00
|
|
|
target += current_rate * efficiencyFactor;
|
2021-03-10 07:26:04 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
target *= localFraction(chain[ii + 1]);
|
|
|
|
}
|
|
|
|
// Avoid negative target rates comming from too large local reductions.
|
2021-08-06 04:47:30 -05:00
|
|
|
const double target_rate = std::max(1e-12, target / efficiencyFactor);
|
2021-06-09 08:15:12 -05:00
|
|
|
double scale = 1.0;
|
|
|
|
if (current_rate > 1e-12)
|
|
|
|
scale = target_rate / current_rate;
|
2021-08-06 04:47:30 -05:00
|
|
|
|
2021-06-09 08:15:12 -05:00
|
|
|
return std::make_pair(current_rate > target_rate, scale);
|
2021-03-10 07:26:04 -06:00
|
|
|
}
|
|
|
|
|
2023-01-11 03:49:51 -06:00
|
|
|
template <class AverageRegionalPressureType>
|
|
|
|
void setRegionAveragePressureCalculator(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const FieldPropsManager& fp,
|
|
|
|
const PhaseUsage& pu,
|
|
|
|
std::map<std::string, std::unique_ptr<AverageRegionalPressureType>>& regionalAveragePressureCalculator)
|
|
|
|
{
|
|
|
|
for (const std::string& groupName : group.groups()) {
|
|
|
|
setRegionAveragePressureCalculator( schedule.getGroup(groupName, reportStepIdx), schedule,
|
|
|
|
reportStepIdx, fp, pu, regionalAveragePressureCalculator);
|
|
|
|
}
|
|
|
|
const auto& gpm = group.gpmaint();
|
|
|
|
if (!gpm)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const auto& reg = gpm->region();
|
|
|
|
if (!reg)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (regionalAveragePressureCalculator.count(reg->first) == 0) {
|
|
|
|
const std::string name = (reg->first.rfind("FIP", 0) == 0) ? reg->first : "FIP" + reg->first;
|
|
|
|
const auto& fipnum = fp.get_int(name);
|
|
|
|
regionalAveragePressureCalculator[reg->first] = std::make_unique<AverageRegionalPressureType>(pu,fipnum);
|
|
|
|
}
|
|
|
|
}
|
2021-06-28 16:12:18 -05:00
|
|
|
|
|
|
|
template <class Comm>
|
|
|
|
void updateGuideRates(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const SummaryState& summary_state,
|
|
|
|
const PhaseUsage& pu,
|
|
|
|
const int report_step,
|
|
|
|
const double sim_time,
|
|
|
|
WellState& well_state,
|
|
|
|
const GroupState& group_state,
|
|
|
|
const Comm& comm,
|
|
|
|
GuideRate* guide_rate,
|
|
|
|
std::vector<double>& pot,
|
|
|
|
Opm::DeferredLogger& deferred_logger)
|
|
|
|
{
|
|
|
|
guide_rate->updateGuideRateExpiration(sim_time, report_step);
|
|
|
|
updateGuideRateForProductionGroups(group, schedule, pu, report_step, sim_time, well_state, group_state, comm, guide_rate, pot);
|
|
|
|
updateGuideRatesForInjectionGroups(group, schedule, summary_state, pu, report_step, well_state, group_state, guide_rate, deferred_logger);
|
|
|
|
updateGuideRatesForWells(schedule, pu, report_step, sim_time, well_state, comm, guide_rate);
|
|
|
|
}
|
|
|
|
|
2021-04-30 02:48:15 -05:00
|
|
|
template <class Comm>
|
|
|
|
void updateGuideRateForProductionGroups(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const PhaseUsage& pu,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const double& simTime,
|
2021-05-20 06:32:18 -05:00
|
|
|
WellState& wellState,
|
2021-04-30 02:48:15 -05:00
|
|
|
const GroupState& group_state,
|
|
|
|
const Comm& comm,
|
|
|
|
GuideRate* guideRate,
|
|
|
|
std::vector<double>& pot)
|
|
|
|
{
|
|
|
|
const int np = pu.num_phases;
|
|
|
|
for (const std::string& groupName : group.groups()) {
|
|
|
|
std::vector<double> thisPot(np, 0.0);
|
|
|
|
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
|
|
|
|
|
|
|
|
// Note that group effiency factors for groupTmp are applied in updateGuideRateForGroups
|
|
|
|
updateGuideRateForProductionGroups(groupTmp, schedule, pu, reportStepIdx, simTime, wellState, group_state, comm, guideRate, thisPot);
|
|
|
|
|
|
|
|
// accumulate group contribution from sub group unconditionally
|
|
|
|
const auto currentGroupControl = group_state.production_control(groupName);
|
|
|
|
if (currentGroupControl != Group::ProductionCMode::FLD
|
|
|
|
&& currentGroupControl != Group::ProductionCMode::NONE) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-08-06 04:47:30 -05:00
|
|
|
|
|
|
|
// Apply group efficiency factor for this goup
|
|
|
|
auto gefac = groupTmp.getGroupEfficiencyFactor();
|
|
|
|
|
2021-04-30 02:48:15 -05:00
|
|
|
for (int phase = 0; phase < np; phase++) {
|
2021-08-06 04:47:30 -05:00
|
|
|
pot[phase] += gefac*thisPot[phase];
|
2021-04-30 02:48:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
for (const std::string& wellName : group.wells()) {
|
|
|
|
const auto& wellTmp = schedule.getWell(wellName, reportStepIdx);
|
|
|
|
const auto wefac = wellTmp.getEfficiencyFactor();
|
|
|
|
|
|
|
|
if (wellTmp.isInjector())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (wellTmp.getStatus() == Well::Status::SHUT)
|
|
|
|
continue;
|
2021-08-06 06:18:18 -05:00
|
|
|
const auto& well_index = wellState.index(wellName);
|
|
|
|
if (!well_index.has_value()) // the well is not found
|
2021-04-30 02:48:15 -05:00
|
|
|
continue;
|
|
|
|
|
2021-08-06 06:18:18 -05:00
|
|
|
if (! wellState.wellIsOwned(well_index.value(), wellName) ) // Only sum once
|
2021-04-30 02:48:15 -05:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-08-06 06:18:18 -05:00
|
|
|
const auto& ws = wellState.well(well_index.value());
|
2021-04-30 02:48:15 -05:00
|
|
|
// add contribution from wells unconditionally
|
|
|
|
for (int phase = 0; phase < np; phase++) {
|
2021-08-05 03:57:15 -05:00
|
|
|
pot[phase] += wefac * ws.well_potentials[phase];
|
2021-04-30 02:48:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-09 05:51:49 -06:00
|
|
|
std::array<double,3> potentials{};
|
|
|
|
auto& [oilPot, gasPot, waterPot] = potentials;
|
2021-04-30 02:48:15 -05:00
|
|
|
if (pu.phase_used[BlackoilPhases::Liquid])
|
|
|
|
oilPot = pot[pu.phase_pos[BlackoilPhases::Liquid]];
|
|
|
|
|
|
|
|
if (pu.phase_used[BlackoilPhases::Vapour])
|
|
|
|
gasPot = pot[pu.phase_pos[BlackoilPhases::Vapour]];
|
|
|
|
|
|
|
|
if (pu.phase_used[BlackoilPhases::Aqua])
|
|
|
|
waterPot = pot[pu.phase_pos[BlackoilPhases::Aqua]];
|
|
|
|
|
2021-11-09 05:51:49 -06:00
|
|
|
comm.sum(potentials.data(), potentials.size());
|
2021-06-17 16:56:02 -05:00
|
|
|
const UnitSystem& unit_system = schedule.getUnits();
|
|
|
|
oilPot = unit_system.from_si(UnitSystem::measure::liquid_surface_rate, oilPot);
|
|
|
|
waterPot = unit_system.from_si(UnitSystem::measure::liquid_surface_rate, waterPot);
|
|
|
|
gasPot = unit_system.from_si(UnitSystem::measure::gas_surface_rate, gasPot);
|
2021-04-30 02:48:15 -05:00
|
|
|
guideRate->compute(group.name(), reportStepIdx, simTime, oilPot, gasPot, waterPot);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Comm>
|
|
|
|
void updateGuideRatesForWells(const Schedule& schedule,
|
|
|
|
const PhaseUsage& pu,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const double& simTime,
|
2021-05-20 06:32:18 -05:00
|
|
|
const WellState& wellState,
|
2021-04-30 02:48:15 -05:00
|
|
|
const Comm& comm,
|
|
|
|
GuideRate* guideRate)
|
|
|
|
{
|
|
|
|
for (const auto& well : schedule.getWells(reportStepIdx)) {
|
2021-11-09 05:51:49 -06:00
|
|
|
std::array<double,3> potentials{};
|
|
|
|
auto& [oilpot, gaspot, waterpot] = potentials;
|
2021-04-30 02:48:15 -05:00
|
|
|
|
2021-08-06 06:18:18 -05:00
|
|
|
const auto& well_index = wellState.index(well.name());
|
|
|
|
if (well_index.has_value() && wellState.wellIsOwned(well_index.value(), well.name()))
|
2021-04-30 02:48:15 -05:00
|
|
|
{
|
|
|
|
// the well is found and owned
|
2021-08-06 06:18:18 -05:00
|
|
|
const auto& ws = wellState.well(well_index.value());
|
2021-08-05 03:57:15 -05:00
|
|
|
const auto& wpot = ws.well_potentials;
|
2021-04-30 02:48:15 -05:00
|
|
|
if (pu.phase_used[BlackoilPhases::Liquid] > 0)
|
|
|
|
oilpot = wpot[pu.phase_pos[BlackoilPhases::Liquid]];
|
|
|
|
|
|
|
|
if (pu.phase_used[BlackoilPhases::Vapour] > 0)
|
|
|
|
gaspot = wpot[pu.phase_pos[BlackoilPhases::Vapour]];
|
|
|
|
|
|
|
|
if (pu.phase_used[BlackoilPhases::Aqua] > 0)
|
|
|
|
waterpot = wpot[pu.phase_pos[BlackoilPhases::Aqua]];
|
|
|
|
}
|
2021-11-09 05:51:49 -06:00
|
|
|
comm.sum(potentials.data(), potentials.size());
|
2021-06-17 16:56:02 -05:00
|
|
|
const UnitSystem& unit_system = schedule.getUnits();
|
|
|
|
oilpot = unit_system.from_si(UnitSystem::measure::liquid_surface_rate, oilpot);
|
|
|
|
waterpot = unit_system.from_si(UnitSystem::measure::liquid_surface_rate, waterpot);
|
|
|
|
gaspot = unit_system.from_si(UnitSystem::measure::gas_surface_rate, gaspot);
|
2021-04-30 02:48:15 -05:00
|
|
|
guideRate->compute(well.name(), reportStepIdx, simTime, oilpot, gaspot, waterpot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-01 07:43:47 -05:00
|
|
|
using AvgP = RegionAverageCalculator::AverageRegionalPressure<BlackOilFluidSystem<double>,std::vector<int>>;
|
2023-01-11 03:49:51 -06:00
|
|
|
using AvgPMap = std::map<std::string, std::unique_ptr<AvgP>>;
|
|
|
|
template void WellGroupHelpers::updateGpMaintTargetForGroups<AvgPMap>(const Group&,
|
2022-09-01 07:43:47 -05:00
|
|
|
const Schedule&,
|
2023-01-11 03:49:51 -06:00
|
|
|
const AvgPMap&,
|
2022-09-01 07:43:47 -05:00
|
|
|
int,
|
|
|
|
double,
|
|
|
|
const WellState&,
|
|
|
|
GroupState&);
|
2023-01-11 03:49:51 -06:00
|
|
|
template void WellGroupHelpers::setRegionAveragePressureCalculator<AvgP>(const Group&,
|
|
|
|
const Schedule&,
|
|
|
|
const int,
|
|
|
|
const FieldPropsManager&,
|
|
|
|
const PhaseUsage&,
|
|
|
|
AvgPMap&);
|
2022-09-01 07:43:47 -05:00
|
|
|
|
2022-09-01 07:47:18 -05:00
|
|
|
template
|
|
|
|
void updateGuideRateForProductionGroups<Parallel::Communication>(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const PhaseUsage& pu,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const double& simTime,
|
|
|
|
WellState& wellState,
|
|
|
|
const GroupState& group_state,
|
|
|
|
const Parallel::Communication& comm,
|
|
|
|
GuideRate* guideRate,
|
|
|
|
std::vector<double>& pot);
|
|
|
|
template
|
|
|
|
void updateGuideRatesForWells<Parallel::Communication>(const Schedule& schedule,
|
|
|
|
const PhaseUsage& pu,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const double& simTime,
|
|
|
|
const WellState& wellState,
|
|
|
|
const Parallel::Communication& comm,
|
|
|
|
GuideRate* guideRate);
|
|
|
|
template
|
|
|
|
void updateGuideRates<Parallel::Communication>(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const SummaryState& summary_state,
|
|
|
|
const PhaseUsage& pu,
|
|
|
|
const int report_step,
|
|
|
|
const double sim_time,
|
|
|
|
WellState& well_state,
|
|
|
|
const GroupState& group_state,
|
|
|
|
const Parallel::Communication& comm,
|
|
|
|
GuideRate* guide_rate,
|
|
|
|
std::vector<double>& pot,
|
|
|
|
DeferredLogger&);
|
2020-03-27 07:27:45 -05:00
|
|
|
|
|
|
|
} // namespace WellGroupHelpers
|
|
|
|
|
|
|
|
} // namespace Opm
|