My Project
Loading...
Searching...
No Matches
GasLiftStage2.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_STAGE2_HEADER_INCLUDED
21#define OPM_GASLIFT_STAGE2_HEADER_INCLUDED
22
23#include <opm/simulators/wells/GasLiftSingleWellGeneric.hpp>
24
25#include <opm/simulators/utils/BlackoilPhases.hpp>
26
27#include <map>
28#include <memory>
29#include <optional>
30#include <string>
31#include <tuple>
32#include <vector>
33
34namespace Opm {
35
36class DeferredLogger;
37class GasLiftOpt;
38template<class Scalar> class GasLiftWellState;
39class Group;
40template<class Scalar> class GroupState;
41class Schedule;
42template<class Scalar> class WellInterfaceGeneric;
43template<class Scalar> class WellState;
44
45template<class Scalar>
46class GasLiftStage2 : public GasLiftCommon<Scalar>
47{
49 using GLiftOptWells = std::map<std::string,std::unique_ptr<GasLiftSingleWell>>;
50 using GLiftProdWells = std::map<std::string,const WellInterfaceGeneric<Scalar>*>;
51 using GLiftWellStateMap = std::map<std::string,std::unique_ptr<GasLiftWellState<Scalar>>>;
52 using GradPair = std::pair<std::string, Scalar>;
53 using GradPairItr = typename std::vector<GradPair>::iterator;
54 using GradInfo = typename GasLiftSingleWellGeneric<Scalar>::GradInfo;
55 using GradMap = std::map<std::string, GradInfo>;
56 using MessageType = typename GasLiftCommon<Scalar>::MessageType;
57
58 static const int Water = BlackoilPhases::Aqua;
59 static const int Oil = BlackoilPhases::Liquid;
60 static const int Gas = BlackoilPhases::Vapour;
61
62public:
64 const Parallel::Communication& comm,
65 const Schedule& schedule,
68 WellState<Scalar>& well_state,
69 const GroupState<Scalar>& group_state,
70 GLiftProdWells& prod_wells,
71 GLiftOptWells& glift_wells,
73 GLiftWellStateMap& state_map,
74 bool glift_debug);
75
76 void runOptimize();
77
78protected:
79 void addOrRemoveALQincrement_(GradMap& grad_map,
80 const std::string& well_name,
81 bool add);
82
83 std::optional<GradInfo> calcIncOrDecGrad_(const std::string name,
85 const std::string& gr_name_dont_limit,
86 bool increase);
87
88 bool checkRateAlreadyLimited_(const std::string& well_name,
90 bool increase);
91
92 GradInfo deleteDecGradItem_(const std::string& name);
93 GradInfo deleteIncGradItem_(const std::string& name);
94 GradInfo deleteGrad_(const std::string& name, bool increase);
95
96 void displayDebugMessage_(const std::string& msg) const override;
97 void displayDebugMessage2B_(const std::string& msg);
98 void displayDebugMessage_(const std::string& msg,
99 const std::string& group_name);
100 void displayWarning_(const std::string& msg,
101 const std::string& group_name);
102 void displayWarning_(const std::string& msg);
103
104 std::tuple<Scalar, Scalar, Scalar, Scalar>
105 getCurrentGroupRates_(const Group& group);
106
107 std::optional<Scalar> getGroupMaxALQ_(const Group& group);
108 std::optional<Scalar> getGroupMaxTotalGas_(const Group& group);
109
110 std::vector<GasLiftSingleWell*> getGroupGliftWells_(const Group& group);
111
112 void getGroupGliftWellsRecursive_(const Group& group,
113 std::vector<GasLiftSingleWell*>& wells);
114
115 void optimizeGroup_(const Group& group);
116 void optimizeGroupsRecursive_(const Group& group);
117
118 void recalculateGradientAndUpdateData_(GradPairItr& grad_itr,
119 const std::string& gr_name_dont_limit,
120 bool increase,
121 std::vector<GradPair>& grads,
122 std::vector<GradPair>& other_grads);
123
124 void redistributeALQ_(std::vector<GasLiftSingleWell*>& wells,
125 const Group& group,
126 std::vector<GradPair>& inc_grads,
127 std::vector<GradPair>& dec_grads);
128
129 void removeSurplusALQ_(const Group& group,
130 std::vector<GradPair>& dec_grads);
131
132 void saveGrad_(GradMap& map, const std::string& name, GradInfo& grad);
133 void saveDecGrad_(const std::string& name, GradInfo& grad);
134 void saveIncGrad_(const std::string& name, GradInfo& grad);
135 void sortGradients_(std::vector<GradPair>& grads);
136
137 std::optional<GradInfo> updateGrad_(const std::string& name,
138 GradInfo& grad, bool increase);
139
140 void updateGradVector_(const std::string& name,
141 std::vector<GradPair>& grads,
142 Scalar grad);
143
144 void mpiSyncGlobalGradVector_(std::vector<GradPair>& grads_global) const;
145 void mpiSyncLocalToGlobalGradVector_(const std::vector<GradPair>& grads_local,
146 std::vector<GradPair>& grads_global) const;
147
148 std::array<Scalar, 4> computeDelta(const std::string& name, bool add);
149 void updateGroupInfo(const std::string& name, bool add);
150
151
152 GLiftProdWells& prod_wells_;
153 GLiftOptWells& stage1_wells_;
154 GasLiftGroupInfo<Scalar>& group_info_;
155 GLiftWellStateMap& well_state_map_;
156
157 int report_step_idx_;
158 const SummaryState& summary_state_;
159 const Schedule& schedule_;
160 const GasLiftOpt& glo_;
161 GradMap inc_grads_;
162 GradMap dec_grads_;
163 int max_iterations_ = 1000;
164 //int time_step_idx_;
165
167 {
168 OptimizeState(GasLiftStage2& parent_, const Group& group_)
169 : parent{parent_}
170 , group{group_}
171 , it{0}
172 {}
173
174 GasLiftStage2& parent;
175 const Group& group;
176 int it;
177
178 using GradInfo = typename GasLiftStage2::GradInfo;
179 using GradPair = typename GasLiftStage2::GradPair;
180 using GradPairItr = typename GasLiftStage2::GradPairItr;
181 using GradMap = typename GasLiftStage2::GradMap;
182
183 void calculateEcoGradients(std::vector<GasLiftSingleWell*>& wells,
184 std::vector<GradPair>& inc_grads,
185 std::vector<GradPair>& dec_grads);
186
187 bool checkAtLeastTwoWells(std::vector<GasLiftSingleWell*>& wells);
188
189 void debugShowIterationInfo();
190
191 std::pair<std::optional<GradPairItr>,std::optional<GradPairItr>>
192 getEcoGradients(std::vector<GradPair>& inc_grads,
193 std::vector<GradPair>& dec_grads);
194
195 void recalculateGradients(std::vector<GradPair>& inc_grads,
196 std::vector<GradPair>& dec_grads,
197 GradPairItr& min_dec_grad_itr,
198 GradPairItr &max_inc_grad_itr);
199
200 void redistributeALQ( GradPairItr& min_dec_grad,
201 GradPairItr& max_inc_grad);
202
203 private:
204 void displayDebugMessage_(const std::string& msg);
205 void displayWarning_(const std::string& msg);
206 };
207
209 {
211 const Group& group_,
212 const WellState<Scalar>& well_state_,
213 Scalar oil_rate_,
214 Scalar gas_rate_,
215 Scalar water_rate_,
216 Scalar alq_,
217 Scalar min_eco_grad_,
218 Scalar oil_target_,
219 Scalar gas_target_,
220 Scalar water_target_,
221 Scalar liquid_target_,
222 std::optional<Scalar> max_glift_,
223 std::optional<Scalar> max_total_gas_)
224 : parent{parent_}
225 , group{group_}
226 , well_state(well_state_)
227 , oil_rate{oil_rate_}
228 , gas_rate{gas_rate_}
229 , water_rate{water_rate_}
230 , alq{alq_}
231 , min_eco_grad{min_eco_grad_}
232 , oil_target{oil_target_}
233 , gas_target{gas_target_}
234 , water_target(water_target_)
235 , liquid_target{liquid_target_}
236 , max_glift{max_glift_}
237 , max_total_gas{max_total_gas_}
238 , it{0}
239 {}
240
241 GasLiftStage2 &parent;
242 const Group &group;
243 const WellState<Scalar>& well_state;
244 Scalar oil_rate;
245 Scalar gas_rate;
246 Scalar water_rate;
247 Scalar alq;
248 const Scalar min_eco_grad;
249 const Scalar oil_target;
250 const Scalar gas_target;
251 const Scalar water_target;
252 const Scalar liquid_target;
253 std::optional<Scalar> max_glift;
254 std::optional<Scalar> max_total_gas;
255 int it;
256
257 void addOrRemoveALQincrement(GradMap &grad_map,
258 const std::string& well_name,
259 bool add);
260
261 bool checkALQlimit();
262 bool checkEcoGradient(const std::string& well_name, Scalar eco_grad);
263 bool checkGasTarget(Scalar delta_gas);
264 bool checkLiquidTarget(Scalar delta_liquid);
265 bool checkOilTarget(Scalar delta_oil);
266 bool checkWaterTarget(Scalar delta_water);
267 std::array<Scalar, 4> computeDelta(const std::string& name);
268 void updateRates(const std::array<Scalar, 4>& delta);
269 };
270};
271
272} // namespace Opm
273
274#endif // OPM_GASLIFT_STAGE2_HEADER_INCLUDED
Definition DeferredLogger.hpp:57
Definition GasLiftCommon.hpp:35
Definition GasLiftGroupInfo.hpp:46
Definition GasLiftSingleWellGeneric.hpp:50
Definition GasLiftStage2.hpp:47
Definition GasLiftWellState.hpp:30
Definition GroupState.hpp:43
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition WellState.hpp:66
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 GasLiftSingleWellGeneric.hpp:64
Definition GasLiftStage2.hpp:167
Definition GasLiftStage2.hpp:209