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 
31 
32 namespace 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  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  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  _count // New entries must be added *before* this
85  };
86 
87  explicit UnitSystem(int ecl_id);
88  explicit UnitSystem(UnitType unit = UnitType::UNIT_TYPE_METRIC);
89  explicit UnitSystem(const std::string& deck_name);
90 
91  static UnitSystem serializeObject();
92 
93  const std::string& getName() const;
94  UnitType getType() const;
95  int ecl_id() const;
96 
97  void addDimension(const std::string& dimension , const Dimension& dim);
98  void addDimension(const std::string& dimension, double SIfactor, double SIoffset = 0.0);
99  const Dimension& getNewDimension(const std::string& dimension);
100  const Dimension& getDimension(const std::string& dimension) const;
101  Dimension getDimension(measure m) const;
102  Dimension uda_dim(UDAControl control) const;
103 
104  bool hasDimension(const std::string& dimension) const;
105  bool equal(const UnitSystem& other) const;
106 
107  bool operator==( const UnitSystem& ) const;
108  bool operator!=( const UnitSystem& ) const;
109  static bool rst_cmp(const UnitSystem& full_arg, const UnitSystem& rst_arg);
110 
111  Dimension parse(const std::string& dimension) const;
112 
113  double from_si( const std::string& dimension, double );
114  double to_si( const std::string& dimension, double );
115  double from_si( measure, double ) const;
116  double to_si( measure, double ) const;
117  void from_si( measure, std::vector<double>& ) const;
118  void to_si( measure, std::vector<double>& ) const;
119  const char* name( measure ) const;
120  std::string deck_name() const;
121  std::size_t use_count() const;
122 
123  static bool valid_name(const std::string& deck_name);
124  static UnitSystem newMETRIC();
125  static UnitSystem newFIELD();
126  static UnitSystem newLAB();
127  static UnitSystem newPVT_M();
128  static UnitSystem newINPUT();
129 
130  template<class Serializer>
131  void serializeOp(Serializer& serializer)
132  {
133  serializer(m_name);
134  serializer(m_unittype);
135  serializer.map(m_dimensions);
136  serializer(m_use_count);
137  if (!serializer.isSerializing())
138  init();
139  }
140 
141  private:
142  Dimension parseFactor( const std::string& ) const;
143  void init();
144  void initINPUT();
145  void initMETRIC();
146  void initFIELD();
147  void initPVT_M();
148  void initLAB();
149 
150  std::string m_name;
151  UnitType m_unittype;
152  std::map< std::string , Dimension > m_dimensions;
153  const double* measure_table_to_si_offset;
154  const double* measure_table_from_si;
155  const double* measure_table_to_si;
156  const char* const* unit_name_table;
157 
158  /*
159  The active unit system is determined runtime, to be certain that we do
160  not end up in a situation where we first use the default unit system,
161  and then subsequently change it.
162 
163  The Deck::selectActiveUnitSystem() method has this code:
164 
165  const auto& current = this->getActiveUnitSystem();
166  if (current.use_count() > 0)
167  throw std::logic_error("Sorry - can not change unit system halways");
168 
169 
170  */
171  mutable std::size_t m_use_count = 0;
172  };
173 }
174 
175 
176 #endif
177 
Definition: Dimension.hpp:27
Definition: Serializer.hpp:38
Definition: UnitSystem.hpp:34
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29