LCOV - code coverage report
Current view: top level - include/astro - constants.hpp (source / functions) Coverage Total Hit
Test: mxlib Lines: 0.0 % 10 0
Test Date: 2026-08-30 22:23:37 Functions: 0.0 % 5 0

            Line data    Source code
       1              : /** \file constants.hpp
       2              :  * \author Jared R. Males (jaredmales@gmail.com)
       3              :  * \brief Constants for astronomy.
       4              :  * \ingroup astrofiles
       5              :  *
       6              :  */
       7              : 
       8              : #ifndef __mx_astro_constants_hpp__
       9              : #define __mx_astro_constants_hpp__
      10              : 
      11              : namespace mx
      12              : {
      13              : 
      14              : namespace astro
      15              : {
      16              : 
      17              : namespace constants
      18              : {
      19              : 
      20              : /** \defgroup dimensionless_constants Dimensionless Constants
      21              :  * \ingroup astroconstants
      22              :  * Constants without dimensions are provided with a template argument specifying the precision.
      23              :  * @{
      24              :  */
      25              : 
      26              : /// Tangent of 1.0 arcsec
      27              : /** Calculated with 100 digits of precision, recorded here with 50 digits.
      28              :  */
      29              : template <typename realT>
      30            0 : constexpr realT tan_arcsec()
      31              : {
      32            0 :     return static_cast<realT>( 4.8481368111333441675396429478852851658848753880815e-06 );
      33              : }
      34              : 
      35              : ///@} Dimensionless Constants
      36              : 
      37              : /** \defgroup dimensioned_constants Constants with Dimensions
      38              :  * \ingroup astroconstants
      39              :  * Constants with dimensions are provided with a template argument specifying the units system to use, see \ref
      40              :  * astrounits.
      41              :  * @{
      42              :  */
      43              : 
      44              : /// Newton's Gravitational Constant
      45              : /** Source: 2014 CODATA recommended values \cite codata_2014, http://physics.nist.gov/cuu/Constants/index.html
      46              :  */
      47              : template <typename units>
      48              : constexpr typename units::realT G()
      49              : {
      50              :     return static_cast<typename units::realT>( 6.67408e-11 ) * ( units::length * units::length * units::length ) /
      51              :            ( units::mass * units::time * units::time );
      52              : }
      53              : 
      54              : /// The speed of light.
      55              : /** Source: 2014 CODATA recommended values \cite codata_2014, http://physics.nist.gov/cuu/Constants/index.html
      56              :  */
      57              : template <typename units>
      58              : constexpr typename units::realT c()
      59              : {
      60              :     return static_cast<typename units::realT>( 299792458 ) * ( units::length / units::time );
      61              : }
      62              : 
      63              : /// Boltzmann Constant
      64              : /** \f$ k = 1.38064852 \times 10^{-23} \: J \: K^{-1}\f$
      65              :  *
      66              :  * Source: 2014 CODATA recommended values \cite codata_2014, http://physics.nist.gov/cuu/Constants/index.html
      67              :  */
      68              : template <typename units>
      69              : constexpr typename units::realT k()
      70              : {
      71              :     return static_cast<typename units::realT>( 1.38064852e-23 ) * units::energy / units::temperature;
      72              : }
      73              : 
      74              : /// Stefan-Boltzmann Constant
      75              : /** \f$ \sigma =  5.670367 \times 10^{-8} \: W \: m^{-2} \: K^{-4} \f$
      76              :  *
      77              :  * Source: 2014 CODATA recommended values \cite codata_2014, http://physics.nist.gov/cuu/Constants/index.html
      78              :  */
      79              : template <typename units>
      80              : constexpr typename units::realT sigma()
      81              : {
      82              :     return static_cast<typename units::realT>( 5.670367e-8 ) * ( units::energy / units::time ) /
      83              :            ( units::length * units::length ) /
      84              :            ( units::temperature * units::temperature * units::temperature * units::temperature );
      85              : }
      86              : 
      87              : /// Planck Constant
      88              : /** Source: 2014 CODATA recommended values \cite codata_2014, http://physics.nist.gov/cuu/Constants/index.html
      89              :  */
      90              : template <typename units>
      91              : constexpr typename units::realT h()
      92              : {
      93              :     return static_cast<typename units::realT>( 6.626070040e-34 ) * units::energy * units::time;
      94              : }
      95              : 
      96              : /// Length of day
      97              : /** As defined by IAU
      98              :  */
      99              : template <typename units>
     100              : constexpr typename units::realT day()
     101              : {
     102              :     return static_cast<typename units::realT>( 86400.0 ) * units::time;
     103              : }
     104              : 
     105              : /// Length of year
     106              : /** As defined by IAU
     107              :  */
     108              : template <typename units>
     109              : constexpr typename units::realT year()
     110              : {
     111              :     return ( static_cast<typename units::realT>( 365.25 ) * static_cast<typename units::realT>( 86400.0 ) ) *
     112              :            units::time;
     113              : }
     114              : 
     115              : /// Astronomical Unit
     116              : /** As defined by IAU Resolution 2012 B2
     117              :  */
     118              : template <typename units>
     119            0 : constexpr typename units::realT au()
     120              : {
     121            0 :     return static_cast<typename units::realT>( 149597870700.0 ) * units::length;
     122              : }
     123              : 
     124              : /// The parsec
     125              : template <typename units>
     126            0 : constexpr typename units::realT parsec()
     127              : {
     128            0 :     return au<units>() / tan_arcsec<typename units::realT>();
     129              : }
     130              : 
     131              : /// Radius of the Sun
     132              : /** \f$ R_{sun} = 6.957\times 10^{8} \: m\f$
     133              :  *
     134              :  * Source: IAU Resolution 2015 B2, <a
     135              :  * href="https://www.iau.org/static/resolutions/IAU2015_English.pdf">https://www.iau.org/static/resolutions/IAU2015_English.pdf</a>
     136              :  */
     137              : template <typename units>
     138              : constexpr typename units::realT radSun()
     139              : {
     140              :     return static_cast<typename units::realT>( 6.957e8 ) * units::length;
     141              : }
     142              : 
     143              : /// Solar Irradiance at 1 au
     144              : /** \f$ S_{sun} = 1361 \: W \: m^{-2}\f$
     145              :  *
     146              :  * Source: IAU Resolution 2015 B2, <a
     147              :  * href="https://www.iau.org/static/resolutions/IAU2015_English.pdf">https://www.iau.org/static/resolutions/IAU2015_English.pdf</a>
     148              :  */
     149              : template <typename units>
     150              : constexpr typename units::realT solarIrrad()
     151              : {
     152              :     return static_cast<typename units::realT>( 1361 ) * units::energy / units::time / ( units::length * units::length );
     153              : }
     154              : 
     155              : /// Luminosity of the Sun
     156              : /** \f$ L_{sun} = 3.828\times 10^{26} \: W\f$
     157              :  *
     158              :  * Source: IAU Resolution 2015 B2, <a
     159              :  * href="https://www.iau.org/static/resolutions/IAU2015_English.pdf">https://www.iau.org/static/resolutions/IAU2015_English.pdf</a>
     160              :  */
     161              : template <typename units>
     162              : constexpr typename units::realT lumSun()
     163              : {
     164              :     return static_cast<typename units::realT>( 3.828e26 ) * units::energy / units::time;
     165              : }
     166              : 
     167              : /// Effective Temperature of the Sun
     168              : /** \f$ T_{sun} = 5772 \: K \f$
     169              :  *
     170              :  * Source: IAU Resolution 2015 B2, <a
     171              :  * href="https://www.iau.org/static/resolutions/IAU2015_English.pdf">https://www.iau.org/static/resolutions/IAU2015_English.pdf</a>
     172              :  */
     173              : template <typename units>
     174            0 : constexpr typename units::realT TeffSun()
     175              : {
     176            0 :     return static_cast<typename units::realT>( 5772.0 ) * units::temperature;
     177              : }
     178              : 
     179              : /// Solar Mass Parameter
     180              : /** \f$ GM_{sun} =  1.3271244 \times 10^20 \: m^3 \: s^{-2} \f$
     181              :  *
     182              :  * Source: IAU Resolution 2015 B2, <a
     183              :  * href="https://www.iau.org/static/resolutions/IAU2015_English.pdf">https://www.iau.org/static/resolutions/IAU2015_English.pdf</a>
     184              :  */
     185              : template <typename units>
     186              : constexpr typename units::realT GMSun()
     187              : {
     188              :     return static_cast<typename units::realT>( 1.3271244e20 ) * ( units::length * units::length * units::length ) /
     189              :            ( units::time * units::time );
     190              : }
     191              : 
     192              : /// Solar Mass
     193              : /** The mass of Sun is the \ref GMSun() "Solar mass parameter" divided by the \ref G() "graviational constant".
     194              :  *
     195              :  * \f$ M_{Sun} =  GM_{Sun}/G \f$
     196              :  *
     197              :  */
     198              : template <typename units>
     199              : constexpr typename units::realT massSun()
     200              : {
     201              :     return GMSun<units>() / G<units>();
     202              : }
     203              : 
     204              : /// Radius of Earth (nominal equatorial)
     205              : /** \f$ R_{e} =  6.3781\times 10^6 \: m \f$
     206              :  *
     207              :  * Source: IAU Resolution 2015 B2, <a
     208              :  * href="https://www.iau.org/static/resolutions/IAU2015_English.pdf">https://www.iau.org/static/resolutions/IAU2015_English.pdf</a>
     209              :  */
     210              : template <typename units>
     211              : constexpr typename units::realT radEarth()
     212              : {
     213              :     return static_cast<typename units::realT>( 6.3781e6 ) * units::length;
     214              : }
     215              : 
     216              : /// Earth Mass Parameter
     217              : /** \f$ GM_{e} =  3.986004 \times 10^14 \: m^3 \: s^{-2} \f$
     218              :  *
     219              :  * Source: IAU Resolution 2015 B2, <a
     220              :  * href="https://www.iau.org/static/resolutions/IAU2015_English.pdf">https://www.iau.org/static/resolutions/IAU2015_English.pdf</a>
     221              :  */
     222              : template <typename units>
     223              : constexpr typename units::realT GMEarth()
     224              : {
     225              :     return static_cast<typename units::realT>( 3.986004e14 ) * ( units::length * units::length * units::length ) /
     226              :            ( units::time * units::time );
     227              : }
     228              : 
     229              : /// Earth Mass
     230              : /** The mass of Earth is the \ref GMEarth() "mass parameter"  divided by the \ref G() "gravitational constant".
     231              :  *
     232              :  * \f$ M_{e} =  GM_{e}/G \f$
     233              :  *
     234              :  */
     235              : template <typename units>
     236              : constexpr typename units::realT massEarth()
     237              : {
     238              :     return GMEarth<units>() / G<units>();
     239              : }
     240              : 
     241              : /// Radius of Jupiter (nominal equatorial)
     242              : /** \f$ R_{J} =  7.1492\times 10^7 \: m \f$
     243              :  *
     244              :  * Source: IAU Resolution 2015 B2, <a
     245              :  * href="https://www.iau.org/static/resolutions/IAU2015_English.pdf">https://www.iau.org/static/resolutions/IAU2015_English.pdf</a>
     246              :  */
     247              : template <typename units>
     248            0 : constexpr typename units::realT radJupiter()
     249              : {
     250            0 :     return static_cast<typename units::realT>( 7.1492e7 ) * units::length;
     251              : }
     252              : 
     253              : /// Jupiter Mass Parameter
     254              : /** \f$ GM_{J} =  1.2668653 \times 10^17 \: m^3 \: s^{-2} \f$
     255              :  *
     256              :  * Source: IAU Resolution 2015 B2, <a
     257              :  * href="https://www.iau.org/static/resolutions/IAU2015_English.pdf">https://www.iau.org/static/resolutions/IAU2015_English.pdf</a>
     258              :  */
     259              : template <typename units>
     260              : constexpr typename units::realT GMJupiter()
     261              : {
     262              :     return static_cast<typename units::realT>( 1.2668653e17 ) * ( units::length * units::length * units::length ) /
     263              :            ( units::time * units::time );
     264              : }
     265              : 
     266              : /// Jupiter Mass
     267              : /** The mass of Jupiter is the \ref GMJupiter() "Jupiter mass parameter"  divided by the \ref G()  "gravitational
     268              :  * constant".
     269              :  *
     270              :  * \f$ M_{J} =  GM_{J}/G \f$
     271              :  *
     272              :  */
     273              : template <typename units>
     274              : constexpr typename units::realT massJupiter()
     275              : {
     276              :     return GMJupiter<units>() / G<units>();
     277              : }
     278              : 
     279              : /// Mass ratio of Mercury to the Sun.
     280              : /**
     281              :  * \f$ M_{Sun}/M_{Me} = 6.023657330 \times 10^{6} \f$
     282              :  *
     283              :  * Source: IAU Resolution 2009 B2, <a
     284              :  * href="https://www.iau.org/static/resolutions/IAU2009_English.pdf">https://www.iau.org/static/resolutions/IAU2009_English.pdf</a>.
     285              :  * see also <a href="http://maia.usno.navy.mil/NSFA/NSFA_cbe.html">http://maia.usno.navy.mil/NSFA/NSFA_cbe.html</a>
     286              :  *
     287              :  */
     288              : template <typename units>
     289              : constexpr typename units::realT mrMercury()
     290              : {
     291              :     return static_cast<typename units::realT>( 6.023657330e6 );
     292              : }
     293              : 
     294              : /// Mass of Mercury.
     295              : /**
     296              :  * The mass of Mercury is the \ref massSun() "mass of the Sun" divided by the \ref mrMercury() "mass ratio of Mercury to
     297              :  * the Sun".
     298              :  *
     299              :  */
     300              : template <typename units>
     301              : constexpr typename units::realT massMercury()
     302              : {
     303              :     return massSun<units>() / mrMercury<units>();
     304              : }
     305              : 
     306              : /// Radius of Mercury.
     307              : /**
     308              :  * \f$ = 2.4397 \times 10^{6} \f$
     309              :  *
     310              :  * Source: Seidelmann et al. (2007) \cite seidelmann_2007
     311              :  *
     312              :  */
     313              : template <typename units>
     314              : constexpr typename units::realT radMercury()
     315              : {
     316              :     return static_cast<typename units::realT>( 2.4397e6 ) * units::length;
     317              : }
     318              : 
     319              : /// Mass ratio of Venus to the Sun.
     320              : /**
     321              :  * \f$ M_{Sun}/M_{Ve} = 4.08523719 \times 10^{5}\f$
     322              :  *
     323              :  * Source: IAU Resolution 2009 B2, <a
     324              :  * href="https://www.iau.org/static/resolutions/IAU2009_English.pdf">https://www.iau.org/static/resolutions/IAU2009_English.pdf</a>.
     325              :  * see also <a href="http://maia.usno.navy.mil/NSFA/NSFA_cbe.html">http://maia.usno.navy.mil/NSFA/NSFA_cbe.html</a>
     326              :  *
     327              :  */
     328              : template <typename units>
     329              : constexpr typename units::realT mrVenus()
     330              : {
     331              :     return static_cast<typename units::realT>( 4.08523719e5 );
     332              : }
     333              : 
     334              : /// Mass of Venus.
     335              : /**
     336              :  * The mass of Venus is the \ref massSun() "mass of the Sun" divided by the \ref mrVenus() "mass ratio of Venus to the
     337              :  * Sun".
     338              :  *
     339              :  */
     340              : template <typename units>
     341              : constexpr typename units::realT massVenus()
     342              : {
     343              :     return massSun<units>() / mrVenus<units>();
     344              : }
     345              : 
     346              : /// Radius of Venus.
     347              : /**
     348              :  * \f$ = 6.0518 \times 10^{6} \f$
     349              :  *
     350              :  * Source: Seidelmann et al. (2007) \cite seidelmann_2007
     351              :  *
     352              :  */
     353              : template <typename units>
     354              : constexpr typename units::realT radVenus()
     355              : {
     356              :     return static_cast<typename units::realT>( 6.0518e6 ) * units::length;
     357              : }
     358              : 
     359              : /// Mass ratio of Mars to the Sun.
     360              : /**
     361              :  * \f$ M_{Sun}/M_{Ma} = 3.09870359 \times 10^{6}\f$
     362              :  *
     363              :  * Source: IAU Resolution 2009 B2, <a
     364              :  * href="https://www.iau.org/static/resolutions/IAU2009_English.pdf">https://www.iau.org/static/resolutions/IAU2009_English.pdf</a>.
     365              :  * see also <a href="http://maia.usno.navy.mil/NSFA/NSFA_cbe.html">http://maia.usno.navy.mil/NSFA/NSFA_cbe.html</a>
     366              :  *
     367              :  */
     368              : template <typename units>
     369              : constexpr typename units::realT mrMars()
     370              : {
     371              :     return static_cast<typename units::realT>( 3.09870359e6 );
     372              : }
     373              : 
     374              : /// Mass of Mars.
     375              : /**
     376              :  * The mass of Mars is the mass of the Sun divided by the mass ratio of Mars to the Sun.
     377              :  *
     378              :  */
     379              : template <typename units>
     380              : constexpr typename units::realT massMars()
     381              : {
     382              :     return massSun<units>() / mrMars<units>();
     383              : }
     384              : 
     385              : /// Radius of Mars.
     386              : /**
     387              :  * \f$ = 3.39619 \times 10^{6} \f$
     388              :  *
     389              :  * Source: Seidelmann et al. (2007) \cite seidelmann_2007
     390              :  *
     391              :  */
     392              : template <typename units>
     393              : constexpr typename units::realT radMars()
     394              : {
     395              :     return static_cast<typename units::realT>( 3.39619e6 ) * units::length;
     396              : }
     397              : 
     398              : /// Mass ratio of Saturn to the Sun.
     399              : /**
     400              :  * \f$ M_{Sun}/M_{Sa} = 3.4979018 \times 10^{3}\f$
     401              :  *
     402              :  * Source: IAU Resolution 2009 B2, <a
     403              :  * href="https://www.iau.org/static/resolutions/IAU2009_English.pdf">https://www.iau.org/static/resolutions/IAU2009_English.pdf</a>.
     404              :  * see also <a href="http://maia.usno.navy.mil/NSFA/NSFA_cbe.html">http://maia.usno.navy.mil/NSFA/NSFA_cbe.html</a>
     405              :  *
     406              :  */
     407              : template <typename units>
     408              : constexpr typename units::realT mrSaturn()
     409              : {
     410              :     return static_cast<typename units::realT>( 3.4979018e3 );
     411              : }
     412              : 
     413              : /// Mass of Saturn.
     414              : /**
     415              :  * The mass of Saturn is the mass of the Sun divided by the mass ratio of Saturn to the Sun.
     416              :  *
     417              :  */
     418              : template <typename units>
     419              : constexpr typename units::realT massSaturn()
     420              : {
     421              :     return massSun<units>() / mrSaturn<units>();
     422              : }
     423              : 
     424              : /// Radius of Saturn.
     425              : /**
     426              :  * \f$ = 6.0268 \times 10^{7} \f$
     427              :  *
     428              :  * Source: Seidelmann et al. (2007) \cite seidelmann_2007
     429              :  *
     430              :  */
     431              : template <typename units>
     432              : constexpr typename units::realT radSaturn()
     433              : {
     434              :     return static_cast<typename units::realT>( 6.0268e7 ) * units::length;
     435              : }
     436              : 
     437              : /// Mass ratio of Uranus to the Sun.
     438              : /**
     439              :  * \f$ M_{Sun}/M_{U} = 2.2902951 \times 10^{4}\f$
     440              :  *
     441              :  * Source: IAU Resolution 2009 B2, <a
     442              :  * href="https://www.iau.org/static/resolutions/IAU2009_English.pdf">https://www.iau.org/static/resolutions/IAU2009_English.pdf</a>.
     443              :  * see also <a href="http://maia.usno.navy.mil/NSFA/NSFA_cbe.html">http://maia.usno.navy.mil/NSFA/NSFA_cbe.html</a>
     444              :  *
     445              :  */
     446              : template <typename units>
     447              : constexpr typename units::realT mrUranus()
     448              : {
     449              :     return static_cast<typename units::realT>( 2.2902951e4 );
     450              : }
     451              : 
     452              : /// Mass of Uranus.
     453              : /**
     454              :  * The mass of Uranus is the mass of the Sun divided by the mass ratio of Uranus to the Sun.
     455              :  *
     456              :  */
     457              : template <typename units>
     458              : constexpr typename units::realT massUranus()
     459              : {
     460              :     return massSun<units>() / mrUranus<units>();
     461              : }
     462              : 
     463              : /// Radius of Uranus.
     464              : /**
     465              :  * \f$ = 2.5559 \times 10^{7} \f$
     466              :  *
     467              :  * Source: Seidelmann et al. (2007) \cite seidelmann_2007
     468              :  *
     469              :  */
     470              : template <typename units>
     471              : constexpr typename units::realT radUranus()
     472              : {
     473              :     return static_cast<typename units::realT>( 2.5559e7 ) * units::length;
     474              : }
     475              : 
     476              : /// Mass ratio of Neptune to the Sun.
     477              : /**
     478              :  * \f$ M_{Sun}/M_{U} = 1.941226 \times 10^{4}\f$
     479              :  *
     480              :  * Source: IAU Resolution 2009 B2, <a
     481              :  * href="https://www.iau.org/static/resolutions/IAU2009_English.pdf">https://www.iau.org/static/resolutions/IAU2009_English.pdf</a>.
     482              :  * see also <a href="http://maia.usno.navy.mil/NSFA/NSFA_cbe.html">http://maia.usno.navy.mil/NSFA/NSFA_cbe.html</a>
     483              :  *
     484              :  */
     485              : template <typename units>
     486              : constexpr typename units::realT mrNeptune()
     487              : {
     488              :     return static_cast<typename units::realT>( 1.941226e4 );
     489              : }
     490              : 
     491              : /// Mass of Neptune.
     492              : /**
     493              :  * The mass of Neptune is the mass of the Sun divided by the mass ratio of Neptune to the Sun.
     494              :  *
     495              :  */
     496              : template <typename units>
     497              : constexpr typename units::realT massNeptune()
     498              : {
     499              :     return massSun<units>() / mrNeptune<units>();
     500              : }
     501              : 
     502              : /// Radius of Neptune.
     503              : /**
     504              :  * \f$ = 2.4764 \times 10^{7} \f$
     505              :  *
     506              :  * Source: Seidelmann et al. (2007) \cite seidelmann_2007
     507              :  *
     508              :  */
     509              : template <typename units>
     510              : constexpr typename units::realT radNeptune()
     511              : {
     512              :     return static_cast<typename units::realT>( 2.4764e7 ) * units::length;
     513              : }
     514              : 
     515              : ///@} Dimensioned constants
     516              : 
     517              : } // namespace constants
     518              : } // namespace astro
     519              : } // namespace mx
     520              : 
     521              : #endif //__mx_astro_constants_hpp__
        

Generated by: LCOV version 2.0-1