My Project
UDQAssign.hpp
1/*
2 Copyright 2018 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
21#ifndef UDQASSIGN_HPP_
22#define UDQASSIGN_HPP_
23
24#include <string>
25#include <unordered_set>
26#include <vector>
27
28#include <opm/input/eclipse/Schedule/UDQ/UDQSet.hpp>
29#include <opm/input/eclipse/Schedule/UDQ/UDQEnums.hpp>
30
31namespace Opm {
32
33
35public:
36
37 /*
38 If the same keyword is assigned several times the different assignment
39 records are assembled in one UDQAssign instance. This is an attempt to
40 support restart in a situation where a full UDQ ASSIGN statement can be
41 swapped with a UDQ DEFINE statement.
42 */
43 struct AssignRecord {
44 std::vector<std::string> input_selector;
45 std::unordered_set<std::string> rst_selector;
46 double value;
47 std::size_t report_step;
48
49 AssignRecord() = default;
50
51 AssignRecord(const std::vector<std::string>& selector, double value_arg, std::size_t report_step_arg)
52 : input_selector(selector)
53 , value(value_arg)
54 , report_step(report_step_arg)
55 {}
56
57 AssignRecord(const std::unordered_set<std::string>& selector, double value_arg, std::size_t report_step_arg)
58 : rst_selector(selector)
59 , value(value_arg)
60 , report_step(report_step_arg)
61 {}
62
63 void eval(UDQSet& values) const {
64 if (this->input_selector.empty() && this->rst_selector.empty())
65 values.assign( this->value );
66 else {
67 if (this->rst_selector.empty())
68 values.assign(this->input_selector[0], this->value);
69 else {
70 for (const auto& wgname : this->rst_selector)
71 values.assign(wgname, this->value);
72 }
73 }
74 }
75
76 bool operator==(const AssignRecord& data) const {
77 return input_selector == data.input_selector &&
78 rst_selector == data.rst_selector &&
79 report_step == data.report_step &&
80 value == data.value;
81 }
82
83 template<class Serializer>
84 void serializeOp(Serializer& serializer)
85 {
86 serializer(input_selector);
87 serializer(rst_selector);
88 serializer(value);
89 serializer(report_step);
90 }
91 };
92
93 UDQAssign();
94 UDQAssign(const std::string& keyword, const std::vector<std::string>& selector, double value, std::size_t report_step);
95 UDQAssign(const std::string& keyword, const std::unordered_set<std::string>& selector, double value, std::size_t report_step);
96
97 static UDQAssign serializationTestObject();
98
99 const std::string& keyword() const;
100 UDQVarType var_type() const;
101 void add_record(const std::vector<std::string>& selector, double value, std::size_t report_step);
102 void add_record(const std::unordered_set<std::string>& rst_selector, double value, std::size_t report_step);
103 UDQSet eval(const std::vector<std::string>& wells) const;
104 UDQSet eval() const;
105 std::size_t report_step() const;
106
107 bool operator==(const UDQAssign& data) const;
108
109 template<class Serializer>
110 void serializeOp(Serializer& serializer)
111 {
112 serializer(m_keyword);
113 serializer(m_var_type);
114 serializer(records);
115 }
116
117private:
118 std::string m_keyword;
119 UDQVarType m_var_type;
120 std::vector<AssignRecord> records;
121};
122}
123
124
125
126#endif
Class for (de-)serializing.
Definition: Serializer.hpp:75
Definition: UDQAssign.hpp:34
Definition: UDQSet.hpp:63
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29
Definition: UDQAssign.hpp:43