My Project
Loading...
Searching...
No Matches
GasLiftGroupInfo.hpp
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
23#include <opm/simulators/wells/GasLiftCommon.hpp>
24
25#include <opm/simulators/utils/BlackoilPhases.hpp>
26
27#include <map>
28#include <optional>
29#include <string>
30#include <tuple>
31#include <vector>
32
33namespace Opm {
34
35class DeferredLogger;
36class GasLiftOpt;
37class Group;
38template<class Scalar> class GroupState;
39class Schedule;
40class SummaryState;
41class Well;
42template<class Scalar> class WellState;
43
44template<class Scalar>
45class GasLiftGroupInfo : public GasLiftCommon<Scalar>
46{
47protected:
48 class GroupRates;
49 // NOTE: In the Well2GroupMap below, in the std::vector value we store
50 // pairs of group names and efficiency factors. The efficiency factors
51 // are the product of the wells efficiency factor and all the efficiency
52 // factors of the child groups of the group all the way down
53 // to the well group.
54 using Well2GroupMap =
55 std::map<std::string, std::vector<std::pair<std::string,Scalar>>>;
56 using GroupRateMap =
57 std::map<std::string, GroupRates>;
58 using GroupIdxMap = std::map<std::string, int>;
59 using Communication = Dune::Communication<Dune::MPIHelper::MPICommunicator>;
60
61 // TODO: same definition with WellInterface, and
62 // WellState eventually they should go to a common header file.
63 static const int Water = BlackoilPhases::Aqua;
64 static const int Oil = BlackoilPhases::Liquid;
65 static const int Gas = BlackoilPhases::Vapour;
66
67public:
68 enum class Rate {oil, gas, water, liquid};
69
70 using GLiftEclWells = std::map<std::string,std::pair<const Well *,int>>;
71 GasLiftGroupInfo(GLiftEclWells& ecl_wells,
72 const Schedule& schedule,
74 const int report_step_idx,
75 const int iteration_idx,
78 WellState<Scalar>& well_state,
79 const GroupState<Scalar>& group_state,
80 const Parallel::Communication& comm,
81 bool glift_debug);
82
83 std::vector<std::pair<std::string,Scalar>>&
84 getWellGroups(const std::string& well_name);
85
86 Scalar alqRate(const std::string& group_name);
87 Scalar gasRate(const std::string& group_name) const;
88 Scalar gasPotential(const std::string& group_name) const;
89 Scalar waterPotential(const std::string& group_name) const;
90 Scalar oilPotential(const std::string& group_name) const;
91 int getGroupIdx(const std::string& group_name);
92 Scalar getRate(Rate rate_type, const std::string& group_name) const;
93 Scalar getPotential(Rate rate_type, const std::string& group_name) const;
94 std::tuple<Scalar,Scalar,Scalar,Scalar> getRates(const int group_idx) const;
95 std::optional<Scalar> gasTarget(const std::string& group_name) const;
96 std::optional<Scalar> getTarget(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);
100 void initialize();
101 std::optional<Scalar> liquidTarget(const std::string& group_name) const;
102 std::optional<Scalar> maxAlq(const std::string& group_name);
103 std::optional<Scalar> maxTotalGasRate(const std::string& group_name);
104 Scalar oilRate(const std::string& group_name) const;
105 std::optional<Scalar> oilTarget(const std::string& group_name) const;
106 static const std::string rateToString(Rate rate);
107 Scalar waterRate(const std::string& group_name) const;
108 std::optional<Scalar> waterTarget(const std::string& group_name) const;
109 void update(const std::string& well_name,
110 Scalar delta_oil,
111 Scalar delta_gas,
112 Scalar delta_water,
113 Scalar delta_alq);
114 void updateRate(int idx,
115 Scalar oil_rate,
116 Scalar gas_rate,
117 Scalar water_rate,
118 Scalar alq);
119 const Well2GroupMap& wellGroupMap() { return well_group_map_; }
120
121protected:
122 bool checkDoGasLiftOptimization_(const std::string& well_name);
123 bool checkNewtonIterationIdxOk_(const std::string& well_name);
124 void debugDisplayWellContribution_(const std::string& gr_name,
125 const std::string& well_name,
126 Scalar eff_factor,
127 Scalar well_oil_rate,
128 Scalar well_gas_rate,
129 Scalar well_water_rate,
130 Scalar well_alq,
131 Scalar oil_rate,
132 Scalar gas_rate,
133 Scalar water_rate,
134 Scalar alq) const;
135 void debugDisplayUpdatedGroupRates(const std::string& name,
136 Scalar oil_rate,
137 Scalar gas_rate,
138 Scalar water_rate,
139 Scalar alq) const;
140 void debugEndInitializeGroup(const std::string& name) const;
141 void debugStartInitializeGroup(const std::string& name) const;
142 void displayDebugMessage_(const std::string& msg) const override;
143 void displayDebugMessage_(const std::string& msg, const std::string& well_name);
144
145 std::tuple<Scalar, Scalar, Scalar, Scalar, Scalar, Scalar>
146 getProducerWellRates_(const Well* well, const int index);
147
148 std::tuple<Scalar, Scalar, Scalar, Scalar, Scalar, Scalar, Scalar>
149 initializeGroupRatesRecursive_(const Group &group);
150
151 void initializeWell2GroupMapRecursive_(const Group& group,
152 std::vector<std::string>& group_names,
153 std::vector<Scalar>& group_efficiency,
154 Scalar cur_efficiency);
155 void updateGroupIdxMap_(const std::string& group_name);
156
158 public:
159 GroupRates(Scalar oil_rate,
160 Scalar gas_rate,
161 Scalar water_rate,
162 Scalar alq,
163 Scalar oil_potential,
164 Scalar gas_potential,
165 Scalar water_potential,
166 std::optional<Scalar> oil_target,
167 std::optional<Scalar> gas_target,
168 std::optional<Scalar> water_target,
169 std::optional<Scalar> liquid_target,
170 std::optional<Scalar> total_gas,
171 std::optional<Scalar> max_alq)
172 : oil_rate_{oil_rate}
173 , gas_rate_{gas_rate}
174 , water_rate_{water_rate}
175 , alq_{alq}
176 , oil_potential_{oil_potential}
177 , gas_potential_{gas_potential}
178 , water_potential_{water_potential}
179 , oil_target_{oil_target}
180 , gas_target_{gas_target}
181 , water_target_{water_target}
182 , liquid_target_{liquid_target}
183 , total_gas_{total_gas}
184 , max_alq_{max_alq}
185 {}
186
187 Scalar alq() const { return alq_; }
188 void assign(Scalar oil_rate,
189 Scalar gas_rate,
190 Scalar water_rate,
191 Scalar alq)
192 {
193 oil_rate_ = oil_rate;
194 gas_rate_ = gas_rate;
195 water_rate_ = water_rate;
196 alq_ = alq;
197 }
198 Scalar gasRate() const { return gas_rate_; }
199 Scalar waterRate() const { return water_rate_; }
200 std::optional<Scalar> gasTarget() const { return gas_target_; }
201 std::optional<Scalar> waterTarget() const { return water_target_; }
202 std::optional<Scalar> maxAlq() const { return max_alq_; }
203 std::optional<Scalar > maxTotalGasRate() const { return total_gas_; }
204 Scalar oilRate() const { return oil_rate_; }
205 std::optional<Scalar> oilTarget() const { return oil_target_; }
206 std::optional<Scalar> liquidTarget() const { return liquid_target_; }
207 Scalar oilPotential() const { return oil_potential_; }
208 Scalar gasPotential() const { return gas_potential_; }
209 Scalar waterPotential() const { return water_potential_; }
210
211 void update(Scalar delta_oil,
212 Scalar delta_gas,
213 Scalar delta_water,
214 Scalar delta_alq)
215 {
216 oil_rate_ += delta_oil;
217 gas_rate_ += delta_gas;
218 water_rate_ += delta_water;
219 alq_ += delta_alq;
220 // Note. We don't updata the potentials at this point. They
221 // are only needed initially.
222 }
223
224 private:
225 Scalar oil_rate_;
226 Scalar gas_rate_;
227 Scalar water_rate_;
228 Scalar alq_;
229 Scalar oil_potential_;
230 Scalar gas_potential_;
231 Scalar water_potential_;
232 std::optional<Scalar> oil_target_;
233 std::optional<Scalar> gas_target_;
234 std::optional<Scalar> water_target_;
235 std::optional<Scalar> liquid_target_;
236 std::optional<Scalar> total_gas_;
237 std::optional<Scalar> max_alq_;
238 };
239
240 GLiftEclWells& ecl_wells_;
241 const Schedule& schedule_;
242 const SummaryState& summary_state_;
243 const int report_step_idx_;
244 const int iteration_idx_;
245 const PhaseUsage& phase_usage_;
246 const GasLiftOpt& glo_;
247 GroupRateMap group_rate_map_;
248 Well2GroupMap well_group_map_;
249 GroupIdxMap group_idx_;
250 int next_group_idx_ = 0;
251 // Optimize only wells under THP control
252 bool optimize_only_thp_wells_ = false;
253};
254
255} // namespace Opm
256
257#endif // OPM_GASLIFT_GROUP_INFO_INCLUDED
Definition DeferredLogger.hpp:57
Definition GasLiftCommon.hpp:35
Definition GasLiftGroupInfo.hpp:157
Definition GasLiftGroupInfo.hpp:46
Definition GroupState.hpp:38
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition WellState.hpp:62
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilboundaryratevector.hh:37
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242
Definition BlackoilPhases.hpp:46