My Project
Deck.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 DECK_HPP
21 #define DECK_HPP
22 
23 #include <functional>
24 #include <map>
25 #include <memory>
26 #include <ostream>
27 #include <optional>
28 #include <vector>
29 #include <string>
30 
31 #include <opm/input/eclipse/Deck/DeckView.hpp>
32 #include <opm/input/eclipse/Deck/DeckTree.hpp>
33 #include <opm/input/eclipse/Deck/DeckKeyword.hpp>
34 #include <opm/input/eclipse/Units/UnitSystem.hpp>
35 
36 #ifdef OPM_PARSER_DECK_API_WARNING
37 #ifndef OPM_PARSER_DECK_API
38 #pragma message "\n\n" \
39 " ----------------------------------------------------------------------------------\n" \
40 " The current compilation unit includes the header Deck.hpp. Outside of opm-parser \n" \
41 " you are encouraged to use the EclipseState API instead of the low level Deck API. \n" \
42 " If use of the Deck API is absolutely necessary you can silence this warning with \n" \
43 " #define OPM_PARSER_DECK_API before including the Deck.hpp header. \n" \
44 " ----------------------------------------------------------------------------------\n" \
45 ""
46 #endif
47 #endif
48 
49 
50 
51 namespace Opm {
52 
53  /*
54  * The Deck (container) class owns all memory given to it via .addX(), as
55  * do all inner objects. This means that the Deck object itself must stay
56  * alive as long as DeckItem (and friends) are needed, to avoid
57  * use-after-free.
58  */
59  class DeckOutput;
60 
61 
62 
63  class Deck {
64  public:
65  using iterator = std::vector< DeckKeyword >::iterator;
66  using const_iterator = std::vector< DeckKeyword >::const_iterator;
67 
68  Deck() = default;
69  Deck( const Deck& );
70  Deck( Deck&& );
71 
72  static Deck serializeObject();
73 
74  Deck& operator=(const Deck& rhs);
75  bool operator==(const Deck& data) const;
76 
77  void addKeyword( DeckKeyword&& keyword );
78  void addKeyword( const DeckKeyword& keyword );
79 
80  const UnitSystem& getDefaultUnitSystem() const;
81  const UnitSystem& getActiveUnitSystem() const;
82  UnitSystem& getActiveUnitSystem();
83  UnitSystem& getDefaultUnitSystem();
84  void selectActiveUnitSystem( UnitSystem::UnitType unit_type );
85 
86  const std::string& getInputPath() const;
87  std::string getDataFile() const;
88  void setDataFile(const std::string& dataFile);
89  std::string makeDeckPath(const std::string& path) const;
90  DeckTree& tree();
91  DeckTree tree() const;
92 
93  std::size_t size() const;
94  bool empty() const;
95  iterator begin();
96  iterator end();
97  void write( DeckOutput& output ) const ;
98  friend std::ostream& operator<<(std::ostream& os, const Deck& deck);
99  const_iterator begin() const;
100  const_iterator end() const;
101 
102  Opm::DeckView operator[](const std::string& keyword) const;
103  const DeckKeyword& operator[](std::size_t index) const;
104 
105  template< class Keyword >
106  Opm::DeckView get() const {
107  return this->operator[](Keyword::keywordName);
108  }
109 
110  std::vector< const DeckKeyword* > getKeywordList( const std::string& keyword ) const;
111  template< class Keyword >
112  std::vector< const DeckKeyword* > getKeywordList() const {
113  return getKeywordList( Keyword::keywordName );
114  }
115 
116  template<class Serializer>
117  void serializeOp(Serializer& serializer)
118  {
119  serializer.vector(keywordList);
120  defaultUnits.serializeOp(serializer);
121  serializer(activeUnits);
122  serializer(m_dataFile);
123  serializer(input_path);
124  serializer(unit_system_access_count);
125  }
126 
127  bool hasKeyword( const std::string& keyword ) const;
128 
129  template< class Keyword >
130  bool hasKeyword() const {
131  return this->hasKeyword( Keyword::keywordName );
132  }
133 
134 
135 
136  const std::vector<std::size_t> index(const std::string& keyword) const {
137  return this->global_view().index(keyword);
138  }
139 
140  template< class Keyword >
141  std::size_t count() const {
142  return count( Keyword::keywordName );
143  }
144  size_t count(const std::string& keyword) const;
145 
146 
147 
148  private:
149 
150  std::vector< DeckKeyword > keywordList;
151  UnitSystem defaultUnits;
152  std::optional<UnitSystem> activeUnits;
153 
154  std::optional<std::string> m_dataFile;
155  std::string input_path;
156  DeckTree file_tree;
157  mutable std::size_t unit_system_access_count = 0;
158 
159  const DeckView& global_view() const;
160  mutable std::unique_ptr<DeckView> m_global_view{nullptr};
161  };
162 }
163 #endif /* DECK_HPP */
Definition: DeckKeyword.hpp:36
Definition: DeckOutput.hpp:29
Definition: DeckTree.hpp:38
Definition: DeckView.hpp:30
Definition: Deck.hpp:63
Definition: Serializer.hpp:38
Definition: UnitSystem.hpp:34
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29