Units.hpp
Go to the documentation of this file.
1 //===========================================================================
2 //
3 // File: Units.hpp
4 //
5 // Created: Thu Jul 2 09:19:08 2009
6 //
7 // Author(s): Halvor M Nilsen <hnil@sintef.no>
8 //
9 // $Date$
10 //
11 // $Revision$
12 //
13 //===========================================================================
14 
15 /*
16  Copyright 2009, 2010, 2011, 2012 SINTEF ICT, Applied Mathematics.
17  Copyright 2009, 2010, 2011, 2012 Statoil ASA.
18 
19  This file is part of the Open Porous Media project (OPM).
20 
21  OPM is free software: you can redistribute it and/or modify
22  it under the terms of the GNU General Public License as published by
23  the Free Software Foundation, either version 3 of the License, or
24  (at your option) any later version.
25 
26  OPM is distributed in the hope that it will be useful,
27  but WITHOUT ANY WARRANTY; without even the implied warranty of
28  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29  GNU General Public License for more details.
30 
31  You should have received a copy of the GNU General Public License
32  along with OPM. If not, see <http://www.gnu.org/licenses/>.
33 */
34 
35 #ifndef OPM_UNITS_HEADER
36 #define OPM_UNITS_HEADER
37 
44 namespace Opm
45 {
46  namespace prefix
48  {
49  const double micro = 1.0e-6;
50  const double milli = 1.0e-3;
51  const double centi = 1.0e-2;
52  const double deci = 1.0e-1;
53  const double kilo = 1.0e3;
54  const double mega = 1.0e6;
55  const double giga = 1.0e9;
56  } // namespace prefix
57 
58  namespace unit
73  {
76  inline double square(double v) { return v * v; }
77  inline double cubic (double v) { return v * v * v; }
79 
80  // --------------------------------------------------------------
81  // Basic (fundamental) units and conversions
82  // --------------------------------------------------------------
83 
86  const double meter = 1;
87  const double inch = 2.54 * prefix::centi*meter;
88  const double feet = 12 * inch;
90 
93  const double second = 1;
94  const double minute = 60 * second;
95  const double hour = 60 * minute;
96  const double day = 24 * hour;
97  const double year = 365 * day;
99 
102  const double gallon = 231 * cubic(inch);
103  const double stb = 42 * gallon;
104  const double liter = 1 * cubic(prefix::deci*meter);
106 
109  const double kilogram = 1;
110  // http://en.wikipedia.org/wiki/Pound_(mass)#Avoirdupois_pound
111  const double pound = 0.45359237 * kilogram;
113 
114  // --------------------------------------------------------------
115  // Standardised constants
116  // --------------------------------------------------------------
117 
120  const double gravity = 9.80665 * meter/square(second);
122 
123  // --------------------------------------------------------------
124  // Derived units and conversions
125  // --------------------------------------------------------------
126 
129  const double Newton = kilogram*meter / square(second); // == 1
130  const double lbf = pound * gravity; // Pound-force
132 
135  const double Pascal = Newton / square(meter); // == 1
136  const double barsa = 100000 * Pascal;
137  const double atm = 101325 * Pascal;
138  const double psia = lbf / square(inch);
140 
143  const double Pas = Pascal * second; // == 1
144  const double Poise = prefix::deci*Pas;
146 
147  namespace perm_details {
148  const double p_grad = atm / (prefix::centi*meter);
149  const double area = square(prefix::centi*meter);
150  const double flux = cubic (prefix::centi*meter) / second;
151  const double velocity = flux / area;
152  const double visc = prefix::centi*Poise;
153  const double darcy = (velocity * visc) / p_grad;
154  // == 1e-7 [m^2] / 101325
155  // == 9.869232667160130e-13 [m^2]
156  }
166  const double darcy = perm_details::darcy;
168 
172  namespace convert {
191  inline double from(const double q, const double unit)
192  {
193  return q * unit;
194  }
195 
214  inline double to(const double q, const double unit)
215  {
216  return q / unit;
217  }
218  } // namespace convert
219  } // namespace unit
220 } // namespace Opm
221 #endif // OPM_UNITS_HEADER
const double minute
Definition: Units.hpp:94
const double day
Definition: Units.hpp:96
const double micro
Definition: Units.hpp:49
Definition: AnisotropicEikonal.hpp:43
const double mega
Definition: Units.hpp:54
const double feet
Definition: Units.hpp:88
const double darcy
Definition: Units.hpp:166
const double lbf
Definition: Units.hpp:130
const double atm
Definition: Units.hpp:137
const double kilogram
Definition: Units.hpp:109
const double inch
Definition: Units.hpp:87
double to(const double q, const double unit)
Definition: Units.hpp:214
const double centi
Definition: Units.hpp:51
const double giga
Definition: Units.hpp:55
const double milli
Definition: Units.hpp:50
const double barsa
Definition: Units.hpp:136
const double darcy
Definition: Units.hpp:153
const double second
Definition: Units.hpp:93
const double gallon
Definition: Units.hpp:102
const double deci
Definition: Units.hpp:52
const double kilo
Definition: Units.hpp:53
const double Poise
Definition: Units.hpp:144
const double area
Definition: Units.hpp:149
const double pound
Definition: Units.hpp:111
double square(double v)
Definition: Units.hpp:76
const double psia
Definition: Units.hpp:138
const double stb
Definition: Units.hpp:103
const double Newton
Definition: Units.hpp:129
const double liter
Definition: Units.hpp:104
const double gravity
Definition: Units.hpp:120
double cubic(double v)
Definition: Units.hpp:77
const double meter
Definition: Units.hpp:86
const double flux
Definition: Units.hpp:150
double from(const double q, const double unit)
Definition: Units.hpp:191
const double year
Definition: Units.hpp:97
const double p_grad
Definition: Units.hpp:148
const double hour
Definition: Units.hpp:95
const double Pascal
Definition: Units.hpp:135
const double visc
Definition: Units.hpp:152
const double velocity
Definition: Units.hpp:151
const double Pas
Definition: Units.hpp:143