My Project
Loading...
Searching...
No Matches
UDAValue.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 UDA_VALUE_HPP
21#define UDA_VALUE_HPP
22
23#include <stdexcept>
24#include <vector>
25#include <string>
26#include <iosfwd>
27
28#include <opm/input/eclipse/Units/Dimension.hpp>
29
30namespace Opm {
31
32class UDAValue {
33public:
34 UDAValue();
35 explicit UDAValue(double);
36 explicit UDAValue(const std::string&);
37 explicit UDAValue(const Dimension& dim);
38 UDAValue(double data, const Dimension& dim);
39 UDAValue(const std::string& data, const Dimension& dim);
40
41 /*
42 The assignment operators have been explicitly deleted, that is to prevent
43 people from adding them at a later stage. It seems very tempting/natural
44 to implement these assignment operators, but the problem is that the
45 resulting UDA object will typically have the wrong dimension member, and
46 subtle dimension related bugs will arise.
47 */
48 UDAValue& operator=(double value) = delete;
49 UDAValue& operator=(const std::string& value) = delete;
50 void update(double d);
51 void update(const std::string& s);
52 void update_value(const UDAValue& other);
53
54 static UDAValue serializationTestObject();
55
56 /*
57 The get<double>() and get<std::string>() methods will throw an
58 exception if the internal type and the template parameter disagree.
59 */
60
61 template<typename T>
62 T get() const;
63
64 /*
65 The getSI() can only be called for numerical values.
66 */
67 double getSI() const;
68 bool zero() const;
69
70 //epsilon limit = 1.E-20 (~= 0.)
71 double epsilonLimit() const;
72
73 template<typename T>
74 bool is() const;
75
76 void assert_numeric() const;
77 void assert_numeric(const std::string& error_msg) const;
78 const Dimension& get_dim() const;
79
80 bool operator==(const UDAValue& other) const;
81 bool operator!=(const UDAValue& other) const;
82
83 bool is_numeric() const { return numeric_value; }
84
85 template<class Serializer>
86 void serializeOp(Serializer& serializer)
87 {
88 serializer(numeric_value);
89 serializer(double_value);
90 serializer(string_value);
91 serializer(dim);
92 }
93
94 void operator*=(double rhs);
95
96
97private:
98 bool numeric_value;
99 double double_value;
100 std::string string_value;
101
102 Dimension dim;
103};
104
105std::ostream& operator<<( std::ostream& stream, const UDAValue& uda_value );
106}
107
108
109
110#endif
Definition Dimension.hpp:27
Class for (de-)serializing.
Definition Serializer.hpp:84
Definition UDAValue.hpp:32
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30