My Project
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 <memory>
24 #include <set>
25 #include <string>
26 #include <unordered_set>
27 #include <variant>
28 #include <vector>
29 
30 #include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQSet.hpp>
31 #include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQContext.hpp>
32 #include <opm/parser/eclipse/EclipseState/Schedule/UDQ/UDQEnums.hpp>
33 
34 
35 
36 namespace Opm {
37 
38 class UDQASTNode {
39 public:
40  UDQASTNode();
41  explicit UDQASTNode(UDQTokenType type_arg);
42  explicit UDQASTNode(double scalar_value);
43  UDQASTNode(UDQTokenType type_arg, const std::variant<std::string, double>& value_arg, const UDQASTNode& left_arg);
44  UDQASTNode(UDQTokenType type_arg, const std::variant<std::string, double>& value_arg, const UDQASTNode& left, const UDQASTNode& right);
45  UDQASTNode(UDQTokenType type_arg, const std::variant<std::string, double>& value_arg);
46  UDQASTNode(UDQTokenType type_arg, const std::variant<std::string, double>& value_arg, const std::vector<std::string>& selector);
47 
48  static UDQASTNode serializeObject();
49 
50  UDQSet eval(UDQVarType eval_target, const UDQContext& context) const;
51 
52  bool valid() const;
53  UDQVarType var_type = UDQVarType::NONE;
54  std::set<UDQTokenType> func_tokens() const;
55  void update_type(const UDQASTNode& arg);
56  void set_left(const UDQASTNode& arg);
57  void set_right(const UDQASTNode& arg);
58  UDQASTNode* get_left() const;
59  UDQASTNode* get_right() const;
60  void scale(double sign_factor);
61 
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 
77 private:
78  UDQTokenType type;
79  void func_tokens(std::set<UDQTokenType>& tokens) const;
80 
81  std::variant<std::string, double> value;
82  double sign = 1.0;
83  std::vector<std::string> selector;
84  std::shared_ptr<UDQASTNode> left;
85  std::shared_ptr<UDQASTNode> right;
86 };
87 
88 UDQASTNode operator*(const UDQASTNode&lhs, double rhs);
89 UDQASTNode operator*(double lhs, const UDQASTNode& rhs);
90 
91 }
92 
93 #endif
Definition: Serializer.hpp:38
Definition: UDQASTNode.hpp:38
Definition: UDQContext.hpp:39
Definition: UDQSet.hpp:66
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29