My Project
ParseContext.hpp
1/*
2 Copyright 2015 Statoil 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
21#ifndef OPM_PARSE_CONTEXT_HPP
22#define OPM_PARSE_CONTEXT_HPP
23
24#include <map>
25#include <optional>
26#include <set>
27#include <string>
28#include <vector>
29
30namespace Opm {
31
32enum class InputErrorAction;
33class KeywordLocation;
34
35
36 /*
37 The ParseContext class is meant to control the behavior of the
38 parsing and EclipseState construction phase when
39 errors/inconsistencies/... are encountered in the input.
40
41 For each of the possible problems encountered the possible
42 actions are goverened by the InputError::Action enum:
43
44 InputError::THROW_EXCEPTION
45 InputError::EXIT1
46 InputError::WARN
47 InputError::IGNORE
48
49 The internal datastructure is a map between string keys and
50 enum InputError::Action values. The string keys are meant to be
51 descriptive like:
52
53 "PARSE_RANDOMTEXT"
54
55
56 The constructor will consult the env variable
57 OPM_ERRORS_IGNORE, OPM_ERRORS_WARN and OPM_ERRORS_EXCEPTION
58 when initializing. The variables should be set as strings of
59 update syntax.
60
61 update_syntax: The main function for updating the policy of a
62 parseContext instance is the update() method. That takes a string
63 as input, and updates the matching flags. The string can
64 contain wildcards ('* and '?' mathced with fnmatch()) and is
65 split on ':' or '|' to allow multiple settings to be applied in
66 one go:
67
68 Just set one variable:
69 update("PARSE_RANDOM_SLASH" , InputError::IGNORE)
70
71 Ignore all unsupported features:
72 update("UNSUPPORTED_*" , InputError::IGNORE)
73
74 Set two variables:
75 update("UNSUPPORTED_INIITIAL_THPRES:PARSE_RANDOM_SLASH" , InputError::IGNORE)
76
77 The update function itself is quite tolerant, and will silently
78 ignore unknown keys. If you use the updateKey() function only
79 recognizd keys will be allowed.
80 */
81
82 class ErrorGuard;
83
85 public:
87 explicit ParseContext(InputErrorAction default_action);
88 explicit ParseContext(const std::vector<std::pair<std::string , InputErrorAction>>& initial);
89
90 void handleError( const std::string& errorKey, const std::string& msg, const std::optional<KeywordLocation>& location, ErrorGuard& errors) const;
91 void handleUnknownKeyword(const std::string& keyword, const std::optional<KeywordLocation>& location, ErrorGuard& errors) const;
92 bool hasKey(const std::string& key) const;
93 ParseContext withKey(const std::string& key, InputErrorAction action) const;
94 ParseContext& withKey(const std::string& key, InputErrorAction action);
95 void updateKey(const std::string& key , InputErrorAction action);
96 void update(InputErrorAction action);
97 void update(const std::string& keyString , InputErrorAction action);
98 void ignoreKeyword(const std::string& keyword);
99 InputErrorAction get(const std::string& key) const;
100 std::map<std::string,InputErrorAction>::const_iterator begin() const;
101 std::map<std::string,InputErrorAction>::const_iterator end() const;
102 /*
103 When the key is added it is inserted in 'strict mode',
104 i.e. with the value 'InputError::THROW_EXCEPTION. If you
105 want a different value you must subsequently call the update
106 method.
107 */
108 void addKey(const std::string& key, InputErrorAction default_action);
109 /*
110 The PARSE_EXTRA_RECORDS field regulates how the parser
111 responds to keywords whose size has been defined in the
112 previous keyword.
113 Example:
114 EQLDIMS
115 2 100 20 1 1 /
116 EQUIL\n
117 2469 382.4 1705.0 0.0 500 0.0 1 1 20 /
118 2469 382.4 1705.0 0.0 500 0.0 1 1 20 /
119 2470 382.4 1705.0 0.0 500 0.0 1 1 20 /
120 EQLDIMS's first entry is 2 and defines the record size of the
121 EQUIL keyword. Since there are 3 records in EQUIL, this results
122 in an error that needs to be handled by the parser. By default,
123 an exception is thrown, or it may be specified in the
124 PARSE_EXTRA_RECORDS field that this error is to be ignored.
125 */
126 const static std::string PARSE_EXTRA_RECORDS;
127 /*
128 The unknownKeyword field regulates how the parser should
129 react when it encounters an unknwon keyword. Observe that
130 'keyword' in this context means:
131
132 o A string of 8 characters or less - starting in column
133 0.
134
135 o A string consisiting of UPPERCASE characters and
136 numerals, staring with an UPPERCASE character [Hmmm -
137 actually lowercase is also accepted?!]
138
139 Observe that unknownKeyword does *not* consult any global
140 collection of keywords to see if a particular string
141 corresponds to a known valid keyword which we just happen
142 to ignore for this particualar parse operation.
143
144 The 'unknownkeyword' and 'randomText' error situations are
145 not fully orthogonal, and in particualar if a unknown
146 keyword has been encountered - without halting the parser, a
147 subsequent piece of 'random text' might not be identified
148 correctly as such.
149 */
150 const static std::string PARSE_UNKNOWN_KEYWORD;
151
152 /*
153 With random text we mean a string in the input deck is not
154 correctly formatted as a keyword heading.
155 */
156 const static std::string PARSE_RANDOM_TEXT;
157
158 /*
159 It turns out that random '/' - i.e. typically an extra slash
160 which is not needed - is quite common. This is therefor a
161 special case treatment of the 'randomText' behaviour.
162 */
163 const static std::string PARSE_RANDOM_SLASH;
164
165
166 /*
167 For some keywords the number of records (i.e. size) is given
168 as an item in another keyword. A typical example is the
169 EQUIL keyword where the number of records is given by the
170 NTEQUL item of the EQLDIMS keyword. If the size defining
171 XXXDIMS keyword is not in the deck, we can use the default
172 values of the XXXDIMS keyword; this is regulated by the
173 'missingDIMskeyword' field.
174
175 Observe that a fully defaulted XXXDIMS keyword does not
176 trigger this behavior.
177 */
178 const static std::string PARSE_MISSING_DIMS_KEYWORD;
179
180 /*
181 If the number of elements in the input record exceeds the
182 number of items in the keyword configuration this error
183 situation will be triggered. Many keywords end with several
184 ECLIPSE300 only items - in some cases we have omitted those
185 items in the Json configuration; that will typically trigger
186 this error situation when encountering an ECLIPSE300 deck.
187 */
188 const static std::string PARSE_EXTRA_DATA;
189
190 /*
191 If an include file is not found we can configure the parser
192 to contine reading; of course the resulting deck can
193 obviously be quite broken.
194 */
195 const static std::string PARSE_MISSING_INCLUDE;
196
197 /*
198 For certain keywords, other, specific keywords are either
199 required or prohibited. When such keywords are found in an
200 invalid combination (missing required or present prohibited
201 keyword), this error situation occurs.
202 */
203 const static std::string PARSE_INVALID_KEYWORD_COMBINATION;
204
207 const static std::string RUNSPEC_NUMWELLS_TOO_LARGE;
208
211 const static std::string RUNSPEC_CONNS_PER_WELL_TOO_LARGE;
212
215 const static std::string RUNSPEC_NUMGROUPS_TOO_LARGE;
216
219 const static std::string RUNSPEC_GROUPSIZE_TOO_LARGE;
220
221 /*
222 Should we allow keywords of length more than eight characters? If the
223 keyword is too long it will be internalized using only the eight first
224 characters.
225 */
226 const static std::string PARSE_LONG_KEYWORD;
227
228 /*
229 The unit system specified via the FILEUNIT keyword is different from the unit
230 system used by the deck.
231 */
232 const static std::string UNIT_SYSTEM_MISMATCH;
233
234
235 /*
236 If the third item in the THPRES keyword is defaulted the
237 threshold pressure is inferred from the initial pressure;
238 this currently not supported.
239 */
240 const static std::string UNSUPPORTED_INITIAL_THPRES;
241
242 /*
243 If the second item in the WHISTCTL keyword is set to YES
244 The simulator is supposed to terminate if the well is
245 changed to BHP control. This feature is not yet supported.
246 */
247 const static std::string UNSUPPORTED_TERMINATE_IF_BHP;
248
249 const static std::string UDQ_PARSE_ERROR;
250 const static std::string UDQ_TYPE_ERROR;
251
252 /*
253 If the third item in the THPRES keyword is defaulted the
254 threshold pressure is inferred from the initial pressure -
255 if you still ask the ThresholdPressure instance for a
256 pressure value this error will be signalled. this currently
257 not supported.
258 */
259 const static std::string INTERNAL_ERROR_UNINITIALIZED_THPRES;
260
261 /*
262 If the deck is partial deck, and thus a full EclipseState is
263 meaningless, we can still construct a slim EclipseGrid.
264 */
265 const static std::string PARSE_MISSING_SECTIONS;
266
267 /*
268 When defining wells and groups with the WELSPECS and GRUPTREE keywords
269 we do not allow leading or trailing spaces. The code in Schedule.cpp
270 will *unconditionally* remove the spaces, but with PARSE_WGNAME_SPACE
271 setting you can additionally configure the normal IGNORE|WARN|ERROR
272 behavior.
273 */
274 const static std::string PARSE_WGNAME_SPACE;
275
276 /*
277 If you have configured a specific well in the summary section,
278 which is not recognized - how to handle.
279 */
280 const static std::string SUMMARY_UNKNOWN_WELL;
281 const static std::string SUMMARY_UNKNOWN_GROUP;
282 const static std::string SUMMARY_UNKNOWN_NODE;
283 const static std::string SUMMARY_UNKNOWN_AQUIFER;
284 const static std::string SUMMARY_UNHANDLED_KEYWORD;
285 const static std::string SUMMARY_UNDEFINED_UDQ;
286 const static std::string SUMMARY_UDQ_MISSING_UNIT;
287 const static std::string SUMMARY_INVALID_FIPNUM;
288 const static std::string SUMMARY_EMPTY_REGION;
289 const static std::string SUMMARY_REGION_TOO_LARGE;
290 /*
291 A well must be specified (e.g. WELSPECS) and have completions
292 (e.g. COMPDAT) to be able to set control mode (e.g. WCONPROD).
293 A well missing specification and/or completion(s) will throw.
294 */
295 const static std::string SCHEDULE_INVALID_NAME;
296
297
298 /*
299 Only keywords explicitly white-listed can be included in the ACTIONX
300 block. This error flag controls what should happen when an illegal
301 keyword is encountered in an ACTIONX block.
302 */
303 const static std::string ACTIONX_ILLEGAL_KEYWORD;
304
305
306 /*
307 The RPTSCH, RPTSOL and RPTSCHED keywords have two alternative forms,
308 in the old style all the items are set as integers, i.e. the RPTRST
309 keyword can be configured as:
310
311 RPTRST
312 0 0 0 1 0 1 0 2 0 0 0 0 0 1 0 0 2/
313
314 The new way is based on string mneomnics which can optionally have an
315 integer value, i.e something like:
316
317 RPTRST
318 BASIC=2 FLOWS ALLPROS /
319
320 It is strictly illegal to mix the two ways to configure keywords. A
321 situation with mixed input style is identified if any of the items are
322 integers. To avoid that the values in the assignments like BASIC=2 are
323 interpreted as integers it is essential that there are no spaces
324 around the '=', and that is also documented in the manual. However -
325 it turns out that Eclipse actually handles e.g.
326
327 RPTRST
328 BASIC = 2 /
329
330 So we have introduced a error mode RPT_MIXED_STYLE which tries to
331 handle this situation. Observe that really mixed input style is
332 impossible to handle, and will lead to a hard exception, but with the
333 RPT_MIXED_STYLE error mode it is possible to configure lenient
334 behavior towards interpreting the input as new style string mneomnics.
335 */
336 const static std::string RPT_MIXED_STYLE;
337
338 const static std::string RPT_UNKNOWN_MNEMONIC;
339
340 const static std::string SCHEDULE_GROUP_ERROR;
341 const static std::string SCHEDULE_IGNORED_GUIDE_RATE;
342
343 const static std::string SCHEDULE_COMPSEGS_INVALID;
344 const static std::string SCHEDULE_COMPSEGS_NOT_SUPPORTED;
345
346 /*
347 The SIMULATOR_KEYWORD_ errormodes are for the situation where the
348 parser recognizes, and correctly parses a keyword, but we know that
349 the simulator does not support the intended use of the keyword. These
350 errormodes are invoked from the simulator.
351 */
352 const static std::string SIMULATOR_KEYWORD_NOT_SUPPORTED;
353 const static std::string SIMULATOR_KEYWORD_NOT_SUPPORTED_CRITICAL;
354 const static std::string SIMULATOR_KEYWORD_ITEM_NOT_SUPPORTED;
355 const static std::string SIMULATOR_KEYWORD_ITEM_NOT_SUPPORTED_CRITICAL;
356
357 private:
358 void initDefault();
359 void initEnv();
360 void envUpdate( const std::string& envVariable , InputErrorAction action );
361 void patternUpdate( const std::string& pattern , InputErrorAction action);
362
363 std::map<std::string , InputErrorAction> m_errorContexts;
364 std::set<std::string> ignore_keywords;
365 };
366}
367
368
369#endif
Definition: ErrorGuard.hpp:29
Definition: ParseContext.hpp:84
static const std::string RUNSPEC_NUMWELLS_TOO_LARGE
Dynamic number of wells exceeds maximum declared in RUNSPEC keyword WELLDIMS (item 1).
Definition: ParseContext.hpp:207
static const std::string RUNSPEC_CONNS_PER_WELL_TOO_LARGE
Dynamic number of connections per well exceeds maximum declared in RUNSPEC keyword WELLDIMS (item 2).
Definition: ParseContext.hpp:211
static const std::string RUNSPEC_GROUPSIZE_TOO_LARGE
Dynamic group size exceeds maximum number declared in RUNSPEC keyword WELLDIMS (item 4).
Definition: ParseContext.hpp:219
static const std::string RUNSPEC_NUMGROUPS_TOO_LARGE
Dynamic number of groups exceeds maximum number declared in RUNSPEC keyword WELLDIMS (item 3).
Definition: ParseContext.hpp:215
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30