My Project
Loading...
Searching...
No Matches
UDQConfig.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
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 UDQINPUT_HPP_
21#define UDQINPUT_HPP_
22
23#include <opm/input/eclipse/Schedule/UDQ/UDQAssign.hpp>
24#include <opm/input/eclipse/Schedule/UDQ/UDQDefine.hpp>
25#include <opm/input/eclipse/Schedule/UDQ/UDQEnums.hpp>
26#include <opm/input/eclipse/Schedule/UDQ/UDQFunctionTable.hpp>
27#include <opm/input/eclipse/Schedule/UDQ/UDQInput.hpp>
28#include <opm/input/eclipse/Schedule/UDQ/UDQParams.hpp>
29
30#include <opm/input/eclipse/EclipseState/Util/OrderedMap.hpp>
31#include <opm/input/eclipse/EclipseState/Util/IOrderSet.hpp>
32
33#include <cstddef>
34#include <functional>
35#include <map>
36#include <memory>
37#include <string>
38#include <unordered_map>
39#include <unordered_set>
40#include <vector>
41
42namespace Opm {
43
44 class DeckRecord;
45 class KeywordLocation;
46 class Schedule;
47 class SegmentMatcher;
48 class SummaryState;
49 class UDQState;
50 class WellMatcher;
51
52} // namespace Opm
53
54namespace Opm { namespace RestartIO {
55 struct RstState;
56}} // namespace Opm::RestartIO
57
58namespace Opm {
59
61 {
62 public:
63 using SegmentMatcherFactory = std::function<std::unique_ptr<SegmentMatcher>()>;
64
65 UDQConfig() = default;
66 explicit UDQConfig(const UDQParams& params);
67 UDQConfig(const UDQParams& params, const RestartIO::RstState& rst_state);
68
69 static UDQConfig serializationTestObject();
70
71 const std::string& unit(const std::string& key) const;
72 bool has_unit(const std::string& keyword) const;
73 bool has_keyword(const std::string& keyword) const;
74
75 void add_record(SegmentMatcherFactory create_segment_matcher,
76 const DeckRecord& record,
77 const KeywordLocation& location,
78 std::size_t report_step);
79
80 void add_unit(const std::string& keyword,
81 const std::string& unit);
82
83 void add_update(const std::string& keyword,
84 std::size_t report_step,
85 const KeywordLocation& location,
86 const std::vector<std::string>& data);
87
88 void add_assign(const std::string& quantity,
89 SegmentMatcherFactory create_segment_matcher,
90 const std::vector<std::string>& selector,
91 double value,
92 std::size_t report_step);
93
94 void add_assign(const std::string& quantity,
95 const std::unordered_set<std::string>& selector,
96 double value,
97 std::size_t report_step);
98
99 void add_define(const std::string& quantity,
100 const KeywordLocation& location,
101 const std::vector<std::string>& expression,
102 std::size_t report_step);
103
104 bool clear_pending_assignments();
105
106 void eval_assign(std::size_t report_step,
107 const Schedule& sched,
108 const WellMatcher& wm,
109 SegmentMatcherFactory create_segment_matcher,
110 SummaryState& st,
111 UDQState& udq_state) const;
112
113 void eval(std::size_t report_step,
114 const Schedule& sched,
115 const WellMatcher& wm,
116 SegmentMatcherFactory create_segment_matcher,
117 SummaryState& st,
118 UDQState& udq_state) const;
119
120 const UDQDefine& define(const std::string& key) const;
121 const UDQAssign& assign(const std::string& key) const;
122
123 std::vector<UDQDefine> definitions() const;
124 std::vector<UDQDefine> definitions(UDQVarType var_type) const;
125 std::vector<UDQInput> input() const;
126
127 // The size() method will return the number of active DEFINE and ASSIGN
128 // statements; this will correspond to the length of the vector returned
129 // from input().
130 std::size_t size() const;
131
132 UDQInput operator[](const std::string& keyword) const;
133 UDQInput operator[](std::size_t insert_index) const;
134
135 std::vector<UDQAssign> assignments() const;
136 std::vector<UDQAssign> assignments(UDQVarType var_type) const;
137 const UDQParams& params() const;
138 const UDQFunctionTable& function_table() const;
139
140 bool operator==(const UDQConfig& config) const;
141 void required_summary(std::unordered_set<std::string>& summary_keys) const;
142
143 template<class Serializer>
144 void serializeOp(Serializer& serializer)
145 {
146 serializer(udq_params);
147 serializer(m_definitions);
148 serializer(m_assignments);
149 serializer(units);
150 serializer(input_index);
151 serializer(type_count);
152 serializer(pending_assignments_);
153
154 // The UDQFunction table is constant up to udq_params, so we can
155 // just construct a new instance here.
156 if (!serializer.isSerializing()) {
157 udqft = UDQFunctionTable(udq_params);
158 }
159 }
160
161 private:
162 UDQParams udq_params;
163 UDQFunctionTable udqft;
164
165 // The choices of data structures are strongly motivated by the
166 // constraints imposed by the ECLIPSE formatted restart files; for
167 // writing restart files it is essential to keep meticulous control
168 // over the ordering of the keywords. In this class the ordering is
169 // mainly maintained by the input_index map which keeps track of the
170 // insert order of each keyword, and whether the keyword is
171 // currently DEFINE'ed or ASSIGN'ed.
172 std::unordered_map<std::string, UDQDefine> m_definitions;
173 std::unordered_map<std::string, UDQAssign> m_assignments;
174 std::unordered_map<std::string, std::string> units;
175
176 IOrderSet<std::string> define_order;
177 OrderedMap<UDQIndex> input_index;
178 std::map<UDQVarType, std::size_t> type_count;
179
180 mutable std::vector<std::string> pending_assignments_{};
181
182 void add_node(const std::string& quantity, UDQAction action);
183 UDQAction action_type(const std::string& udq_key) const;
184
185 void eval_assign(std::size_t report_step,
186 const Schedule& sched,
187 UDQContext& context) const;
188
189 void eval_define(std::size_t report_step,
190 UDQState& udq_state,
191 UDQContext& context) const;
192
193 void add_named_assign(const std::string& quantity,
194 const std::vector<std::string>& selector,
195 double value,
196 std::size_t report_step);
197
198 void add_enumerated_assign(const std::string& quantity,
199 SegmentMatcherFactory create_segment_matcher,
200 const std::vector<std::string>& selector,
201 double value,
202 std::size_t report_step);
203 };
204
205} // namespace Opm
206
207#endif // UDQINPUT_HPP_
Definition DeckRecord.hpp:32
Definition IOrderSet.hpp:48
Definition KeywordLocation.hpp:27
A map with iteration in the order of insertion.
Definition OrderedMap.hpp:121
Definition Schedule.hpp:133
Class for (de-)serializing.
Definition Serializer.hpp:84
bool isSerializing() const
Returns true if we are currently doing a serialization operation.
Definition Serializer.hpp:183
Definition SummaryState.hpp:68
Definition UDQAssign.hpp:35
Definition UDQConfig.hpp:61
Definition UDQContext.hpp:46
Definition UDQDefine.hpp:51
Definition UDQFunctionTable.hpp:32
Definition UDQInput.hpp:84
Definition UDQParams.hpp:31
Definition UDQState.hpp:38
Definition WellMatcher.hpp:32
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition state.hpp:54