!23456789a123456789b123456789c123456789d123456789e123456789f123456789g12
! 2017_10_28oct28:  Copyright D.J. Jeffery
!
! constant.f is a set of module setting numerical, physical,
! and astronomical constants.
! 
!23456789a123456789b123456789c123456789d123456789e123456789f123456789g12
!
      module contants
      include '/module_precision_set_implicit.f'
!
!23456789a123456789b123456789c123456789d123456789e123456789f123456789g12
!
! Numerical constants
!
      integer, parameter ::                                                &
     & iprecision_nd=precision(1.0_nd),                                    & ! See MRC-167 for precision function.
! Standard precision significant decimal digits and standard range of exponents.
!   Standard precision is set to double precision.                           ! 18 2020jan19 Jeffery machine
     & iprecision_np=precision(1.0_np),                                    & ! 18 
     & iminexponent_np=minexponent(1.0_np),                                & ! -16381  
     & imaxexponent_np=maxexponent(1.0_np),                                & !  16384
! Single precision significant decimal digits and standard range of exponents.
     & iprecision_ns=precision(1.0_ns),                                    & ! 15
     & iminexponent_ns=minexponent(1.0_ns),                                & ! -1021
     & imaxexponent_ns=maxexponent(1.0_ns),                                & !  1024
     & itc_numerical=1                                                     & 
!        ! The last line is just so all the real lines end in commas for uniformity.
!
      real (kind=np), parameter ::                                         &
!
     & exp1=2.71828182845904523536028747135266249775724709369995_np,       &
!           !!23456789a123456789b123456789c123456789d123456789e123456789f123456789g12
!           !https://en.wikipedia.org/wiki/E_(mathematical_constant) AKA Euler constant 51 digits
     & exp1_inverse=1.0_np/exp1,                                           &
!
     & f_1_2=0.5_np,                                                     &  ! Needs that zero to compile.
     & f_1_4=0.25_np,                                                    &
     & f_1_3=1.0_np/3.0_np,                                              &
     & f_2_3=2.0_np*f_1_3,                                               &
     & f_4_3=4.0_np*f_1_3,                                               &
     & f_1_6=1.0_np/6.0_np,                                              &
!
     & f_1_8=0.125_np,                                                   &
     & f_1_16=(0.5_np)**4,                                               &
     & f_1_32=(0.5_np)**5,                                               &
     & f_1_64=(0.5_np)**6,                                               &
     & f_1_128=(0.5_np)**7,                                              &
     & f_1_256=(0.5_np)**8,                                              &
     & f_1_512=(0.5_np)**9,                                              &
     & f_1_1024=(0.5_np)**10,                                            &
!
     & xln2=0.693147180559945309417232121458_np,                           &
!           !!123456789a123456789b123456789c123456789d123456789e123456789f123456789g12
!           ! https://en.wikipedia.org/wiki/Natural_logarithm_of_2 30 digits
!
     & phi_0_golden_ratio=1.618033988749894848204586834365638117720_np,   &
     & phi_1_golden_ratio=0.618033988749894848204586834365638117720_np,   &
!                        !1!23456789a123456789b123456789c123456789d123456789e123456789f123456789g12
!           ! phi_0=(1+sqrt(5))/2 , phi_1=phi-1=(sqrt(5)-1)/2
!           ! https://en.wikipedia.org/wiki/Golden_ratio
!           ! http://mathworld.wolfram.com/GoldenRatio.html for value to 40 decimal digits.
!
     &   pi=3.14159265358979323846264338327950288419716939937510_np,       &
!           !!23456789a123456789b123456789c123456789d123456789e123456789f123456789g12    
!           ! https://en.wikipedia.org/wiki/Pi#Approximate_value_and_digits 51 digits
     &   pi_1_2=pi*0.5_np,                                                 &
     &   pi_2=pi*2.0_np,                                                   &
     &   pi_sqroot=sqrt(pi),                                               &
!
     & sqroot_2=                                                           &
     & 1.4142                                                              &
     & 1356237309504880168872420969807856967187537694807317667973799_np,   & 
!        !23456789a123456789b123456789c123456789d123456789e123456789f123456789g12    
!        ! From https://en.wikipedia.org/wiki/Square_root_of_2 .  66 digits
!        ! Spaces in numbers 
!        ! are not allowed by some compilers.
     & xprecision=10.0_np**(-iprecision_np+1),                             &
!        !  Relative machine precision almost.
!
     & etc_numerical_np=1.0_np
!
!23456789a123456789b123456789c123456789d123456789e123456789f123456789g12
!
! See https://physics.nist.gov/cuu/Constants/Table/allascii.txt generally
!
! Physical constants:  fundamental
!
      real (kind=np), parameter ::                                              &
!
     & amu    =1.660 539 066 60 e-24_np,                                        &
     & amu_mks=1.660 539 066 60 e-27_np,                                        &
! https://physics.nist.gov/cuu/Constants/Table/allascii.txt error (50)
!
     & clight=    2.99792458e10_np,                                             &
     & clight_mks=2.99792458e8_np,                                              &
     & ckms=clight_mks*1.e-3_np,                                                &
