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 <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 area,
55 liquid_surface_volume,
56 gas_surface_volume,
57 volume,
58 geometric_volume,
59 liquid_surface_rate,
60 gas_surface_rate,
61 rate,
62 geometric_volume_rate,
63 pipeflow_velocity,
64 transmissibility,
65 effective_Kh,
66 mass,
67 mass_rate,
68 gas_oil_ratio,
69 oil_gas_ratio,
70 water_cut,
71 gas_formation_volume_factor,
72 oil_formation_volume_factor,
73 water_formation_volume_factor,
74 gas_inverse_formation_volume_factor,
75 oil_inverse_formation_volume_factor,
76 water_inverse_formation_volume_factor,
77 liquid_productivity_index,
78 gas_productivity_index,
79 energy,
80 energy_rate,
81 icd_strength,
82 aicd_strength,
83 polymer_density,
84 salinity,
85 gas_oil_ratio_rate,
86 moles,
87 ppm,
88 ymodule,
89 _count // New entries must be added *before* this
90 };
91
92 explicit UnitSystem(int ecl_id);
93 explicit UnitSystem(UnitType unit = UnitType::UNIT_TYPE_METRIC);
94 explicit UnitSystem(const std::string& deck_name);
95
96 static UnitSystem serializationTestObject();
97
98 const std::string& getName() const;
99 UnitType getType() const;
100 int ecl_id() const;
101
102 void addDimension(const std::string& dimension , const Dimension& dim);
103 void addDimension(const std::string& dimension, double SIfactor, double SIoffset = 0.0);
104 const Dimension& getNewDimension(const std::string& dimension);
105 const Dimension& getDimension(const std::string& dimension) const;
106 Dimension getDimension(measure m) const;
107 Dimension uda_dim(UDAControl control) const;
108
109 bool hasDimension(const std::string& dimension) const;
110 bool equal(const UnitSystem& other) const;
111
112 bool operator==( const UnitSystem& ) const;
113 bool operator!=( const UnitSystem& ) const;
114 static bool rst_cmp(const UnitSystem& full_arg, const UnitSystem& rst_arg);
115
116 Dimension parse(const std::string& dimension) const;
117
118 double from_si( const std::string& dimension, double );
119 double to_si( const std::string& dimension, double );
120 double from_si( measure, double ) const;
121 double to_si( measure, double ) const;
122 void from_si( measure, std::vector<double>& ) const;
123 void to_si( measure, std::vector<double>& ) const;
124 const char* name( measure ) const;
125 std::string deck_name() const;
126 std::size_t use_count() const;
127
128 static bool valid_name(const std::string& deck_name);
129 static UnitSystem newMETRIC();
130 static UnitSystem newFIELD();
131 static UnitSystem newLAB();
132 static UnitSystem newPVT_M();
133 static UnitSystem newINPUT();
134
135 template<class Serializer>
136 void serializeOp(Serializer& serializer)
137 {
138 serializer(m_name);
139 serializer(m_unittype);
140 serializer(m_dimensions);
141 serializer(m_use_count);
142 if (!serializer.isSerializing())
143 init();
144 }
145
146 private:
147 Dimension parseFactor( const std::string& ) const;
148 void init();
149 void initINPUT();
150 void initMETRIC();
151 void initFIELD();
152 void initPVT_M();
153 void initLAB();
154
155 std::string m_name;
156 UnitType m_unittype;
157 std::map< std::string , Dimension > m_dimensions;
158 const double* measure_table_to_si_offset;
159 const double* measure_table_from_si;
160 const double* measure_table_to_si;
161 const char* const* unit_name_table;
162
163 /*
164 The active unit system is determined runtime, to be certain that we do
165 not end up in a situation where we first use the default unit system,
166 and then subsequently change it.
167
168 The Deck::selectActiveUnitSystem() method has this code:
169
170 const auto& current = this->getActiveUnitSystem();
171 if (current.use_count() > 0)
172 throw std::logic_error("Sorry - can not change unit system halways");
173
174
175 */
176 mutable std::size_t m_use_count = 0;
177 };
178
179} // namespace Opm
180
181#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