opm-common
Loading...
Searching...
No Matches
UDQASTNode.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#ifndef UDQASTNODE_HPP
21#define UDQASTNODE_HPP
22
23#include <opm/input/eclipse/Schedule/UDQ/UDQContext.hpp>
24#include <opm/input/eclipse/Schedule/UDQ/UDQEnums.hpp>
25#include <opm/input/eclipse/Schedule/UDQ/UDQSet.hpp>
26
27#include <memory>
28#include <set>
29#include <string>
30#include <unordered_set>
31#include <variant>
32#include <vector>
33
34namespace Opm {
35
36class UDQASTNode
37{
38public:
39 UDQVarType var_type { UDQVarType::NONE };
40
41 UDQASTNode();
42 explicit UDQASTNode(UDQTokenType type_arg);
43 explicit UDQASTNode(double scalar_value);
44
45 UDQASTNode(UDQTokenType type_arg,
46 const std::variant<std::string, double>& value_arg,
47 const UDQASTNode& left_arg);
48
49 UDQASTNode(UDQTokenType type_arg,
50 const std::variant<std::string, double>& value_arg,
51 const UDQASTNode& left,
52 const UDQASTNode& right);
53
54 UDQASTNode(UDQTokenType type_arg,
55 const std::variant<std::string, double>& value_arg);
56
57 UDQASTNode(UDQTokenType type_arg,
58 const std::variant<std::string, double>& value_arg,
59 const std::vector<std::string>& selector);
60
61 static UDQASTNode serializationTestObject();
62
63 UDQSet eval(UDQVarType eval_target, const UDQContext& context) const;
64 bool valid() const;
65 std::set<UDQTokenType> func_tokens() const;
66
67 void update_type(const UDQASTNode& arg);
68 void set_left(const UDQASTNode& arg);
69 void set_right(const UDQASTNode& arg);
70 void scale(double sign_factor);
71
72 UDQASTNode* get_left() const;
73 UDQASTNode* get_right() const;
74 bool operator==(const UDQASTNode& data) const;
75 void required_summary(std::unordered_set<std::string>& summary_keys) const;
76
83
84 template <class Serializer>
85 void serializeOp(Serializer& serializer)
86 {
87 serializer(var_type);
88 serializer(type);
89 serializer(value);
90 serializer(sign);
91 serializer(selector);
92 serializer(left);
93 serializer(right);
94 }
95
96private:
97 UDQTokenType type;
98
99 std::variant<std::string, double> value;
100 double sign = 1.0;
101 std::vector<std::string> selector;
102 std::shared_ptr<UDQASTNode> left;
103 std::shared_ptr<UDQASTNode> right;
104
105 UDQSet eval_expression(const UDQContext& context) const;
106
107 UDQSet eval_well_expression(const std::string& string_value,
108 const UDQContext& context) const;
109
110 UDQSet eval_group_expression(const std::string& string_value,
111 const UDQContext& context) const;
112
113 UDQSet eval_segment_expression(const std::string& string_value,
114 const UDQContext& context) const;
115
116 UDQSet eval_region_expression(const std::string& string_value,
117 const UDQContext& context) const;
118
119 UDQSet eval_scalar_function(const UDQVarType target_type,
120 const UDQContext& context) const;
121
122 UDQSet eval_elemental_unary_function(const UDQVarType target_type,
123 const UDQContext& context) const;
124
125 UDQSet eval_binary_function(const UDQVarType target_type,
126 const UDQContext& context) const;
127
128 UDQSet eval_number(const UDQVarType target_type,
129 const UDQContext& context) const;
130
131 UDQSet eval_table_lookup(const UDQVarType target_type,
132 const std::string& string_value,
133 const UDQContext& context) const;
134
135 UDQSet eval_table_lookup_field(const std::string& string_value,
136 const UDQContext& context) const;
137 UDQSet eval_table_lookup_group(const std::string& string_value,
138 const UDQContext& context) const;
139 UDQSet eval_table_lookup_segment(const std::string& string_value,
140 const UDQContext& context) const;
141 UDQSet eval_table_lookup_well(const std::string& string_value,
142 const UDQContext& context) const;
143
144 void func_tokens(std::set<UDQTokenType>& tokens) const;
145
152 void populateRequiredObjects(UDQ::RequisiteEvaluationObjects& objects) const;
153
161 void populateRequiredGroupObjects(UDQ::RequisiteEvaluationObjects& objects) const;
162
170 void populateRequiredRegionObjects(UDQ::RequisiteEvaluationObjects& objects) const;
171
179 void populateRequiredSegmentObjects(UDQ::RequisiteEvaluationObjects& objects) const;
180
188 void populateRequiredWellObjects(UDQ::RequisiteEvaluationObjects& objects) const;
189};
190
191UDQASTNode operator*(const UDQASTNode&lhs, double rhs);
192UDQASTNode operator*(double lhs, const UDQASTNode& rhs);
193
194} // namespace Opm
195
196#endif // UDQASTNODE_HPP
Class for (de-)serializing.
Definition Serializer.hpp:94
Definition UDQASTNode.hpp:37
void requiredObjects(UDQ::RequisiteEvaluationObjects &objects) const
Populate collection of requisite objects needed to evaluate this node.
Definition UDQASTNode.cpp:309
Definition UDQContext.hpp:50
Definition UDQSet.hpp:187
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30
Collection of specific Schedule objects named in a UDQ definition.
Definition UDQEnums.hpp:206