My Project
Loading...
Searching...
No Matches
Groups.hpp
1/*
2 Copyright 2016 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 OPM_OUTPUT_GROUPS_HPP
21#define OPM_OUTPUT_GROUPS_HPP
22
23#include <cstddef>
24#include <map>
25#include <string>
26#include <utility>
27
28#include <opm/output/data/GuideRateValue.hpp>
29#include <opm/json/JsonObject.hpp>
30#include <opm/input/eclipse/Schedule/Group/Group.hpp>
31
32namespace Opm { namespace data {
33
35 Opm::Group::ProductionCMode currentProdConstraint;
36 Opm::Group::InjectionCMode currentGasInjectionConstraint;
37 Opm::Group::InjectionCMode currentWaterInjectionConstraint;
38
39 template <class MessageBufferType>
40 void write(MessageBufferType& buffer) const;
41
42 template <class MessageBufferType>
43 void read(MessageBufferType& buffer);
44
45 bool operator==(const GroupConstraints& other) const
46 {
47 return this->currentProdConstraint == other.currentProdConstraint &&
48 this->currentGasInjectionConstraint == other.currentGasInjectionConstraint &&
49 this->currentWaterInjectionConstraint == other.currentWaterInjectionConstraint;
50 }
51
52 inline GroupConstraints& set(Opm::Group::ProductionCMode cpc,
53 Opm::Group::InjectionCMode cgic,
54 Opm::Group::InjectionCMode cwic);
55
56 void init_json(Json::JsonObject& json_data) const {
57 json_data.add_item("prod", Opm::Group::ProductionCMode2String(this->currentProdConstraint));
58 json_data.add_item("water_inj", Opm::Group::InjectionCMode2String(this->currentGasInjectionConstraint));
59 json_data.add_item("gas_inj", Opm::Group::InjectionCMode2String(this->currentWaterInjectionConstraint));
60 }
61
62 template<class Serializer>
63 void serializeOp(Serializer& serializer)
64 {
65 serializer(currentProdConstraint);
66 serializer(currentGasInjectionConstraint);
67 serializer(currentWaterInjectionConstraint);
68 }
69
70 static GroupConstraints serializationTestObject()
71 {
72 return GroupConstraints{Group::ProductionCMode::GRAT,
73 Group::InjectionCMode::RATE,
74 Group::InjectionCMode::RESV};
75 }
76 };
77
79 GuideRateValue production{};
80 GuideRateValue injection{};
81
82 template <class MessageBufferType>
83 void write(MessageBufferType& buffer) const
84 {
85 this->production.write(buffer);
86 this->injection .write(buffer);
87 }
88
89 template <class MessageBufferType>
90 void read(MessageBufferType& buffer)
91 {
92 this->production.read(buffer);
93 this->injection .read(buffer);
94 }
95
96 bool operator==(const GroupGuideRates& other) const
97 {
98 return this->production == other.production
99 && this->injection == other.injection;
100 }
101
102 void init_json(Json::JsonObject& json_data) const {
103 auto json_prod = json_data.add_object("production");
104 this->production.init_json(json_prod);
105
106 auto json_inj = json_data.add_object("injection");
107 this->injection.init_json(json_inj);
108 }
109
110 template<class Serializer>
111 void serializeOp(Serializer& serializer)
112 {
113 serializer(production);
114 serializer(injection);
115 }
116
117 static GroupGuideRates serializationTestObject()
118 {
119 return GroupGuideRates{GuideRateValue::serializationTestObject(),
120 GuideRateValue::serializationTestObject()};
121 }
122 };
123
124 struct GroupData {
125 GroupConstraints currentControl;
126 GroupGuideRates guideRates{};
127
128 template <class MessageBufferType>
129 void write(MessageBufferType& buffer) const
130 {
131 this->currentControl.write(buffer);
132 this->guideRates .write(buffer);
133 }
134
135 template <class MessageBufferType>
136 void read(MessageBufferType& buffer)
137 {
138 this->currentControl.read(buffer);
139 this->guideRates .read(buffer);
140 }
141
142 bool operator==(const GroupData& other) const
143 {
144 return this->currentControl == other.currentControl
145 && this->guideRates == other.guideRates;
146 }
147
148
149 void init_json(Json::JsonObject& json_data) const {
150 auto json_constraints = json_data.add_object("constraints");
151 this->currentControl.init_json(json_constraints);
152
153 auto json_gr = json_data.add_object("guide_rate");
154 this->guideRates.init_json(json_gr);
155 }
156
157 template<class Serializer>
158 void serializeOp(Serializer& serializer)
159 {
160 serializer(currentControl);
161 serializer(guideRates);
162 }
163
164 static GroupData serializationTestObject()
165 {
166 return GroupData{GroupConstraints::serializationTestObject(),
167 GroupGuideRates::serializationTestObject()};
168 }
169 };
170
171 struct NodeData {
172 double pressure { 0.0 };
173 double converged_pressure { 0.0 };
174
175 template <class MessageBufferType>
176 void write(MessageBufferType& buffer) const
177 {
178 buffer.write(this->pressure);
179 buffer.write(this->converged_pressure);
180 }
181
182 template <class MessageBufferType>
183 void read(MessageBufferType& buffer)
184 {
185 buffer.read(this->pressure);
186 buffer.read(this->converged_pressure);
187 }
188
189 bool operator==(const NodeData& other) const
190 {
191 return this->pressure == other.pressure && this->converged_pressure == other.converged_pressure;
192 }
193
194 void init_json(Json::JsonObject& json_data) const {
195 json_data.add_item("pressure", this->pressure);
196 json_data.add_item("converged_pressure", this->converged_pressure);
197 }
198
199 template<class Serializer>
200 void serializeOp(Serializer& serializer)
201 {
202 serializer(pressure);
203 serializer(converged_pressure);
204 }
205
206 static NodeData serializationTestObject()
207 {
208 return NodeData{10.0, 10.0};
209 }
210 };
211
213 public:
214 std::map<std::string, GroupData> groupData {};
215 std::map<std::string, NodeData> nodeData {};
216
217 template <class MessageBufferType>
218 void write(MessageBufferType& buffer) const
219 {
220 this->writeMap(this->groupData, buffer);
221 this->writeMap(this->nodeData, buffer);
222 }
223
224 template <class MessageBufferType>
225 void read(MessageBufferType& buffer)
226 {
227 this->readMap(buffer, this->groupData);
228 this->readMap(buffer, this->nodeData);
229 }
230
231 bool operator==(const GroupAndNetworkValues& other) const
232 {
233 return (this->groupData == other.groupData)
234 && (this->nodeData == other.nodeData);
235 }
236
237 void clear()
238 {
239 this->groupData.clear();
240 this->nodeData.clear();
241 }
242
243 void init_json(Json::JsonObject& json_data) const {
244 auto group_data = json_data.add_object("group_data");
245 for (const auto& [gname, gdata] : this->groupData) {
246 auto group_json_data = group_data.add_object(gname);
247 gdata.init_json( group_json_data );
248 }
249
250 auto node_data = json_data.add_object("node_data");
251 for (const auto& [gname, ndata] : this->nodeData) {
252 auto node_json_data = node_data.add_object(gname);
253 ndata.init_json( node_json_data );
254 }
255 }
256
257 Json::JsonObject json() const {
258 Json::JsonObject json_data;
259 this->init_json(json_data);
260 return json_data;
261 }
262
263 template<class Serializer>
264 void serializeOp(Serializer& serializer)
265 {
266 serializer(groupData);
267 serializer(nodeData);
268 }
269
270 static GroupAndNetworkValues serializationTestObject()
271 {
273 {{"test_data", GroupData::serializationTestObject()}},
274 {{"test_node", NodeData::serializationTestObject()}}
275 };
276 }
277
278 private:
279 template <class MessageBufferType, class ValueType>
280 void writeMap(const std::map<std::string, ValueType>& map,
281 MessageBufferType& buffer) const
282 {
283 const unsigned int size = map.size();
284 buffer.write(size);
285
286 for (const auto& [name, elm] : map) {
287 buffer.write(name);
288 elm .write(buffer);
289 }
290 }
291
292 template <class MessageBufferType, class ValueType>
293 void readMap(MessageBufferType& buffer,
294 std::map<std::string, ValueType>& map)
295 {
296 unsigned int size;
297 buffer.read(size);
298
299 for (std::size_t i = 0; i < size; ++i) {
300 std::string name;
301 buffer.read(name);
302
303 auto elm = ValueType{};
304 elm.read(buffer);
305
306 map.emplace(name, std::move(elm));
307 }
308 }
309 };
310
311 /* IMPLEMENTATIONS */
312
313 template <class MessageBufferType>
314 void GroupConstraints::write(MessageBufferType& buffer) const {
315 buffer.write(this->currentProdConstraint);
316 buffer.write(this->currentGasInjectionConstraint);
317 buffer.write(this->currentWaterInjectionConstraint);
318 }
319
320 template <class MessageBufferType>
321 void GroupConstraints::read(MessageBufferType& buffer) {
322 buffer.read(this->currentProdConstraint);
323 buffer.read(this->currentGasInjectionConstraint);
324 buffer.read(this->currentWaterInjectionConstraint);
325 }
326
327 inline GroupConstraints&
328 GroupConstraints::set(Opm::Group::ProductionCMode cpc,
329 Opm::Group::InjectionCMode cgic,
330 Opm::Group::InjectionCMode cwic)
331 {
332 this->currentGasInjectionConstraint = cgic;
333 this->currentWaterInjectionConstraint = cwic;
334 this->currentProdConstraint = cpc;
335
336 return *this;
337 }
338
339}} // Opm::data
340
341#endif //OPM_OUTPUT_GROUPS_HPP
Definition JsonObject.hpp:31
Class for (de-)serializing.
Definition Serializer.hpp:84
Definition Groups.hpp:212
Definition GuideRateValue.hpp:32
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition Groups.hpp:34
Definition Groups.hpp:124
Definition Groups.hpp:78
Definition Groups.hpp:171