opm-common
DeckKeyword.hpp
1 /*
2  Copyright 2016 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 DECKKEYWORD_HPP
21 #define DECKKEYWORD_HPP
22 
23 #include <opm/common/OpmLog/KeywordLocation.hpp>
24 
25 #include <opm/input/eclipse/Deck/DeckRecord.hpp>
26 #include <opm/input/eclipse/Deck/value_status.hpp>
27 
28 #include <cstddef>
29 #include <string>
30 #include <vector>
31 
32 namespace Opm {
33  class DeckOutput;
34  class DeckValue;
35  class ParserKeyword;
36  class UnitSystem;
37 
38  class DeckKeyword {
39  public:
40 
41  typedef std::vector< DeckRecord >::const_iterator const_iterator;
42 
43  DeckKeyword();
44  explicit DeckKeyword(const ParserKeyword& parserKeyword);
45  DeckKeyword(const KeywordLocation& location, const ParserKeyword& parserKeyword);
46  DeckKeyword(const KeywordLocation& location, const std::string& keywordName);
47  DeckKeyword(const ParserKeyword& parserKeyword, const std::vector<std::vector<DeckValue>>& record_list, const UnitSystem& system_active, const UnitSystem& system_default);
48  DeckKeyword(const ParserKeyword& parserKeyword, const std::vector<int>& data, const KeywordLocation& location = KeywordLocation {});
49  DeckKeyword(const ParserKeyword& parserKeyword, const std::vector<double>& data, const UnitSystem& system_active, const UnitSystem& system_default, const KeywordLocation& location = KeywordLocation {});
50 
51  static DeckKeyword serializationTestObject();
52 
53  const std::string& name() const;
54  void setFixedSize();
55  const KeywordLocation& location() const;
56  DeckKeyword emptyStructuralCopy() const;
57 
58  std::size_t size() const;
59  bool empty() const;
60  void addRecord(DeckRecord&& record);
61  const DeckRecord& getRecord(std::size_t index) const;
62  DeckRecord& getRecord(std::size_t index);
63  const DeckRecord& getDataRecord() const;
64  const DeckRecord& operator[](std::size_t index) const;
65  DeckRecord& operator[](std::size_t index);
66  void setDataKeyword(bool isDataKeyword = true);
67  void setDoubleRecordKeyword(bool isDoubleRecordKeyword = true);
68  bool isDataKeyword() const;
69  bool isDoubleRecordKeyword() const;
70 
71  std::vector<int>& getIntData();
72  std::vector<double>& getRawDoubleData();
73 
74  const std::vector<int>& getIntData() const;
75  const std::vector<double>& getRawDoubleData() const;
76  const std::vector<double>& getSIDoubleData() const;
77  const std::vector<std::string>& getStringData() const;
78  const std::vector<value::status>& getValueStatus() const;
79  std::size_t getDataSize() const;
80  void write( DeckOutput& output ) const;
81  void write_data( DeckOutput& output ) const;
82  void write_TITLE( DeckOutput& output ) const;
83 
84  template <class Keyword>
85  bool is() const {
86  if (Keyword::keywordName == this->m_keywordName)
87  return true;
88  else
89  return false;
90  }
91 
92  const_iterator begin() const;
93  const_iterator end() const;
94  bool equal_data(const DeckKeyword& other, bool cmp_default = false, bool cmp_numeric = true) const;
95  bool equal(const DeckKeyword& other, bool cmp_default = false, bool cmp_numeric = true) const;
96  bool operator==(const DeckKeyword& other) const;
97  bool operator!=(const DeckKeyword& other) const;
98 
99  friend std::ostream& operator<<(std::ostream& os, const DeckKeyword& keyword);
100 
101  template<class Serializer>
102  void serializeOp(Serializer& serializer)
103  {
104  serializer(m_keywordName);
105  serializer(m_location);
106  serializer(m_recordList);
107  serializer(m_isDataKeyword);
108  serializer(m_slashTerminated);
109  serializer(m_isDoubleRecordKeyword);
110  }
111 
112  private:
113  std::string m_keywordName;
114  KeywordLocation m_location;
115 
116  std::vector< DeckRecord > m_recordList;
117  bool m_isDataKeyword;
118  bool m_slashTerminated;
119  bool m_isDoubleRecordKeyword = false;
120  };
121 }
122 
123 #endif /* DECKKEYWORD_HPP */
Definition: KeywordLocation.hpp:27
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: DeckOutput.hpp:29
Definition: ParserKeyword.hpp:86
Definition: UnitSystem.hpp:34
Definition: DeckRecord.hpp:33
Class for (de-)serializing.
Definition: Serializer.hpp:95
Definition: DeckKeyword.hpp:38