My Project
Loading...
Searching...
No Matches
FieldPropsManager.hpp
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 <string>
24#include <unordered_map>
25#include <vector>
26
27namespace Opm {
28
29class EclipseGrid;
30class Deck;
31class DeckKeyword;
32namespace Fieldprops {
33class TranCalculator;
34template<typename T> struct FieldData;
35}
36class FieldProps;
37class Phases;
38class TableManager;
39class NumericalAquifers;
40
42
43
44public:
45 // The default constructor should be removed when the FieldPropsManager is mandatory
46 // The default constructed fieldProps object is **NOT** usable
47 FieldPropsManager() = default;
48 FieldPropsManager(const Deck& deck, const Phases& ph, const EclipseGrid& grid, const TableManager& tables);
49 virtual ~FieldPropsManager() = default;
50
51 virtual void reset_actnum(const std::vector<int>& actnum);
52 const std::string& default_region() const;
53 virtual std::vector<int> actnum() const;
54 virtual std::vector<double> porv(bool global = false) const;
55
56
57 void apply_schedule_keywords(const std::vector<DeckKeyword>& keywords);
58
60 bool is_usable() const;
61
62 /*
63 The number of cells in the fields managed by this FieldPropsManager.
64 Initially this will correspond to the number of active cells in the grid
65 used when constructing the FieldPropsManager, but using the reset_actnum()
66 method it is possible to deactivate additional cells.
67 */
68 std::size_t active_size() const;
69
70 bool operator==(const FieldPropsManager& other) const;
71 static bool rst_cmp(const FieldPropsManager& full_arg, const FieldPropsManager& rst_arg);
72
73 /*
74 Because the FieldProps class can autocreate properties the semantics of
75 get() and has() is slightly non intuitve:
76
77 - The has<T>("KW") method will check if the current FieldProps container
78 has an installed "KW" keyword; if the container has the keyword in
79 question it will check if all elements have been assigned a value - only
80 in that case will it return true. The has<T>("KW") method will *not* try
81 to create a new keyword.
82
83 - The has<T>("KW") method will *not* consult the supported<T>("KW")
84 method; i.e. if you ask has<T>("UNKNOWN_KEYWORD") you will just get a
85 false.
86
87 - The get<T>("KW") method will try to create a new keyword if it does not
88 already have the keyword you are asking for. This implies that you can
89 get the following non intuitive sequence of events:
90
91 FieldPropsManager fpm(deck, grid);
92
93 fpm.has<int>("SATNUM"); => false
94 auto satnum = fpm.get<int>("SATNUM"); => SATNUM is autocreated
95 fpm.has<int>("SATNUM"); => true
96
97 - When checking whether the container has the keyword you should rephrase
98 the question slightly:
99
100 * Does the container have the keyword *right now* => has<T>("KW")
101 * Can the container provide the keyword => ptr = try_get<T>("KW")
102
103 - It is quite simple to create a deck where the keywords are only partly
104 initialized, all the methods in the FieldPropsManager only consider
105 fully initialized keywords.
106 */
107
108
109 /*
110 The get_copy() has exactly the same behaviour as get(), but the important
111 difference is that said keyword is not already in the container it is not
112 installed in the container; if we look at SATNUM which is a keywor which
113 can be automatically instantiated we have the following behavior:
114
115 get():
116 fp.has<int>("SATNUM") -> false
117 const std::vector<int>& satnum = fp.get<int>("SATNUM")
118 fp.has<int>("SATNUM") -> true;
119
120
121 get_copy():
122 fp.has<int>("SATNUM") -> false
123 const std::vector<int>& satnum = fp.get_copy<int>("SATNUM")
124 fp.has<int>("SATNUM") -> false
125 */
126
127
128 template <typename T>
129 std::vector<T> get_copy(const std::string& keyword, bool global=false) const;
130
131 /*
132 Will return a pointer to the keyword data, or nullptr if the container
133 does not have suce a keyword. Observe that container will hold on to an
134 manage the underlying keyword data.
135
136 The try_get function will return a nullptr if the container does not
137 contain said keyword, or if the keyword has not been fully initialized. If
138 you ask for a totally unknown keyword the method will return nullptr.
139 */
140 template <typename T>
141 const std::vector<T>* try_get(const std::string& keyword) const;
142
143 /*
144 You can ask whether the elements in the keyword have a default value -
145 which typically is calculated in some way, or if it has been explicitly
146 assigned to in the deck.
147 */
148 template <typename T>
149 std::vector<bool> defaulted(const std::string& keyword) const;
150
151
152 /*
153 Check whether the container supports/recognizes a keyword at all:
154
155 supported<double>("PORO") => true
156 supported<double>("NO_SUCH_KEYWORD") => false
157
158 The method does not at all consult the content of the container - it is a
159 static method.
160 */
161 template <typename T>
162 static bool supported(const std::string& keyword);
163
164 /*
165 The keys() function will return a list of keys corresponding to the fully
166 initialized keywords in the container. Observe that the implementation
167 special cases the PORV and ACTNUM keywords, since these are present with
168 special functions porv(bool) and actnum() the "PORV" and "ACTNUM" string
169 literals are excluded from the keys() list.
170 */
171 template <typename T>
172 std::vector<std::string> keys() const;
173
175 get_int_field_data(const std::string& keyword) const;
176
181 get_double_field_data(const std::string& keyword, bool allow_unsupported=false) const;
182 virtual const std::vector<int>& get_int(const std::string& keyword) const { return this->get<int>(keyword); }
183 virtual std::vector<int> get_global_int(const std::string& keyword) const { return this->get_global<int>(keyword); }
184
185 virtual const std::vector<double>& get_double(const std::string& keyword) const { return this->get<double>(keyword); }
186 virtual std::vector<double> get_global_double(const std::string& keyword) const { return this->get_global<double>(keyword); }
187
188 virtual bool has_int(const std::string& keyword) const { return this->has<int>(keyword); }
189 virtual bool has_double(const std::string& keyword) const { return this->has<double>(keyword); }
190
191 /*
192 The transmissibility keywords TRANX, TRANY and TRANZ do not really fit
193 well in the FieldProps system. The opm codebase is based on a full
194 internalization in the parse phase, and then passing fully assembled
195 objects to the simulator. When it comes to the transmissibilities this
196 model breaks down because the input code in opm-common is not capable of
197 calculating the transmissibility, that is performed in the simulator.
198
199 The EDIT section can have modifiers on TRAN, these must be applied *after*
200 the initial transmissibilities are calculated. To support this all the
201 modifiers to the TRAN{XYZ} fields are assembled in "transmissibility
202 calculators", and then these modifiers can be applied to a TRAN vector
203 after it has been calculated in the simulator. Usage from the simulator
204 could look like:
205
206
207 const auto& fp = eclState.fieldProps();
208
209 // Calculate transmissibilities using grid and permeability
210 std::vector<double> tranx = ....
211
212 // Check if there are any active TRANX modifiers and apply them
213 if (fp.tran_active("TRANX"))
214 fp.apply_tran("TRANX", tranx);
215
216
217 */
218
219 /*
220 Will check if there are any TRAN{XYZ} modifiers active in the deck.
221 */
222 virtual bool tran_active(const std::string& keyword) const;
223
224
225 /*
226 Will apply all the TRAN modifiers which are present in the deck on the
227 already initialized vector tran_data. The vector tran_data should be
228 organised as the data vectors in the fieldpropsmanager - i.e. one element
229 for each active cell - in lexicographical order. The operations which are
230 supported by the transmissibility calculator are those given by the enum
231 ScalarOperation in FieldProps.hpp.
232 */
233 virtual void apply_tran(const std::string& keyword, std::vector<double>& tran_data) const;
234
235 void apply_numerical_aquifers(const NumericalAquifers& aquifers);
236
237 const std::unordered_map<std::string,Fieldprops::TranCalculator>& getTran() const;
238
239private:
240 /*
241 Return the keyword values as a std::vector<>. All elements in the return
242 value are guaranteed to be assigned a valid value. If the keyword is not
243 in the container, or not all elements have a valid value - an exception
244 will be raised:
245
246 - keyword which is not supported at all -> std::logic_error
247 - keyword which is not in the deck at all -> std::out_of_range
248 - keyword which has not been fully initialized -> std::runtime_error
249
250 Many of the keywords in the container can be automatically created, in
251 that case the get() method will silently create a new keyword and default
252 initialize if it is not already in the container. The different exceptions
253 raised for the different error conditions are the same for get(),
254 get_copy() and get_global().
255 */
256 template <typename T>
257 const std::vector<T>& get(const std::string& keyword) const;
258
259 /*
260 Will check if the container has the keyword loaded; in a fully initialized
261 state. If you ask for a keyword which is not supported at all you will
262 just get false back.
263 */
264 template <typename T>
265 bool has(const std::string& keyword) const;
266
267 /*
268 This is exactly like the get() method, but the returned vector will have
269 global cartesian size. If the field has a default value that value will be
270 used for filling in in the inactive cells, otherwise zero is used.
271 */
272 template <typename T>
273 std::vector<T> get_global(const std::string& keyword) const;
274
275 std::shared_ptr<FieldProps> fp;
276};
277
278template<class MapType>
279void apply_tran(const std::unordered_map<std::string, Fieldprops::TranCalculator>& tran,
280 const MapType& double_data,
281 std::size_t active_size,
282 const std::string& keyword, std::vector<double>& data);
283
284}
285
286#endif
Definition Deck.hpp:49
About cell information and dimension: The actual grid information is held in a pointer to an ERT ecl_...
Definition EclipseGrid.hpp:55
Definition FieldPropsManager.hpp:41
const Fieldprops::FieldData< double > & get_double_field_data(const std::string &keyword, bool allow_unsupported=false) const
Get double field data associated with a keyword.
bool is_usable() const
Whether we can call methods on the manager.
Definition Runspec.hpp:36
Definition TableManager.hpp:66
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition FieldData.hpp:55