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