My Project
Loading...
Searching...
No Matches
UDQActive.hpp
1/*
2 Copyright 2019 Equinor 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
21#ifndef UDQ_USAGE_HPP
22#define UDQ_USAGE_HPP
23
24#include <cstdlib>
25#include <optional>
26#include <string>
27#include <vector>
28
29#include <opm/input/eclipse/Deck/UDAValue.hpp>
30#include <opm/input/eclipse/Schedule/UDQ/UDQEnums.hpp>
31#include <opm/input/eclipse/EclipseState/Phase.hpp>
32
33namespace Opm {
34
35class UDAValue;
36class UDQConfig;
37class UnitSystem;
38
39namespace RestartIO {
40 struct RstState;
41}
42
43class UDQActive {
44public:
45
46 struct RstRecord {
47
48 RstRecord(UDAControl control_arg, UDAValue value_arg,
49 const std::string& wgname_arg)
50 : control(control_arg)
51 , value(value_arg)
52 , wgname(wgname_arg)
53 {};
54
55 RstRecord(UDAControl control_arg, UDAValue value_arg,
56 const std::string& wgname_arg, Phase phase)
57 : RstRecord(control_arg, value_arg, wgname_arg)
58 {
59 this->ig_phase = phase;
60 };
61
62 UDAControl control;
63 UDAValue value;
64 std::string wgname;
65 std::optional<Phase> ig_phase;
66 };
67
68
69
71 public:
72 OutputRecord() :
73 input_index(0),
74 control(UDAControl::WCONPROD_ORAT),
75 uda_code(0),
76 use_count(1)
77 {}
78
79 OutputRecord(const std::string& udq_arg, std::size_t input_index_arg, std::size_t use_index_arg, const std::string& wgname_arg, UDAControl control_arg) :
80 udq(udq_arg),
81 input_index(input_index_arg),
82 use_index(use_index_arg),
83 control(control_arg),
84 uda_code(UDQ::udaCode(control_arg)),
85 use_count(1),
86 wgname(wgname_arg)
87 {}
88
89 bool operator==(const OutputRecord& other) const {
90 if ((this->udq == other.udq) &&
91 (this->input_index == other.input_index) &&
92 (this->use_index == other.use_index) &&
93 (this->wgname == other.wgname) &&
94 (this->control == other.control) &&
95 (this->uda_code == other.uda_code) &&
96 (this->use_count == other.use_count))
97 return true;
98 return false;
99 }
100
101 bool operator!=(const OutputRecord& other) const {
102 return !(*this == other);
103 }
104
105 template<class Serializer>
106 void serializeOp(Serializer& serializer)
107 {
108 serializer(udq);
109 serializer(input_index);
110 serializer(use_index);
111 serializer(wgname);
112 serializer(control);
113 serializer(uda_code);
114 serializer(use_count);
115 }
116
117 std::string udq;
118 std::size_t input_index;
119 std::size_t use_index = 0;
120 UDAControl control;
121 int uda_code;
122 std::string wg_name() const;
123 std::size_t use_count;
124 private:
125 // The wgname is need in the update process, but it should
126 // not be exported out.
127 std::string wgname;
128 };
129
131 public:
132 InputRecord() :
133 input_index(0),
134 control(UDAControl::WCONPROD_ORAT)
135 {}
136
137 InputRecord(std::size_t input_index_arg, const std::string& udq_arg, const std::string& wgname_arg, UDAControl control_arg) :
138 input_index(input_index_arg),
139 udq(udq_arg),
140 wgname(wgname_arg),
141 control(control_arg)
142 {}
143
144 bool operator==(const InputRecord& other) const {
145 return this->input_index == other.input_index &&
146 this->udq == other.udq &&
147 this->wgname == other.wgname &&
148 this->control == other.control;
149 }
150
151 template<class Serializer>
152 void serializeOp(Serializer& serializer)
153 {
154 serializer(input_index);
155 serializer(udq);
156 serializer(wgname);
157 serializer(control);
158 }
159
160 std::size_t input_index;
161 std::string udq;
162 std::string wgname;
163 UDAControl control;
164 };
165
166 static UDQActive serializationTestObject();
167 UDQActive() = default;
168 static std::vector<RstRecord> load_rst(const UnitSystem& units,
169 const UDQConfig& udq_config,
170 const RestartIO::RstState& rst_state,
171 const std::vector<std::string>& well_names,
172 const std::vector<std::string>& group_names);
173 int update(const UDQConfig& udq_config, const UDAValue& uda, const std::string& wgname, UDAControl control);
174 explicit operator bool() const;
175 const std::vector<OutputRecord>& iuad() const;
176 std::vector<InputRecord> iuap() const;
177
178 bool operator==(const UDQActive& data) const;
179
180 template<class Serializer>
181 void serializeOp(Serializer& serializer)
182 {
183 serializer(input_data);
184 serializer(output_data);
185 }
186
187private:
188 std::string udq_hash(const std::string& udq, UDAControl control);
189 std::string wg_hash(const std::string& wgname, UDAControl control);
190 int add(const UDQConfig& udq_config, const std::string& udq, const std::string& wgname, UDAControl control);
191 int update_input(const UDQConfig& udq_config, const UDAValue& uda, const std::string& wgname, UDAControl control);
192 int drop(const std::string& wgname, UDAControl control);
193
194 std::vector<InputRecord> input_data;
195 std::vector<OutputRecord> mutable output_data;
196};
197
198}
199
200#endif
Class for (de-)serializing.
Definition Serializer.hpp:84
Definition UDAValue.hpp:32
Definition UDQActive.hpp:130
Definition UDQActive.hpp:70
Definition UDQActive.hpp:43
Definition UDQConfig.hpp:63
Definition UnitSystem.hpp:34
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Definition state.hpp:54
Definition UDQActive.hpp:46