My Project
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/parser/eclipse/EclipseState/Schedule/Schedule.hpp>
30 #include <opm/parser/eclipse/EclipseState/Schedule/Well/Well.hpp>
31 #include <opm/parser/eclipse/EclipseState/Schedule/Group/Group.hpp>
32 #include <opm/parser/eclipse/EclipseState/Schedule/GasLiftOpt.hpp>
33 #include <opm/parser/eclipse/EclipseState/Schedule/SummaryState.hpp>
34 #include <opm/simulators/wells/WellState.hpp>
35 #include <opm/simulators/utils/DeferredLogger.hpp>
36 
37 #include <algorithm>
38 #include <map>
39 #include <string>
40 #include <vector>
41 #include <fmt/format.h>
42 
43 namespace Opm
44 {
46 {
47  class GroupRates;
48  // NOTE: In the Well2GroupMap below, in the std::vector value we store
49  // pairs of group names and efficiency factors. The efficiency factors
50  // are the product of the wells efficiency factor and all the efficiency
51  // factors of the child groups of the group all the way down
52  // to the well group.
53  using Well2GroupMap =
54  std::map<std::string, std::vector<std::pair<std::string,double>>>;
55  using GroupRateMap =
56  std::map<std::string, GroupRates>;
57  using GroupIdxMap = std::map<std::string, int>;
58 #if DUNE_VERSION_NEWER(DUNE_COMMON, 2, 7)
59  using Communication = Dune::Communication<Dune::MPIHelper::MPICommunicator>;
60 #else
61  using Communication = Dune::CollectiveCommunication<Dune::MPIHelper::MPICommunicator>;
62 #endif
63 
64  // TODO: same definition with WellInterface, and
65  // WellState eventually they should go to a common header file.
66  static const int Water = BlackoilPhases::Aqua;
67  static const int Oil = BlackoilPhases::Liquid;
68  static const int Gas = BlackoilPhases::Vapour;
69 public:
70  using GLiftEclWells = std::map<std::string,std::pair<const Well *,int>>;
72  GLiftEclWells& ecl_wells,
73  const Schedule& schedule,
74  const SummaryState& summary_state,
75  const int report_step_idx,
76  const int iteration_idx,
77  const PhaseUsage& phase_usage,
78  DeferredLogger& deferred_logger,
79  WellState& well_state,
80  const Parallel::Communication& comm);
81  std::vector<std::pair<std::string,double>>& getWellGroups(
82  const std::string& well_name);
83 
84  double alqRate(const std::string& group_name);
85  double gasRate(const std::string& group_name);
86  int getGroupIdx(const std::string& group_name);
87  std::tuple<double,double,double> getRates(int group_idx);
88  std::optional<double> gasTarget(const std::string& group_name);
89  const std::string& groupIdxToName(int group_idx);
90  bool hasWell(const std::string& well_name);
91  void initialize();
92  std::optional<double> maxAlq(const std::string& group_name);
93  double oilRate(const std::string& group_name);
94  std::optional<double> oilTarget(const std::string& group_name);
95  void update(const std::string& well_name,
96  double delta_oil, double delta_gas, double delta_alq);
97  void updateRate(int idx, double oil_rate, double gas_rate, double alq);
98  const Well2GroupMap& wellGroupMap() { return well_group_map_; }
99 private:
100  bool checkDoGasLiftOptimization_(const std::string& well_name);
101  bool checkNewtonIterationIdxOk_(const std::string& well_name);
102  void displayDebugMessage_(const std::string& msg);
103  void displayDebugMessage_(const std::string& msg, const std::string& well_name);
104  std::pair<double, double> getProducerWellRates_(const int index);
105  std::tuple<double, double, double>
106  initializeGroupRatesRecursive_(const Group &group);
107  void initializeWell2GroupMapRecursive_(
108  const Group& group, std::vector<std::string>& group_names,
109  std::vector<double>& group_efficiency, double cur_efficiency);
110  void updateGroupIdxMap_(const std::string& group_name);
111 
112 
113  class GroupRates {
114  public:
115  GroupRates( double oil_rate, double gas_rate, double alq,
116  std::optional<double> oil_target,
117  std::optional<double> gas_target,
118  std::optional<double> total_gas,
119  std::optional<double> max_alq
120  ) :
121  oil_rate_{oil_rate},
122  gas_rate_{gas_rate},
123  alq_{alq},
124  oil_target_{oil_target},
125  gas_target_{gas_target},
126  total_gas_{total_gas},
127  max_alq_{max_alq}
128  {}
129  double alq() const { return alq_; }
130  void assign(double oil_rate, double gas_rate, double alq)
131  {
132  oil_rate_ = oil_rate;
133  gas_rate_ = gas_rate;
134  alq_ = alq;
135  }
136  double gasRate() const { return gas_rate_; }
137  std::optional<double> gasTarget() const { return gas_target_; }
138  std::optional<double> maxAlq() const { return max_alq_; }
139  double oilRate() const { return oil_rate_; }
140  std::optional<double> oilTarget() const { return oil_target_; }
141  void update(double delta_oil, double delta_gas, double delta_alq)
142  {
143  oil_rate_ += delta_oil;
144  gas_rate_ += delta_gas;
145  alq_ += delta_alq;
146  }
147  private:
148  double oil_rate_;
149  double gas_rate_;
150  double alq_;
151  std::optional<double> oil_target_;
152  std::optional<double> gas_target_;
153  std::optional<double> total_gas_;
154  std::optional<double> max_alq_;
155  };
156 
157  GLiftEclWells &ecl_wells_;
158  const Schedule &schedule_;
159  const SummaryState &summary_state_;
160  const int report_step_idx_;
161  const int iteration_idx_;
162  const PhaseUsage &phase_usage_;
163  DeferredLogger &deferred_logger_;
164  WellState &well_state_;
165  const Parallel::Communication &comm_;
166  const GasLiftOpt& glo_;
167  GroupRateMap group_rate_map_;
168  Well2GroupMap well_group_map_;
169  bool debug;
170  GroupIdxMap group_idx_;
171  int next_group_idx_ = 0;
172  // Optimize only wells under THP control
173  bool optimize_only_thp_wells_ = false;
174 
175 };
176 
177 } // namespace Opm
178 
179 #endif // OPM_GASLIFT_GROUP_INFO_INCLUDED
Definition: DeferredLogger.hpp:57
Definition: GasLiftGroupInfo.hpp:46
The state of a set of wells, tailored for use by the fully implicit blackoil simulator.
Definition: WellState.hpp:56
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:26
Definition: BlackoilPhases.hpp:45