FieldPropsManager.hpp
Go to the documentation of this file.
1/*
2 Copyright 2019 Equinor 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 it under the terms
7 of the GNU General Public License as published by the Free Software
8 Foundation, either version 3 of the License, or (at your option) any later
9 version.
10
11 OPM is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along with
16 OPM. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#ifndef FIELDPROPS_MANAGER_HPP
20#define FIELDPROPS_MANAGER_HPP
21
22#include <memory>
23#include <vector>
24
25namespace Opm {
26
27class EclipseGrid;
28class Deck;
29class FieldProps;
30class Phases;
31class TableManager;
32
34
35struct MemInfo {
36 std::size_t global_size;
37 std::size_t active_size;
38 std::size_t int_fields;
39 std::size_t double_fields;
40 std::size_t total;
41
42 MemInfo(std::size_t gsize, std::size_t asize, std::size_t num_int, std::size_t num_double) :
43 global_size(gsize),
44 active_size(asize),
45 int_fields(num_int),
46 double_fields(num_double),
47 total(asize * sizeof(int) * num_int + // The integer fields like SATNUM and PVTNUM
48 asize * sizeof(double) * num_double + // The double fields like PORO and SWATINIT
49 asize * sizeof(double) * 2 + // Depth and volume of all active cells
50 asize * sizeof(unsigned char) * (num_int + num_double) + // The per cell value status flag
51 gsize * sizeof(int)) // The global ACTNUM mapping
52 {
53 };
54
55
56};
57
58
59
60public:
61 // The default constructor should be removed when the FieldPropsManager is mandatory
62 // The default constructed fieldProps object is **NOT** usable
63 FieldPropsManager() = default;
64 FieldPropsManager(const Deck& deck, const Phases& ph, const EclipseGrid& grid, const TableManager& tables);
65 virtual void reset_actnum(const std::vector<int>& actnum);
67 virtual std::vector<int> actnum() const;
68 virtual std::vector<double> porv(bool global = false) const;
69 MemInfo meminfo( ) const;
70
71 /*
72 The number of cells in the fields managed by this FieldPropsManager.
73 Initially this will correspond to the number of active cells in the grid
74 used when constructing the FieldPropsManager, but using the reset_actnum()
75 method it is possible to deactivate additional cells.
76 */
77 std::size_t active_size() const;
78
79
80 /*
81 Because the FieldProps class can autocreate properties the semantics of
82 get() and has() is slightly non intuitve:
83
84 - The has<T>("KW") method will check if the current FieldProps container
85 has an installed "KW" keyword; if the container has the keyword in
86 question it will check if all elements have been assigned a value - only
87 in that case will it return true. The has<T>("KW") method will *not* try
88 to create a new keyword.
89
90 - The has<T>("KW") method will *not* consult the supported<T>("KW")
91 method; i.e. if you ask has<T>("UNKNOWN_KEYWORD") you will just get a
92 false.
93
94 - The get<T>("KW") method will try to create a new keyword if it does not
95 already have the keyword you are asking for. This implies that you can
96 get the following non intuitive sequence of events:
97
98 FieldPropsManager fpm(deck, grid);
99
100 fpm.has<int>("SATNUM"); => false
101 auto satnum = fpm.get<int>("SATNUM"); => SATNUM is autocreated
102 fpm.has<int>("SATNUM"); => true
103
104 - When checking whether the container has the keyword you should rephrase
105 the question slightly:
106
107 * Does the container have the keyword *right now* => has<T>("KW")
108 * Can the container provide the keyword => ptr = try_get<T>("KW")
109
110 - It is quite simple to create a deck where the keywords are only partly
111 initialized, all the methods in the FieldPropsManager only consider
112 fully initialized keywords.
113 */
114
115
116 /*
117 The get_copy() has exactly the same behaviour as get(), but the important
118 difference is that said keyword is not already in the container it is not
119 installed in the container; if we look at SATNUM which is a keywor which
120 can be automatically instantiated we have the following behavior:
121
122 get():
123 fp.has<int>("SATNUM") -> false
124 const std::vector<int>& satnum = fp.get<int>("SATNUM")
125 fp.has<int>("SATNUM") -> true;
126
127
128 get_copy():
129 fp.has<int>("SATNUM") -> false
130 const std::vector<int>& satnum = fp.get_copy<int>("SATNUM")
131 fp.has<int>("SATNUM") -> false
132 */
133
134
135 template <typename T>
136 std::vector<T> get_copy(const std::string& keyword, bool global=false) const;
137
138 /*
139 Will return a pointer to the keyword data, or nullptr if the container
140 does not have suce a keyword. Observe that container will hold on to an
141 manage the underlying keyword data.
142
143 The try_get function will return a nullptr if the container does not
144 contain said keyword, or if the keyword has not been fully initialized. If
145 you ask for a totally unknown keyword the method will return nullptr.
146 */
147 template <typename T> const std::vector<T>* try_get(const
148 std::string& keyword) const;
149
150 /*
151 You can ask whether the elements in the keyword have a default value -
152 which typically is calculated in some way, or if it has been explicitly
153 assigned to in the deck.
154 */
155 template <typename T>
156 std::vector<bool> defaulted(const std::string& keyword) const;
157
158
159 /*
160 Check whether the container supports/recognizes a keyword at all:
161
162 supported<double>("PORO") => true
163 supported<double>("NO_SUCH_KEYWORD") => false
164
165 The method does not at all consult the content of the container - it is a
166 static method.
167 */
168 template <typename T>
169 static bool supported(const std::string& keyword);
170
171 /*
172 The keys() function will return a list of keys corresponding to the fully
173 initialized keywords in the container. Observe that the implementation
174 special cases the PORV and ACTNUM keywords, since these are present with
175 special functions porv(bool) and actnum() the "PORV" and "ACTNUM" string
176 literals are excluded from the keys() list.
177 */
178 template <typename T>
179 std::vector<std::string> keys() const;
180
181 virtual const std::vector<int>& get_int(const std::string& keyword) const { return this->get<int>(keyword); }
182 virtual std::vector<int> get_global_int(const std::string& keyword) const { return this->get_global<int>(keyword); }
183
184 virtual const std::vector<double>& get_double(const std::string& keyword) const { return this->get<double>(keyword); }
185 virtual std::vector<double> get_global_double(const std::string& keyword) const { return this->get_global<double>(keyword); }
186
187 virtual bool has_int(const std::string& keyword) const { return this->has<int>(keyword); }
188 virtual bool has_double(const std::string& keyword) const { return this->has<double>(keyword); }
189
190private:
191 /*
192 Return the keyword values as a std::vector<>. All elements in the return
193 value are guaranteed to be assigned a valid value. If the keyword is not
194 in the container, or not all elements have a valid value - an exception
195 will be raised:
196
197 - keyword which is not supported at all -> std::logic_error
198 - keyword which is not in the deck at all -> std::out_of_range
199 - keyword which has not been fully initialized -> std::runtime_error
200
201 Many of the keywords in the container can be automatically created, in
202 that case the get() method will silently create a new keyword and default
203 initialize if it is not already in the container. The different exceptions
204 raised for the different error conditions are the same for get(),
205 get_copy() and get_global().
206 */
207 template <typename T>
208 const std::vector<T>& get(const std::string& keyword) const;
209
210 /*
211 Will check if the container has the keyword loaded; in a fully initialized
212 state. If you ask for a keyword which is not supported at all you will
213 just get false back.
214 */
215 template <typename T>
216 bool has(const std::string& keyword) const;
217
218 /*
219 This is exactly like the get() method, but the returned vector will have
220 global cartesian size, where all inactive cells have been filled with
221 zeros.
222 */
223 template <typename T>
224 std::vector<T> get_global(const std::string& keyword) const;
225
226
227 std::shared_ptr<FieldProps> fp;
228};
229
230}
231
232#endif
const char *const string
Definition: cJSON.h:170
Definition: Deck.hpp:115
Definition: EclipseGrid.hpp:54
Definition: FieldPropsManager.hpp:33
virtual const std::vector< double > & get_double(const std::string &keyword) const
Definition: FieldPropsManager.hpp:184
const std::string & default_region() const
FieldPropsManager(const Deck &deck, const Phases &ph, const EclipseGrid &grid, const TableManager &tables)
virtual std::vector< double > porv(bool global=false) const
virtual bool has_int(const std::string &keyword) const
Definition: FieldPropsManager.hpp:187
virtual void reset_actnum(const std::vector< int > &actnum)
const std::vector< T > * try_get(const std::string &keyword) const
virtual const std::vector< int > & get_int(const std::string &keyword) const
Definition: FieldPropsManager.hpp:181
MemInfo meminfo() const
std::vector< bool > defaulted(const std::string &keyword) const
static bool supported(const std::string &keyword)
virtual bool has_double(const std::string &keyword) const
Definition: FieldPropsManager.hpp:188
std::vector< std::string > keys() const
std::vector< T > get_copy(const std::string &keyword, bool global=false) const
virtual std::vector< int > get_global_int(const std::string &keyword) const
Definition: FieldPropsManager.hpp:182
virtual std::vector< int > actnum() const
virtual std::vector< double > get_global_double(const std::string &keyword) const
Definition: FieldPropsManager.hpp:185
std::size_t active_size() const
Definition: Runspec.hpp:52
Definition: TableManager.hpp:63
UDAKeyword keyword(UDAControl control)
Definition: A.hpp:4