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 UDQASTNode(UDQTokenType type_arg, const std::variant<std::string, double>& value_arg, const UDQASTNode& left_arg);
45 UDQASTNode(UDQTokenType type_arg, const std::variant<std::string, double>& value_arg, const UDQASTNode& left, const UDQASTNode& right);
46 UDQASTNode(UDQTokenType type_arg, const std::variant<std::string, double>& value_arg);
47 UDQASTNode(UDQTokenType type_arg, const std::variant<std::string, double>& value_arg, const std::vector<std::string>& selector);
48
49 static UDQASTNode serializationTestObject();
50
51 UDQSet eval(UDQVarType eval_target, const UDQContext& context) const;
52 bool valid() const;
53 std::set<UDQTokenType> func_tokens() const;
54
55 void update_type(const UDQASTNode& arg);
56 void set_left(const UDQASTNode& arg);
57 void set_right(const UDQASTNode& arg);
58 void scale(double sign_factor);
59
60 UDQASTNode* get_left() const;
61 UDQASTNode* get_right() const;
62 bool operator==(const UDQASTNode& data) const;
63 void required_summary(std::unordered_set<std::string>& summary_keys) const;
64
65 template <class Serializer>
66 void serializeOp(Serializer& serializer)
67 {
68 serializer(var_type);
69 serializer(type);
70 serializer(value);
71 serializer(sign);
72 serializer(selector);
73 serializer(left);
74 serializer(right);
75 }
76
77private:
78 UDQTokenType type;
79
80 std::variant<std::string, double> value;
81 double sign = 1.0;
82 std::vector<std::string> selector;
83 std::shared_ptr<UDQASTNode> left;
84 std::shared_ptr<UDQASTNode> right;
85
86 UDQSet eval_expression(const UDQContext& context) const;
87
88 UDQSet eval_well_expression(const std::string& string_value,
89 const UDQContext& context) const;
90
91 UDQSet eval_group_expression(const std::string& string_value,
92 const UDQContext& context) const;
93
94 UDQSet eval_segment_expression(const std::string& string_value,
95 const UDQContext& context) const;
96
97 UDQSet eval_scalar_function(const UDQVarType target_type,
98 const UDQContext& context) const;
99
100 UDQSet eval_elemental_unary_function(const UDQVarType target_type,
101 const UDQContext& context) const;
102
103 UDQSet eval_binary_function(const UDQVarType target_type,
104 const UDQContext& context) const;
105
106 UDQSet eval_number(const UDQVarType target_type,
107 const UDQContext& context) const;
108
109 void func_tokens(std::set<UDQTokenType>& tokens) const;
110};
111
112UDQASTNode operator*(const UDQASTNode&lhs, double rhs);
113UDQASTNode operator*(double lhs, const UDQASTNode& rhs);
114
115}
116
117#endif
Class for (de-)serializing.
Definition Serializer.hpp:84
Definition UDQASTNode.hpp:37
Definition UDQContext.hpp:46
Definition UDQSet.hpp:186
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30