Groups.hpp
Go to the documentation of this file.
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 <algorithm>
24#include <cstddef>
25#include <initializer_list>
26#include <map>
27#include <stdexcept>
28#include <string>
29#include <type_traits>
30#include <unordered_map>
31#include <vector>
32
34
35namespace Opm {
36
37 namespace data {
38
43
44 template <class MessageBufferType>
45 void write(MessageBufferType& buffer) const;
46 template <class MessageBufferType>
47 void read(MessageBufferType& buffer);
48
52 };
53
54
55 class Group : public std::map<std::string, Opm::data::currentGroupConstraints> {
56 public:
57
58 template <class MessageBufferType>
59 void write(MessageBufferType& buffer) const {
60 unsigned int size = this->size();
61 buffer.write(size);
62 for (const auto& witr : *this) {
63 const std::string& name = witr.first;
64 buffer.write(name);
65 const auto& pi_constr = witr.second;
66 pi_constr.write(buffer);
67 }
68 }
69
70 template <class MessageBufferType>
71 void read(MessageBufferType& buffer) {
72 unsigned int size;
73 buffer.read(size);
74 for (size_t i = 0; i < size; ++i) {
76 buffer.read(name);
78 cgc.read(buffer);
79 this->emplace(name, cgc);
80 }
81 }
82 };
83
84 /* IMPLEMENTATIONS */
85
86 template <class MessageBufferType>
87 void currentGroupConstraints::write(MessageBufferType& buffer) const {
88 buffer.write(this->currentProdConstraint);
89 buffer.write(this->currentGasInjectionConstraint);
90 buffer.write(this->currentWaterInjectionConstraint);
91 }
92
93 template <class MessageBufferType>
94 void currentGroupConstraints::read(MessageBufferType& buffer) {
95 buffer.read(this->currentProdConstraint);
96 buffer.read(this->currentGasInjectionConstraint);
97 buffer.read(this->currentWaterInjectionConstraint);
98 }
99
100
106 this->currentProdConstraint = cpc;
107 return *this;
108 }
109
110}} // Opm::data
111
112#endif //OPM_OUTPUT_GROUPS_HPP
const char *const name
Definition: cJSON.h:258
const char *const string
Definition: cJSON.h:170
char * buffer
Definition: cJSON.h:161
InjectionCMode
Definition: parser/eclipse/EclipseState/Schedule/Group/group.hpp:62
ProductionCMode
Definition: parser/eclipse/EclipseState/Schedule/Group/group.hpp:75
Definition: Groups.hpp:55
void read(MessageBufferType &buffer)
Definition: Groups.hpp:71
void write(MessageBufferType &buffer) const
Definition: Groups.hpp:59
std::vector< typename std::result_of< F(typename C::const_iterator::value_type &) >::type > map(F f, const C &src)
Definition: Functional.hpp:84
Definition: A.hpp:4
static std::string data()
Definition: exprtk.hpp:40022
Definition: Groups.hpp:39
currentGroupConstraints & set(Opm::Group::ProductionCMode cpc, Opm::Group::InjectionCMode cgic, Opm::Group::InjectionCMode cwic)
Definition: Groups.hpp:101
void write(MessageBufferType &buffer) const
Definition: Groups.hpp:87
Opm::Group::InjectionCMode currentWaterInjectionConstraint
Definition: Groups.hpp:42
Opm::Group::ProductionCMode currentProdConstraint
Definition: Groups.hpp:40
void read(MessageBufferType &buffer)
Definition: Groups.hpp:94
Opm::Group::InjectionCMode currentGasInjectionConstraint
Definition: Groups.hpp:41