20#ifndef OPM_OUTPUT_GROUPS_HPP
21#define OPM_OUTPUT_GROUPS_HPP
30#include <opm/output/data/GuideRateValue.hpp>
31#include <opm/json/JsonObject.hpp>
32#include <opm/input/eclipse/Schedule/Group/Group.hpp>
34namespace Opm {
namespace data {
37 Opm::Group::ProductionCMode currentProdConstraint;
38 Opm::Group::InjectionCMode currentGasInjectionConstraint;
39 Opm::Group::InjectionCMode currentWaterInjectionConstraint;
41 template <
class MessageBufferType>
42 void write(MessageBufferType& buffer)
const;
44 template <
class MessageBufferType>
45 void read(MessageBufferType& buffer);
49 return this->currentProdConstraint == other.currentProdConstraint &&
50 this->currentGasInjectionConstraint == other.currentGasInjectionConstraint &&
51 this->currentWaterInjectionConstraint == other.currentWaterInjectionConstraint;
55 Opm::Group::InjectionCMode cgic,
56 Opm::Group::InjectionCMode cwic);
59 json_data.add_item(
"prod", Opm::Group::ProductionCMode2String(this->currentProdConstraint));
60 json_data.add_item(
"water_inj", Opm::Group::InjectionCMode2String(this->currentGasInjectionConstraint));
61 json_data.add_item(
"gas_inj", Opm::Group::InjectionCMode2String(this->currentWaterInjectionConstraint));
64 template<
class Serializer>
67 serializer(currentProdConstraint);
68 serializer(currentGasInjectionConstraint);
69 serializer(currentWaterInjectionConstraint);
75 Group::InjectionCMode::RATE,
76 Group::InjectionCMode::RESV};
84 template <
class MessageBufferType>
85 void write(MessageBufferType& buffer)
const
87 this->production.write(buffer);
88 this->injection .write(buffer);
91 template <
class MessageBufferType>
92 void read(MessageBufferType& buffer)
94 this->production.read(buffer);
95 this->injection .read(buffer);
100 return this->production == other.production
101 && this->injection == other.injection;
105 auto json_prod = json_data.add_object(
"production");
106 this->production.init_json(json_prod);
108 auto json_inj = json_data.add_object(
"injection");
109 this->injection.init_json(json_inj);
112 template<
class Serializer>
115 serializer(production);
116 serializer(injection);
122 GuideRateValue::serializationTestObject()};
130 template <
class MessageBufferType>
131 void write(MessageBufferType& buffer)
const
133 this->currentControl.write(buffer);
134 this->guideRates .write(buffer);
137 template <
class MessageBufferType>
138 void read(MessageBufferType& buffer)
140 this->currentControl.read(buffer);
141 this->guideRates .read(buffer);
144 bool operator==(
const GroupData& other)
const
146 return this->currentControl == other.currentControl
147 && this->guideRates == other.guideRates;
152 auto json_constraints = json_data.add_object(
"constraints");
153 this->currentControl.init_json(json_constraints);
155 auto json_gr = json_data.add_object(
"guide_rate");
156 this->guideRates.init_json(json_gr);
159 template<
class Serializer>
162 serializer(currentControl);
163 serializer(guideRates);
166 static GroupData serializationTestObject()
168 return GroupData{GroupConstraints::serializationTestObject(),
169 GroupGuideRates::serializationTestObject()};
174 double pressure { 0.0 };
176 template <
class MessageBufferType>
177 void write(MessageBufferType& buffer)
const
179 buffer.write(this->pressure);
182 template <
class MessageBufferType>
183 void read(MessageBufferType& buffer)
185 buffer.read(this->pressure);
188 bool operator==(
const NodeData& other)
const
190 return this->pressure == other.pressure;
194 json_data.add_item(
"pressure", this->pressure);
197 template<
class Serializer>
200 serializer(pressure);
203 static NodeData serializationTestObject()
211 std::map<std::string, GroupData> groupData {};
212 std::map<std::string, NodeData> nodeData {};
214 template <
class MessageBufferType>
215 void write(MessageBufferType& buffer)
const
217 this->writeMap(this->groupData, buffer);
218 this->writeMap(this->nodeData, buffer);
221 template <
class MessageBufferType>
222 void read(MessageBufferType& buffer)
224 this->readMap(buffer, this->groupData);
225 this->readMap(buffer, this->nodeData);
230 return (this->groupData == other.groupData)
231 && (this->nodeData == other.nodeData);
236 this->groupData.clear();
237 this->nodeData.clear();
241 auto group_data = json_data.add_object(
"group_data");
242 for (
const auto& [gname, gdata] : this->groupData) {
243 auto group_json_data = group_data.add_object(gname);
244 gdata.init_json( group_json_data );
247 auto node_data = json_data.add_object(
"node_data");
248 for (
const auto& [gname, ndata] : this->nodeData) {
249 auto node_json_data = node_data.add_object(gname);
250 ndata.init_json( node_json_data );
256 this->init_json(json_data);
260 template<
class Serializer>
263 serializer(groupData);
264 serializer(nodeData);
270 {{
"test_data", GroupData::serializationTestObject()}},
271 {{
"test_node", NodeData::serializationTestObject()}}
276 template <
class MessageBufferType,
class ValueType>
277 void writeMap(
const std::map<std::string, ValueType>& map,
278 MessageBufferType& buffer)
const
280 const unsigned int size = map.size();
283 for (
const auto& [name, elm] : map) {
289 template <
class MessageBufferType,
class ValueType>
290 void readMap(MessageBufferType& buffer,
291 std::map<std::string, ValueType>& map)
296 for (std::size_t i = 0; i < size; ++i) {
300 auto elm = ValueType{};
303 map.emplace(name, std::move(elm));
310 template <
class MessageBufferType>
311 void GroupConstraints::write(MessageBufferType& buffer)
const {
312 buffer.write(this->currentProdConstraint);
313 buffer.write(this->currentGasInjectionConstraint);
314 buffer.write(this->currentWaterInjectionConstraint);
317 template <
class MessageBufferType>
318 void GroupConstraints::read(MessageBufferType& buffer) {
319 buffer.read(this->currentProdConstraint);
320 buffer.read(this->currentGasInjectionConstraint);
321 buffer.read(this->currentWaterInjectionConstraint);
324 inline GroupConstraints&
325 GroupConstraints::set(Opm::Group::ProductionCMode cpc,
326 Opm::Group::InjectionCMode cgic,
327 Opm::Group::InjectionCMode cwic)
329 this->currentGasInjectionConstraint = cgic;
330 this->currentWaterInjectionConstraint = cwic;
331 this->currentProdConstraint = cpc;
Definition: JsonObject.hpp:32
Class for (de-)serializing.
Definition: Serializer.hpp:84
Definition: Groups.hpp:209
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:36
Definition: Groups.hpp:126
Definition: Groups.hpp:80
Definition: Groups.hpp:173