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