2019-08-07 07:13:11 -05:00
|
|
|
/*
|
|
|
|
Copyright 2019 Norce.
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef OPM_WELLGROUPHELPERS_HEADER_INCLUDED
|
|
|
|
#define OPM_WELLGROUPHELPERS_HEADER_INCLUDED
|
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Group/Group.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Group/GuideRate.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
|
2020-02-10 08:16:09 -06:00
|
|
|
#include <opm/simulators/utils/DeferredLogger.hpp>
|
|
|
|
#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
|
2020-05-15 04:21:32 -05:00
|
|
|
#include <opm/simulators/wells/VFPProdProperties.hpp>
|
2020-03-27 07:27:45 -05:00
|
|
|
#include <opm/simulators/wells/WellStateFullyImplicitBlackoil.hpp>
|
2020-02-11 05:55:31 -06:00
|
|
|
|
2020-02-10 08:16:09 -06:00
|
|
|
#include <algorithm>
|
2020-03-27 07:27:45 -05:00
|
|
|
#include <cassert>
|
2020-05-15 04:21:32 -05:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2020-03-27 07:27:45 -05:00
|
|
|
#include <type_traits>
|
2019-08-07 07:13:11 -05:00
|
|
|
#include <vector>
|
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
namespace Opm
|
|
|
|
{
|
2019-08-07 07:13:11 -05:00
|
|
|
|
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
namespace WellGroupHelpers
|
|
|
|
{
|
2019-08-07 07:13:11 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
void setCmodeGroup(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const SummaryState& summaryState,
|
|
|
|
const int reportStepIdx,
|
|
|
|
WellStateFullyImplicitBlackoil& wellState);
|
2019-09-23 08:15:55 -05:00
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
void accumulateGroupEfficiencyFactor(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const int reportStepIdx,
|
|
|
|
double& factor);
|
|
|
|
|
|
|
|
double sumWellPhaseRates(const std::vector<double>& rates,
|
|
|
|
const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const WellStateFullyImplicitBlackoil& wellState,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const int phasePos,
|
|
|
|
const bool injector);
|
|
|
|
|
|
|
|
double sumWellRates(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const WellStateFullyImplicitBlackoil& wellState,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const int phasePos,
|
|
|
|
const bool injector);
|
|
|
|
|
|
|
|
double sumWellResRates(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const WellStateFullyImplicitBlackoil& wellState,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const int phasePos,
|
|
|
|
const bool injector);
|
|
|
|
|
|
|
|
double sumSolventRates(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const WellStateFullyImplicitBlackoil& wellState,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const bool injector);
|
|
|
|
|
|
|
|
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,
|
2020-03-27 07:27:45 -05:00
|
|
|
const WellStateFullyImplicitBlackoil& wellStateNupcol,
|
|
|
|
WellStateFullyImplicitBlackoil& wellState,
|
|
|
|
std::vector<double>& groupTargetReduction);
|
2019-11-05 08:12:01 -06:00
|
|
|
|
2019-12-12 02:22:37 -06:00
|
|
|
template <class Comm>
|
2021-03-10 07:26:04 -06:00
|
|
|
void updateGuideRateForProductionGroups(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const PhaseUsage& pu,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const double& simTime,
|
|
|
|
WellStateFullyImplicitBlackoil& wellState,
|
|
|
|
const Comm& comm,
|
|
|
|
GuideRate* guideRate,
|
|
|
|
std::vector<double>& pot)
|
2019-12-16 06:48:48 -06:00
|
|
|
{
|
|
|
|
const int np = pu.num_phases;
|
2019-08-07 07:13:11 -05:00
|
|
|
for (const std::string& groupName : group.groups()) {
|
2019-12-16 06:48:48 -06:00
|
|
|
std::vector<double> thisPot(np, 0.0);
|
2019-11-13 16:16:11 -06:00
|
|
|
const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx);
|
2021-03-01 04:00:00 -06:00
|
|
|
|
|
|
|
// Note that group effiency factors for groupTmp are applied in updateGuideRateForGroups
|
2021-03-10 07:26:04 -06:00
|
|
|
updateGuideRateForProductionGroups(
|
|
|
|
groupTmp, schedule, pu, reportStepIdx, simTime, wellState, comm, guideRate, thisPot);
|
2019-12-16 06:48:48 -06:00
|
|
|
|
2020-02-10 08:16:09 -06:00
|
|
|
// accumulate group contribution from sub group unconditionally
|
2021-03-10 07:26:04 -06:00
|
|
|
const Group::ProductionCMode& currentGroupControl = wellState.currentProductionGroupControl(groupName);
|
|
|
|
if (currentGroupControl != Group::ProductionCMode::FLD
|
2020-03-27 07:27:45 -05:00
|
|
|
&& currentGroupControl != Group::ProductionCMode::NONE) {
|
2021-03-10 07:26:04 -06:00
|
|
|
continue;
|
2019-12-16 06:48:48 -06:00
|
|
|
}
|
2021-03-10 07:26:04 -06:00
|
|
|
for (int phase = 0; phase < np; phase++) {
|
|
|
|
pot[phase] += thisPot[phase];
|
|
|
|
}
|
|
|
|
|
2019-08-07 07:13:11 -05:00
|
|
|
}
|
2019-12-16 06:48:48 -06:00
|
|
|
for (const std::string& wellName : group.wells()) {
|
|
|
|
const auto& wellTmp = schedule.getWell(wellName, reportStepIdx);
|
2020-07-08 08:49:08 -05:00
|
|
|
const auto wefac = wellTmp.getEfficiencyFactor();
|
2019-09-30 05:49:36 -05:00
|
|
|
|
2021-03-10 07:26:04 -06:00
|
|
|
if (wellTmp.isInjector())
|
2019-12-16 06:48:48 -06:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (wellTmp.getStatus() == Well::Status::SHUT)
|
|
|
|
continue;
|
|
|
|
const auto& end = wellState.wellMap().end();
|
2020-03-27 07:27:45 -05:00
|
|
|
const auto& it = wellState.wellMap().find(wellName);
|
|
|
|
if (it == end) // the well is not found
|
2019-12-16 06:48:48 -06:00
|
|
|
continue;
|
|
|
|
|
|
|
|
int well_index = it->second[0];
|
2020-12-09 05:29:56 -06:00
|
|
|
|
|
|
|
if (! wellState.wellIsOwned(well_index, wellName) ) // Only sum once
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-12-16 06:48:48 -06:00
|
|
|
const auto wellrate_index = well_index * wellState.numPhases();
|
2020-02-10 08:16:09 -06:00
|
|
|
// add contribution from wells unconditionally
|
|
|
|
for (int phase = 0; phase < np; phase++) {
|
2020-07-08 08:49:08 -05:00
|
|
|
pot[phase] += wefac * wellState.wellPotentials()[wellrate_index + phase];
|
2019-12-16 06:48:48 -06:00
|
|
|
}
|
|
|
|
}
|
2019-09-30 05:49:36 -05:00
|
|
|
|
2021-03-01 04:00:00 -06:00
|
|
|
// Apply group efficiency factor for this goup
|
|
|
|
auto gefac = group.getGroupEfficiencyFactor();
|
|
|
|
|
|
|
|
for (int phase = 0; phase < np; phase++) {
|
|
|
|
pot[phase] *= gefac;
|
|
|
|
}
|
|
|
|
|
2019-09-30 05:49:36 -05:00
|
|
|
double oilPot = 0.0;
|
|
|
|
if (pu.phase_used[BlackoilPhases::Liquid])
|
2020-03-27 07:27:45 -05:00
|
|
|
oilPot = pot[pu.phase_pos[BlackoilPhases::Liquid]];
|
2019-12-12 02:22:37 -06:00
|
|
|
|
2019-09-30 05:49:36 -05:00
|
|
|
double gasPot = 0.0;
|
|
|
|
if (pu.phase_used[BlackoilPhases::Vapour])
|
2020-03-27 07:27:45 -05:00
|
|
|
gasPot = pot[pu.phase_pos[BlackoilPhases::Vapour]];
|
2019-09-30 05:49:36 -05:00
|
|
|
|
|
|
|
double waterPot = 0.0;
|
|
|
|
if (pu.phase_used[BlackoilPhases::Aqua])
|
2020-03-27 07:27:45 -05:00
|
|
|
waterPot = pot[pu.phase_pos[BlackoilPhases::Aqua]];
|
2019-09-30 05:49:36 -05:00
|
|
|
|
2020-07-08 08:49:08 -05:00
|
|
|
oilPot = comm.sum(oilPot);
|
|
|
|
gasPot = comm.sum(gasPot);
|
|
|
|
waterPot = comm.sum(waterPot);
|
2021-03-10 07:26:04 -06:00
|
|
|
guideRate->productionGroupCompute(group.name(), reportStepIdx, simTime, oilPot, gasPot, waterPot);
|
2019-09-30 05:49:36 -05:00
|
|
|
}
|
|
|
|
|
2019-12-12 02:22:37 -06:00
|
|
|
template <class Comm>
|
2020-03-27 07:27:45 -05:00
|
|
|
void updateGuideRatesForWells(const Schedule& schedule,
|
|
|
|
const PhaseUsage& pu,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const double& simTime,
|
|
|
|
const WellStateFullyImplicitBlackoil& wellState,
|
|
|
|
const Comm& comm,
|
|
|
|
GuideRate* guideRate)
|
|
|
|
{
|
2019-12-12 02:22:37 -06:00
|
|
|
|
|
|
|
const auto& end = wellState.wellMap().end();
|
|
|
|
for (const auto& well : schedule.getWells(reportStepIdx)) {
|
|
|
|
double oilpot = 0.0;
|
|
|
|
double gaspot = 0.0;
|
|
|
|
double waterpot = 0.0;
|
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
const auto& it = wellState.wellMap().find(well.name());
|
2020-12-09 05:29:56 -06:00
|
|
|
if (it != end && wellState.wellIsOwned(it->second[0], well.name()))
|
|
|
|
{
|
|
|
|
// the well is found and owned
|
2019-12-12 02:22:37 -06:00
|
|
|
int well_index = it->second[0];
|
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
const auto wpot = wellState.wellPotentials().data() + well_index * wellState.numPhases();
|
2019-12-12 02:22:37 -06: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]];
|
|
|
|
}
|
2020-07-08 08:49:08 -05:00
|
|
|
oilpot = comm.sum(oilpot);
|
|
|
|
gaspot = comm.sum(gaspot);
|
|
|
|
waterpot = comm.sum(waterpot);
|
2021-03-10 07:26:04 -06:00
|
|
|
guideRate->wellCompute(well.name(), reportStepIdx, simTime, oilpot, gaspot, waterpot);
|
2019-12-12 02:22:37 -06:00
|
|
|
}
|
2020-03-24 03:24:45 -05:00
|
|
|
}
|
2019-08-07 07:13:11 -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,
|
|
|
|
const WellStateFullyImplicitBlackoil& wellState,
|
|
|
|
GuideRate* guideRate);
|
2019-12-12 02:22:37 -06:00
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
void updateVREPForGroups(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const WellStateFullyImplicitBlackoil& wellStateNupcol,
|
|
|
|
WellStateFullyImplicitBlackoil& wellState);
|
|
|
|
|
|
|
|
void updateReservoirRatesInjectionGroups(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const WellStateFullyImplicitBlackoil& wellStateNupcol,
|
|
|
|
WellStateFullyImplicitBlackoil& wellState);
|
|
|
|
|
|
|
|
void updateWellRates(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const WellStateFullyImplicitBlackoil& wellStateNupcol,
|
|
|
|
WellStateFullyImplicitBlackoil& wellState);
|
|
|
|
|
|
|
|
void updateGroupProductionRates(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const WellStateFullyImplicitBlackoil& wellStateNupcol,
|
|
|
|
WellStateFullyImplicitBlackoil& wellState);
|
|
|
|
|
|
|
|
void updateREINForGroups(const Group& group,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const PhaseUsage& pu,
|
|
|
|
const SummaryState& st,
|
|
|
|
const WellStateFullyImplicitBlackoil& wellStateNupcol,
|
|
|
|
WellStateFullyImplicitBlackoil& wellState);
|
|
|
|
|
2020-05-15 04:21:32 -05:00
|
|
|
std::map<std::string, double>
|
|
|
|
computeNetworkPressures(const Opm::Network::ExtNetwork& network,
|
|
|
|
const WellStateFullyImplicitBlackoil& well_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
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
GuideRate::RateVector
|
2021-03-10 07:26:04 -06:00
|
|
|
getWellRateVector(const WellStateFullyImplicitBlackoil& 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
|
|
|
GuideRate::RateVector
|
|
|
|
getProductionGroupRateVector(const WellStateFullyImplicitBlackoil& well_state, const PhaseUsage& pu, const std::string& group_name);
|
2020-03-27 07:27:45 -05:00
|
|
|
|
|
|
|
double getGuideRate(const std::string& name,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const WellStateFullyImplicitBlackoil& wellState,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const GuideRate* guideRate,
|
|
|
|
const GuideRateModel::Target target,
|
|
|
|
const PhaseUsage& pu);
|
|
|
|
|
|
|
|
|
|
|
|
double getGuideRateInj(const std::string& name,
|
|
|
|
const Schedule& schedule,
|
|
|
|
const WellStateFullyImplicitBlackoil& wellState,
|
|
|
|
const int reportStepIdx,
|
|
|
|
const GuideRate* guideRate,
|
|
|
|
const GuideRateModel::Target target,
|
|
|
|
const Phase& injectionPhase,
|
|
|
|
const PhaseUsage& pu);
|
2019-09-30 08:26:47 -05:00
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
int groupControlledWells(const Schedule& schedule,
|
|
|
|
const WellStateFullyImplicitBlackoil& well_state,
|
|
|
|
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);
|
2019-08-07 07:13:11 -05:00
|
|
|
|
2020-02-10 08:16:09 -06:00
|
|
|
|
|
|
|
class FractionCalculator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FractionCalculator(const Schedule& schedule,
|
2021-03-10 07:26:04 -06:00
|
|
|
const SummaryState& summary_state,
|
2020-02-10 08:16:09 -06:00
|
|
|
const WellStateFullyImplicitBlackoil& well_state,
|
|
|
|
const int report_step,
|
|
|
|
const GuideRate* guide_rate,
|
2020-03-23 10:14:31 -05:00
|
|
|
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
|
|
|
double fraction(const std::string& name, const std::string& control_group_name, const bool always_include_this);
|
|
|
|
double localFraction(const std::string& name, const std::string& always_included_child);
|
2020-03-23 10:14:31 -05:00
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
private:
|
|
|
|
std::string parent(const std::string& name);
|
2020-04-23 02:39:28 -05:00
|
|
|
double guideRateSum(const Group& group, const std::string& always_included_child);
|
2020-03-27 07:27:45 -05:00
|
|
|
double guideRate(const std::string& name, const std::string& always_included_child);
|
|
|
|
int groupControlledWells(const std::string& group_name, const std::string& always_included_child);
|
|
|
|
GuideRate::RateVector getGroupRateVector(const std::string& group_name);
|
2020-02-10 08:16:09 -06:00
|
|
|
const Schedule& schedule_;
|
2021-03-10 07:26:04 -06:00
|
|
|
const SummaryState& summary_state_;
|
2020-02-10 08:16:09 -06:00
|
|
|
const WellStateFullyImplicitBlackoil& well_state_;
|
|
|
|
int report_step_;
|
|
|
|
const GuideRate* guide_rate_;
|
|
|
|
GuideRateModel::Target target_;
|
2020-03-23 10:14:31 -05:00
|
|
|
PhaseUsage pu_;
|
2021-03-10 07:26:04 -06:00
|
|
|
bool is_producer_;
|
|
|
|
Phase injection_phase_;
|
2020-02-10 08:16:09 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
std::pair<bool, double> checkGroupConstraintsInj(const std::string& name,
|
|
|
|
const std::string& parent,
|
|
|
|
const Group& group,
|
|
|
|
const WellStateFullyImplicitBlackoil& wellState,
|
|
|
|
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);
|
2020-02-10 08:16:09 -06:00
|
|
|
|
2019-09-30 05:49:36 -05:00
|
|
|
|
2020-02-10 08:16:09 -06:00
|
|
|
|
2019-12-16 06:48:48 -06:00
|
|
|
|
2020-02-10 08:16:09 -06:00
|
|
|
|
|
|
|
|
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);
|
2020-02-10 08:16:09 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-30 05:49:36 -05:00
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
std::pair<bool, double> checkGroupConstraintsProd(const std::string& name,
|
|
|
|
const std::string& parent,
|
|
|
|
const Group& group,
|
|
|
|
const WellStateFullyImplicitBlackoil& wellState,
|
|
|
|
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);
|
2019-09-30 05:49:36 -05:00
|
|
|
|
2019-08-07 07:13:11 -05:00
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
} // namespace WellGroupHelpers
|
2019-08-07 07:13:11 -05:00
|
|
|
|
2020-03-27 07:27:45 -05:00
|
|
|
} // namespace Opm
|
2019-08-07 07:13:11 -05:00
|
|
|
|
|
|
|
#endif
|