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