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