My Project
Loading...
Searching...
No Matches
Parser.hpp
1/*
2 Copyright 2013 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#ifndef OPM_PARSER_HPP
21#define OPM_PARSER_HPP
22
23#include <filesystem>
24#include <iosfwd>
25#include <list>
26#include <map>
27#include <memory>
28#include <string>
29#include <utility>
30#include <vector>
31
32#include <stddef.h>
33
34#include <opm/input/eclipse/Parser/ParserKeyword.hpp>
35
36namespace Json {
37 class JsonObject;
38}
39
40namespace Opm {
41
42 namespace Ecl {
43
44 enum SectionType {
45 RUNSPEC, GRID, EDIT, PROPS, REGIONS, SOLUTION, SUMMARY, SCHEDULE
46 };
47 }
48
49 class Deck;
50 class EclipseGrid;
51 class EclipseState;
52 class ParseContext;
53 class ErrorGuard;
54 class RawKeyword;
55
59
60 class Parser {
61 public:
62 explicit Parser(bool addDefault = true);
63
64 static std::string stripComments(const std::string& inputString);
65
67 Deck parseFile(const std::string &dataFile,
68 const ParseContext&,
69 ErrorGuard& errors,
70 const std::vector<Opm::Ecl::SectionType>& sections = {}) const;
71
72 Deck parseFile(const std::string&,
73 const ParseContext&) const;
74
75 Deck parseFile(const std::string&,
76 const ParseContext&,
77 const std::vector<Opm::Ecl::SectionType>& sections
78 ) const;
79
80 Deck parseFile(const std::string& datafile) const;
81
82 Deck parseString(const std::string &data,
83 const ParseContext&,
84 ErrorGuard& errors) const;
85 Deck parseString(const std::string &data, const ParseContext& ) const;
86 Deck parseString(const std::string &data) const;
87
88 Deck parseStream(std::unique_ptr<std::istream>&& inputStream , const ParseContext& parseContext, ErrorGuard& errors) const;
89
91 void addParserKeyword(const Json::JsonObject& jsonKeyword);
92 void addParserKeyword(ParserKeyword parserKeyword);
93
97 bool hasKeyword( const std::string& ) const;
98 const ParserKeyword& getKeyword(const std::string& name) const;
99
111 bool isRecognizedKeyword(std::string_view deckKeywordName) const;
112
122 bool isBaseRecognizedKeyword(std::string_view deckKeywordName) const;
123
124 const ParserKeyword& getParserKeywordFromDeckName(const std::string_view& deckKeywordName) const;
125 std::vector<std::string> getAllDeckNames () const;
126
127 void loadKeywords(const Json::JsonObject& jsonKeywords);
128 bool loadKeywordFromFile(const std::filesystem::path& configFile);
129
130 void loadKeywordsFromDirectory(const std::filesystem::path& directory , bool recursive = true);
131 void applyUnitsToDeck(Deck& deck) const;
132
138 size_t size() const;
139
140 template <class T>
141 void addKeyword() {
142 addParserKeyword( T() );
143 }
144
145 static EclipseState parse(const Deck& deck, const ParseContext& context);
146 static EclipseState parse(const std::string &filename, const ParseContext& context, ErrorGuard& errors);
147 static EclipseState parseData(const std::string &data, const ParseContext& context, ErrorGuard& errors);
148
152 static EclipseGrid parseGrid(const std::string &filename,
153 const ParseContext& context,
154 ErrorGuard& errors);
155
159 static EclipseGrid parseGrid(const Deck& deck,
160 const ParseContext& context);
161
165 static EclipseGrid parseGridData(const std::string &data,
166 const ParseContext& context,
167 ErrorGuard& errors);
168
169 const std::vector<std::pair<std::string,std::string>> codeKeywords() const;
170
171 private:
172 bool hasWildCardKeyword(const std::string& keyword) const;
173 const ParserKeyword* matchingKeyword(const std::string_view& keyword) const;
174 void addDefaultKeywords();
175
176 // std::vector< std::unique_ptr< const ParserKeyword > > keyword_storage;
177 std::list<ParserKeyword> keyword_storage;
178
179 // associative map of deck names and the corresponding ParserKeyword object
180 std::map< std::string_view, const ParserKeyword* > m_deckParserKeywords;
181
182 // associative map of the parser internal names and the corresponding
183 // ParserKeyword object for keywords which match a regular expression
184 std::map< std::string_view, const ParserKeyword* > m_wildCardKeywords;
185
186 std::vector<std::pair<std::string,std::string>> code_keywords;
187 };
188
189} // namespace Opm
190#endif /* PARSER_H */
191
Definition JsonObject.hpp:31
Definition Deck.hpp:49
About cell information and dimension: The actual grid information is held in a pointer to an ERT ecl_...
Definition EclipseGrid.hpp:55
Definition EclipseState.hpp:63
Definition ErrorGuard.hpp:29
Definition ParseContext.hpp:84
Definition ParserKeyword.hpp:85
The hub of the parsing process.
Definition Parser.hpp:60
static EclipseGrid parseGrid(const std::string &filename, const ParseContext &context, ErrorGuard &errors)
Parses the deck specified in filename.
Definition Parser.cpp:1505
void addParserKeyword(const Json::JsonObject &jsonKeyword)
Method to add ParserKeyword instances, these holding type and size information about the keywords and...
Definition Parser.cpp:1680
bool isBaseRecognizedKeyword(std::string_view deckKeywordName) const
Whether or not string is a valid keyword.
Definition Parser.cpp:1639
bool hasKeyword(const std::string &) const
Returns whether the parser knows about a keyword.
Definition Parser.cpp:1684
static EclipseGrid parseGridData(const std::string &data, const ParseContext &context, ErrorGuard &errors)
Parses the provided deck string.
Definition Parser.cpp:1518
Deck parseFile(const std::string &dataFile, const ParseContext &, ErrorGuard &errors, const std::vector< Opm::Ecl::SectionType > &sections={}) const
The starting point of the parsing process. The supplied file is parsed, and the resulting Deck is ret...
Definition Parser.cpp:1527
size_t size() const
Returns the approximate number of recognized keywords in decks.
Definition Parser.cpp:1613
bool isRecognizedKeyword(std::string_view deckKeywordName) const
Whether or not string is a valid keyword.
Definition Parser.cpp:1629
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30