2021-05-31 07:31:56 -05:00
|
|
|
/*
|
|
|
|
Copyright 2017 SINTEF Digital, Mathematics and Cybernetics.
|
|
|
|
Copyright 2017 Statoil ASA.
|
|
|
|
Copyright 2018 IRIS
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2022-10-31 10:03:59 -05:00
|
|
|
#include <opm/simulators/wells/WellAssemble.hpp>
|
2021-05-31 07:31:56 -05:00
|
|
|
|
|
|
|
#include <opm/material/densead/Evaluation.hpp>
|
|
|
|
#include <opm/material/fluidsystems/BlackOilFluidSystem.hpp>
|
|
|
|
|
2021-12-14 01:30:15 -06:00
|
|
|
#include <opm/input/eclipse/Schedule/Schedule.hpp>
|
2021-05-31 07:31:56 -05:00
|
|
|
|
|
|
|
#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
|
|
|
|
#include <opm/simulators/wells/GroupState.hpp>
|
|
|
|
#include <opm/simulators/wells/RateConverter.hpp>
|
|
|
|
#include <opm/simulators/wells/VFPProperties.hpp>
|
2022-10-19 02:55:14 -05:00
|
|
|
#include <opm/simulators/wells/WellGroupControls.hpp>
|
2021-05-31 07:31:56 -05:00
|
|
|
#include <opm/simulators/wells/WellHelpers.hpp>
|
|
|
|
#include <opm/simulators/wells/WellInterfaceFluidSystem.hpp>
|
|
|
|
#include <opm/simulators/wells/WellState.hpp>
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <cmath>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
namespace Opm
|
|
|
|
{
|
|
|
|
|
|
|
|
template<class FluidSystem>
|
2022-10-31 10:03:59 -05:00
|
|
|
WellAssemble<FluidSystem>::
|
|
|
|
WellAssemble(const WellInterfaceFluidSystem<FluidSystem>& well)
|
|
|
|
: well_(well)
|
2021-05-31 07:31:56 -05:00
|
|
|
{}
|
|
|
|
|
|
|
|
template<class FluidSystem>
|
|
|
|
template<class EvalWell>
|
|
|
|
void
|
2022-10-31 10:03:59 -05:00
|
|
|
WellAssemble<FluidSystem>::
|
|
|
|
assembleControlEqProd(const WellState& well_state,
|
|
|
|
const GroupState& group_state,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const SummaryState& summaryState,
|
|
|
|
const Well::ProductionControls& controls,
|
|
|
|
const EvalWell& bhp,
|
|
|
|
const std::vector<EvalWell>& rates, // Always 3 canonical rates.
|
|
|
|
const std::function<EvalWell()>& bhp_from_thp,
|
|
|
|
EvalWell& control_eq,
|
|
|
|
DeferredLogger& deferred_logger) const
|
2021-05-31 07:31:56 -05:00
|
|
|
{
|
2022-10-31 10:03:59 -05:00
|
|
|
const auto current = well_state.well(well_.indexOfWell()).production_cmode;
|
|
|
|
const auto& pu = well_.phaseUsage();
|
|
|
|
const double efficiencyFactor = well_.wellEcl().getEfficiencyFactor();
|
2021-05-31 07:31:56 -05:00
|
|
|
|
|
|
|
switch (current) {
|
|
|
|
case Well::ProducerCMode::ORAT: {
|
|
|
|
assert(FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx));
|
|
|
|
const EvalWell rate = -rates[BlackoilPhases::Liquid];
|
|
|
|
control_eq = rate - controls.oil_rate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Well::ProducerCMode::WRAT: {
|
|
|
|
assert(FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx));
|
|
|
|
const EvalWell rate = -rates[BlackoilPhases::Aqua];
|
|
|
|
control_eq = rate - controls.water_rate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Well::ProducerCMode::GRAT: {
|
|
|
|
assert(FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx));
|
|
|
|
const EvalWell rate = -rates[BlackoilPhases::Vapour];
|
|
|
|
control_eq = rate - controls.gas_rate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Well::ProducerCMode::LRAT: {
|
|
|
|
assert(FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx));
|
|
|
|
assert(FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx));
|
|
|
|
EvalWell rate = -rates[BlackoilPhases::Aqua] - rates[BlackoilPhases::Liquid];
|
|
|
|
control_eq = rate - controls.liquid_rate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Well::ProducerCMode::CRAT: {
|
2022-10-31 10:03:59 -05:00
|
|
|
OPM_DEFLOG_THROW(std::runtime_error, "CRAT control not supported " << well_.name(), deferred_logger);
|
2021-05-31 07:31:56 -05:00
|
|
|
}
|
|
|
|
case Well::ProducerCMode::RESV: {
|
|
|
|
auto total_rate = rates[0]; // To get the correct type only.
|
|
|
|
total_rate = 0.0;
|
2022-10-31 10:03:59 -05:00
|
|
|
std::vector<double> convert_coeff(well_.numPhases(), 1.0);
|
|
|
|
well_.rateConverter().calcCoeff(/*fipreg*/ 0, well_.pvtRegionIdx(), convert_coeff);
|
2021-05-31 07:31:56 -05:00
|
|
|
for (int phase = 0; phase < 3; ++phase) {
|
|
|
|
if (pu.phase_used[phase]) {
|
|
|
|
const int pos = pu.phase_pos[phase];
|
|
|
|
total_rate -= rates[phase] * convert_coeff[pos]; // Note different indices.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (controls.prediction_mode) {
|
|
|
|
control_eq = total_rate - controls.resv_rate;
|
|
|
|
} else {
|
2022-10-31 10:03:59 -05:00
|
|
|
std::vector<double> hrates(well_.numPhases(), 0.);
|
2021-05-31 07:31:56 -05:00
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) {
|
|
|
|
hrates[pu.phase_pos[Water]] = controls.water_rate;
|
|
|
|
}
|
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)) {
|
|
|
|
hrates[pu.phase_pos[Oil]] = controls.oil_rate;
|
|
|
|
}
|
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) {
|
|
|
|
hrates[pu.phase_pos[Gas]] = controls.gas_rate;
|
|
|
|
}
|
2022-10-31 10:03:59 -05:00
|
|
|
std::vector<double> hrates_resv(well_.numPhases(), 0.);
|
|
|
|
well_.rateConverter().calcReservoirVoidageRates(/*fipreg*/ 0, well_.pvtRegionIdx(), hrates, hrates_resv);
|
2021-05-31 07:31:56 -05:00
|
|
|
double target = std::accumulate(hrates_resv.begin(), hrates_resv.end(), 0.0);
|
|
|
|
control_eq = total_rate - target;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Well::ProducerCMode::BHP: {
|
|
|
|
control_eq = bhp - controls.bhp_limit;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Well::ProducerCMode::THP: {
|
|
|
|
control_eq = bhp - bhp_from_thp();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Well::ProducerCMode::GRUP: {
|
2022-10-31 10:03:59 -05:00
|
|
|
assert(well_.wellEcl().isAvailableForGroupControl());
|
|
|
|
const auto& group = schedule.getGroup(well_.wellEcl().groupName(), well_.currentStep());
|
2021-05-31 07:31:56 -05:00
|
|
|
// Annoying thing: the rates passed to this function are
|
|
|
|
// always of size 3 and in canonical (for PhaseUsage)
|
|
|
|
// order. This is what is needed for VFP calculations if
|
|
|
|
// they are required (THP controlled well). But for the
|
|
|
|
// group production control things we must pass only the
|
|
|
|
// active phases' rates.
|
|
|
|
std::vector<EvalWell> active_rates(pu.num_phases);
|
|
|
|
for (int canonical_phase = 0; canonical_phase < 3; ++canonical_phase) {
|
|
|
|
if (pu.phase_used[canonical_phase]) {
|
|
|
|
active_rates[pu.phase_pos[canonical_phase]] = rates[canonical_phase];
|
|
|
|
}
|
|
|
|
}
|
2022-10-19 02:55:14 -05:00
|
|
|
auto rCoeff = [this](const RegionId id, const int region, std::vector<double>& coeff)
|
|
|
|
{
|
2022-10-31 10:03:59 -05:00
|
|
|
well_.rateConverter().calcCoeff(id, region, coeff);
|
2022-10-19 02:55:14 -05:00
|
|
|
};
|
2022-10-31 10:03:59 -05:00
|
|
|
WellGroupControls(well_).getGroupProductionControl(group, well_state,
|
2022-10-19 02:55:14 -05:00
|
|
|
group_state,
|
|
|
|
schedule,
|
|
|
|
summaryState,
|
|
|
|
bhp, active_rates,
|
|
|
|
rCoeff,
|
|
|
|
efficiencyFactor,
|
|
|
|
control_eq);
|
2021-05-31 07:31:56 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Well::ProducerCMode::CMODE_UNDEFINED: {
|
2022-10-31 10:03:59 -05:00
|
|
|
OPM_DEFLOG_THROW(std::runtime_error, "Well control must be specified for well " + well_.name(), deferred_logger);
|
2021-05-31 07:31:56 -05:00
|
|
|
}
|
|
|
|
case Well::ProducerCMode::NONE: {
|
2022-10-31 10:03:59 -05:00
|
|
|
OPM_DEFLOG_THROW(std::runtime_error, "Well control must be specified for well " + well_.name(), deferred_logger);
|
2021-05-31 07:31:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class FluidSystem>
|
|
|
|
template<class EvalWell>
|
|
|
|
void
|
2022-10-31 10:03:59 -05:00
|
|
|
WellAssemble<FluidSystem>::
|
|
|
|
assembleControlEqInj(const WellState& well_state,
|
|
|
|
const GroupState& group_state,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const SummaryState& summaryState,
|
|
|
|
const Well::InjectionControls& controls,
|
|
|
|
const EvalWell& bhp,
|
|
|
|
const EvalWell& injection_rate,
|
|
|
|
const std::function<EvalWell()>& bhp_from_thp,
|
|
|
|
EvalWell& control_eq,
|
|
|
|
DeferredLogger& deferred_logger) const
|
2021-05-31 07:31:56 -05:00
|
|
|
{
|
2022-10-31 10:03:59 -05:00
|
|
|
auto current = well_state.well(well_.indexOfWell()).injection_cmode;
|
2021-05-31 07:31:56 -05:00
|
|
|
const InjectorType injectorType = controls.injector_type;
|
2022-10-31 10:03:59 -05:00
|
|
|
const auto& pu = well_.phaseUsage();
|
|
|
|
const double efficiencyFactor = well_.wellEcl().getEfficiencyFactor();
|
2021-05-31 07:31:56 -05:00
|
|
|
|
|
|
|
switch (current) {
|
|
|
|
case Well::InjectorCMode::RATE: {
|
|
|
|
control_eq = injection_rate - controls.surface_rate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Well::InjectorCMode::RESV: {
|
2022-10-31 10:03:59 -05:00
|
|
|
std::vector<double> convert_coeff(well_.numPhases(), 1.0);
|
|
|
|
well_.rateConverter().calcInjCoeff(/*fipreg*/ 0, well_.pvtRegionIdx(), convert_coeff);
|
2021-05-31 07:31:56 -05:00
|
|
|
|
|
|
|
double coeff = 1.0;
|
|
|
|
|
|
|
|
switch (injectorType) {
|
|
|
|
case InjectorType::WATER: {
|
|
|
|
coeff = convert_coeff[pu.phase_pos[BlackoilPhases::Aqua]];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case InjectorType::OIL: {
|
|
|
|
coeff = convert_coeff[pu.phase_pos[BlackoilPhases::Liquid]];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case InjectorType::GAS: {
|
|
|
|
coeff = convert_coeff[pu.phase_pos[BlackoilPhases::Vapour]];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2022-10-31 10:03:59 -05:00
|
|
|
throw("Expected WATER, OIL or GAS as type for injectors " + well_.wellEcl().name());
|
2021-05-31 07:31:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
control_eq = coeff * injection_rate - controls.reservoir_rate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Well::InjectorCMode::THP: {
|
|
|
|
control_eq = bhp - bhp_from_thp();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Well::InjectorCMode::BHP: {
|
|
|
|
control_eq = bhp - controls.bhp_limit;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Well::InjectorCMode::GRUP: {
|
2022-10-31 10:03:59 -05:00
|
|
|
assert(well_.wellEcl().isAvailableForGroupControl());
|
|
|
|
const auto& group = schedule.getGroup(well_.wellEcl().groupName(), well_.currentStep());
|
2022-10-19 02:55:14 -05:00
|
|
|
auto rCoeff = [this](const RegionId id, const int region, std::vector<double>& coeff)
|
|
|
|
{
|
2022-10-31 10:03:59 -05:00
|
|
|
well_.rateConverter().calcInjCoeff(id, region, coeff);
|
2022-10-19 02:55:14 -05:00
|
|
|
};
|
2022-10-31 10:03:59 -05:00
|
|
|
WellGroupControls(well_).getGroupInjectionControl(group,
|
2022-10-19 02:55:14 -05:00
|
|
|
well_state,
|
|
|
|
group_state,
|
|
|
|
schedule,
|
|
|
|
summaryState,
|
|
|
|
injectorType,
|
|
|
|
bhp,
|
|
|
|
injection_rate,
|
|
|
|
rCoeff,
|
|
|
|
efficiencyFactor,
|
|
|
|
control_eq,
|
|
|
|
deferred_logger);
|
2021-05-31 07:31:56 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Well::InjectorCMode::CMODE_UNDEFINED: {
|
2022-10-31 10:03:59 -05:00
|
|
|
OPM_DEFLOG_THROW(std::runtime_error, "Well control must be specified for well " + well_.name(), deferred_logger);
|
2021-05-31 07:31:56 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define INSTANCE_METHODS(A,...) \
|
2022-10-31 10:03:59 -05:00
|
|
|
template void WellAssemble<A>:: \
|
|
|
|
assembleControlEqProd<__VA_ARGS__>(const WellState&, \
|
2021-05-31 07:31:56 -05:00
|
|
|
const GroupState&, \
|
|
|
|
const Schedule&, \
|
|
|
|
const SummaryState&, \
|
2022-10-31 10:03:59 -05:00
|
|
|
const Well::ProductionControls&, \
|
2021-05-31 07:31:56 -05:00
|
|
|
const __VA_ARGS__&, \
|
2022-10-31 10:03:59 -05:00
|
|
|
const std::vector<__VA_ARGS__>&, \
|
2021-05-31 07:31:56 -05:00
|
|
|
const std::function<__VA_ARGS__()>&, \
|
|
|
|
__VA_ARGS__&, \
|
2022-10-31 10:03:59 -05:00
|
|
|
DeferredLogger&) const; \
|
|
|
|
template void WellAssemble<A>:: \
|
|
|
|
assembleControlEqInj<__VA_ARGS__>(const WellState&, \
|
|
|
|
const GroupState&, \
|
|
|
|
const Schedule&, \
|
|
|
|
const SummaryState&, \
|
|
|
|
const Well::InjectionControls&, \
|
|
|
|
const __VA_ARGS__&, \
|
|
|
|
const __VA_ARGS__&, \
|
|
|
|
const std::function<__VA_ARGS__()>&, \
|
|
|
|
__VA_ARGS__&, \
|
|
|
|
DeferredLogger&) const;
|
2021-05-31 07:31:56 -05:00
|
|
|
|
|
|
|
using FluidSys = BlackOilFluidSystem<double, BlackOilDefaultIndexTraits>;
|
|
|
|
|
2022-10-31 10:03:59 -05:00
|
|
|
template class WellAssemble<FluidSys>;
|
2021-05-31 07:31:56 -05:00
|
|
|
|
|
|
|
INSTANCE_METHODS(FluidSys, DenseAd::Evaluation<double,3,0u>)
|
|
|
|
INSTANCE_METHODS(FluidSys, DenseAd::Evaluation<double,4,0u>)
|
|
|
|
INSTANCE_METHODS(FluidSys, DenseAd::Evaluation<double,5,0u>)
|
|
|
|
INSTANCE_METHODS(FluidSys, DenseAd::Evaluation<double,6,0u>)
|
|
|
|
INSTANCE_METHODS(FluidSys, DenseAd::Evaluation<double,7,0u>)
|
|
|
|
INSTANCE_METHODS(FluidSys, DenseAd::Evaluation<double,8,0u>)
|
2021-10-07 07:01:54 -05:00
|
|
|
INSTANCE_METHODS(FluidSys, DenseAd::Evaluation<double,9,0u>)
|
2021-05-31 07:31:56 -05:00
|
|
|
INSTANCE_METHODS(FluidSys, DenseAd::Evaluation<double,-1,4u>)
|
|
|
|
INSTANCE_METHODS(FluidSys, DenseAd::Evaluation<double,-1,5u>)
|
|
|
|
INSTANCE_METHODS(FluidSys, DenseAd::Evaluation<double,-1,6u>)
|
|
|
|
INSTANCE_METHODS(FluidSys, DenseAd::Evaluation<double,-1,7u>)
|
|
|
|
INSTANCE_METHODS(FluidSys, DenseAd::Evaluation<double,-1,8u>)
|
|
|
|
INSTANCE_METHODS(FluidSys, DenseAd::Evaluation<double,-1,9u>)
|
|
|
|
INSTANCE_METHODS(FluidSys, DenseAd::Evaluation<double,-1,10u>)
|
|
|
|
|
|
|
|
} // namespace Opm
|