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