mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
units.hpp
Go to the documentation of this file.
1 /** \file units.hpp
2  * \author Jared R. Males (jaredmales@gmail.com)
3  * \brief Unit specifications and conversions.
4  * \ingroup astrofiles
5  *
6  */
7 
8 #ifndef __mx_astro_units_hpp__
9 #define __mx_astro_units_hpp__
10 
11 #include "constants.hpp"
12 
13 namespace mx
14 {
15 
16 namespace astro
17 {
18 
19 
20 namespace units
21 {
22 
23 /** \defgroup astrounits Unit Conversions
24  * \brief Definitions of unit coversions for physical constants.
25  * \ingroup phyconstants
26  *
27  * These types provide the ratios to convert from SI units to the desired system.
28  *
29  * @{
30  */
31 
32 /// International System of Units (SI) units-type
33 /** Since all constants are specified in SI units, all conversions here are 1.0.
34  */
35 template<typename _realT>
36 struct si
37 {
38  typedef _realT realT; ///< The real floating point type in which to specify constants.
39  static constexpr realT length = static_cast<realT>(1.0); ///< Conversion from SI (m) to SI (m)
40  static constexpr realT time = static_cast<realT>(1.0); ///< Conversion from SI (s) to SI (s)
41  static constexpr realT mass = static_cast<realT>(1.0); ///< Conversion from SI (kg) to SI (kg)
42  static constexpr realT energy = static_cast<realT>(1.0); ///< Conversion from SI (J) to SI (J)
43  static constexpr realT temperature = static_cast<realT>(1.0); ///< Conversion from SI (K) to SI (K)
44 };
45 
46 /// Centimeter-Gram-Second (cgs) units-type
47 /** The units are:
48  * - Length: centimeter (cm)
49  * - Time: second (s)
50  * - Mass: gram (g)
51  * - Energy: erg (erg)
52  * - Temperature: Kelvin (K)
53  */
54 template<typename _realT>
55 struct cgs
56 {
57  typedef _realT realT; ///< The real floating point type in which to specify constants.
58  static constexpr realT length = static_cast<realT>(100.0); ///< Conversion from SI (m) to cgs (cm)
59  static constexpr realT time = static_cast<realT>(1.0); ///< Conversion from SI (s) to cgs (s)
60  static constexpr realT mass = static_cast<realT>(1000.0); ///< Conversion from SI (kg) to cgs (g)
61  static constexpr realT energy = static_cast<realT>(1e7); ///< Conversion from SI (J) to cgs (erg)
62  static constexpr realT temperature = static_cast<realT>(1.0); ///< Conversion from SI (K) to cgs (K)
63 };
64 
65 /// Solar units-type
66 /** The units are:
67  * - Length: au
68  * - Time: year
69  * - Mass: solar mass
70  * - Energy: solar-luminosity-year
71  * - Temperature: solar effective temperature
72  */
73 template<typename _realT>
74 struct solar
75 {
76  typedef _realT realT; ///< The real floating point type in which to specify constants.
77  static constexpr realT length = static_cast<realT>(1)/constants::au<si<realT>>(); ///< Conversion from SI (m) to solar (au)
78  static constexpr realT time = static_cast<realT>(1.0) / constants::year<si<realT>>(); ///< Conversion from SI (s) to solar (yr)
79  static constexpr realT mass = constants::G<si<realT>>()/constants::GMSun<si<realT>>(); ///< Conversion from SI (kg) to solar (M_sun)
80  static constexpr realT energy = static_cast<realT>(1.0)/( constants::lumSun<si<realT>>()*static_cast<realT>(365.25)*static_cast<realT>(86400.0)); ///< Conversion from SI (J) to solar (Solar-luminosities X year)
81  static constexpr realT temperature = static_cast<realT>(1.0) / constants::TeffSun<si<realT>>(); ///< Conversion from SI (K) to solar (5772 K)
82 };
83 
84 /// Earth units-type
85 /** The units are:
86  * - Length: Earth-radii
87  * - Time: s
88  * - Mass: Earth mass
89  * - Energy: J
90  * - Temperature: K
91  */
92 template<typename _realT>
93 struct earth
94 {
95  typedef _realT realT; ///< The real floating point type in which to specify constants.
96  static constexpr realT length = static_cast<realT>(1)/constants::radEarth<si<realT>>(); ///< Conversion from SI (m)
97  static constexpr realT time = static_cast<realT>(1.0); ///< Conversion from SI (s)
98  static constexpr realT mass = static_cast<realT>(1.0)/constants::massEarth<si<realT>>(); ///< Conversion from SI (kg)
99  static constexpr realT energy = static_cast<realT>(1.0); ///< Conversion from SI (J)
100  static constexpr realT temperature = static_cast<realT>(1.0); ///< Conversion from SI (K)
101 };
102 
103 /// Jupiter units-type
104 /** The units are:
105  * - Length: Jupiter-radii
106  * - Time: s
107  * - Mass: Jupiter mass
108  * - Energy: J
109  * - Temperature: K
110  */
111 template<typename _realT>
112 struct jupiter
113 {
114  typedef _realT realT; ///< The real floating point type in which to specify constants.
115  static constexpr realT length = static_cast<realT>(1)/constants::radJupiter<si<realT>>(); ///< Conversion from SI (m)
116  static constexpr realT time = static_cast<realT>(1.0); ///< Conversion from SI (s)
117  static constexpr realT mass = static_cast<realT>(1.0)/constants::massJupiter<si<realT>>(); ///< Conversion from SI (kg)
118  static constexpr realT energy = static_cast<realT>(1.0); ///< Conversion from SI (J)
119  static constexpr realT temperature = static_cast<realT>(1.0); ///< Conversion from SI (K)
120 };
121 
122 ///@}
123 
124 }//namespace units
125 
126 } //namespace astro
127 } //namespace mx
128 
129 
130 #endif //__mx_astro_units_hpp__
131 
constexpr units::realT year()
Length of year.
Definition: constants.hpp:109
constexpr units::realT radEarth()
Radius of Earth (nominal equatorial)
Definition: constants.hpp:204
constexpr units::realT radJupiter()
Radius of Jupiter (nominal equatorial)
Definition: constants.hpp:238
constexpr units::realT lumSun()
Luminosity of the Sun.
Definition: constants.hpp:159
constexpr units::realT GMSun()
Solar Mass Parameter.
Definition: constants.hpp:181
constexpr units::realT massEarth()
Earth Mass.
Definition: constants.hpp:227
constexpr units::realT au()
Astronomical Unit.
Definition: constants.hpp:118
constexpr units::realT TeffSun()
Effective Temperature of the Sun.
Definition: constants.hpp:170
constexpr units::realT massJupiter()
Jupiter Mass.
Definition: constants.hpp:261
The mxlib c++ namespace.
Definition: mxError.hpp:107
Centimeter-Gram-Second (cgs) units-type.
Definition: units.hpp:56
_realT realT
The real floating point type in which to specify constants.
Definition: units.hpp:57
static constexpr realT length
Conversion from SI (m) to cgs (cm)
Definition: units.hpp:58
static constexpr realT temperature
Conversion from SI (K) to cgs (K)
Definition: units.hpp:62
static constexpr realT mass
Conversion from SI (kg) to cgs (g)
Definition: units.hpp:60
static constexpr realT energy
Conversion from SI (J) to cgs (erg)
Definition: units.hpp:61
static constexpr realT time
Conversion from SI (s) to cgs (s)
Definition: units.hpp:59
Earth units-type.
Definition: units.hpp:94
static constexpr realT energy
Conversion from SI (J)
Definition: units.hpp:99
static constexpr realT mass
Conversion from SI (kg)
Definition: units.hpp:98
static constexpr realT length
Conversion from SI (m)
Definition: units.hpp:96
static constexpr realT temperature
Conversion from SI (K)
Definition: units.hpp:100
_realT realT
The real floating point type in which to specify constants.
Definition: units.hpp:95
static constexpr realT time
Conversion from SI (s)
Definition: units.hpp:97
Jupiter units-type.
Definition: units.hpp:113
_realT realT
The real floating point type in which to specify constants.
Definition: units.hpp:114
static constexpr realT mass
Conversion from SI (kg)
Definition: units.hpp:117
static constexpr realT temperature
Conversion from SI (K)
Definition: units.hpp:119
static constexpr realT time
Conversion from SI (s)
Definition: units.hpp:116
static constexpr realT energy
Conversion from SI (J)
Definition: units.hpp:118
static constexpr realT length
Conversion from SI (m)
Definition: units.hpp:115
International System of Units (SI) units-type.
Definition: units.hpp:37
static constexpr realT mass
Conversion from SI (kg) to SI (kg)
Definition: units.hpp:41
static constexpr realT temperature
Conversion from SI (K) to SI (K)
Definition: units.hpp:43
static constexpr realT length
Conversion from SI (m) to SI (m)
Definition: units.hpp:39
_realT realT
The real floating point type in which to specify constants.
Definition: units.hpp:38
static constexpr realT time
Conversion from SI (s) to SI (s)
Definition: units.hpp:40
static constexpr realT energy
Conversion from SI (J) to SI (J)
Definition: units.hpp:42
Solar units-type.
Definition: units.hpp:75
static constexpr realT length
Conversion from SI (m) to solar (au)
Definition: units.hpp:77
_realT realT
The real floating point type in which to specify constants.
Definition: units.hpp:76
static constexpr realT time
Conversion from SI (s) to solar (yr)
Definition: units.hpp:78
static constexpr realT temperature
Conversion from SI (K) to solar (5772 K)
Definition: units.hpp:81
static constexpr realT energy
Conversion from SI (J) to solar (Solar-luminosities X year)
Definition: units.hpp:80
static constexpr realT mass
Conversion from SI (kg) to solar (M_sun)
Definition: units.hpp:79