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