My Project
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 GRID, 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
100 bool isRecognizedKeyword( const std::string_view& deckKeywordName) const;
101 const ParserKeyword& getParserKeywordFromDeckName(const std::string_view& deckKeywordName) const;
102 std::vector<std::string> getAllDeckNames () const;
103
104 void loadKeywords(const Json::JsonObject& jsonKeywords);
105 bool loadKeywordFromFile(const std::filesystem::path& configFile);
106
107 void loadKeywordsFromDirectory(const std::filesystem::path& directory , bool recursive = true);
108 void applyUnitsToDeck(Deck& deck) const;
109
115 size_t size() const;
116
117 template <class T>
118 void addKeyword() {
119 addParserKeyword( T() );
120 }
121
122 static EclipseState parse(const Deck& deck, const ParseContext& context);
123 static EclipseState parse(const std::string &filename, const ParseContext& context, ErrorGuard& errors);
124 static EclipseState parseData(const std::string &data, const ParseContext& context, ErrorGuard& errors);
125
129 static EclipseGrid parseGrid(const std::string &filename,
130 const ParseContext& context,
131 ErrorGuard& errors);
132
136 static EclipseGrid parseGrid(const Deck& deck,
137 const ParseContext& context);
138
142 static EclipseGrid parseGridData(const std::string &data,
143 const ParseContext& context,
144 ErrorGuard& errors);
145
146 const std::vector<std::pair<std::string,std::string>> codeKeywords() const;
147
148 private:
149 bool hasWildCardKeyword(const std::string& keyword) const;
150 const ParserKeyword* matchingKeyword(const std::string_view& keyword) const;
151 void addDefaultKeywords();
152
153 // std::vector< std::unique_ptr< const ParserKeyword > > keyword_storage;
154 std::list<ParserKeyword> keyword_storage;
155
156 // associative map of deck names and the corresponding ParserKeyword object
157 std::map< std::string_view, const ParserKeyword* > m_deckParserKeywords;
158
159 // associative map of the parser internal names and the corresponding
160 // ParserKeyword object for keywords which match a regular expression
161 std::map< std::string_view, const ParserKeyword* > m_wildCardKeywords;
162
163 std::vector<std::pair<std::string,std::string>> code_keywords;
164 };
165
166} // namespace Opm
167#endif /* PARSER_H */
168
Definition: JsonObject.hpp:32
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:54
Definition: EclipseState.hpp:55
Definition: ErrorGuard.hpp:29
Definition: ParseContext.hpp:84
Definition: ParserKeyword.hpp:85
The hub of the parsing process.
Definition: Parser.hpp:60
void addParserKeyword(const Json::JsonObject &jsonKeyword)
Method to add ParserKeyword instances, these holding type and size information about the keywords and...
static EclipseGrid parseGrid(const Deck &deck, const ParseContext &context)
Parses the provided deck.
static EclipseGrid parseGridData(const std::string &data, const ParseContext &context, ErrorGuard &errors)
Parses the provided deck string.
bool hasKeyword(const std::string &) const
Returns whether the parser knows about a keyword.
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...
size_t size() const
Returns the approximate number of recognized keywords in decks.
static EclipseGrid parseGrid(const std::string &filename, const ParseContext &context, ErrorGuard &errors)
Parses the deck specified in filename.
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30