2021-05-11 16:03:33 -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>
|
|
|
|
#include <opm/simulators/wells/WellInterfaceFluidSystem.hpp>
|
|
|
|
|
2022-10-19 02:55:14 -05:00
|
|
|
#include <opm/grid/utility/RegionMapping.hpp>
|
2021-05-11 16:03:33 -05:00
|
|
|
|
2021-12-14 01:30:15 -06:00
|
|
|
#include <opm/input/eclipse/Schedule/Schedule.hpp>
|
2021-05-11 16:03:33 -05:00
|
|
|
|
2022-10-19 02:55:14 -05:00
|
|
|
#include <opm/material/fluidsystems/BlackOilFluidSystem.hpp>
|
|
|
|
|
2021-05-11 16:03:33 -05:00
|
|
|
#include <opm/simulators/utils/DeferredLogger.hpp>
|
2022-10-19 02:55:14 -05:00
|
|
|
#include <opm/simulators/wells/GroupState.hpp>
|
2021-05-11 16:03:33 -05:00
|
|
|
#include <opm/simulators/wells/ParallelWellInfo.hpp>
|
2022-10-19 02:55:14 -05:00
|
|
|
#include <opm/simulators/wells/RateConverter.hpp>
|
2021-09-20 04:16:32 -05:00
|
|
|
#include <opm/simulators/wells/SingleWellState.hpp>
|
2021-06-10 08:09:05 -05:00
|
|
|
#include <opm/simulators/wells/TargetCalculator.hpp>
|
2022-10-19 02:55:14 -05:00
|
|
|
#include <opm/simulators/wells/WellConstraints.hpp>
|
2022-10-19 02:55:14 -05:00
|
|
|
#include <opm/simulators/wells/WellGroupConstraints.hpp>
|
2022-10-21 08:50:14 -05:00
|
|
|
#include <opm/simulators/wells/WellGroupControls.hpp>
|
2022-10-19 02:55:14 -05:00
|
|
|
#include <opm/simulators/wells/WellGroupHelpers.hpp>
|
|
|
|
#include <opm/simulators/wells/WellState.hpp>
|
2021-05-11 16:03:33 -05:00
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
namespace Opm
|
|
|
|
{
|
|
|
|
|
|
|
|
template<class FluidSystem>
|
|
|
|
WellInterfaceFluidSystem<FluidSystem>::
|
|
|
|
WellInterfaceFluidSystem(const Well& well,
|
|
|
|
const ParallelWellInfo& parallel_well_info,
|
|
|
|
const int time_step,
|
|
|
|
const RateConverterType& rate_converter,
|
|
|
|
const int pvtRegionIdx,
|
|
|
|
const int num_components,
|
|
|
|
const int num_phases,
|
|
|
|
const int index_of_well,
|
|
|
|
const std::vector<PerforationData>& perf_data)
|
|
|
|
: WellInterfaceGeneric(well, parallel_well_info, time_step,
|
|
|
|
pvtRegionIdx, num_components, num_phases,
|
2021-06-06 01:58:41 -05:00
|
|
|
index_of_well, perf_data)
|
2021-05-11 16:03:33 -05:00
|
|
|
, rateConverter_(rate_converter)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-01-12 07:57:22 -06:00
|
|
|
template <typename FluidSystem>
|
2021-05-11 16:03:33 -05:00
|
|
|
void
|
|
|
|
WellInterfaceFluidSystem<FluidSystem>::
|
2021-09-20 04:16:32 -05:00
|
|
|
calculateReservoirRates(SingleWellState& ws) const
|
2021-05-11 16:03:33 -05:00
|
|
|
{
|
|
|
|
const int fipreg = 0; // not considering the region for now
|
|
|
|
const int np = number_of_phases_;
|
|
|
|
|
2023-01-12 07:57:22 -06:00
|
|
|
this->rateConverter_
|
|
|
|
.calcReservoirVoidageRates(fipreg,
|
|
|
|
this->pvtRegionIdx_,
|
|
|
|
ws.surface_rates,
|
|
|
|
ws.reservoir_rates);
|
|
|
|
|
|
|
|
// Compute total connection reservoir rate CVPR/CVIR
|
|
|
|
auto& perf_data = ws.perf_data;
|
|
|
|
const auto num_perf_well = perf_data.size();
|
|
|
|
const auto& surf_perf_rates = perf_data.phase_rates;
|
|
|
|
for (auto i = 0*num_perf_well; i < num_perf_well; ++i) {
|
|
|
|
const auto surface_rates_perf = std::vector<double>
|
|
|
|
{ surf_perf_rates.begin() + (i + 0)*np ,
|
|
|
|
surf_perf_rates.begin() + (i + 1)*np };
|
|
|
|
|
|
|
|
std::vector<double> voidage_rates_perf(np, 0.0);
|
|
|
|
this->rateConverter_
|
|
|
|
.calcReservoirVoidageRates(fipreg,
|
|
|
|
this->pvtRegionIdx_,
|
|
|
|
surface_rates_perf,
|
|
|
|
voidage_rates_perf);
|
|
|
|
|
|
|
|
perf_data.rates[i] =
|
|
|
|
std::accumulate(voidage_rates_perf.begin(),
|
|
|
|
voidage_rates_perf.end(), 0.0);
|
2021-05-11 16:03:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-26 10:42:26 -05:00
|
|
|
template <typename FluidSystem>
|
|
|
|
bool
|
|
|
|
WellInterfaceFluidSystem<FluidSystem>::
|
2021-09-20 04:16:32 -05:00
|
|
|
checkIndividualConstraints(SingleWellState& ws,
|
2022-02-23 04:11:11 -06:00
|
|
|
const SummaryState& summaryState,
|
|
|
|
DeferredLogger& deferred_logger) const
|
2021-07-26 10:42:26 -05:00
|
|
|
{
|
2022-10-19 02:55:14 -05:00
|
|
|
auto rRates = [this](const int fipreg,
|
|
|
|
const int pvtRegion,
|
|
|
|
const std::vector<double>& surface_rates,
|
|
|
|
std::vector<double>& voidage_rates)
|
|
|
|
{
|
|
|
|
return rateConverter_.calcReservoirVoidageRates(fipreg, pvtRegion,
|
|
|
|
surface_rates, voidage_rates);
|
|
|
|
};
|
|
|
|
|
2022-10-21 02:34:36 -05:00
|
|
|
return WellConstraints(*this).
|
|
|
|
checkIndividualConstraints(ws, summaryState, rRates,
|
|
|
|
this->operability_status_.thp_limit_violated_but_not_switched,
|
|
|
|
deferred_logger);
|
2021-05-11 16:03:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FluidSystem>
|
|
|
|
bool
|
|
|
|
WellInterfaceFluidSystem<FluidSystem>::
|
|
|
|
checkGroupConstraints(WellState& well_state,
|
|
|
|
const GroupState& group_state,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const SummaryState& summaryState,
|
|
|
|
DeferredLogger& deferred_logger) const
|
|
|
|
{
|
2023-03-31 04:47:33 -05:00
|
|
|
|
|
|
|
if (!this->wellEcl().isAvailableForGroupControl())
|
|
|
|
return false;
|
|
|
|
|
2023-03-24 08:59:52 -05:00
|
|
|
auto rCoeff = [this, &group_state](const RegionId id, const int region, const std::optional<std::string>& prod_gname, std::vector<double>& coeff)
|
2022-10-19 02:55:14 -05:00
|
|
|
{
|
2023-03-24 08:59:52 -05:00
|
|
|
if (prod_gname)
|
|
|
|
this->rateConverter().calcCoeff(id, region, group_state.production_rates(*prod_gname), coeff);
|
|
|
|
else
|
|
|
|
this->rateConverter().calcInjCoeff(id, region, coeff);
|
|
|
|
|
2022-10-19 02:55:14 -05:00
|
|
|
};
|
|
|
|
|
2022-10-24 02:36:05 -05:00
|
|
|
return WellGroupConstraints(*this).checkGroupConstraints(well_state, group_state,
|
|
|
|
schedule, summaryState,
|
|
|
|
rCoeff, deferred_logger);
|
2021-05-11 16:03:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename FluidSystem>
|
|
|
|
bool
|
|
|
|
WellInterfaceFluidSystem<FluidSystem>::
|
|
|
|
checkConstraints(WellState& well_state,
|
|
|
|
const GroupState& group_state,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const SummaryState& summaryState,
|
|
|
|
DeferredLogger& deferred_logger) const
|
|
|
|
{
|
2022-02-23 04:11:11 -06:00
|
|
|
const bool ind_broken = checkIndividualConstraints(well_state.well(this->index_of_well_), summaryState, deferred_logger);
|
2021-05-11 16:03:33 -05:00
|
|
|
if (ind_broken) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return checkGroupConstraints(well_state, group_state, schedule, summaryState, deferred_logger);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-31 06:21:31 -05:00
|
|
|
template<typename FluidSystem>
|
|
|
|
int
|
|
|
|
WellInterfaceFluidSystem<FluidSystem>::
|
|
|
|
flowPhaseToEbosPhaseIdx(const int phaseIdx) const
|
|
|
|
{
|
|
|
|
const auto& pu = this->phaseUsage();
|
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx) && pu.phase_pos[Water] == phaseIdx)
|
|
|
|
return FluidSystem::waterPhaseIdx;
|
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx) && pu.phase_pos[Oil] == phaseIdx)
|
|
|
|
return FluidSystem::oilPhaseIdx;
|
|
|
|
if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx) && pu.phase_pos[Gas] == phaseIdx)
|
|
|
|
return FluidSystem::gasPhaseIdx;
|
|
|
|
|
|
|
|
// for other phases return the index
|
|
|
|
return phaseIdx;
|
|
|
|
}
|
|
|
|
|
2021-06-10 08:09:05 -05:00
|
|
|
template<typename FluidSystem>
|
|
|
|
std::optional<double>
|
|
|
|
WellInterfaceFluidSystem<FluidSystem>::
|
|
|
|
getGroupInjectionTargetRate(const Group& group,
|
|
|
|
const WellState& well_state,
|
|
|
|
const GroupState& group_state,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const SummaryState& summaryState,
|
|
|
|
const InjectorType& injectorType,
|
|
|
|
double efficiencyFactor,
|
|
|
|
DeferredLogger& deferred_logger) const
|
|
|
|
{
|
2023-03-24 08:59:52 -05:00
|
|
|
auto rCoeff = [this, &group_state](const RegionId id, const int region, const std::optional<std::string>& prod_gname, std::vector<double>& coeff)
|
2021-06-10 08:09:05 -05:00
|
|
|
{
|
2023-03-24 08:59:52 -05:00
|
|
|
if (prod_gname)
|
|
|
|
this->rateConverter().calcCoeff(id, region, group_state.production_rates(*prod_gname), coeff);
|
|
|
|
else
|
|
|
|
this->rateConverter().calcInjCoeff(id, region, coeff);
|
|
|
|
|
2021-06-10 08:09:05 -05:00
|
|
|
};
|
|
|
|
|
2022-10-19 02:55:14 -05:00
|
|
|
return WellGroupControls(*this).getGroupInjectionTargetRate(group, well_state,
|
|
|
|
group_state, schedule,
|
|
|
|
summaryState, injectorType,
|
|
|
|
rCoeff, efficiencyFactor,
|
|
|
|
deferred_logger);
|
2021-06-10 08:09:05 -05:00
|
|
|
}
|
2022-10-21 08:50:14 -05:00
|
|
|
|
2021-06-10 08:09:05 -05:00
|
|
|
template<typename FluidSystem>
|
|
|
|
double
|
|
|
|
WellInterfaceFluidSystem<FluidSystem>::
|
|
|
|
getGroupProductionTargetRate(const Group& group,
|
|
|
|
const WellState& well_state,
|
|
|
|
const GroupState& group_state,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const SummaryState& summaryState,
|
2023-01-10 08:32:08 -06:00
|
|
|
double efficiencyFactor,
|
|
|
|
DeferredLogger& deferred_logger) const
|
2021-06-10 08:09:05 -05:00
|
|
|
{
|
2023-03-24 08:59:52 -05:00
|
|
|
auto rCoeff = [this, &group_state](const RegionId id, const int region, const std::optional<std::string>& prod_gname, std::vector<double>& coeff)
|
2022-10-21 08:50:14 -05:00
|
|
|
{
|
2023-03-24 08:59:52 -05:00
|
|
|
if (prod_gname)
|
|
|
|
this->rateConverter().calcCoeff(id, region, group_state.production_rates(*prod_gname), coeff);
|
|
|
|
else
|
|
|
|
this->rateConverter().calcInjCoeff(id, region, coeff);
|
|
|
|
|
2021-06-10 08:09:05 -05:00
|
|
|
};
|
|
|
|
|
2022-10-21 08:50:14 -05:00
|
|
|
return WellGroupControls(*this).getGroupProductionTargetRate(group, well_state,
|
|
|
|
group_state, schedule,
|
|
|
|
summaryState,
|
2023-01-10 08:32:08 -06:00
|
|
|
rCoeff, efficiencyFactor,
|
|
|
|
deferred_logger);
|
2021-06-10 08:09:05 -05:00
|
|
|
}
|
2022-10-21 08:50:14 -05:00
|
|
|
|
2021-05-11 16:03:33 -05:00
|
|
|
template class WellInterfaceFluidSystem<BlackOilFluidSystem<double,BlackOilDefaultIndexTraits>>;
|
|
|
|
|
|
|
|
} // namespace Opm
|