antioch-0.4.0
unit_store.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // Antioch - A Gas Dynamics Thermochemistry Library
5 //
6 // Copyright (C) 2014-2016 Paul T. Bauman, Benjamin S. Kirk,
7 // Sylvain Plessis, Roy H. Stonger
8 //
9 // Copyright (C) 2013 The PECOS Development Team
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the Version 2.1 GNU Lesser General
13 // Public License as published by the Free Software Foundation.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
23 // Boston, MA 02110-1301 USA
24 //
25 //-----------------------------------------------------------------------el-
26 #ifndef ANTIOCH_UNITS_STORE_H
27 #define ANTIOCH_UNITS_STORE_H
28 
52 //Antioch
53 #include "antioch/unit_base.h"
54 #include "antioch/siprefix.h"
55 #include "antioch/math_constants.h"
56 
57 //C++
58 #include <map>
59 #include <vector>
60 
61 
62 namespace Antioch{
63 
64 namespace UnitBaseConstant{
65 
66  template <typename T = double>
68  public:
71  {
72  /* base UnitBase,
73  * UnitBase<T>(string symbol, string name,
74  * double a, double b,
75  * int m, int kg = 0, int s = 0, int A = 0, int K = 0, int mol = 0, int cd = 0, int rad = 0)
76  */
77  store.push_back(UnitBase<T>("m", "meter", 1.0L,0.,1));
78  store.push_back(UnitBase<T>("kg", "kilogram",1.0L,0.,0,1));
79  store.push_back(UnitBase<T>("s", "second", 1.0L,0.,0,0,1));
80  store.push_back(UnitBase<T>("A", "ampere", 1.0L,0.,0,0,0,1));
81  store.push_back(UnitBase<T>("K", "kelvin", 1.0L,0.,0,0,0,0,1));
82  store.push_back(UnitBase<T>("mol","mole", 1.0L,0.,0,0,0,0,0,1));
83  store.push_back(UnitBase<T>("cd", "candela", 1.0L,0.,0,0,0,0,0,0,1));
84  store.push_back(UnitBase<T>("rad","radian", 1.0L,0.,0,0,0,0,0,0,0,1));
85  /* others known Units using constructor
86  * UnitBase<T>(string symbol, string name,
87  * double a, double b,
88  * int m, int kg=0, int s=0, int A=0, int K=0, int mol=0, int cd=0, int rad=0)
89  */
90  //length
91  store.push_back(UnitBase<T>("in", "inch", 0.0254L, 0.,1));
92  store.push_back(UnitBase<T>("ft", "foot", 0.3048L, 0.,1));
93  store.push_back(UnitBase<T>("ua", "astronomical unit",1.49597870700e11L,0.,1)); //~ Sun-Earth distance, BIPM symbol
94  store.push_back(UnitBase<T>("ang","angstrom", 1e-10L, 0.,1));
95  //mass
96  store.push_back(UnitBase<T>("Da","dalton", 1.660538921e-27L,0.,0,1));
97  store.push_back(UnitBase<T>("u", "unified atomic mass",1.660538921e-27L,0.,0,1));
98  //Time
99  store.push_back(UnitBase<T>("min", "minute",60.0L, 0.,0,0,1));
100  store.push_back(UnitBase<T>("hour","hour", 3600.0L,0.,0,0,1));
101  //Current
102  //Temperature
103  store.push_back(UnitBase<T>("degC","degree Celsius", 1.L, 273.15L, 0,0,0,0,1));
104  store.push_back(UnitBase<T>("degF","degree Farenheit",5.L/9.L,459.57L*5.0L/9.0L,0,0,0,0,1));
105  //angle
106  store.push_back(UnitBase<T>("deg", "degree", Constants::pi<T>()/180.0L, 0.,0,0,0,0,0,0,0,1));
107  store.push_back(UnitBase<T>("\'", "Arcminute", Constants::pi<T>()/(180.0L*60.0L), 0.,0,0,0,0,0,0,0,1));
108  store.push_back(UnitBase<T>("\'\'","Arcsecond", Constants::pi<T>()/(180.0L*60.0L*60.0L),0.,0,0,0,0,0,0,0,1));
109  //volume
110  store.push_back(UnitBase<T>("l","litre",1e-3L,0.,3));
111  store.push_back(UnitBase<T>("L","litre",1e-3L,0.,3));
112  //Force m.kg.s-2
113  store.push_back(UnitBase<T>("N", "newton",1.0L, 0.,1,1,-2));
114  store.push_back(UnitBase<T>("dyn","dyne", 1e-5L,0.,1,1,-2));
115  //Pressure N.m-2 (m-1.kg.s-2)
116  store.push_back(UnitBase<T>("Pa", "pascal", 1.0L, 0.,-1,1,-2));
117  store.push_back(UnitBase<T>("bar", "bar", 1e5L, 0.,-1,1,-2));
118  store.push_back(UnitBase<T>("at", "technical atmosphere", 9.80665e4L, 0.,-1,1,-2));
119  store.push_back(UnitBase<T>("atm", "atmosphere", 1.01325e5L, 0.,-1,1,-2));
120  store.push_back(UnitBase<T>("Torr","Torr", 101325.0L/760.0L,0.,-1,1,-2)); // 1 atm / 760 by def
121  store.push_back(UnitBase<T>("psi", "pound per square inch",6.895e3L, 0.,-1,1,-2));
122  store.push_back(UnitBase<T>("mmHg","millimeter of mercury",133.322387415L, 0.,-1,1,-2));
123  //viscosity Pa.s (m-1.kg.s-1)
124  store.push_back(UnitBase<T>("P","poise",0.1L,0.,-1,1,-1));
125  //Power W (m2.kg.s-3)
126  store.push_back(UnitBase<T>("W","watt" ,1.0L,0.,2 ,1,-3));
127  //Energy N.m (m2.kg.s-2)
128  store.push_back(UnitBase<T>("J", "joule", 1.0L, 0.,2,1,-2));
129  store.push_back(UnitBase<T>("cal", "calorie", 4.1868L, 0.,2,1,-2));//International table
130  store.push_back(UnitBase<T>("calth","calorie thermodynamic", 4.184L,0.,2,1,-2));//thermodynamics
131  store.push_back(UnitBase<T>("eV", "electronVolt",1.602176565e-19L,0.,2,1,-2));
132  store.push_back(UnitBase<T>("erg", "erg", 1.e-7L, 0.,2,1,-2));
133  store.push_back(UnitBase<T>("Ha", "hartree", 4.35974434e-18L, 0.,2,1,-2));
134  //Electric charge A.s
135  store.push_back(UnitBase<T>("C","coulomb",1.0L,0.,0,0,1,1));
136  //Frequency s-1
137  store.push_back(UnitBase<T>("Hz","herzt", 1.0L, 0.,0,0,-1));
138  store.push_back(UnitBase<T>("Ci","curie", 3.7e10L,0.,0,0,-1));
139  store.push_back(UnitBase<T>("Bq","becquerel",1.0L, 0.,0,0,-1));
140  // dipole moment C.m = A.s.m
141  store.push_back(UnitBase<T>("D","debye",3.335641e-30L,0.,1,0,1,1)); // http://cccbdb.nist.gov/debye.asp)
142  //no unit
143  store.push_back(UnitBase<T>("molecule","molecule",1.0L,0.,0,0,0,0,0,0));
144  store.push_back(UnitBase<T>("photon", "photon", 1.0L,0.,0,0,0,0,0,0));
145 
146  _n_known_units = store.size();
147 
148  for(int i = 0; i < (int)store.size(); i++)
149  {
150  map_store[store[i].symbol()] = i;
151  }
152  }
153 
154  int stored_index(const std::string &symb) const
155  {
156  return (symb == "g")?map_store.at("kg"): //special case for gram
157  (map_store.count(symb))?map_store.at(symb):-1;
158  }
159 
160  const UnitBase<T> stored(const int &iunit) const
161  {
162  return store[iunit];
163  }
164 
165  int n_known_units() const
166  {
167  return _n_known_units;
168  }
169 
170  private:
171  std::map<std::string,unsigned int> map_store;
172  std::vector<UnitBase<T> > store;
173  unsigned int _n_known_units;
174  };
175 
176 
201 template <typename T = double>
203  public:
206  store.push_back(SIPrefixes<T>("y", "yocto",1e-24L));
207  store.push_back(SIPrefixes<T>("z", "zepto",1e-21L));
208  store.push_back(SIPrefixes<T>("a", "atto", 1e-18L));
209  store.push_back(SIPrefixes<T>("f", "femto",1e-15L));
210  store.push_back(SIPrefixes<T>("p", "pico", 1e-12L));
211  store.push_back(SIPrefixes<T>("n", "nano", 1e-9L));
212  store.push_back(SIPrefixes<T>("mu","micro",1e-6L));
213  store.push_back(SIPrefixes<T>("m", "milli",1e-3L));
214  store.push_back(SIPrefixes<T>("c", "centi",1e-2L));
215  store.push_back(SIPrefixes<T>("d", "deci", 1e-1L));
216  store.push_back(SIPrefixes<T>("da","deca", 1e1L));
217  store.push_back(SIPrefixes<T>("h", "hecto",1e2L));
218  store.push_back(SIPrefixes<T>("k", "kilo", 1e3L));
219  store.push_back(SIPrefixes<T>("M", "mega", 1e6L));
220  store.push_back(SIPrefixes<T>("G", "giga", 1e9L));
221  store.push_back(SIPrefixes<T>("T", "tera", 1e12L));
222  store.push_back(SIPrefixes<T>("P", "peta", 1e15L));
223  store.push_back(SIPrefixes<T>("E", "exa", 1e18L));
224  store.push_back(SIPrefixes<T>("Z", "zetta",1e21L));
225  store.push_back(SIPrefixes<T>("Y", "yotta",1e24L));
226 
227  _n_prefixes = store.size();
228 
229  for(int i = 0; i < (int)store.size(); i++)
230  {
231  map_store[store[i].symbol()] = i;
232  }
233  }
234 
235  int stored_index(const std::string &symb) const
236  {
237  return (map_store.count(symb))?map_store.at(symb):-1;
238  }
239 
240  const SIPrefixes<T> stored(const int &ipre) const
241  {
242  return store[ipre];
243  }
244 
245  int n_known_prefixes() const
246  {
247  return _n_prefixes;
248  }
249 
250  private:
251  std::map<std::string, int> map_store;
252  std::vector<SIPrefixes<T> > store;
253  unsigned int _n_prefixes;
254  };
255 
256 
257 }//end namespace UnitBase
258 
259 
260 }//end namespace Antioch
261 #endif
const SIPrefixes< T > stored(const int &ipre) const
Definition: unit_store.h:240
std::vector< SIPrefixes< T > > store
Definition: unit_store.h:252
Prefixes, SI micro is mu.
Definition: unit_store.h:202
const UnitBase< T > stored(const int &iunit) const
Definition: unit_store.h:160
Prefixes in unit.
Definition: siprefix.h:52
a int
Definition: eigen_utils.h:67
std::vector< UnitBase< T > > store
Definition: unit_store.h:172
int stored_index(const std::string &symb) const
Definition: unit_store.h:235
std::map< std::string, int > map_store
Definition: unit_store.h:251
wrapper for unit storage
Definition: unit_base.h:42
The parameters are reduced parameters.
std::map< std::string, unsigned int > map_store
Definition: unit_store.h:171
int stored_index(const std::string &symb) const
Definition: unit_store.h:154

Generated on Thu Jul 7 2016 11:09:46 for antioch-0.4.0 by  doxygen 1.8.8