opm-common
UDQInput.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 UDQINPUT__HPP_
21 #define UDQINPUT__HPP_
22 
23 #include <opm/input/eclipse/Schedule/UDQ/UDQAssign.hpp>
24 #include <opm/input/eclipse/Schedule/UDQ/UDQDefine.hpp>
25 #include <opm/input/eclipse/Schedule/UDQ/UDQEnums.hpp>
26 
27 #include <cstddef>
28 #include <string>
29 #include <variant>
30 
31 namespace Opm {
32 
33 class UDQIndex
34 {
35 public:
36  UDQIndex() = default;
37 
38  UDQIndex(const std::size_t insert_index_arg,
39  const std::size_t typed_insert_index_arg,
40  const UDQAction action_arg,
41  const UDQVarType var_type_arg)
42  : insert_index (insert_index_arg)
43  , typed_insert_index(typed_insert_index_arg)
44  , action (action_arg)
45  , var_type (var_type_arg)
46  {}
47 
48  static UDQIndex serializationTestObject()
49  {
50  UDQIndex result;
51  result.insert_index = 1;
52  result.typed_insert_index = 2;
53  result.action = UDQAction::ASSIGN;
54  result.var_type = UDQVarType::WELL_VAR;
55 
56  return result;
57  }
58 
59  bool operator==(const UDQIndex& data) const
60  {
61  return (insert_index == data.insert_index)
62  && (typed_insert_index == data.typed_insert_index)
63  && (action == data.action)
64  && (var_type == data.var_type)
65  ;
66  }
67 
68  template <class Serializer>
69  void serializeOp(Serializer& serializer)
70  {
71  serializer(insert_index);
72  serializer(typed_insert_index);
73  serializer(action);
74  serializer(var_type);
75  }
76 
77  std::size_t insert_index{};
78  std::size_t typed_insert_index{};
79  UDQAction action{UDQAction::ASSIGN};
80  UDQVarType var_type{UDQVarType::NONE};
81 };
82 
83 class UDQInput
84 {
85 public:
86  UDQInput(const UDQIndex& index, const UDQDefine* udq_define, const std::string& unit);
87  UDQInput(const UDQIndex& index, const UDQAssign* udq_assign, const std::string& unit);
88 
89  template <typename T>
90  const T& get() const;
91 
92  template <typename T>
93  bool is() const;
94 
95  const std::string& keyword() const { return this->m_keyword; }
96  const std::string& unit() const { return this->m_unit; }
97  UDQVarType var_type() const { return this->m_var_type; }
98  const UDQIndex index;
99 
100  bool operator==(const UDQInput& other) const;
101 
102 private:
103  std::variant<const UDQDefine*, const UDQAssign*> value{};
104  std::string m_keyword{};
105  UDQVarType m_var_type{UDQVarType::NONE};
106  std::string m_unit{};
107 };
108 
109 } // namespace Opm
110 
111 #endif // UDQINPUT__HPP_
Definition: UDQDefine.hpp:50
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: UDQInput.hpp:83
Definition: UDQInput.hpp:33
Representation of a UDQ ASSIGN statement.
Definition: UDQAssign.hpp:40
Class for (de-)serializing.
Definition: Serializer.hpp:94