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/core/props/BlackoilPhases.hpp>
24#include <opm/simulators/wells/GasLiftSingleWellGeneric.hpp>
25
26#include <map>
27#include <memory>
28#include <optional>
29#include <string>
30#include <tuple>
31#include <vector>
32
33namespace Opm
34{
35
36class DeferredLogger;
37class GasLiftOpt;
38class GasLiftWellState;
39class Group;
40class GroupState;
41class Schedule;
42class WellInterfaceGeneric;
43class WellState;
44
47 using GLiftOptWells = std::map<std::string,std::unique_ptr<GasLiftSingleWell>>;
48 using GLiftProdWells = std::map<std::string,const WellInterfaceGeneric*>;
49 using GLiftWellStateMap = std::map<std::string,std::unique_ptr<GasLiftWellState>>;
50 using GradPair = std::pair<std::string, double>;
51 using GradPairItr = std::vector<GradPair>::iterator;
52 using GradInfo = typename GasLiftSingleWellGeneric::GradInfo;
53 using GradMap = std::map<std::string, GradInfo>;
54 using MPIComm = typename Dune::MPIHelper::MPICommunicator;
55 static const int Water = BlackoilPhases::Aqua;
56 static const int Oil = BlackoilPhases::Liquid;
57 static const int Gas = BlackoilPhases::Vapour;
58public:
60 const int report_step_idx,
61 const Parallel::Communication& comm,
62 const Schedule& schedule,
63 const SummaryState& summary_state,
64 DeferredLogger& deferred_logger,
65 WellState& well_state,
66 const GroupState& group_state,
67 GLiftProdWells& prod_wells,
68 GLiftOptWells& glift_wells,
69 GasLiftGroupInfo& group_info,
70 GLiftWellStateMap& state_map,
71 bool glift_debug
72 );
73 void runOptimize();
74protected:
75 void addOrRemoveALQincrement_(
76 GradMap& grad_map, const std::string& well_name, bool add);
77 std::optional<GradInfo> calcIncOrDecGrad_(
78 const std::string name, const GasLiftSingleWell& gs_well, const std::string& gr_name_dont_limit, bool increase);
79 bool checkRateAlreadyLimited_(const std::string& well_name, GasLiftWellState& state, bool increase);
80 GradInfo deleteDecGradItem_(const std::string& name);
81 GradInfo deleteIncGradItem_(const std::string& name);
82 GradInfo deleteGrad_(const std::string& name, bool increase);
83 void displayDebugMessage_(const std::string& msg) const override;
84 void displayDebugMessage2B_(const std::string& msg);
85 void displayDebugMessage_(const std::string& msg, const std::string& group_name);
86 void displayWarning_(const std::string& msg, const std::string& group_name);
87 void displayWarning_(const std::string& msg);
88 std::tuple<double, double, double, double> getCurrentGroupRates_(const Group& group);
89 std::optional<double> getGroupMaxALQ_(const Group &group);
90 std::optional<double> getGroupMaxTotalGas_(const Group &group);
91 std::vector<GasLiftSingleWell *> getGroupGliftWells_(
92 const Group& group);
93 void getGroupGliftWellsRecursive_(
94 const Group& group, std::vector<GasLiftSingleWell *>& wells);
95 void optimizeGroup_(const Group& group);
96 void optimizeGroupsRecursive_(const Group& group);
97 void recalculateGradientAndUpdateData_(
98 GradPairItr& grad_itr, const std::string& gr_name_dont_limit, bool increase,
99 std::vector<GradPair>& grads, std::vector<GradPair>& other_grads);
100 void redistributeALQ_(
101 std::vector<GasLiftSingleWell *>& wells, const Group& group,
102 std::vector<GradPair>& inc_grads, std::vector<GradPair>& dec_grads);
103 void removeSurplusALQ_(
104 const Group& group,
105 std::vector<GradPair>& inc_grads, std::vector<GradPair>& dec_grads);
106 void saveGrad_(GradMap& map, const std::string& name, GradInfo& grad);
107 void saveDecGrad_(const std::string& name, GradInfo& grad);
108 void saveIncGrad_(const std::string& name, GradInfo& grad);
109 void sortGradients_(std::vector<GradPair>& grads);
110 std::optional<GradInfo> updateGrad_(
111 const std::string& name, GradInfo& grad, bool increase);
112 void updateGradVector_(
113 const std::string& name, std::vector<GradPair>& grads, double grad);
114 void mpiSyncGlobalGradVector_(std::vector<GradPair>& grads_global) const;
115 void mpiSyncLocalToGlobalGradVector_(
116 const std::vector<GradPair>& grads_local,
117 std::vector<GradPair>& grads_global) const;
118
119
120 GLiftProdWells& prod_wells_;
121 GLiftOptWells& stage1_wells_;
122 GasLiftGroupInfo& group_info_;
123 GLiftWellStateMap& well_state_map_;
124
125 int report_step_idx_;
126 const SummaryState& summary_state_;
127 const Schedule& schedule_;
128 const GasLiftOpt& glo_;
129 GradMap inc_grads_;
130 GradMap dec_grads_;
131 int max_iterations_ = 1000;
132 //int time_step_idx_;
133
135 OptimizeState(GasLiftStage2& parent_, const Group& group_ ) :
136 parent{parent_},
137 group{group_},
138 it{0}
139 {}
140 GasLiftStage2& parent;
141 const Group& group;
142 int it;
143
144 using GradInfo = typename GasLiftStage2::GradInfo;
145 using GradPair = typename GasLiftStage2::GradPair;
146 using GradPairItr = typename GasLiftStage2::GradPairItr;
147 using GradMap = typename GasLiftStage2::GradMap;
148 void calculateEcoGradients(std::vector<GasLiftSingleWell *>& wells,
149 std::vector<GradPair>& inc_grads, std::vector<GradPair>& dec_grads);
150 bool checkAtLeastTwoWells(std::vector<GasLiftSingleWell *>& wells);
151 void debugShowIterationInfo();
152 std::pair<std::optional<GradPairItr>,std::optional<GradPairItr>>
153 getEcoGradients(
154 std::vector<GradPair>& inc_grads, std::vector<GradPair>& dec_grads);
155 void recalculateGradients(
156 std::vector<GradPair>& inc_grads, std::vector<GradPair>& dec_grads,
157 GradPairItr& min_dec_grad_itr, GradPairItr &max_inc_grad_itr);
158 void redistributeALQ( GradPairItr& min_dec_grad, GradPairItr& max_inc_grad);
159
160 private:
161 void displayDebugMessage_(const std::string& msg);
162 void displayWarning_(const std::string& msg);
163
164 };
165
167 SurplusState( GasLiftStage2& parent_, const Group& group_,
168 double oil_rate_, double gas_rate_, double water_rate_, double alq_,
169 double min_eco_grad_,
170 double oil_target_, double gas_target_, double water_target_, double liquid_target_,
171 std::optional<double> max_glift_, std::optional<double> max_total_gas_) :
172 parent{parent_},
173 group{group_},
174 oil_rate{oil_rate_},
175 gas_rate{gas_rate_},
176 water_rate{water_rate_},
177 alq{alq_},
178 min_eco_grad{min_eco_grad_},
179 oil_target{oil_target_},
180 gas_target{gas_target_},
181 water_target(water_target_),
182 liquid_target{liquid_target_},
183 max_glift{max_glift_},
184 max_total_gas{max_total_gas_},
185 it{0}
186 {}
187 GasLiftStage2 &parent;
188 const Group &group;
189 double oil_rate;
190 double gas_rate;
191 double water_rate;
192 double alq;
193 const double min_eco_grad;
194 const double oil_target;
195 const double gas_target;
196 const double water_target;
197 const double liquid_target;
198 std::optional<double> max_glift;
199 std::optional<double> max_total_gas;
200 int it;
201
202 void addOrRemoveALQincrement(
203 GradMap &grad_map, const std::string& well_name, bool add);
204 bool checkALQlimit(double delta_alq, double delta_gas);
205 bool checkEcoGradient(const std::string& well_name, double eco_grad);
206 bool checkGasTarget(double delta_gas);
207 bool checkLiquidTarget(double delta_liquid);
208 bool checkOilTarget(double delta_oil);
209 bool checkWaterTarget(double delta_water);
210 std::array<double, 4> computeDelta(const std::string& name);
211 void updateRates(const std::array<double, 4>& delta);
212 };
213};
214
215} // namespace Opm
216
217#endif // OPM_GASLIFT_STAGE2_HEADER_INCLUDED
Definition DeferredLogger.hpp:57
Definition GasLiftCommon.hpp:35
Definition GasLiftGroupInfo.hpp:45
Definition GasLiftSingleWellGeneric.hpp:49
Definition GasLiftStage2.hpp:45
Definition GasLiftWellState.hpp:29
Definition GroupState.hpp:34
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition WellState.hpp:61
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition BlackoilPhases.hpp:27
Definition GasLiftSingleWellGeneric.hpp:61
Definition GasLiftStage2.hpp:134
Definition GasLiftStage2.hpp:166