UnitSystem.hpp
Go to the documentation of this file.
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
29
30namespace Opm {
31
32 class UnitSystem {
33 public:
34 enum class UnitType {
35 UNIT_TYPE_METRIC = 0,
36 UNIT_TYPE_FIELD = 1,
37 UNIT_TYPE_LAB = 2,
38 UNIT_TYPE_PVT_M = 3,
39 UNIT_TYPE_INPUT = 4
40 };
41
42 enum class measure : int {
43 identity,
44 length,
45 time,
46 density,
47 pressure,
48 temperature_absolute,
49 temperature,
50 viscosity,
51 permeability,
52 liquid_surface_volume,
53 gas_surface_volume,
54 volume,
55 geometric_volume,
56 liquid_surface_rate,
57 gas_surface_rate,
58 rate,
59 geometric_volume_rate,
60 transmissibility,
61 effective_Kh,
62 mass,
63 mass_rate,
64 gas_oil_ratio,
65 oil_gas_ratio,
66 water_cut,
67 gas_formation_volume_factor,
68 oil_formation_volume_factor,
69 water_formation_volume_factor,
70 gas_inverse_formation_volume_factor,
71 oil_inverse_formation_volume_factor,
72 water_inverse_formation_volume_factor,
73 liquid_productivity_index,
74 gas_productivity_index,
75 energy,
76 icd_strength,
77 _count // New entries must be added *before* this
78 };
79
80 explicit UnitSystem(int ecl_id);
83
85
86 const std::string& getName() const;
88 int ecl_id() const;
89
90 void addDimension(const std::string& dimension , const Dimension& dim);
91 void addDimension(const std::string& dimension, double SIfactor, double SIoffset = 0.0);
92 const Dimension& getNewDimension(const std::string& dimension);
93 const Dimension& getDimension(const std::string& dimension) const;
95
96
97 bool hasDimension(const std::string& dimension) const;
98 bool equal(const UnitSystem& other) const;
99
100 bool operator==( const UnitSystem& ) const;
101 bool operator!=( const UnitSystem& ) const;
102
103 Dimension parse(const std::string& dimension) const;
104
105 double from_si( measure, double ) const;
106 double to_si( measure, double ) const;
107 void from_si( measure, std::vector<double>& ) const;
108 void to_si( measure, std::vector<double>& ) const;
109 const char* name( measure ) const;
111 std::size_t use_count() const;
112
113 static bool valid_name(const std::string& deck_name);
119
120 template<class Serializer>
121 void serializeOp(Serializer& serializer)
122 {
123 serializer(m_name);
124 serializer(m_unittype);
125 serializer.map(m_dimensions);
126 serializer(m_use_count);
127 if (!serializer.isSerializing())
128 init();
129 }
130
131 private:
132 Dimension parseFactor( const std::string& ) const;
133 void init();
134 void initINPUT();
135 void initMETRIC();
136 void initFIELD();
137 void initPVT_M();
138 void initLAB();
139
140 std::string m_name;
141 UnitType m_unittype;
142 std::map< std::string , Dimension > m_dimensions;
143 const double* measure_table_to_si_offset;
144 const double* measure_table_from_si;
145 const double* measure_table_to_si;
146 const char* const* unit_name_table;
147
148 /*
149 The active unit system is determined runtime, to be certain that we do
150 not end up in a situation where we first use the default unit system,
151 and then subsequently change it.
152
153 The Deck::selectActiveUnitSystem() method has this code:
154
155 const auto& current = this->getActiveUnitSystem();
156 if (current.use_count() > 0)
157 throw std::logic_error("Sorry - can not change unit system halways");
158
159
160 */
161 mutable std::size_t m_use_count = 0;
162 };
163}
164
165
166#endif
167
char const int length
Definition: cJSON.h:161
const char *const string
Definition: cJSON.h:170
Definition: Dimension.hpp:27
Definition: Serializer.hpp:38
Definition: UnitSystem.hpp:32
const Dimension & getNewDimension(const std::string &dimension)
std::size_t use_count() const
const Dimension & getDimension(const std::string &dimension) const
static UnitSystem newINPUT()
void serializeOp(Serializer &serializer)
Definition: UnitSystem.hpp:121
static UnitSystem serializeObject()
void addDimension(const std::string &dimension, const Dimension &dim)
std::string deck_name() const
int ecl_id() const
const std::string & getName() const
double from_si(measure, double) const
static UnitSystem newPVT_M()
UnitSystem(int ecl_id)
double to_si(measure, double) const
Dimension getDimension(measure m) const
static UnitSystem newLAB()
UnitSystem(UnitType unit=UnitType::UNIT_TYPE_METRIC)
static UnitSystem newFIELD()
bool operator==(const UnitSystem &) const
static bool valid_name(const std::string &deck_name)
UnitSystem(const std::string &deck_name)
measure
Definition: UnitSystem.hpp:42
UnitType
Definition: UnitSystem.hpp:34
UnitType getType() const
void addDimension(const std::string &dimension, double SIfactor, double SIoffset=0.0)
const char * name(measure) const
bool operator!=(const UnitSystem &) const
void to_si(measure, std::vector< double > &) const
void from_si(measure, std::vector< double > &) const
static UnitSystem newMETRIC()
Dimension parse(const std::string &dimension) const
bool hasDimension(const std::string &dimension) const
bool equal(const UnitSystem &other) const
Definition: A.hpp:4