opm-common
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 OPM_GROUP_HPP
21 #define OPM_GROUP_HPP
22 
23 #include <opm/input/eclipse/EclipseState/Phase.hpp>
24 #include <opm/input/eclipse/EclipseState/Util/IOrderSet.hpp>
25 
26 #include <opm/input/eclipse/Schedule/Group/GPMaint.hpp>
27 
28 #include <opm/input/eclipse/Deck/UDAValue.hpp>
29 
30 #include <opm/input/eclipse/Units/UnitSystem.hpp>
31 
32 #include <cstddef>
33 #include <cstdint>
34 #include <map>
35 #include <optional>
36 #include <string>
37 
38 namespace Opm {
39  class SummaryState;
40  class UDQConfig;
41  class UDQActive;
42 } // namespace Opm
43 
44 namespace Opm::RestartIO {
45  struct RstGroup;
46 } // namespace Opm::RestartIO
47 
48 namespace Opm {
49 class Group
50 {
51 public:
52  // A group can have both injection controls and production controls set
53  // at the same time, i.e. this enum is used as a bitmask.
54  enum class GroupType : unsigned {
55  NONE = 0,
56  PRODUCTION = 1,
57  INJECTION = 2,
58  MIXED = 3,
59  };
60 
61  enum class ExceedAction {
62  NONE = 0,
63  CON = 1,
64  CON_PLUS = 2, // String: "+CON"
65  WELL = 3,
66  PLUG = 4,
67  RATE = 5
68  };
69  static std::string ExceedAction2String(ExceedAction enumValue);
70  static ExceedAction ExceedActionFromString(const std::string& stringValue);
71  static ExceedAction ExceedActionFromInt(const int value);
72 
73  enum class InjectionCMode : int {
74  NONE = 0,
75  RATE = 1,
76  RESV = 2,
77  REIN = 4,
78  VREP = 8,
79  FLD = 16,
80  SALE = 32
81  };
82  static std::string InjectionCMode2String(InjectionCMode enumValue);
83  static InjectionCMode InjectionCModeFromString(const std::string& stringValue);
84  static InjectionCMode InjectionCModeFromInt(int ecl_int);
85  static int InjectionCMode2Int(InjectionCMode enumValue);
86 
87  enum class ProductionCMode : int {
88  NONE = 0,
89  ORAT = 1,
90  WRAT = 2,
91  GRAT = 4,
92  LRAT = 8,
93  CRAT = 16,
94  RESV = 32,
95  PRBL = 64,
96  FLD = 128
97  };
98  static std::string ProductionCMode2String(ProductionCMode enumValue);
99  static ProductionCMode ProductionCModeFromString(const std::string& stringValue);
100  static ProductionCMode ProductionCModeFromInt(int ecl_int);
101  static int ProductionCMode2Int(Group::ProductionCMode cmode);
102 
103  enum class GuideRateProdTarget {
104  OIL = 0,
105  WAT = 1,
106  GAS = 2,
107  LIQ = 3,
108  RES = 4,
109  COMB = 5,
110  WGA = 6,
111  CVAL = 7,
112  INJV = 8,
113  POTN = 9,
114  FORM = 10,
115  NO_GUIDE_RATE = 11
116  };
117  static GuideRateProdTarget GuideRateProdTargetFromString(const std::string& stringValue);
118  static GuideRateProdTarget GuideRateProdTargetFromInt(int ecl_id);
119 
120  enum class GuideRateInjTarget {
121  RATE = 1,
122  VOID = 2,
123  NETV = 3,
124  RESV = 4,
125  NO_GUIDE_RATE = 5
126  };
127  static GuideRateInjTarget GuideRateInjTargetFromString(const std::string& stringValue);
128  static GuideRateInjTarget GuideRateInjTargetFromInt(int ecl_id);
129  static int GuideRateInjTargetToInt(GuideRateInjTarget target);
130 
132  {
133  GroupInjectionProperties() = default;
134  explicit GroupInjectionProperties(std::string group_name_arg);
135  GroupInjectionProperties(std::string group_name_arg, Phase phase, const UnitSystem& unit_system);
136 
137  std::string name{};
138  Phase phase = Phase::WATER;
139  InjectionCMode cmode = InjectionCMode::NONE;
140  UDAValue surface_max_rate;
141  UDAValue resv_max_rate;
142  UDAValue target_reinj_fraction;
143  UDAValue target_void_fraction;
144  std::optional<std::string> reinj_group;
145  std::optional<std::string> voidage_group;
146  bool available_group_control = true;
147  double guide_rate = 0;
148  GuideRateInjTarget guide_rate_def = GuideRateInjTarget::NO_GUIDE_RATE;
149 
150  static GroupInjectionProperties serializationTestObject();
151 
152  int injection_controls = 0;
153  bool operator==(const GroupInjectionProperties& other) const;
154  bool operator!=(const GroupInjectionProperties& other) const;
155  bool updateUDQActive(const UDQConfig& udq_config, UDQActive& active) const;
156  bool uda_phase() const;
157  void update_uda(const UDQConfig& udq_config, UDQActive& udq_active, UDAControl control, const UDAValue& value);
158 
159  template<class Serializer>
160  void serializeOp(Serializer& serializer)
161  {
162  serializer(this->name);
163  serializer(phase);
164  serializer(cmode);
165  serializer(surface_max_rate);
166  serializer(resv_max_rate);
167  serializer(target_reinj_fraction);
168  serializer(target_void_fraction);
169  serializer(reinj_group);
170  serializer(voidage_group);
171  serializer(injection_controls);
172  serializer(available_group_control);
173  serializer(guide_rate);
174  serializer(guide_rate_def);
175  }
176  };
177 
179  {
180  // \Note: we do not use allRates in the simulation, while keeping it for now for RESTART output purpose
181  ExceedAction allRates{ExceedAction::NONE};
182  ExceedAction oil{ExceedAction::NONE};
183  ExceedAction water{ExceedAction::NONE};
184  ExceedAction gas{ExceedAction::NONE};
185  ExceedAction liquid{ExceedAction::NONE};
186 
187  template<class Serializer>
188  void serializeOp(Serializer& serializer)
189  {
190  serializer(allRates);
191  serializer(oil);
192  serializer(water);
193  serializer(gas);
194  serializer(liquid);
195  }
196 
197  bool operator==(const GroupLimitAction& other) const
198  {
199  return (this->allRates == other.allRates)
200  && (this->oil == other.oil)
201  && (this->water == other.water)
202  && (this->gas == other.gas)
203  && (this->liquid == other.liquid);
204  }
205  };
206 
208  {
209  Phase phase;
210  InjectionCMode cmode;
211  double surface_max_rate;
212  double resv_max_rate;
213  double target_reinj_fraction;
214  double target_void_fraction;
215  int injection_controls = 0;
216  std::string reinj_group;
217  std::string voidage_group;
218  double guide_rate;
219  GuideRateInjTarget guide_rate_def = GuideRateInjTarget::NO_GUIDE_RATE;
220  };
221 
223  {
225  GroupProductionProperties(const UnitSystem& unit_system, const std::string& gname);
226 
227  std::string name;
228  ProductionCMode cmode = ProductionCMode::NONE;
229  GroupLimitAction group_limit_action;
230  UDAValue oil_target;
231  UDAValue water_target;
232  UDAValue gas_target;
233  UDAValue liquid_target;
234  double guide_rate = 0;
235  GuideRateProdTarget guide_rate_def = GuideRateProdTarget::NO_GUIDE_RATE;
236  UDAValue resv_target;
237  bool available_group_control = true;
238  static GroupProductionProperties serializationTestObject();
239 
240  int production_controls = 0;
241  bool operator==(const GroupProductionProperties& other) const;
242  bool operator!=(const GroupProductionProperties& other) const;
243  bool updateUDQActive(const UDQConfig& udq_config, UDQActive& active) const;
244  void update_uda(const UDQConfig& udq_config, UDQActive& udq_active, UDAControl control, const UDAValue& value);
245 
246  template<class Serializer>
247  void serializeOp(Serializer& serializer)
248  {
249  serializer(name);
250  serializer(cmode);
251  serializer(group_limit_action);
252  serializer(oil_target);
253  serializer(water_target);
254  serializer(gas_target);
255  serializer(liquid_target);
256  serializer(guide_rate);
257  serializer(guide_rate_def);
258  serializer(resv_target);
259  serializer(available_group_control);
260  serializer(production_controls);
261  }
262  };
263 
265  {
266  ProductionCMode cmode;
267  GroupLimitAction group_limit_action;
268  double oil_target;
269  double water_target;
270  double gas_target;
271  double liquid_target;
272  double guide_rate;
273  GuideRateProdTarget guide_rate_def = GuideRateProdTarget::NO_GUIDE_RATE;
274  double resv_target = 0;
275  int production_controls = 0;
276  };
277 
278  Group();
279  Group(const std::string& group_name,
280  std::size_t insert_index_arg,
281  double udq_undefined_arg,
282  const UnitSystem& unit_system);
283 
284  Group(const RestartIO::RstGroup& rst_group,
285  std::size_t insert_index_arg,
286  double udq_undefined_arg,
287  const UnitSystem& unit_system);
288 
289  static Group serializationTestObject();
290 
291  std::size_t insert_index() const;
292  const std::string& name() const;
293  bool is_field() const;
294 
295  bool update_gefac(double gefac, bool use_efficiency_in_network);
296 
297  // [[deprecated("use Group::control_group() or Group::flow_group()")]]
298  const std::string& parent() const;
299  std::optional<std::string> control_group() const;
300  std::optional<std::string> flow_group() const;
301 
302  bool updateParent(const std::string& parent);
303  bool updateInjection(const GroupInjectionProperties& injection);
304  bool updateProduction(const GroupProductionProperties& production);
305  bool isProductionGroup() const;
306  bool isInjectionGroup() const;
307  void setProductionGroup();
308  void setInjectionGroup();
309  double getGroupEfficiencyFactor(bool network = false) const;
310  bool useEfficiencyInNetwork() const;
311 
317 
323  bool hasSatelliteProduction() const;
324 
330 
336  bool hasSatelliteInjection() const;
337 
338  std::size_t numWells() const;
339  bool addGroup(const std::string& group_name);
340  bool hasGroup(const std::string& group_name) const;
341  void delGroup(const std::string& group_name);
342  bool addWell(const std::string& well_name);
343  bool hasWell(const std::string& well_name) const;
344  void delWell(const std::string& well_name);
345 
346  const std::vector<std::string>& wells() const;
347  const std::vector<std::string>& groups() const;
348  bool wellgroup() const;
349  ProductionControls productionControls(const SummaryState& st) const;
350  InjectionControls injectionControls(Phase phase, const SummaryState& st) const;
351  bool hasInjectionControl(Phase phase) const;
352  const GroupProductionProperties& productionProperties() const;
353  const std::map<Phase , GroupInjectionProperties>& injectionProperties() const;
354  const GroupInjectionProperties& injectionProperties(Phase phase) const;
355  const GroupType& getGroupType() const;
356  ProductionCMode prod_cmode() const;
357  InjectionCMode injection_cmode() const;
358  Phase injection_phase() const;
359  bool has_control(ProductionCMode control) const;
360  bool has_control(Phase phase, InjectionCMode control) const;
361  bool productionGroupControlAvailable() const;
362  bool injectionGroupControlAvailable(const Phase phase) const;
363  const std::optional<GPMaint>& gpmaint() const;
364  void set_gpmaint(GPMaint gpmaint);
365  void set_gpmaint();
366  bool has_gpmaint_control(Phase phase, InjectionCMode cmode) const;
367  bool has_gpmaint_control(ProductionCMode cmode) const;
368  bool as_choke() const;
369  void as_choke(const std::string& group);
370 
371  bool operator==(const Group& data) const;
372  const std::optional<Phase>& topup_phase() const;
373 
374  template<class Serializer>
375  void serializeOp(Serializer& serializer)
376  {
377  serializer(m_name);
378  serializer(m_insert_index);
379  serializer(udq_undefined);
380  serializer(unit_system);
381  serializer(group_type);
382  serializer(gefac);
383  serializer(use_efficiency_in_network);
384  serializer(satellite_status);
385  serializer(parent_group);
386  serializer(m_wells);
387  serializer(m_groups);
388  serializer(injection_properties);
389  serializer(production_properties);
390  serializer(m_topup_phase);
391  serializer(m_gpmaint);
392  }
393 
394 private:
395  bool hasType(GroupType gtype) const;
396  void addType(GroupType new_gtype);
397 
398  std::string m_name{};
399  std::size_t m_insert_index{};
400  double udq_undefined{};
401  UnitSystem unit_system{};
402  GroupType group_type{};
403  double gefac{};
404  bool use_efficiency_in_network{};
405 
406  std::uint_least8_t satellite_status{};
407 
408  std::string parent_group{};
409  IOrderSet<std::string> m_wells{};
410  IOrderSet<std::string> m_groups{};
411 
412  std::map<Phase, GroupInjectionProperties> injection_properties{};
413  GroupProductionProperties production_properties{};
414  std::optional<Phase> m_topup_phase{};
415  std::optional<GPMaint> m_gpmaint{};
416  std::optional<std::string> m_choke_group{};
417 };
418 
419 Group::GroupType operator |(Group::GroupType lhs, Group::GroupType rhs);
420 Group::GroupType operator &(Group::GroupType lhs, Group::GroupType rhs);
421 
422 } // namespace Opm
423 
424 #endif // OPM_GROUP_HPP
Collection of all user-defined quantities in the current simulation run.
Definition: UDQConfig.hpp:68
Definition: Group.hpp:207
Definition: Group.hpp:49
Definition: UDAValue.hpp:31
bool hasSatelliteProduction() const
Predicate for whether or not this group is tagged as a satellite producer.
Definition: Group.cpp:931
Definition: GPMaint.hpp:31
Definition: group.hpp:37
Definition: Group.hpp:222
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: Group.hpp:264
Definition: Group.hpp:131
Definition: Group.hpp:178
void recordSatelliteProduction()
Tag current group as being one with satellite production.
Definition: Group.cpp:924
Internalised representation of all UDAs in a simulation run.
Definition: UDQActive.hpp:49
bool hasSatelliteInjection() const
Predicate for whether or not this group is tagged as a satellite injector.
Definition: Group.cpp:944
Definition: UnitSystem.hpp:34
Definition: SummaryState.hpp:72
void recordSatelliteInjection()
Tag current group as being one with satellite injection.
Definition: Group.cpp:937
Definition: Aquancon.hpp:40
Class for (de-)serializing.
Definition: Serializer.hpp:94