ParseMode.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_MODE_HPP
22 #define OPM_PARSE_MODE_HPP
23 
24 #include <string>
25 #include <map>
26 #include <vector>
27 
29 
30 namespace Opm {
31 
32 
33  /*
34  The ParseMode class is meant to control the behavior of the
35  parsing and EclipseState construction phase when
36  errors/inconsistencies/... are encountered in the input.
37 
38  For each of the possible problems encountered the possible
39  actions are goverened by the InputError::Action enum:
40 
41  InputError::THROW_EXCEPTION
42  InputError::WARN
43  InputError::IGNORE
44 
45  The internal datastructure is a map between string keys and
46  enum InputError::Action values. The string keys are meant to be
47  descriptive like:
48 
49  "PARSE_RANDOMTEXT"
50 
51 
52  The constructor will consult the env variable
53  OPM_ERRORS_IGNORE, OPM_ERRORS_WARN and OPM_ERRORS_EXCEPTION
54  when initializing. The variables should be set as strings of
55  update syntax.
56 
57  update_syntax: The main function for updating the policy of a
58  parseMode instance is the update() method. That takes a string
59  as input, and updates the matching flags. The string can
60  contain wildcards ('* and '?' mathced with fnmatch()) and is
61  split on ':' or '|' to allow multiple settings to be applied in
62  one go:
63 
64  Just set one variable:
65  update("PARSE_RANDOM_SLASH" , InputError::IGNORE)
66 
67  Ignore all unsupported features:
68  update("UNSUPPORTED_*" , InputError::IGNORE)
69 
70  Set two variables:
71  update("UNSUPPORTED_INIITIAL_THPRES:PARSE_RANDOM_SLASH" , InputError::IGNORE)
72 
73  The update function itself is quite tolerant, and will silently
74  ignore unknown keys. If you use the updateKey() function only
75  recognizd keys will be allowed.
76  */
77 
78  class ParseMode {
79  public:
80  ParseMode();
81  ParseMode(const std::vector<std::pair<std::string , InputError::Action>> initial);
82  void handleError( const std::string& errorKey , const std::string& msg) const;
83  bool hasKey(const std::string& key) const;
84  void updateKey(const std::string& key , InputError::Action action);
85  void update(InputError::Action action);
86  void update(const std::string& keyString , InputError::Action action);
87  InputError::Action get(const std::string& key) const;
88  std::map<std::string,InputError::Action>::const_iterator begin() const;
89  std::map<std::string,InputError::Action>::const_iterator end() const;
90 
91  /*
92  When the key is added it is inserted in 'strict mode',
93  i.e. with the value 'InputError::THROW_EXCEPTION. If you
94  want a different value you must subsequently call the update
95  method.
96  */
97  void addKey(const std::string& key);
98  /*
99  The unknownKeyword field regulates how the parser should
100  react when it encounters an unknwon keyword. Observe that
101  'keyword' in this context means:
102 
103  o A string of 8 characters or less - starting in column
104  0.
105 
106  o A string consisiting of UPPERCASE characters and
107  numerals, staring with an UPPERCASE character [Hmmm -
108  actually lowercase is also accepted?!]
109 
110  Observe that unknownKeyword does *not* consult any global
111  collection of keywords to see if a particular string
112  corresponds to a known valid keyword which we just happen
113  to ignore for this particualar parse operation.
114 
115  The 'unknownkeyword' and 'randomText' error situations are
116  not fully orthogonal, and in particualar if a unknown
117  keyword has been encountered - without halting the parser, a
118  subsequent piece of 'random text' might not be identified
119  correctly as such.
120  */
121  const static std::string PARSE_UNKNOWN_KEYWORD;
122 
123  /*
124  With random text we mean a string in the input deck is not
125  correctly formatted as a keyword heading.
126  */
127  const static std::string PARSE_RANDOM_TEXT;
128 
129  /*
130  It turns out that random '/' - i.e. typically an extra slash
131  which is not needed - is quite common. This is therefor a
132  special case treatment of the 'randomText' behaviour.
133  */
134  const static std::string PARSE_RANDOM_SLASH;
135 
136 
137  /*
138  For some keywords the number of records (i.e. size) is given
139  as an item in another keyword. A typical example is the
140  EQUIL keyword where the number of records is given by the
141  NTEQUL item of the EQLDIMS keyword. If the size defining
142  XXXDIMS keyword is not in the deck, we can use the default
143  values of the XXXDIMS keyword; this is regulated by the
144  'missingDIMskeyword' field.
145 
146  Observe that a fully defaulted XXXDIMS keyword does not
147  trigger this behavior.
148  */
149  const static std::string PARSE_MISSING_DIMS_KEYWORD;
150 
151  /*
152  If the number of elements in the input record exceeds the
153  number of items in the keyword configuration this error
154  situation will be triggered. Many keywords end with several
155  ECLIPSE300 only items - in some cases we have omitted those
156  items in the Json configuration; that will typically trigger
157  this error situation when encountering an ECLIPSE300 deck.
158  */
159  const static std::string PARSE_EXTRA_DATA;
160 
161  /*
162  Some property modfiers can be modified in the Schedule
163  section; this effectively means that Eclipse supports time
164  dependent geology. This is marked as an exocit special
165  feature in Eclipse, and not supported at all in the
166  EclipseState object of opm-parser. If these modifiers are
167  encountered in the Schedule section the behavior is
168  regulated by this setting.
169  */
170  const static std::string UNSUPPORTED_SCHEDULE_GEO_MODIFIER;
171 
172  /*
173  In the COMPORD implementation only the 'TRACK' input mode is supported.
174  */
175  const static std::string UNSUPPORTED_COMPORD_TYPE;
176 
177  /*
178  If the third item in the THPRES keyword is defaulted the
179  threshold pressure is inferred from the initial pressure;
180  this currently not supported.
181  */
182  const static std::string UNSUPPORTED_INITIAL_THPRES;
183 
184 
185  /*
186  If the third item in the THPRES keyword is defaulted the
187  threshold pressure is inferred from the initial pressure -
188  if you still ask the ThresholdPressure instance for a
189  pressure value this error will be signalled. this currently
190  not supported.
191  */
192  const static std::string INTERNAL_ERROR_UNINITIALIZED_THPRES;
193 
194  private:
195  void initDefault();
196  void initEnv();
197  void envUpdate( const std::string& envVariable , InputError::Action action );
198  void patternUpdate( const std::string& pattern , InputError::Action action);
199  std::map<std::string , InputError::Action> m_errorModes;
200 }; }
201 
202 
203 #endif
std::map< std::string, InputError::Action >::const_iterator begin() const
Definition: Deck.hpp:29
static const std::string PARSE_RANDOM_SLASH
Definition: ParseMode.hpp:134
std::map< std::string, InputError::Action >::const_iterator end() const
static const std::string UNSUPPORTED_SCHEDULE_GEO_MODIFIER
Definition: ParseMode.hpp:170
bool hasKey(const std::string &key) const
static const std::string PARSE_RANDOM_TEXT
Definition: ParseMode.hpp:127
static const std::string PARSE_UNKNOWN_KEYWORD
Definition: ParseMode.hpp:121
void addKey(const std::string &key)
static const std::string UNSUPPORTED_COMPORD_TYPE
Definition: ParseMode.hpp:175
static const std::string PARSE_EXTRA_DATA
Definition: ParseMode.hpp:159
Definition: ParseMode.hpp:78
static const std::string INTERNAL_ERROR_UNINITIALIZED_THPRES
Definition: ParseMode.hpp:192
static const std::string PARSE_MISSING_DIMS_KEYWORD
Definition: ParseMode.hpp:149
Action
Definition: InputErrorAction.hpp:27
void update(InputError::Action action)
void updateKey(const std::string &key, InputError::Action action)
void handleError(const std::string &errorKey, const std::string &msg) const
static const std::string UNSUPPORTED_INITIAL_THPRES
Definition: ParseMode.hpp:182