! https://en.wikipedia.org/wiki/Speed_of_light
! https://en.wikipedia.org/wiki/Centimetre%E2%80%93gram%E2%80%93second_system_of_units#Physical_constants_in_CGS_units
!
     & ev_electronvolt    =1.602 176 634 e-12_np,                                   &
     & ev_electronvolt_mks=1.602 176 634 e-19_np,                                   &
! https://physics.nist.gov/cuu/Constants/Table/allascii.txt exact
! The electron-volt = eV.  Units of erg or erg/eV
! 
     & alpha_fine_structure=7.297 352 5693 e-3_np,                               &
     & alpha_fine_structure_inverse=137.035 999 084_np,                          &
! https://physics.nist.gov/cuu/Constants/Table/allascii.txt 
! Error: 11 digits: (11) 
! The fine structure constant which is dimensionless.
! One often gives 1/137. 
! 
     & g_grav=    6.67430e-8_np,                                                 &
     & g_grav_mks=6.67430e-11_np,                                                &
! http://en.wikipedia.org/wiki/Gravitational_constant MKS error (15):
! Wik says this 2018 Codata recomended.
! So 4 digit accurate, but there may still be controversy beyond.
! https://physics.nist.gov/cuu/Constants/Table/allascii.txt
!
     & h_planck=    6.626 070 15e-27_np,                                          &
     & h_planck_mks=6.626 070 15e-34_np,                                          &
! https://physics.nist.gov/cuu/Constants/Table/allascii.txt exact
! https://en.wikipedia.org/wiki/Planck_constant
     & h_bar=h_planck/pi_2,                  !     1.054 571 817e-27_np NIST
     & h_bar_mks=h_planck_mks/pi_2,           !    1.054 571 817e-34_np NIST
! https://physics.nist.gov/cuu/Constants/Table/allascii.txt 
!
     & xk_boltzmann=    1.380 649e-16_np,                                     &
     & xk_boltzmann_mks=1.380 649e-23_np,                                     &
     & xk_boltzmann_ev= 8.617 333 262e-5_np,                                  &  ! approx 10e-4
     & xk_boltzmann_mev=8.617 333 262e-11_np,                                 &  ! approx 10e-10
! https://physics.nist.gov/cuu/Constants/Table/allascii.txt exact in MKS, not eV
! https://en.wikipedia.org/wiki/Boltzmann_constant for CGS
!
!    Electron mass:
     & xm_e=    9.109 383 7015e-28_np,                                      &
     & xm_e_mks=9.109 383 7015e-31_np,                                      &
! https://physics.nist.gov/cuu/Constants/Table/allascii.txt
! error 11 digits: (28 cgs,mks)
! https://en.wikipedia.org/wiki/Electron_rest_mass
!
     & xm_hyd=1.00782505_np*amu,                                                &
! https://en.wikipedia.org/wiki/Atomic_mass#Mass_defects_in_atomic_masses for H-1 
!
!    Proton mass:
     & xm_p=    1.672 621 923 69e-24_np,                                      &
     & xm_p_mks=1.672 621 923 69e-27_np,                                      &
! https://physics.nist.gov/cuu/Constants/Table/allascii.txt
! error 12 digits: (51 cgs,mks)
! https://en.wikipedia.org/wiki/Proton
     & xm_e_reduced=xm_e/(1.0_np+xm_e/xm_p),                                   &
!
!
     & xm_planck=sqrt(h_bar*clight/g_grav),
! https://en.wikipedia.org/wiki/Planck_mass
!
     & xna_avogadro=6.022 140 76 e23_np,                                       &
! https://physics.nist.gov/cuu/Constants/Table/allascii.txt
! https://en.wikipedia.org/wiki/Avogadro_constant = number of particles per mole
! m_i=A_i*u_amu and xna approx 1 g/u_amu to 3.5e-10 relative accuracy.
!   So m = A_i*u_amu = approx A_i*(1 g) is a molar mass to high accuracy.
!
! Physical constants:  derived
!
!    Rydberg energy:
     & e_rydberg_ev=13.605 693 122 994_np,                                     &
     & e_rydberg=2.179 872 361 1035d-11,                                       &
! https://physics.nist.gov/cuu/Constants/Table/allascii.txt 
! error: 14 digits both: (26 eV),(42 cgs)
! https://en.wikipedia.org/wiki/Rydberg_constant
     & e_rydberg_ev_reduced=e_rydberg_ev*(xm_e_reduced/xm_e),                  &
!                          =13.598 287 264 286831241
!                          =13.598 287 264 287
! https://en.wikipedia.org/wiki/Rydberg_constant#Rydberg_constant
!
     & etc_physical_np=1.0_np
!
!  !23456789a123456789b123456789c123456789d123456789e123456789f123456789g12
!
! Astronomical constants
!
      real (kind=np), parameter ::                                             &
!
!  Distances
!     & pc_m=(1.49597870700e11_np/(pi/(180.0_np*3600.0_np))),                  &
     & pc_m=9.6939420213600000e+16_np/pi,                                      &
