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/input/eclipse/EclipseState/Phase.hpp>
29 #include <opm/output/data/GuideRateValue.hpp>
30 #include <opm/input/eclipse/Schedule/Group/Group.hpp>
31 
32 namespace 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  template<class Serializer>
57  void serializeOp(Serializer& serializer)
58  {
59  serializer(currentProdConstraint);
60  serializer(currentGasInjectionConstraint);
61  serializer(currentWaterInjectionConstraint);
62  }
63 
64  static GroupConstraints serializationTestObject()
65  {
66  return GroupConstraints{Group::ProductionCMode::GRAT,
67  Group::InjectionCMode::RATE,
68  Group::InjectionCMode::RESV};
69  }
70  };
71 
72  struct GroupGuideRates {
73  GuideRateValue production{};
74  GuideRateValue injection{};
75 
76  template <class MessageBufferType>
77  void write(MessageBufferType& buffer) const
78  {
79  this->production.write(buffer);
80  this->injection .write(buffer);
81  }
82 
83  template <class MessageBufferType>
84  void read(MessageBufferType& buffer)
85  {
86  this->production.read(buffer);
87  this->injection .read(buffer);
88  }
89 
90  bool operator==(const GroupGuideRates& other) const
91  {
92  return this->production == other.production
93  && this->injection == other.injection;
94  }
95 
96  template<class Serializer>
97  void serializeOp(Serializer& serializer)
98  {
99  serializer(production);
100  serializer(injection);
101  }
102 
103  static GroupGuideRates serializationTestObject()
104  {
105  return GroupGuideRates{GuideRateValue::serializationTestObject(),
106  GuideRateValue::serializationTestObject()};
107  }
108  };
109 
110  struct GroupData {
111  GroupConstraints currentControl;
112  GroupGuideRates guideRates{};
113 
114  template <class MessageBufferType>
115  void write(MessageBufferType& buffer) const
116  {
117  this->currentControl.write(buffer);
118  this->guideRates .write(buffer);
119  }
120 
121  template <class MessageBufferType>
122  void read(MessageBufferType& buffer)
123  {
124  this->currentControl.read(buffer);
125  this->guideRates .read(buffer);
126  }
127 
128  bool operator==(const GroupData& other) const
129  {
130  return this->currentControl == other.currentControl
131  && this->guideRates == other.guideRates;
132  }
133 
134  template<class Serializer>
135  void serializeOp(Serializer& serializer)
136  {
137  serializer(currentControl);
138  serializer(guideRates);
139  }
140 
141  static GroupData serializationTestObject()
142  {
143  return GroupData{GroupConstraints::serializationTestObject(),
144  GroupGuideRates::serializationTestObject()};
145  }
146  };
147 
148  struct NodeData {
149  double pressure { 0.0 };
150  double converged_pressure { 0.0 };
151 
152  template <class MessageBufferType>
153  void write(MessageBufferType& buffer) const
154  {
155  buffer.write(this->pressure);
156  buffer.write(this->converged_pressure);
157  }
158 
159  template <class MessageBufferType>
160  void read(MessageBufferType& buffer)
161  {
162  buffer.read(this->pressure);
163  buffer.read(this->converged_pressure);
164  }
165 
166  bool operator==(const NodeData& other) const
167  {
168  return this->pressure == other.pressure && this->converged_pressure == other.converged_pressure;
169  }
170 
171  template<class Serializer>
172  void serializeOp(Serializer& serializer)
173  {
174  serializer(pressure);
175  serializer(converged_pressure);
176  }
177 
178  static NodeData serializationTestObject()
179  {
180  return NodeData{10.0, 10.0};
181  }
182  };
183 
184  struct BranchData {
185  double pressure_drop { 0.0 };
186  double oil_rate { 0.0 };
187  double water_rate { 0.0 };
188  double gas_rate { 0.0 };
189 
190  template <class MessageBufferType>
191  void write(MessageBufferType& buffer) const
192  {
193  buffer.write(this->pressure_drop);
194  buffer.write(this->oil_rate);
195  buffer.write(this->water_rate);
196  buffer.write(this->gas_rate);
197  }
198 
199  template <class MessageBufferType>
200  void read(MessageBufferType& buffer)
201  {
202  buffer.read(this->pressure_drop);
203  buffer.read(this->oil_rate);
204  buffer.read(this->water_rate);
205  buffer.read(this->gas_rate);
206  }
207 
208  bool operator==(const BranchData& other) const
209  {
210  return this->pressure_drop == other.pressure_drop
211  && this->oil_rate == other.oil_rate
212  && this->water_rate == other.water_rate
213  && this->gas_rate == other.gas_rate;
214  }
215 
216  template<class Serializer>
217  void serializeOp(Serializer& serializer)
218  {
219  serializer(pressure_drop);
220  serializer(oil_rate);
221  serializer(water_rate);
222  serializer(gas_rate);
223  }
224 
225  static BranchData serializationTestObject()
226  {
227  return BranchData{10.0, 100.0, 200.0, 20000.0};
228  }
229  };
230 
231 
233  public:
234  std::map<std::string, GroupData> groupData {};
235  std::map<std::string, NodeData> nodeData {};
236  std::map<std::string, BranchData> branchData {};
237  std::map<std::string, BranchData> convergedBranchData {};
238 
239  template <class MessageBufferType>
240  void write(MessageBufferType& buffer) const
241  {
242  this->writeMap(this->groupData, buffer);
243  this->writeMap(this->nodeData, buffer);
244  this->writeMap(this->branchData, buffer);
245  this->writeMap(this->convergedBranchData, buffer);
246  }
247 
248  template <class MessageBufferType>
249  void read(MessageBufferType& buffer)
250  {
251  this->readMap(buffer, this->groupData);
252  this->readMap(buffer, this->nodeData);
253  this->readMap(buffer, this->branchData);
254  this->readMap(buffer, this->convergedBranchData);
255  }
256 
257  bool operator==(const GroupAndNetworkValues& other) const
258  {
259  return (this->groupData == other.groupData)
260  && (this->nodeData == other.nodeData)
261  && (this->branchData == other.branchData)
262  && (this->convergedBranchData == other.convergedBranchData);
263  }
264 
265  void clear()
266  {
267  this->groupData.clear();
268  this->nodeData.clear();
269  this->branchData.clear();
270  this->convergedBranchData.clear();
271  }
272 
273  template<class Serializer>
274  void serializeOp(Serializer& serializer)
275  {
276  serializer(groupData);
277  serializer(nodeData);
278  serializer(branchData);
279  serializer(convergedBranchData);
280  }
281 
282  static GroupAndNetworkValues serializationTestObject()
283  {
284  return GroupAndNetworkValues{
285  {{"test_data", GroupData::serializationTestObject()}},
286  {{"test_node", NodeData::serializationTestObject()}},
287  {{"test_branch", BranchData::serializationTestObject()}},
288  {{"test_converged_branch", BranchData::serializationTestObject()}}
289  };
290  }
291 
292  private:
293  template <class MessageBufferType, class ValueType>
294  void writeMap(const std::map<std::string, ValueType>& map,
295  MessageBufferType& buffer) const
296  {
297  const unsigned int size = map.size();
298  buffer.write(size);
299 
300  for (const auto& [name, elm] : map) {
301  buffer.write(name);
302  elm .write(buffer);
303  }
304  }
305 
306  template <class MessageBufferType, class ValueType>
307  void readMap(MessageBufferType& buffer,
308  std::map<std::string, ValueType>& map)
309  {
310  unsigned int size;
311  buffer.read(size);
312 
313  for (std::size_t i = 0; i < size; ++i) {
314  std::string name;
315  buffer.read(name);
316 
317  auto elm = ValueType{};
318  elm.read(buffer);
319 
320  map.emplace(name, std::move(elm));
321  }
322  }
323  };
324 
325  /* IMPLEMENTATIONS */
326 
327  template <class MessageBufferType>
328  void GroupConstraints::write(MessageBufferType& buffer) const {
329  buffer.write(this->currentProdConstraint);
330  buffer.write(this->currentGasInjectionConstraint);
331  buffer.write(this->currentWaterInjectionConstraint);
332  }
333 
334  template <class MessageBufferType>
335  void GroupConstraints::read(MessageBufferType& buffer) {
336  buffer.read(this->currentProdConstraint);
337  buffer.read(this->currentGasInjectionConstraint);
338  buffer.read(this->currentWaterInjectionConstraint);
339  }
340 
341  inline GroupConstraints&
342  GroupConstraints::set(Opm::Group::ProductionCMode cpc,
343  Opm::Group::InjectionCMode cgic,
344  Opm::Group::InjectionCMode cwic)
345  {
346  this->currentGasInjectionConstraint = cgic;
347  this->currentWaterInjectionConstraint = cwic;
348  this->currentProdConstraint = cpc;
349 
350  return *this;
351  }
352 
359  double oil{0}, gas{0}, water{0}, resv{0};
360  };
361  struct InjectionRates {
362  double surface{0}, reservoir{0};
363  };
365  std::map<std::string, ProductionRates> production;
367  std::map<std::string, std::map<Opm::Phase, InjectionRates>> injection;
368  };
369 
370 }} // Opm::data
371 
372 #endif //OPM_OUTPUT_GROUPS_HPP
std::map< std::string, ProductionRates > production
Per master-group production rates (positive values, SI units).
Definition: Groups.hpp:365
Definition: Groups.hpp:72
Definition: Groups.hpp:232
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: Groups.hpp:110
Definition: GuideRateValue.hpp:31
Definition: Groups.hpp:34
Definition: Groups.hpp:148
std::map< std::string, std::map< Opm::Phase, InjectionRates > > injection
Per master-group, per-phase injection rates (SI units).
Definition: Groups.hpp:367
Production and injection rates for reservoir coupling master groups.
Definition: Groups.hpp:357
Definition: Groups.hpp:184
Class for (de-)serializing.
Definition: Serializer.hpp:95