My Project
UnitSystem.hpp
1/*
2 Copyright 2013 Statoil 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 UNITSYSTEM_H
21#define UNITSYSTEM_H
22
23#include <string>
24#include <map>
25#include <vector>
26#include <memory>
27
28#include <opm/input/eclipse/Units/Dimension.hpp>
29#include <opm/input/eclipse/Schedule/UDQ/UDQEnums.hpp>
30
31namespace Opm {
32
33 class UnitSystem {
34 public:
35 enum class UnitType {
36 UNIT_TYPE_METRIC = 0,
37 UNIT_TYPE_FIELD = 1,
38 UNIT_TYPE_LAB = 2,
39 UNIT_TYPE_PVT_M = 3,
40 UNIT_TYPE_INPUT = 4
41 };
42
43 enum class measure : int {
44 identity,
45 length,
46 time,
47 runtime,
48 density,
49 pressure,
50 temperature_absolute,
51 temperature,
52 viscosity,
53 permeability,
54 liquid_surface_volume,
55 gas_surface_volume,
56 volume,
57 geometric_volume,
58 liquid_surface_rate,
59 gas_surface_rate,
60 rate,
61 geometric_volume_rate,
62 pipeflow_velocity,
63 transmissibility,
64 effective_Kh,
65 mass,
66 mass_rate,
67 gas_oil_ratio,
68 oil_gas_ratio,
69 water_cut,
70 gas_formation_volume_factor,
71 oil_formation_volume_factor,
72 water_formation_volume_factor,
73 gas_inverse_formation_volume_factor,
74 oil_inverse_formation_volume_factor,
75 water_inverse_formation_volume_factor,
76 liquid_productivity_index,
77 gas_productivity_index,
78 energy,
79 energy_rate,
80 icd_strength,
81 aicd_strength,
82 polymer_density,
83 salinity,
84 gas_oil_ratio_rate,
85 moles,
86 _count // New entries must be added *before* this
87 };
88
89 explicit UnitSystem(int ecl_id);
90 explicit UnitSystem(UnitType unit = UnitType::UNIT_TYPE_METRIC);
91 explicit UnitSystem(const std::string& deck_name);
92
93 static UnitSystem serializationTestObject();
94
95 const std::string& getName() const;
96 UnitType getType() const;
97 int ecl_id() const;
98
99 void addDimension(const std::string& dimension , const Dimension& dim);
100 void addDimension(const std::string& dimension, double SIfactor, double SIoffset = 0.0);
101 const Dimension& getNewDimension(const std::string& dimension);
102 const Dimension& getDimension(const std::string& dimension) const;
103 Dimension getDimension(measure m) const;
104 Dimension uda_dim(UDAControl control) const;
105
106 bool hasDimension(const std::string& dimension) const;
107 bool equal(const UnitSystem& other) const;
108
109 bool operator==( const UnitSystem& ) const;
110 bool operator!=( const UnitSystem& ) const;
111 static bool rst_cmp(const UnitSystem& full_arg, const UnitSystem& rst_arg);
112
113 Dimension parse(const std::string& dimension) const;
114
115 double from_si( const std::string& dimension, double );
116 double to_si( const std::string& dimension, double );
117 double from_si( measure, double ) const;
118 double to_si( measure, double ) const;
119 void from_si( measure, std::vector<double>& ) const;
120 void to_si( measure, std::vector<double>& ) const;
121 const char* name( measure ) const;
122 std::string deck_name() const;
123 std::size_t use_count() const;
124
125 static bool valid_name(const std::string& deck_name);
126 static UnitSystem newMETRIC();
127 static UnitSystem newFIELD();
128 static UnitSystem newLAB();
129 static UnitSystem newPVT_M();
130 static UnitSystem newINPUT();
131
132 template<class Serializer>
133 void serializeOp(Serializer& serializer)
134 {
135 serializer(m_name);
136 serializer(m_unittype);
137 serializer(m_dimensions);
138 serializer(m_use_count);
139 if (!serializer.isSerializing())
140 init();
141 }
142
143 private:
144 Dimension parseFactor( const std::string& ) const;
145 void init();
146 void initINPUT();
147 void initMETRIC();
148 void initFIELD();
149 void initPVT_M();
150 void initLAB();
151
152 std::string m_name;
153 UnitType m_unittype;
154 std::map< std::string , Dimension > m_dimensions;
155 const double* measure_table_to_si_offset;
156 const double* measure_table_from_si;
157 const double* measure_table_to_si;
158 const char* const* unit_name_table;
159
160 /*
161 The active unit system is determined runtime, to be certain that we do
162 not end up in a situation where we first use the default unit system,
163 and then subsequently change it.
164
165 The Deck::selectActiveUnitSystem() method has this code:
166
167 const auto& current = this->getActiveUnitSystem();
168 if (current.use_count() > 0)
169 throw std::logic_error("Sorry - can not change unit system halways");
170
171
172 */
173 mutable std::size_t m_use_count = 0;
174 };
175
176} // namespace Opm
177
178#endif // UNITSYSTEM_H
Definition: Dimension.hpp:27
Class for (de-)serializing.
Definition: Serializer.hpp:84
bool isSerializing() const
Returns true if we are currently doing a serialization operation.
Definition: Serializer.hpp:183
Definition: UnitSystem.hpp:33
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30