! https://en.wikipedia.org/wiki/Parsec#Calculating_the_value_of_a_parsec 
! http://en.wikipedia.org/wiki/Astronomical_unit
! r_pc * pc_m = b_AU *au_m /(theta_arcs * pi/(180*3600)) defines pc_m
     & xly_m=9.460730472580800e15_np,                                          &
! exact value by definition,
! light distance traveled in 1 Jyr
! https://en.wikipedia.org/wiki/Light-year#Definitions
     & pc_ly=pc_m/xly_m,                                                       &
! x m * factor of unity = x_m (1 ly/ly_m) 
     & xmpc_km=pc_m*1.e+6_np*1.e-3_np,                                         &
! xmpc_km/xmpc = 1 Converts Mpc to km
! inverse  converts H_0 (km/s)/Mpc in standard to inverse seconds
     & gpc_m=pc_m*1.e+9_np,                                                    &
!              ! Also the conversion Gpc to m
!
!  Times
     & daysec=86400.0_np,                                                      &
     &    xjy=365.25_np,                                                       &  ! Julian year in days
     &  xjy_s=xjy*daysec,                                                      &  ! Julian year in seconds
     &  gjy_s=xjy_s*1.0e9_np,                                                  &  ! Gigayear in seconds
     &
!
!  Radiative transfer (radtran)
     & saha_con=0.5_np*(h_planck**2/(pi_2*xm_e*xk_boltzmann))**1.5_np,         &  ! Saha constant 
     & saha_con_inverse=1.0_np/saha_con,                                       &  ! Saha constant inverse
     & saha_con_inverse_natural=2.0_np*                                        &  !   in natural units
     & (pi_2*xm_e*e_rydberg/h_planck**2)**1.5_np,                              &  ! 1st formula
!     & (pi_sqroot*alpha_fine_structure*xm_e*clight/h_planck)**3,              &  ! 2nd formula
! 
! Mihalas-1978-113:  his value is 2.07e-16 cm**3 K**3/2
! The above expresion evaluates to saha_con=2.070 665 142 40573681148E-0016
! Planck constant exact, pi exact, xm_e 11 digits, xk_b 7 exact
! The above expresion evaluates to saha_con_inverse=4.829 366 079 143 929 688 0e+15
! saha_con_inverse_natural is for kT=rydberg
!   3.029 784 927 54121276948E+0023 1st formula
!   3.029 784 927 53254453019E+0023 2nd formula 
!   They agree to 11 digits.  Since the Rydberg has 14 digits and 
!      the fine structure constant only 11, one guesses the first formula
!      maybe better.
!
! Thomson cross-section
     & sigma_e=    6.652 458 7321 e-25_np,                                     &  ! Thomson cross-section
     & sigma_e_mks=6.652 458 7321 e-29_np,                                     &  ! Thomson cross-section
! https://physics.nist.gov/cuu/Constants/Table/allascii.txt error (60)
! Mihalas-1978-106
!
! Rydberg temperature
     & temperature_rydberg=e_rydberg_ev/xk_boltzmann_ev,                       &  
!                         =157887.5124 0469316319 K
! 14 digits for e_rydberg_ev ,10 digits for xk_boltzmann_ev, so 10 digits
!
!  Solar units
     & xm_sun=    1.98847e33_np,                                                &  ! grams
     & xm_sun_mks=1.98847e30_np,                                                &  ! kilograms
! https://en.wikipedia.org/wiki/Solar_mass revised 2019
!
!  Supernovae units
     & w3_lane_emden=2.018236_np, ! approximate
!     & xmue=1.0_np/(0.5_np*6.0_np/12.0_np+0.5_np*8.0_np/16.0_np),               &
! https://en.wikipedia.org/wiki/Chandrasekhar_limit#Physics
! Pure carbon-oxygen fully ionized, default atomic weights
     & xmue=2.0_np,                                                             & 
! default fully ionized above hydroge
     & xm_chan=w3_lane_emden*sqrt(3.0_np*pi)*0.5_np*xm_planck**3
     &         /(xmue*amu)**2,                                                  &
     & xm_chan_xm_sun=xm_chan/xm_sun,                                           &
     & xm_wd_explosion=1.38_np,                                                 &
! 1.456 Msun 
! https://arxiv.org/pdf/1010.5292.pdf woosley & kasen 2010
! https://arxiv.org/pdf/1710.04254.pdf Leung and nomoto 2017
! https://astro.uni-bonn.de/~nlanger/thesis/rudy.pdf p. 5
! gives 1.38 Msun which must mean 
!  either finite temperature or some non-fiducial mix of isotopes?
!  This is the explosion mass which is only near the Chandrasekhar mass,
!  not actually at it.
! 
!
     & etc_astronomical_np=1.0_np
!
!  !23456789a123456789b123456789c123456789d123456789e123456789f123456789g12
!
      end module contants 
!
!23456789a123456789b123456789c123456789d123456789e123456789f123456789g12
