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