opm-common
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/input/eclipse/Schedule/Group/Group.hpp>
30 
31 namespace Opm { namespace data {
32 
34  Opm::Group::ProductionCMode currentProdConstraint;
35  Opm::Group::InjectionCMode currentGasInjectionConstraint;
36  Opm::Group::InjectionCMode currentWaterInjectionConstraint;
37 
38  template <class MessageBufferType>
39  void write(MessageBufferType& buffer) const;
40 
41  template <class MessageBufferType>
42  void read(MessageBufferType& buffer);
43 
44  bool operator==(const GroupConstraints& other) const
45  {
46  return this->currentProdConstraint == other.currentProdConstraint &&
47  this->currentGasInjectionConstraint == other.currentGasInjectionConstraint &&
48  this->currentWaterInjectionConstraint == other.currentWaterInjectionConstraint;
49  }
50 
51  inline GroupConstraints& set(Opm::Group::ProductionCMode cpc,
52  Opm::Group::InjectionCMode cgic,
53  Opm::Group::InjectionCMode cwic);
54 
55  template<class Serializer>
56  void serializeOp(Serializer& serializer)
57  {
58  serializer(currentProdConstraint);
59  serializer(currentGasInjectionConstraint);
60  serializer(currentWaterInjectionConstraint);
61  }
62 
63  static GroupConstraints serializationTestObject()
64  {
65  return GroupConstraints{Group::ProductionCMode::GRAT,
66  Group::InjectionCMode::RATE,
67  Group::InjectionCMode::RESV};
68  }
69  };
70 
71  struct GroupGuideRates {
72  GuideRateValue production{};
73  GuideRateValue injection{};
74 
75  template <class MessageBufferType>
76  void write(MessageBufferType& buffer) const
77  {
78  this->production.write(buffer);
79  this->injection .write(buffer);
80  }
81 
82  template <class MessageBufferType>
83  void read(MessageBufferType& buffer)
84  {
85  this->production.read(buffer);
86  this->injection .read(buffer);
87  }
88 
89  bool operator==(const GroupGuideRates& other) const
90  {
91  return this->production == other.production
92  && this->injection == other.injection;
93  }
94 
95  template<class Serializer>
96  void serializeOp(Serializer& serializer)
97  {
98  serializer(production);
99  serializer(injection);
100  }
101 
102  static GroupGuideRates serializationTestObject()
103  {
104  return GroupGuideRates{GuideRateValue::serializationTestObject(),
105  GuideRateValue::serializationTestObject()};
106  }
107  };
108 
109  struct GroupData {
110  GroupConstraints currentControl;
111  GroupGuideRates guideRates{};
112 
113  template <class MessageBufferType>
114  void write(MessageBufferType& buffer) const
115  {
116  this->currentControl.write(buffer);
117  this->guideRates .write(buffer);
118  }
119 
120  template <class MessageBufferType>
121  void read(MessageBufferType& buffer)
122  {
123  this->currentControl.read(buffer);
124  this->guideRates .read(buffer);
125  }
126 
127  bool operator==(const GroupData& other) const
128  {
129  return this->currentControl == other.currentControl
130  && this->guideRates == other.guideRates;
131  }
132 
133  template<class Serializer>
134  void serializeOp(Serializer& serializer)
135  {
136  serializer(currentControl);
137  serializer(guideRates);
138  }
139 
140  static GroupData serializationTestObject()
141  {
142  return GroupData{GroupConstraints::serializationTestObject(),
143  GroupGuideRates::serializationTestObject()};
144  }
145  };
146 
147  struct NodeData {
148  double pressure { 0.0 };
149  double converged_pressure { 0.0 };
150 
151  template <class MessageBufferType>
152  void write(MessageBufferType& buffer) const
153  {
154  buffer.write(this->pressure);
155  buffer.write(this->converged_pressure);
156  }
157 
158  template <class MessageBufferType>
159  void read(MessageBufferType& buffer)
160  {
161  buffer.read(this->pressure);
162  buffer.read(this->converged_pressure);
163  }
164 
165  bool operator==(const NodeData& other) const
166  {
167  return this->pressure == other.pressure && this->converged_pressure == other.converged_pressure;
168  }
169 
170  template<class Serializer>
171  void serializeOp(Serializer& serializer)
172  {
173  serializer(pressure);
174  serializer(converged_pressure);
175  }
176 
177  static NodeData serializationTestObject()
178  {
179  return NodeData{10.0, 10.0};
180  }
181  };
182 
184  public:
185  std::map<std::string, GroupData> groupData {};
186  std::map<std::string, NodeData> nodeData {};
187 
188  template <class MessageBufferType>
189  void write(MessageBufferType& buffer) const
190  {
191  this->writeMap(this->groupData, buffer);
192  this->writeMap(this->nodeData, buffer);
193  }
194 
195  template <class MessageBufferType>
196  void read(MessageBufferType& buffer)
197  {
198  this->readMap(buffer, this->groupData);
199  this->readMap(buffer, this->nodeData);
200  }
201 
202  bool operator==(const GroupAndNetworkValues& other) const
203  {
204  return (this->groupData == other.groupData)
205  && (this->nodeData == other.nodeData);
206  }
207 
208  void clear()
209  {
210  this->groupData.clear();
211  this->nodeData.clear();
212  }
213 
214  template<class Serializer>
215  void serializeOp(Serializer& serializer)
216  {
217  serializer(groupData);
218  serializer(nodeData);
219  }
220 
221  static GroupAndNetworkValues serializationTestObject()
222  {
223  return GroupAndNetworkValues{
224  {{"test_data", GroupData::serializationTestObject()}},
225  {{"test_node", NodeData::serializationTestObject()}}
226  };
227  }
228 
229  private:
230  template <class MessageBufferType, class ValueType>
231  void writeMap(const std::map<std::string, ValueType>& map,
232  MessageBufferType& buffer) const
233  {
234  const unsigned int size = map.size();
235  buffer.write(size);
236 
237  for (const auto& [name, elm] : map) {
238  buffer.write(name);
239  elm .write(buffer);
240  }
241  }
242 
243  template <class MessageBufferType, class ValueType>
244  void readMap(MessageBufferType& buffer,
245  std::map<std::string, ValueType>& map)
246  {
247  unsigned int size;
248  buffer.read(size);
249 
250  for (std::size_t i = 0; i < size; ++i) {
251  std::string name;
252  buffer.read(name);
253 
254  auto elm = ValueType{};
255  elm.read(buffer);
256 
257  map.emplace(name, std::move(elm));
258  }
259  }
260  };
261 
262  /* IMPLEMENTATIONS */
263 
264  template <class MessageBufferType>
265  void GroupConstraints::write(MessageBufferType& buffer) const {
266  buffer.write(this->currentProdConstraint);
267  buffer.write(this->currentGasInjectionConstraint);
268  buffer.write(this->currentWaterInjectionConstraint);
269  }
270 
271  template <class MessageBufferType>
272  void GroupConstraints::read(MessageBufferType& buffer) {
273  buffer.read(this->currentProdConstraint);
274  buffer.read(this->currentGasInjectionConstraint);
275  buffer.read(this->currentWaterInjectionConstraint);
276  }
277 
278  inline GroupConstraints&
279  GroupConstraints::set(Opm::Group::ProductionCMode cpc,
280  Opm::Group::InjectionCMode cgic,
281  Opm::Group::InjectionCMode cwic)
282  {
283  this->currentGasInjectionConstraint = cgic;
284  this->currentWaterInjectionConstraint = cwic;
285  this->currentProdConstraint = cpc;
286 
287  return *this;
288  }
289 
290 }} // Opm::data
291 
292 #endif //OPM_OUTPUT_GROUPS_HPP
Definition: Groups.hpp:71
Definition: Groups.hpp:183
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: Groups.hpp:109
Definition: GuideRateValue.hpp:31
Definition: Groups.hpp:33
Definition: Groups.hpp:147
Class for (de-)serializing.
Definition: Serializer.hpp:94