ParseContext.hpp
Go to the documentation of this file.
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 <string>
25#include <map>
26#include <set>
27#include <vector>
28
30
32
33namespace Opm {
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(InputError::Action default_action);
88 explicit ParseContext(const std::vector<std::pair<std::string , InputError::Action>>& initial);
89
90 void handleError( const std::string& errorKey, const std::string& msg, ErrorGuard& errors ) const;
92 bool hasKey(const std::string& key) const;
95 void updateKey(const std::string& key , InputError::Action action);
97 void update(const std::string& keyString , InputError::Action action);
100 std::map<std::string,InputError::Action>::const_iterator begin() const;
101 std::map<std::string,InputError::Action>::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, InputError::Action 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 */
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 */
151
152 /*
153 With random text we mean a string in the input deck is not
154 correctly formatted as a keyword heading.
155 */
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 */
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 */
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 */
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 */
196
200
204
208
212
213 /*
214 Should we allow keywords of length more than eight characters? If the
215 keyword is too long it will be internalized using only the eight first
216 characters.
217 */
219
220 /*
221 The unit system specified via the FILEUNIT keyword is different from the unit
222 system used by the deck.
223 */
225
226 /*
227 Some property modfiers can be modified in the Schedule
228 section; this effectively means that Eclipse supports time
229 dependent geology. This is marked as an exocit special
230 feature in Eclipse, and not supported at all in the
231 EclipseState object of opm-parser. If these modifiers are
232 encountered in the Schedule section the behavior is
233 regulated by this setting.
234 */
236
237 /*
238 In the COMPORD implementation only the 'TRACK' input mode is supported.
239 */
241
242 /*
243 If the third item in the THPRES keyword is defaulted the
244 threshold pressure is inferred from the initial pressure;
245 this currently not supported.
246 */
248
249 /*
250 If the second item in the WHISTCTL keyword is set to YES
251 The simulator is supposed to terminate if the well is
252 changed to BHP control. This feature is not yet supported.
253 */
255
258
259 /*
260 If the third item in the THPRES keyword is defaulted the
261 threshold pressure is inferred from the initial pressure -
262 if you still ask the ThresholdPressure instance for a
263 pressure value this error will be signalled. this currently
264 not supported.
265 */
267
268 /*
269 If the deck is partial deck, and thus a full EclipseState is
270 meaningless, we can still construct a slim EclipseGrid.
271 */
273
274 /*
275 When defining wells and groups with the WELSPECS and GRUPTREE keywords
276 we do not allow leading or trailing spaces. The code in Schedule.cpp
277 will *unconditionally* remove the spaces, but with PARSE_WGNAME_SPACE
278 setting you can additionally configure the normal IGNORE|WARN|ERROR
279 behavior.
280 */
282
283 /*
284 If you have configured a specific well in the summary section,
285 which is not recognized - how to handle.
286 */
292
293 /*
294 A well must be specified (e.g. WELSPECS) and have completions
295 (e.g. COMPDAT) to be able to set control mode (e.g. WCONPROD).
296 A well missing specification and/or completion(s) will throw.
297 */
299
300
301 /*
302 Only keywords explicitly white-listed can be included in the ACTIONX
303 block. This error flag controls what should happen when an illegal
304 keyword is encountered in an ACTIONX block.
305 */
307
308
309 /*
310 The RPTSCH, RPTSOL and RPTSCHED keywords have two alternative forms,
311 in the old style all the items are set as integers, i.e. the RPTRST
312 keyword can be configured as:
313
314 RPTRST
315 0 0 0 1 0 1 0 2 0 0 0 0 0 1 0 0 2/
316
317 The new way is based on string mneomnics which can optionally have an
318 integer value, i.e something like:
319
320 RPTRST
321 BASIC=2 FLOWS ALLPROS /
322
323 It is strictly illegal to mix the two ways to configure keywords. A
324 situation with mixed input style is identified if any of the items are
325 integers. To avoid that the values in the assignments like BASIC=2 are
326 interpreted as integers it is essential that there are no spaces
327 around the '=', and that is also documented in the manual. However -
328 it turns out that Eclipse actually handles e.g.
329
330 RPTRST
331 BASIC = 2 /
332
333 So we have introduced a error mode RPT_MIXED_STYLE which tries to
334 handle this situation. Observe that really mixed input style is
335 impossible to handle, and will lead to a hard exception, but with the
336 RPT_MIXED_STYLE error mode it is possible to configure lenient
337 behavior towards interpreting the input as new style string mneomnics.
338 */
340
342
345
348
349 /*
350 The SIMULATOR_KEYWORD_ errormodes are for the situation where the
351 parser recognizes, and correctly parses a keyword, but we know that
352 the simulator does not support the intended use of the keyword. These
353 errormodes are invoked from the simulator.
354 */
357
358 private:
359 void initDefault();
360 void initEnv();
361 void envUpdate( const std::string& envVariable , InputError::Action action );
362 void patternUpdate( const std::string& pattern , InputError::Action action);
363
364 std::map<std::string , InputError::Action> m_errorContexts;
365 std::set<std::string> ignore_keywords;
366 };
367}
368
369
370#endif
const char *const string
Definition: cJSON.h:170
Definition: ErrorGuard.hpp:29
Definition: ParseContext.hpp:84
static const std::string PARSE_RANDOM_TEXT
Definition: ParseContext.hpp:156
static const std::string RUNSPEC_NUMWELLS_TOO_LARGE
Definition: ParseContext.hpp:199
void update(const std::string &keyString, InputError::Action action)
void addKey(const std::string &key, InputError::Action default_action)
static const std::string SIMULATOR_KEYWORD_NOT_SUPPORTED
Definition: ParseContext.hpp:355
static const std::string PARSE_RANDOM_SLASH
Definition: ParseContext.hpp:163
void handleError(const std::string &errorKey, const std::string &msg, ErrorGuard &errors) const
static const std::string PARSE_MISSING_SECTIONS
Definition: ParseContext.hpp:272
static const std::string SCHEDULE_GROUP_ERROR
Definition: ParseContext.hpp:343
ParseContext withKey(const std::string &key, InputError::Action action=InputError::WARN) const
static const std::string SUMMARY_UDQ_MISSING_UNIT
Definition: ParseContext.hpp:291
static const std::string PARSE_MISSING_INCLUDE
Definition: ParseContext.hpp:195
static const std::string RUNSPEC_CONNS_PER_WELL_TOO_LARGE
Definition: ParseContext.hpp:203
static const std::string PARSE_UNKNOWN_KEYWORD
Definition: ParseContext.hpp:150
static const std::string UNIT_SYSTEM_MISMATCH
Definition: ParseContext.hpp:224
ParseContext & withKey(const std::string &key, InputError::Action action=InputError::WARN)
bool hasKey(const std::string &key) const
static const std::string PARSE_MISSING_DIMS_KEYWORD
Definition: ParseContext.hpp:178
static const std::string PARSE_EXTRA_RECORDS
Definition: ParseContext.hpp:126
static const std::string UNSUPPORTED_TERMINATE_IF_BHP
Definition: ParseContext.hpp:254
static const std::string RUNSPEC_GROUPSIZE_TOO_LARGE
Definition: ParseContext.hpp:211
static const std::string UDQ_TYPE_ERROR
Definition: ParseContext.hpp:257
static const std::string UNSUPPORTED_COMPORD_TYPE
Definition: ParseContext.hpp:240
static const std::string RPT_UNKNOWN_MNEMONIC
Definition: ParseContext.hpp:341
static const std::string SIMULATOR_KEYWORD_ITEM_NOT_SUPPORTED
Definition: ParseContext.hpp:356
void handleUnknownKeyword(const std::string &keyword, ErrorGuard &errors) const
void update(InputError::Action action)
static const std::string UDQ_PARSE_ERROR
Definition: ParseContext.hpp:256
InputError::Action get(const std::string &key) const
static const std::string ACTIONX_ILLEGAL_KEYWORD
Definition: ParseContext.hpp:306
ParseContext(InputError::Action default_action)
ParseContext(const std::vector< std::pair< std::string, InputError::Action > > &initial)
std::map< std::string, InputError::Action >::const_iterator end() const
static const std::string SCHEDULE_INVALID_NAME
Definition: ParseContext.hpp:298
static const std::string SUMMARY_UNKNOWN_GROUP
Definition: ParseContext.hpp:288
static const std::string UNSUPPORTED_INITIAL_THPRES
Definition: ParseContext.hpp:247
void updateKey(const std::string &key, InputError::Action action)
static const std::string RPT_MIXED_STYLE
Definition: ParseContext.hpp:339
static const std::string PARSE_WGNAME_SPACE
Definition: ParseContext.hpp:281
static const std::string SCHEDULE_COMPSEGS_NOT_SUPPORTED
Definition: ParseContext.hpp:347
static const std::string PARSE_LONG_KEYWORD
Definition: ParseContext.hpp:218
static const std::string SUMMARY_UNHANDLED_KEYWORD
Definition: ParseContext.hpp:289
static const std::string RUNSPEC_NUMGROUPS_TOO_LARGE
Definition: ParseContext.hpp:207
static const std::string UNSUPPORTED_SCHEDULE_GEO_MODIFIER
Definition: ParseContext.hpp:235
static const std::string INTERNAL_ERROR_UNINITIALIZED_THPRES
Definition: ParseContext.hpp:266
std::map< std::string, InputError::Action >::const_iterator begin() const
static const std::string SCHEDULE_IGNORED_GUIDE_RATE
Definition: ParseContext.hpp:344
static const std::string PARSE_EXTRA_DATA
Definition: ParseContext.hpp:188
static const std::string SCHEDULE_COMPSEGS_INVALID
Definition: ParseContext.hpp:346
static const std::string SUMMARY_UNDEFINED_UDQ
Definition: ParseContext.hpp:290
static const std::string SUMMARY_UNKNOWN_WELL
Definition: ParseContext.hpp:287
void ignoreKeyword(const std::string &keyword)
Action
Definition: InputErrorAction.hpp:36
@ WARN
Definition: InputErrorAction.hpp:38
UDAKeyword keyword(UDAControl control)
Definition: A.hpp:4