My Project
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
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
77 template <class Serializer>
78 void serializeOp(Serializer& serializer)
79 {
80 serializer(var_type);
81 serializer(type);
82 serializer(value);
83 serializer(sign);
84 serializer(selector);
85 serializer(left);
86 serializer(right);
87 }
88
89private:
90 UDQTokenType type;
91
92 std::variant<std::string, double> value;
93 double sign = 1.0;
94 std::vector<std::string> selector;
95 std::shared_ptr<UDQASTNode> left;
96 std::shared_ptr<UDQASTNode> right;
97
98 UDQSet eval_expression(const UDQContext& context) const;
99
100 UDQSet eval_well_expression(const std::string& string_value,
101 const UDQContext& context) const;
102
103 UDQSet eval_group_expression(const std::string& string_value,
104 const UDQContext& context) const;
105
106 UDQSet eval_segment_expression(const std::string& string_value,
107 const UDQContext& context) const;
108
109 UDQSet eval_region_expression(const std::string& string_value,
110 const UDQContext& context) const;
111
112 UDQSet eval_scalar_function(const UDQVarType target_type,
113 const UDQContext& context) const;
114
115 UDQSet eval_elemental_unary_function(const UDQVarType target_type,
116 const UDQContext& context) const;
117
118 UDQSet eval_binary_function(const UDQVarType target_type,
119 const UDQContext& context) const;
120
121 UDQSet eval_number(const UDQVarType target_type,
122 const UDQContext& context) const;
123
124 UDQSet eval_table_lookup(const UDQVarType target_type,
125 const std::string& string_value,
126 const UDQContext& context) const;
127
128 UDQSet eval_table_lookup_field(const std::string& string_value,
129 const UDQContext& context) const;
130 UDQSet eval_table_lookup_group(const std::string& string_value,
131 const UDQContext& context) const;
132 UDQSet eval_table_lookup_segment(const std::string& string_value,
133 const UDQContext& context) const;
134 UDQSet eval_table_lookup_well(const std::string& string_value,
135 const UDQContext& context) const;
136
137 void func_tokens(std::set<UDQTokenType>& tokens) const;
138};
139
140UDQASTNode operator*(const UDQASTNode&lhs, double rhs);
141UDQASTNode operator*(double lhs, const UDQASTNode& rhs);
142
143} // namespace Opm
144
145#endif // UDQASTNODE_HPP
Class for (de-)serializing.
Definition Serializer.hpp:84
Definition UDQASTNode.hpp:37
Definition UDQContext.hpp:49
Definition UDQSet.hpp:187
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30