opm-common
UDQEnums.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 UDQ_ENUMS_HPP
21 #define UDQ_ENUMS_HPP
22 
23 #include <cstddef>
24 #include <map>
25 #include <set>
26 #include <string>
27 #include <vector>
28 
29 namespace Opm {
30 
31 // The UDQ variables can be of many different types. Additionally they can
32 // be either scalars or vector sets. The archetypal example of a vector set
33 // is well variables. For instance, in the expressions:
34 //
35 // UDQ
36 // DEFINE WUBHP WBHP * 1.15 /
37 // DEFINE WUORAT 1000 /
38 // /
39 //
40 // we define two UDQ values 'WUBHP' and 'WUORAT'. Both of these UDQ values
41 // will apply to all wells; the WUBHP vector will correspond to the normal
42 // BHP scaled up 15%, the WUORAT has the scalar value 1000 for all wells.
43 // The well sets can be constrained with a well name. If the well name is a
44 // template, we get a well set. Otherwise, i.e., if the well name is fully
45 // qualified we have a scalar:
46 //
47 // UDQ
48 // DEFINE WUWCT WWCT 'OP*' /
49 // DEFINE FUORAT WOPR 'OPX' * 100 /
50 // /
51 //
52 // Here the UDQ WUCWT corresponds to the well WWCT for all wells matching
53 // the template 'OP*', and it is undefined for other wells. The UDQ FUORAT
54 // is a scalar, given by the WOPR of well 'OPX' - multiplied by 100.
55 //
56 // There are clearly rules for how the different variable types can be
57 // combined in expressions, and what will be resulting type from an
58 // expression - unfortunately that is not yet very well implemented in the
59 // opm codebase. In UDQParser.cpp there is a function static_type_check and
60 // in UDQDefine there is a function dynamic_type_check - these functions try
61 // to verfiy that the type conversions are legitimate, but currently they
62 // are woefully inadequate.
63 
64 enum class UDQVarType
65 {
66  NONE = 0,
67  SCALAR = 1,
68  CONNECTION_VAR = 2,
69  FIELD_VAR = 3,
70  REGION_VAR = 4,
71  SEGMENT_VAR = 5,
72  AQUIFER_VAR = 6,
73  BLOCK_VAR = 7,
74  WELL_VAR = 8,
75  GROUP_VAR = 9,
76  TABLE_LOOKUP = 10,
77 
78  // -------------------------------------------------------------------------
79  // Implementation helper. Must be last enumerator.
80  NumTypes,
81 };
82 
83 enum class UDQTokenType
84 {
85  error = 0,
86  number = 1,
87  open_paren = 2,
88  close_paren = 3,
89  comp_expr = 6,
90  ecl_expr = 7,
91  //
92  binary_op_add = 8,
93  binary_op_sub = 9,
94  binary_op_div = 10,
95  binary_op_mul = 11,
96  binary_op_pow = 12,
97  binary_op_uadd = 13,
98  binary_op_umul = 14,
99  binary_op_umin = 15,
100  binary_op_umax = 16,
101  binary_cmp_eq = 17,
102  binary_cmp_ne = 18,
103  binary_cmp_le = 19,
104  binary_cmp_ge = 20,
105  binary_cmp_lt = 21,
106  binary_cmp_gt = 22,
107  //
108  elemental_func_randn = 23,
109  elemental_func_randu = 24,
110  elemental_func_rrandn = 25,
111  elemental_func_rrandu = 26,
112  elemental_func_abs = 27,
113  elemental_func_def = 28,
114  elemental_func_exp = 29,
115  elemental_func_idv = 30,
116  elemental_func_ln = 31,
117  elemental_func_log = 32,
118  elemental_func_nint = 33,
119  elemental_func_sorta = 34,
120  elemental_func_sortd = 35,
121  elemental_func_undef = 36,
122  //
123  scalar_func_sum = 37,
124  scalar_func_avea = 38,
125  scalar_func_aveg = 39,
126  scalar_func_aveh = 40,
127  scalar_func_max = 41,
128  scalar_func_min = 42,
129  scalar_func_norm1 = 43,
130  scalar_func_norm2 = 44,
131  scalar_func_normi = 45,
132  scalar_func_prod = 46,
133  //
134  table_lookup = 47,
135  table_lookup_start = 48,
136  table_lookup_end = 49,
137  //
138  end = 100,
139 };
140 
141 enum class UDQAction
142 {
143  ASSIGN,
144  DEFINE,
145  UNITS,
146  UPDATE,
147 };
148 
149 enum class UDQUpdate
150 {
151  ON,
152  OFF,
153  NEXT,
154 };
155 
156 enum class UDAControl
157 {
158  WCONPROD_ORAT,
159  WCONPROD_WRAT,
160  WCONPROD_GRAT,
161  WCONPROD_LRAT,
162  WCONPROD_RESV,
163  WCONPROD_BHP,
164  WCONPROD_THP,
165  WCONPROD_LIFT,
166  //
167  WCONINJE_RATE,
168  WCONINJE_RESV,
169  WCONINJE_BHP,
170  WCONINJE_THP,
171  //
172  GCONPROD_OIL_TARGET,
173  GCONPROD_WATER_TARGET,
174  GCONPROD_GAS_TARGET,
175  GCONPROD_LIQUID_TARGET,
176  GCONPROD_RESV_TARGET,
177  //
178  GCONINJE_SURFACE_MAX_RATE,
179  GCONINJE_RESV_MAX_RATE,
180  GCONINJE_TARGET_REINJ_FRACTION,
181  GCONINJE_TARGET_VOID_FRACTION,
182  //
183  WELTARG_ORAT,
184  WELTARG_WRAT,
185  WELTARG_GRAT,
186  WELTARG_LRAT,
187  WELTARG_RESV,
188  WELTARG_BHP,
189  WELTARG_THP,
190  WELTARG_LIFT,
191 };
192 
193 enum class UDAKeyword
194 {
195  WCONPROD,
196  WCONINJE,
197  WELTARG,
198  GCONINJE,
199  GCONPROD,
200 };
201 
202 namespace UDQ {
203 
206  {
208  using NamedObjects = std::set<std::string>;
209 
214  using EnumeratedObjects = std::map<std::string, std::set<std::size_t>>;
215 
221 
226 
230 
233  };
234 
235  UDQVarType targetType(const std::string& keyword, const std::vector<std::string>& selector);
236  UDQVarType targetType(const std::string& keyword);
237  UDQVarType varType(const std::string& keyword);
238  UDQVarType coerce(UDQVarType t1, UDQVarType t2);
239 
240  UDQAction actionType(const std::string& action_string);
241 
242  UDQUpdate updateType(const std::string& update_string);
243  UDQUpdate updateType(int int_value);
244 
245  UDQTokenType tokenType(const std::string& func_name);
246  UDQTokenType funcType(const std::string& func_name);
247 
248  bool binaryFunc(UDQTokenType token_type);
249  bool elementalUnaryFunc(UDQTokenType token_type);
250  bool scalarFunc(UDQTokenType token_type);
251  bool cmpFunc(UDQTokenType token_type);
252  bool setFunc(UDQTokenType token_type);
253  bool trailingSpace(UDQTokenType token_type);
254  bool leadingSpace(UDQTokenType token_type);
255  bool group_control(UDAControl control);
256  bool well_control(UDAControl control);
257  bool is_well_injection_control(UDAControl control, const bool isInjector);
258  bool is_well_production_control(UDAControl control, const bool isProducer);
259  bool is_group_injection_control(UDAControl control);
260  bool is_group_production_control(UDAControl control);
261 
262  std::string typeName(UDQVarType var_type);
263  std::string controlName(UDAControl control);
264 
265  UDAKeyword keyword(UDAControl control);
266 
267  enum class RstFileUDAVersion {
268  vUnsupp, v0, vCurr,
269  };
270 
271  RstFileUDAVersion rstFileUDAVersion(const int rstFileVersion);
272 
273  int udaCode(UDAControl control);
274  UDAControl udaControl(int uda_code, RstFileUDAVersion udaVersion = RstFileUDAVersion::vCurr);
275 
276  constexpr double restart_default = -0.3E+21;
277 
278 } // namespace UDQ
279 
280 } // namespace Opm
281 
282 #endif // UDQ_ENUMS_HPP
NamedObjects wells
Wells named in a UDQ definition.
Definition: UDQEnums.hpp:220
NamedObjects groups
Groups named in a UDQ definition.
Definition: UDQEnums.hpp:225
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
std::set< std::string > NamedObjects
Collection of named objects–typically wells or groups.
Definition: UDQEnums.hpp:208
EnumeratedObjects msWells
Multi-segmented wells and specific segment numbers named in UDQ definition.
Definition: UDQEnums.hpp:229
Collection of specific Schedule objects named in a UDQ definition.
Definition: UDQEnums.hpp:205
std::map< std::string, std::set< std::size_t > > EnumeratedObjects
Collection of named and enumerated objects.
Definition: UDQEnums.hpp:214
EnumeratedObjects regions
Specific region sets and region IDs named in UDQ definition.
Definition: UDQEnums.hpp:232