My Project
UDQSet.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 UDQSET_HPP
21 #define UDQSET_HPP
22 
23 #include <optional>
24 #include <stdexcept>
25 #include <string>
26 #include <unordered_map>
27 #include <vector>
28 
29 #include <opm/input/eclipse/Schedule/UDQ/UDQEnums.hpp>
30 
31 namespace Opm {
32 
33 class UDQScalar {
34 public:
35  UDQScalar() = default;
36  explicit UDQScalar(double value);
37  explicit UDQScalar(const std::string& wgname);
38 
39  void operator+=(const UDQScalar& rhs);
40  void operator+=(double rhs);
41  void operator*=(const UDQScalar& rhs);
42  void operator*=(double rhs);
43  void operator/=(const UDQScalar& rhs);
44  void operator/=(double rhs);
45  void operator-=(const UDQScalar& rhs);
46  void operator-=(double rhs);
47 
48  operator bool() const;
49  void assign(const std::optional<double>& value);
50  void assign(double value);
51  bool defined() const;
52  double get() const;
53  const std::optional<double>& value() const;
54  const std::string& wgname() const;
55  bool operator==(const UDQScalar& other) const;
56 
57 public:
58  std::optional<double> m_value;
59  std::string m_wgname;
60 };
61 
62 
63 class UDQSet {
64 public:
65  UDQSet(const std::string& name, UDQVarType var_type);
66  UDQSet(const std::string& name, UDQVarType var_type, const std::vector<std::string>& wgnames);
67  UDQSet(const std::string& name, UDQVarType var_type, std::size_t size);
68  UDQSet(const std::string& name, std::size_t size);
69  static UDQSet scalar(const std::string& name, const std::optional<double>& scalar_value);
70  static UDQSet scalar(const std::string& name, double value);
71  static UDQSet empty(const std::string& name);
72  static UDQSet wells(const std::string& name, const std::vector<std::string>& wells);
73  static UDQSet wells(const std::string& name, const std::vector<std::string>& wells, double scalar_value);
74  static UDQSet groups(const std::string& name, const std::vector<std::string>& groups);
75  static UDQSet groups(const std::string& name, const std::vector<std::string>& groups, double scalar_value);
76  static UDQSet field(const std::string& name, double scalar_value);
77 
78  void assign(const std::optional<double>& value);
79  void assign(const std::string& wgname, const std::optional<double>& value);
80 
81  void assign(double value);
82  void assign(std::size_t index, double value);
83  void assign(const std::string& wgname, double value);
84 
85  bool has(const std::string& name) const;
86  std::size_t size() const;
87  void operator+=(const UDQSet& rhs);
88  void operator+=(double rhs);
89  void operator-=(const UDQSet& rhs);
90  void operator-=(double rhs);
91  void operator*=(const UDQSet& rhs);
92  void operator*=(double rhs);
93  void operator/=(const UDQSet& rhs);
94  void operator/=(double rhs);
95 
96  const UDQScalar& operator[](std::size_t index) const;
97  const UDQScalar& operator[](const std::string& wgname) const;
98  std::vector<UDQScalar>::const_iterator begin() const;
99  std::vector<UDQScalar>::const_iterator end() const;
100 
101  std::vector<std::string> wgnames() const;
102  std::vector<double> defined_values() const;
103  std::size_t defined_size() const;
104  const std::string& name() const;
105  void name(const std::string& name);
106  UDQVarType var_type() const;
107  bool operator==(const UDQSet& other) const;
108 private:
109  UDQSet() = default;
110 
111  std::string m_name;
112  UDQVarType m_var_type = UDQVarType::NONE;
113  std::vector<UDQScalar> values;
114 };
115 
116 
117 UDQScalar operator+(const UDQScalar&lhs, const UDQScalar& rhs);
118 UDQScalar operator+(const UDQScalar&lhs, double rhs);
119 UDQScalar operator+(double lhs, const UDQScalar& rhs);
120 
121 UDQScalar operator-(const UDQScalar&lhs, const UDQScalar& rhs);
122 UDQScalar operator-(const UDQScalar&lhs, double rhs);
123 UDQScalar operator-(double lhs, const UDQScalar& rhs);
124 
125 UDQScalar operator*(const UDQScalar&lhs, const UDQScalar& rhs);
126 UDQScalar operator*(const UDQScalar&lhs, double rhs);
127 UDQScalar operator*(double lhs, const UDQScalar& rhs);
128 
129 UDQScalar operator/(const UDQScalar&lhs, const UDQScalar& rhs);
130 UDQScalar operator/(const UDQScalar&lhs, double rhs);
131 UDQScalar operator/(double lhs, const UDQScalar& rhs);
132 
133 UDQSet operator+(const UDQSet&lhs, const UDQSet& rhs);
134 UDQSet operator+(const UDQSet&lhs, double rhs);
135 UDQSet operator+(double lhs, const UDQSet& rhs);
136 
137 UDQSet operator-(const UDQSet&lhs, const UDQSet& rhs);
138 UDQSet operator-(const UDQSet&lhs, double rhs);
139 UDQSet operator-(double lhs, const UDQSet& rhs);
140 
141 UDQSet operator*(const UDQSet&lhs, const UDQSet& rhs);
142 UDQSet operator*(const UDQSet&lhs, double rhs);
143 UDQSet operator*(double lhs, const UDQSet& rhs);
144 
145 UDQSet operator/(const UDQSet&lhs, const UDQSet& rhs);
146 UDQSet operator/(const UDQSet&lhs, double rhs);
147 UDQSet operator/(double lhs, const UDQSet&rhs);
148 
149 }
150 
151 
152 
153 #endif
Definition: UDQSet.hpp:33
Definition: UDQSet.hpp:63
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29