GasLiftGroupInfo.hpp
Go to the documentation of this file.
1/*
2 Copyright 2021 Equinor ASA.
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef OPM_GASLIFT_GROUP_INFO_HEADER_INCLUDED
21#define OPM_GASLIFT_GROUP_INFO_HEADER_INCLUDED
22
25
26#include <map>
27#include <optional>
28#include <string>
29#include <tuple>
30#include <vector>
31
32namespace Opm
33{
34
35class DeferredLogger;
36class GasLiftOpt;
37class Group;
38template<class Scalar> class GroupState;
39class Schedule;
40class SummaryState;
41class Well;
42template<class Scalar> class WellState;
43
45{
46protected:
47 class GroupRates;
48 // NOTE: In the Well2GroupMap below, in the std::vector value we store
49 // pairs of group names and efficiency factors. The efficiency factors
50 // are the product of the wells efficiency factor and all the efficiency
51 // factors of the child groups of the group all the way down
52 // to the well group.
54 std::map<std::string, std::vector<std::pair<std::string,double>>>;
56 std::map<std::string, GroupRates>;
57 using GroupIdxMap = std::map<std::string, int>;
58 using Communication = Dune::Communication<Dune::MPIHelper::MPICommunicator>;
59
60 // TODO: same definition with WellInterface, and
61 // WellState eventually they should go to a common header file.
62 static const int Water = BlackoilPhases::Aqua;
63 static const int Oil = BlackoilPhases::Liquid;
64 static const int Gas = BlackoilPhases::Vapour;
65public:
66 enum class Rate {oil, gas, water, liquid};
67
68 using GLiftEclWells = std::map<std::string,std::pair<const Well *,int>>;
70 GLiftEclWells& ecl_wells,
71 const Schedule& schedule,
72 const SummaryState& summary_state,
73 const int report_step_idx,
74 const int iteration_idx,
75 const PhaseUsage& phase_usage,
76 DeferredLogger& deferred_logger,
77 WellState<double>& well_state,
78 const GroupState<double>& group_state,
79 const Parallel::Communication& comm,
80 bool glift_debug
81 );
82 std::vector<std::pair<std::string,double>>& getWellGroups(
83 const std::string& well_name);
84
85 double alqRate(const std::string& group_name);
86 double gasRate(const std::string& group_name) const;
87 double gasPotential(const std::string& group_name) const;
88 double waterPotential(const std::string& group_name) const;
89 double oilPotential(const std::string& group_name) const;
90 int getGroupIdx(const std::string& group_name);
91 double getRate(Rate rate_type, const std::string& group_name) const;
92 double getPotential(Rate rate_type, const std::string& group_name) const;
93 std::tuple<double,double,double,double> getRates(const int group_idx) const;
94 std::optional<double> gasTarget(const std::string& group_name) const;
95 std::optional<double> getTarget(
96 Rate rate_type, const std::string& group_name) const;
97 const std::string& groupIdxToName(int group_idx) const;
98 bool hasAnyTarget(const std::string& group_name) const;
99 bool hasWell(const std::string& well_name);
101 std::optional<double> liquidTarget(const std::string& group_name) const;
102 std::optional<double> maxAlq(const std::string& group_name);
103 std::optional<double> maxTotalGasRate(const std::string& group_name);
104 double oilRate(const std::string& group_name) const;
105 std::optional<double> oilTarget(const std::string& group_name) const;
106 static const std::string rateToString(Rate rate);
107 double waterRate(const std::string& group_name) const;
108 std::optional<double> waterTarget(const std::string& group_name) const;
109 void update(const std::string& well_name,
110 double delta_oil, double delta_gas, double delta_water, double delta_alq);
111 void updateRate(int idx, double oil_rate, double gas_rate, double water_rate, double alq);
113protected:
114 bool checkDoGasLiftOptimization_(const std::string& well_name);
115 bool checkNewtonIterationIdxOk_(const std::string& well_name);
117 const std::string& gr_name, const std::string& well_name,
118 double eff_factor,
119 double well_oil_rate, double well_gas_rate, double well_water_rate,
120 double well_alq,
121 double oil_rate, double gas_rate, double water_rate,
122 double alq
123 ) const;
124 void debugDisplayUpdatedGroupRates(const std::string& name,
125 double oil_rate, double gas_rate, double water_rate, double alq) const;
126 void debugEndInitializeGroup(const std::string& name) const;
127 void debugStartInitializeGroup(const std::string& name) const;
128 void displayDebugMessage_(const std::string& msg) const override;
129 void displayDebugMessage_(const std::string& msg, const std::string& well_name);
130 std::tuple<double, double, double, double, double, double>
131 getProducerWellRates_(const Well* well, const int index);
132 std::tuple<double, double, double, double, double, double, double>
135 const Group& group, std::vector<std::string>& group_names,
136 std::vector<double>& group_efficiency, double cur_efficiency);
137 void updateGroupIdxMap_(const std::string& group_name);
138
139
141 public:
142 GroupRates( double oil_rate, double gas_rate, double water_rate, double alq,
143 double oil_potential, double gas_potential, double water_potential,
144 std::optional<double> oil_target,
145 std::optional<double> gas_target,
146 std::optional<double> water_target,
147 std::optional<double> liquid_target,
148 std::optional<double> total_gas,
149 std::optional<double> max_alq
150 ) :
151 oil_rate_{oil_rate},
152 gas_rate_{gas_rate},
153 water_rate_{water_rate},
154 alq_{alq},
155 oil_potential_{oil_potential},
156 gas_potential_{gas_potential},
157 water_potential_{water_potential},
158 oil_target_{oil_target},
159 gas_target_{gas_target},
160 water_target_{water_target},
161 liquid_target_{liquid_target},
162 total_gas_{total_gas},
163 max_alq_{max_alq}
164 {}
165 double alq() const { return alq_; }
166 void assign(double oil_rate, double gas_rate, double water_rate, double alq)
167 {
168 oil_rate_ = oil_rate;
169 gas_rate_ = gas_rate;
170 water_rate_ = water_rate;
171 alq_ = alq;
172 }
173 double gasRate() const { return gas_rate_; }
174 double waterRate() const { return water_rate_; }
175 std::optional<double> gasTarget() const { return gas_target_; }
176 std::optional<double> waterTarget() const { return water_target_; }
177 std::optional<double> maxAlq() const { return max_alq_; }
178 std::optional<double> maxTotalGasRate() const { return total_gas_; }
179 double oilRate() const { return oil_rate_; }
180 std::optional<double> oilTarget() const { return oil_target_; }
181 std::optional<double> liquidTarget() const { return liquid_target_; }
182 double oilPotential() const { return oil_potential_; }
183 double gasPotential() const { return gas_potential_; }
184 double waterPotential() const { return water_potential_; }
185
186 void update(double delta_oil, double delta_gas, double delta_water, double delta_alq)
187 {
188 oil_rate_ += delta_oil;
189 gas_rate_ += delta_gas;
190 water_rate_ += delta_water;
191 alq_ += delta_alq;
192 // Note. We don't updata the potentials at this point. They
193 // are only needed initially.
194 }
195 private:
196 double oil_rate_;
197 double gas_rate_;
198 double water_rate_;
199 double alq_;
200 double oil_potential_;
201 double gas_potential_;
202 double water_potential_;
203 std::optional<double> oil_target_;
204 std::optional<double> gas_target_;
205 std::optional<double> water_target_;
206 std::optional<double> liquid_target_;
207 std::optional<double> total_gas_;
208 std::optional<double> max_alq_;
209 };
210
212 const Schedule &schedule_;
213 const SummaryState &summary_state_;
215 const int iteration_idx_;
217 const GasLiftOpt& glo_;
222 // Optimize only wells under THP control
224
225};
226
227} // namespace Opm
228
229#endif // OPM_GASLIFT_GROUP_INFO_INCLUDED
@ Liquid
Definition: BlackoilPhases.hpp:42
@ Aqua
Definition: BlackoilPhases.hpp:42
@ Vapour
Definition: BlackoilPhases.hpp:42
Definition: DeferredLogger.hpp:57
Definition: GasLiftCommon.hpp:35
Definition: GasLiftGroupInfo.hpp:140
std::optional< double > oilTarget() const
Definition: GasLiftGroupInfo.hpp:180
double gasPotential() const
Definition: GasLiftGroupInfo.hpp:183
std::optional< double > gasTarget() const
Definition: GasLiftGroupInfo.hpp:175
std::optional< double > maxTotalGasRate() const
Definition: GasLiftGroupInfo.hpp:178
void update(double delta_oil, double delta_gas, double delta_water, double delta_alq)
Definition: GasLiftGroupInfo.hpp:186
std::optional< double > maxAlq() const
Definition: GasLiftGroupInfo.hpp:177
double waterRate() const
Definition: GasLiftGroupInfo.hpp:174
void assign(double oil_rate, double gas_rate, double water_rate, double alq)
Definition: GasLiftGroupInfo.hpp:166
double oilPotential() const
Definition: GasLiftGroupInfo.hpp:182
std::optional< double > liquidTarget() const
Definition: GasLiftGroupInfo.hpp:181
GroupRates(double oil_rate, double gas_rate, double water_rate, double alq, double oil_potential, double gas_potential, double water_potential, std::optional< double > oil_target, std::optional< double > gas_target, std::optional< double > water_target, std::optional< double > liquid_target, std::optional< double > total_gas, std::optional< double > max_alq)
Definition: GasLiftGroupInfo.hpp:142
double alq() const
Definition: GasLiftGroupInfo.hpp:165
std::optional< double > waterTarget() const
Definition: GasLiftGroupInfo.hpp:176
double gasRate() const
Definition: GasLiftGroupInfo.hpp:173
double oilRate() const
Definition: GasLiftGroupInfo.hpp:179
double waterPotential() const
Definition: GasLiftGroupInfo.hpp:184
Definition: GasLiftGroupInfo.hpp:45
std::optional< double > maxAlq(const std::string &group_name)
GLiftEclWells & ecl_wells_
Definition: GasLiftGroupInfo.hpp:211
bool hasAnyTarget(const std::string &group_name) const
void initializeWell2GroupMapRecursive_(const Group &group, std::vector< std::string > &group_names, std::vector< double > &group_efficiency, double cur_efficiency)
std::map< std::string, std::pair< const Well *, int > > GLiftEclWells
Definition: GasLiftGroupInfo.hpp:68
void debugEndInitializeGroup(const std::string &name) const
std::optional< double > getTarget(Rate rate_type, const std::string &group_name) const
int getGroupIdx(const std::string &group_name)
std::tuple< double, double, double, double, double, double > getProducerWellRates_(const Well *well, const int index)
GasLiftGroupInfo(GLiftEclWells &ecl_wells, const Schedule &schedule, const SummaryState &summary_state, const int report_step_idx, const int iteration_idx, const PhaseUsage &phase_usage, DeferredLogger &deferred_logger, WellState< double > &well_state, const GroupState< double > &group_state, const Parallel::Communication &comm, bool glift_debug)
static const int Gas
Definition: GasLiftGroupInfo.hpp:64
void debugDisplayWellContribution_(const std::string &gr_name, const std::string &well_name, double eff_factor, double well_oil_rate, double well_gas_rate, double well_water_rate, double well_alq, double oil_rate, double gas_rate, double water_rate, double alq) const
double gasRate(const std::string &group_name) const
double oilRate(const std::string &group_name) const
Dune::Communication< Dune::MPIHelper::MPICommunicator > Communication
Definition: GasLiftGroupInfo.hpp:58
void displayDebugMessage_(const std::string &msg) const override
std::optional< double > maxTotalGasRate(const std::string &group_name)
Well2GroupMap well_group_map_
Definition: GasLiftGroupInfo.hpp:219
const SummaryState & summary_state_
Definition: GasLiftGroupInfo.hpp:213
double waterPotential(const std::string &group_name) const
void debugStartInitializeGroup(const std::string &name) const
const int report_step_idx_
Definition: GasLiftGroupInfo.hpp:214
Rate
Definition: GasLiftGroupInfo.hpp:66
double getPotential(Rate rate_type, const std::string &group_name) const
std::optional< double > gasTarget(const std::string &group_name) const
bool checkNewtonIterationIdxOk_(const std::string &well_name)
std::optional< double > liquidTarget(const std::string &group_name) const
double gasPotential(const std::string &group_name) const
const PhaseUsage & phase_usage_
Definition: GasLiftGroupInfo.hpp:216
std::map< std::string, int > GroupIdxMap
Definition: GasLiftGroupInfo.hpp:57
bool checkDoGasLiftOptimization_(const std::string &well_name)
const GasLiftOpt & glo_
Definition: GasLiftGroupInfo.hpp:217
double alqRate(const std::string &group_name)
void updateRate(int idx, double oil_rate, double gas_rate, double water_rate, double alq)
std::tuple< double, double, double, double, double, double, double > initializeGroupRatesRecursive_(const Group &group)
int next_group_idx_
Definition: GasLiftGroupInfo.hpp:221
const Well2GroupMap & wellGroupMap()
Definition: GasLiftGroupInfo.hpp:112
std::map< std::string, std::vector< std::pair< std::string, double > > > Well2GroupMap
Definition: GasLiftGroupInfo.hpp:54
void debugDisplayUpdatedGroupRates(const std::string &name, double oil_rate, double gas_rate, double water_rate, double alq) const
double oilPotential(const std::string &group_name) const
std::optional< double > waterTarget(const std::string &group_name) const
const int iteration_idx_
Definition: GasLiftGroupInfo.hpp:215
GroupIdxMap group_idx_
Definition: GasLiftGroupInfo.hpp:220
std::optional< double > oilTarget(const std::string &group_name) const
const std::string & groupIdxToName(int group_idx) const
const Schedule & schedule_
Definition: GasLiftGroupInfo.hpp:212
bool optimize_only_thp_wells_
Definition: GasLiftGroupInfo.hpp:223
double getRate(Rate rate_type, const std::string &group_name) const
static const std::string rateToString(Rate rate)
void displayDebugMessage_(const std::string &msg, const std::string &well_name)
static const int Water
Definition: GasLiftGroupInfo.hpp:62
std::map< std::string, GroupRates > GroupRateMap
Definition: GasLiftGroupInfo.hpp:56
std::tuple< double, double, double, double > getRates(const int group_idx) const
bool hasWell(const std::string &well_name)
void update(const std::string &well_name, double delta_oil, double delta_gas, double delta_water, double delta_alq)
std::vector< std::pair< std::string, double > > & getWellGroups(const std::string &well_name)
GroupRateMap group_rate_map_
Definition: GasLiftGroupInfo.hpp:218
static const int Oil
Definition: GasLiftGroupInfo.hpp:63
void updateGroupIdxMap_(const std::string &group_name)
double waterRate(const std::string &group_name) const
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
bool water(const PhaseUsage &pu)
Definition: RegionAttributeHelpers.hpp:308
bool oil(const PhaseUsage &pu)
Definition: RegionAttributeHelpers.hpp:321
bool gas(const PhaseUsage &pu)
Definition: RegionAttributeHelpers.hpp:334
Definition: BlackoilPhases.hpp:27
Definition: BlackoilPhases.hpp:46