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