My Project
Loading...
Searching...
No Matches
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 <opm/input/eclipse/Deck/DeckView.hpp>
24#include <opm/input/eclipse/Deck/DeckTree.hpp>
25#include <opm/input/eclipse/Deck/DeckKeyword.hpp>
26#include <opm/input/eclipse/Units/UnitSystem.hpp>
27
28#include <iosfwd>
29#include <memory>
30#include <optional>
31#include <string>
32#include <vector>
33
34namespace Opm {
35
36 /*
37 * The Deck (container) class owns all memory given to it via .addX(), as
38 * do all inner objects. This means that the Deck object itself must stay
39 * alive as long as DeckItem (and friends) are needed, to avoid
40 * use-after-free.
41 */
42 class DeckOutput;
43
44
45
46 class Deck {
47 public:
48 using iterator = std::vector< DeckKeyword >::iterator;
49 using const_iterator = std::vector< DeckKeyword >::const_iterator;
50
51 Deck() = default;
52 Deck( const Deck& );
53 Deck( Deck&& );
54
55 static Deck serializationTestObject();
56
57 Deck& operator=(const Deck& rhs);
58 bool operator==(const Deck& data) const;
59
60 void addKeyword( DeckKeyword&& keyword );
61 void addKeyword( const DeckKeyword& keyword );
62
63 const UnitSystem& getDefaultUnitSystem() const;
64 const UnitSystem& getActiveUnitSystem() const;
65 UnitSystem& getActiveUnitSystem();
66 UnitSystem& getDefaultUnitSystem();
67 void selectActiveUnitSystem( UnitSystem::UnitType unit_type );
68
69 const std::string& getInputPath() const;
70 std::string getDataFile() const;
71 void setDataFile(const std::string& dataFile);
72 std::string makeDeckPath(const std::string& path) const;
73 DeckTree& tree();
74 DeckTree tree() const;
75
76 std::size_t size() const;
77 bool empty() const;
78 iterator begin();
79 iterator end();
80 void write( DeckOutput& output ) const ;
81 friend std::ostream& operator<<(std::ostream& os, const Deck& deck);
82 const_iterator begin() const;
83 const_iterator end() const;
84
85 Opm::DeckView operator[](const std::string& keyword) const;
86 const DeckKeyword& operator[](std::size_t index) const;
87
88 template< class Keyword >
89 Opm::DeckView get() const {
90 return this->operator[](Keyword::keywordName);
91 }
92
93 std::vector< const DeckKeyword* > getKeywordList( const std::string& keyword ) const;
94 template< class Keyword >
95 std::vector< const DeckKeyword* > getKeywordList() const {
96 return getKeywordList( Keyword::keywordName );
97 }
98
99 template<class Serializer>
100 void serializeOp(Serializer& serializer)
101 {
102 serializer(keywordList);
103 serializer(defaultUnits);
104 serializer(activeUnits);
105 serializer(m_dataFile);
106 serializer(input_path);
107 serializer(unit_system_access_count);
108 }
109
110 bool hasKeyword( const std::string& keyword ) const;
111
112 template< class Keyword >
113 bool hasKeyword() const {
114 return this->hasKeyword( Keyword::keywordName );
115 }
116
117
118
119 const std::vector<std::size_t> index(const std::string& keyword) const {
120 return this->global_view().index(keyword);
121 }
122
123 template< class Keyword >
124 std::size_t count() const {
125 return count( Keyword::keywordName );
126 }
127 size_t count(const std::string& keyword) const;
128
129 void remove_keywords(int from, int to) { keywordList.erase(keywordList.begin() +from, keywordList.begin() + to); };
130
131 private:
132
133 std::vector< DeckKeyword > keywordList;
134 UnitSystem defaultUnits;
135 std::optional<UnitSystem> activeUnits;
136
137 std::optional<std::string> m_dataFile;
138 std::string input_path;
139 DeckTree file_tree;
140 mutable std::size_t unit_system_access_count = 0;
141
142 const DeckView& global_view() const;
143 mutable std::unique_ptr<DeckView> m_global_view{nullptr};
144 };
145}
146#endif /* DECK_HPP */
Definition DeckKeyword.hpp:36
Definition DeckOutput.hpp:29
Definition DeckTree.hpp:38
Definition DeckView.hpp:31
Definition Deck.hpp:46
Class for (de-)serializing.
Definition Serializer.hpp:94
Definition UnitSystem.hpp:34
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30