My Project
Group.hpp
1 /*
2  Copyright 2019 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 GROUP2_HPP
21 #define GROUP2_HPP
22 
23 #include <algorithm>
24 #include <map>
25 #include <optional>
26 #include <string>
27 
28 #include <opm/parser/eclipse/Deck/UDAValue.hpp>
29 #include <opm/parser/eclipse/EclipseState/Util/IOrderSet.hpp>
30 #include <opm/parser/eclipse/EclipseState/Runspec.hpp>
31 #include <opm/parser/eclipse/EclipseState/Schedule/Group/GPMaint.hpp>
32 #include <opm/parser/eclipse/Units/UnitSystem.hpp>
33 
34 namespace Opm {
35 
36 namespace RestartIO {
37 struct RstGroup;
38 }
39 
40 
41 class SummaryState;
42 class UDQConfig;
43 class UDQActive;
44 class Group {
45 public:
46 
47 // A group can have both injection controls and production controls set at
48 // the same time, i.e. this enum is used as a bitmask.
49 enum class GroupType : unsigned {
50  NONE = 0,
51  PRODUCTION = 1,
52  INJECTION = 2,
53  MIXED = 3
54 };
55 
56 
57 
58 enum class ExceedAction {
59  NONE = 0,
60  CON = 1,
61  CON_PLUS = 2, // String: "+CON"
62  WELL = 3,
63  PLUG = 4,
64  RATE = 5
65 };
66 static const std::string ExceedAction2String( ExceedAction enumValue );
67 static ExceedAction ExceedActionFromString( const std::string& stringValue );
68 static ExceedAction ExceedActionFromInt(const int value);
69 
70 enum class InjectionCMode : int {
71  NONE = 0,
72  RATE = 1,
73  RESV = 2,
74  REIN = 4,
75  VREP = 8,
76  FLD = 16,
77  SALE = 32
78 };
79 static const std::string InjectionCMode2String( InjectionCMode enumValue );
80 static InjectionCMode InjectionCModeFromString( const std::string& stringValue );
81 static InjectionCMode InjectionCModeFromInt(int ecl_int);
82 static int InjectionCMode2Int(InjectionCMode enumValue);
83 
84 enum class ProductionCMode : int {
85  NONE = 0,
86  ORAT = 1,
87  WRAT = 2,
88  GRAT = 4,
89  LRAT = 8,
90  CRAT = 16,
91  RESV = 32,
92  PRBL = 64,
93  FLD = 128
94 };
95 static const std::string ProductionCMode2String( ProductionCMode enumValue );
96 static ProductionCMode ProductionCModeFromString( const std::string& stringValue );
97 static ProductionCMode ProductionCModeFromInt(int ecl_int);
98 static int ProductionCMode2Int(Group::ProductionCMode cmode);
99 
100 enum class GuideRateProdTarget {
101  OIL = 0,
102  WAT = 1,
103  GAS = 2,
104  LIQ = 3,
105  RES = 4,
106  COMB = 5,
107  WGA = 6,
108  CVAL = 7,
109  INJV = 8,
110  POTN = 9,
111  FORM = 10,
112  NO_GUIDE_RATE = 11
113 };
114 static GuideRateProdTarget GuideRateProdTargetFromString( const std::string& stringValue );
115 static GuideRateProdTarget GuideRateProdTargetFromInt(int ecl_id);
116 
117 
118 enum class GuideRateInjTarget {
119  RATE = 1,
120  VOID = 2,
121  NETV = 3,
122  RESV = 4,
123  POTN = 5,
124  NO_GUIDE_RATE = 6
125 };
126 static GuideRateInjTarget GuideRateInjTargetFromString( const std::string& stringValue );
127 static GuideRateInjTarget GuideRateInjTargetFromInt(int ecl_id);
128 
129 
131  GroupInjectionProperties() = default;
132  explicit GroupInjectionProperties(std::string group_name_arg);
133  GroupInjectionProperties(std::string group_name_arg, Phase phase, const UnitSystem& unit_system);
134 
135  std::string name{};
136  Phase phase = Phase::WATER;
137  InjectionCMode cmode = InjectionCMode::NONE;
138  UDAValue surface_max_rate;
139  UDAValue resv_max_rate;
140  UDAValue target_reinj_fraction;
141  UDAValue target_void_fraction;
142  std::optional<std::string> reinj_group;
143  std::optional<std::string> voidage_group;
144  bool available_group_control = true;
145  double guide_rate = 0;
146  GuideRateInjTarget guide_rate_def = GuideRateInjTarget::NO_GUIDE_RATE;
147 
148  static GroupInjectionProperties serializeObject();
149 
150  int injection_controls = 0;
151  bool operator==(const GroupInjectionProperties& other) const;
152  bool operator!=(const GroupInjectionProperties& other) const;
153  bool updateUDQActive(const UDQConfig& udq_config, UDQActive& active) const;
154  bool uda_phase() const;
155  void update_uda(const UDQConfig& udq_config, UDQActive& udq_active, UDAControl control, const UDAValue& value);
156 
157  template<class Serializer>
158  void serializeOp(Serializer& serializer)
159  {
160  serializer(this->name);
161  serializer(phase);
162  serializer(cmode);
163  surface_max_rate.serializeOp(serializer);
164  resv_max_rate.serializeOp(serializer);
165  target_reinj_fraction.serializeOp(serializer);
166  target_void_fraction.serializeOp(serializer);
167  serializer(reinj_group);
168  serializer(voidage_group);
169  serializer(injection_controls);
170  serializer(available_group_control);
171  serializer(guide_rate);
172  serializer(guide_rate_def);
173  }
174 };
175 
177  Phase phase;
178  InjectionCMode cmode;
179  double surface_max_rate;
180  double resv_max_rate;
181  double target_reinj_fraction;
182  double target_void_fraction;
183  int injection_controls = 0;
184  std::string reinj_group;
185  std::string voidage_group;
186  double guide_rate;
187  GuideRateInjTarget guide_rate_def = GuideRateInjTarget::NO_GUIDE_RATE;
188 };
189 
192  GroupProductionProperties(const UnitSystem& unit_system, const std::string& gname);
193 
194  std::string name;
195  ProductionCMode cmode = ProductionCMode::NONE;
196  ExceedAction exceed_action = ExceedAction::NONE;
197  UDAValue oil_target;
198  UDAValue water_target;
199  UDAValue gas_target;
200  UDAValue liquid_target;
201  double guide_rate = 0;
202  GuideRateProdTarget guide_rate_def = GuideRateProdTarget::NO_GUIDE_RATE;
203  double resv_target = 0;
204  bool available_group_control = true;
205  static GroupProductionProperties serializeObject();
206 
207  int production_controls = 0;
208  bool operator==(const GroupProductionProperties& other) const;
209  bool operator!=(const GroupProductionProperties& other) const;
210  bool updateUDQActive(const UDQConfig& udq_config, UDQActive& active) const;
211  void update_uda(const UDQConfig& udq_config, UDQActive& udq_active, UDAControl control, const UDAValue& value);
212 
213  template<class Serializer>
214  void serializeOp(Serializer& serializer)
215  {
216  serializer(name);
217  serializer(cmode);
218  serializer(exceed_action);
219  oil_target.serializeOp(serializer);
220  water_target.serializeOp(serializer);
221  gas_target.serializeOp(serializer);
222  liquid_target.serializeOp(serializer);
223  serializer(guide_rate);
224  serializer(guide_rate_def);
225  serializer(resv_target);
226  serializer(available_group_control);
227  serializer(production_controls);
228  }
229 };
230 
231 
233  ProductionCMode cmode;
234  ExceedAction exceed_action;
235  double oil_target;
236  double water_target;
237  double gas_target;
238  double liquid_target;
239  double guide_rate;
240  GuideRateProdTarget guide_rate_def = GuideRateProdTarget::NO_GUIDE_RATE;
241  double resv_target = 0;
242  int production_controls = 0;
243 };
244 
245 
246  Group();
247  Group(const std::string& group_name, std::size_t insert_index_arg, double udq_undefined_arg, const UnitSystem& unit_system);
248  Group(const RestartIO::RstGroup& rst_group, std::size_t insert_index_arg, double udq_undefined_arg, const UnitSystem& unit_system);
249 
250  static Group serializeObject();
251 
252  std::size_t insert_index() const;
253  const std::string& name() const;
254  bool is_field() const;
255  int getGroupNetVFPTable() const;
256 
257  bool updateNetVFPTable(int vfp_arg);
258  bool update_gefac(double gefac, bool transfer_gefac);
259 
260  // [[deprecated("use Group::control_group() or Group::flow_group()")]]
261  const std::string& parent() const;
262  std::optional<std::string> control_group() const;
263  std::optional<std::string> flow_group() const;
264 
265  bool updateParent(const std::string& parent);
266  bool updateInjection(const GroupInjectionProperties& injection);
267  bool updateProduction(const GroupProductionProperties& production);
268  bool isProductionGroup() const;
269  bool isInjectionGroup() const;
270  void setProductionGroup();
271  void setInjectionGroup();
272  double getGroupEfficiencyFactor() const;
273  bool getTransferGroupEfficiencyFactor() const;
274 
275  std::size_t numWells() const;
276  bool addGroup(const std::string& group_name);
277  bool hasGroup(const std::string& group_name) const;
278  void delGroup(const std::string& group_name);
279  bool addWell(const std::string& well_name);
280  bool hasWell(const std::string& well_name) const;
281  void delWell(const std::string& well_name);
282 
283  const std::vector<std::string>& wells() const;
284  const std::vector<std::string>& groups() const;
285  bool wellgroup() const;
286  ProductionControls productionControls(const SummaryState& st) const;
287  InjectionControls injectionControls(Phase phase, const SummaryState& st) const;
288  bool hasInjectionControl(Phase phase) const;
289  const GroupProductionProperties& productionProperties() const;
290  const std::map<Phase , GroupInjectionProperties>& injectionProperties() const;
291  const GroupInjectionProperties& injectionProperties(Phase phase) const;
292  const GroupType& getGroupType() const;
293  ProductionCMode prod_cmode() const;
294  InjectionCMode injection_cmode() const;
295  Phase injection_phase() const;
296  bool has_control(ProductionCMode control) const;
297  bool has_control(Phase phase, InjectionCMode control) const;
298  bool productionGroupControlAvailable() const;
299  bool injectionGroupControlAvailable(const Phase phase) const;
300  const std::optional<GPMaint>& gpmaint() const;
301  void set_gpmaint(GPMaint gpmaint);
302  void set_gpmaint();
303  bool has_gpmaint_control(Phase phase, InjectionCMode cmode) const;
304  bool has_gpmaint_control(ProductionCMode cmode) const;
305 
306  bool operator==(const Group& data) const;
307  const std::optional<Phase>& topup_phase() const;
308 
309  template<class Serializer>
310  void serializeOp(Serializer& serializer)
311  {
312  serializer(m_name);
313  serializer(m_insert_index);
314  serializer(udq_undefined);
315  unit_system.serializeOp(serializer);
316  serializer(group_type);
317  serializer(gefac);
318  serializer(transfer_gefac);
319  serializer(vfp_table);
320  serializer(parent_group);
321  m_wells.serializeOp(serializer);
322  m_groups.serializeOp(serializer);
323  serializer.map(injection_properties);
324  production_properties.serializeOp(serializer);
325  serializer(m_topup_phase);
326  serializer(m_gpmaint);
327  }
328 
329 private:
330  bool hasType(GroupType gtype) const;
331  void addType(GroupType new_gtype);
332 
333  std::string m_name;
334  std::size_t m_insert_index;
335  double udq_undefined;
336  UnitSystem unit_system;
337  GroupType group_type;
338  double gefac;
339  bool transfer_gefac;
340  int vfp_table;
341 
342  std::string parent_group;
343  IOrderSet<std::string> m_wells;
344  IOrderSet<std::string> m_groups;
345 
346  std::map<Phase, GroupInjectionProperties> injection_properties;
347  GroupProductionProperties production_properties;
348  std::optional<Phase> m_topup_phase;
349  std::optional<GPMaint> m_gpmaint;
350 };
351 
352 Group::GroupType operator |(Group::GroupType lhs, Group::GroupType rhs);
353 Group::GroupType operator &(Group::GroupType lhs, Group::GroupType rhs);
354 
355 }
356 
357 #endif
Definition: GPMaint.hpp:30
Definition: Group.hpp:44
Definition: Serializer.hpp:38
Definition: SummaryState.hpp:69
Definition: UDAValue.hpp:32
Definition: UDQActive.hpp:43
Definition: UDQConfig.hpp:51
Definition: UnitSystem.hpp:34
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29
Definition: Group.hpp:130
Definition: Group.hpp:190
Definition: Group.hpp:176
Definition: Group.hpp:232
Definition: group.hpp:33