Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <cmath> 7 : 8 : #include "Utilities/ConstantExpressions.hpp" 9 : 10 : namespace hydro { 11 : /*! 12 : * \brief Functions, constants, and classes for converting between different 13 : * units. 14 : * 15 : * In SpECTRE we prefer to use geometric units where \f$G=c=M_{\odot}=1\f$, as 16 : * is standard in numerical relativity. However, in order to interface with 17 : * other codes, we need to sometimes convert units. This namespace is designed 18 : * to hold the various conversion factors and functions. A unit library/system 19 : * would be nice, but is a non-trivial amount of work. 20 : */ 21 1 : namespace units { 22 : /*! 23 : * \brief Entities for converting between geometric units where 24 : * \f$G=c=M_{\odot}=1\f$ and CGS units. 25 : * 26 : */ 27 1 : namespace cgs { 28 : 29 : /// The speed of light in cm/s (This is exact) 30 1 : constexpr double speed_of_light = 29979245800.0; 31 : /// Newton's gravitational constant as given by 32 : /// https://journals.aps.org/rmp/abstract/10.1103/RevModPhys.93.025010. 33 : /// G is likely to vary between sources, even beyond the reported uncertainty 34 1 : constexpr double G_Newton = 6.67430e-8; 35 : /// Note G*M_Sun = 1.32712440042x10^26 +/- 1e16 [1/cm] 36 : /// G*M_Sun factor from https://doi.org/10.1063/1.4921980 37 1 : static constexpr double G_Newton_times_m_sun = 1.32712440042e26; 38 : /// k_B factor in erg/K from 39 : /// https://journals.aps.org/rmp/pdf/10.1103/RevModPhys.93.025010. 40 : /// (This is exact) 41 1 : static constexpr double k_Boltzmann = 1.380649e-16; 42 : 43 : /// `mass_cgs = mass_geometric * mass_unit` 44 : /// Heuristically the mass of the sun in grams 45 1 : constexpr double mass_unit = G_Newton_times_m_sun / G_Newton; 46 : /// `length_cgs = length_geometric * length_unit` 47 : /// Heuristically, half the schwarzschild radius of the sun 48 : /// in cm 49 1 : constexpr double length_unit = G_Newton_times_m_sun / square(speed_of_light); 50 : /// `time_cgs = time_geometric * time_unit` 51 : /// Heuristically, half the light crossing time of a 52 : /// solar schwarzschild radius in seconds 53 1 : constexpr double time_unit = length_unit / speed_of_light; 54 : /// `rho_cgs = rho_geometric * rho_unit` 55 : /// Heuristically, the density in g/cm^3 of matter ~2200 times the density of 56 : /// atomic nuclei. Note this is much larger than any density realized in the 57 : /// universe. 58 1 : constexpr double rest_mass_density_unit = 59 : mass_unit / (length_unit * length_unit * length_unit); 60 : /// `pressure_cgs = pressure_geometric * pressure_unit` 61 : /// Heuristically, the quantity above but times the speed of light squared in 62 : /// cgs 63 1 : constexpr double pressure_unit = 64 : mass_unit / (length_unit * time_unit * time_unit); 65 : 66 : // Extra constants, which are known to greatest precision in SI / (equvialently 67 : // CGS) 68 : /// The accepted value for the atomic mass unit in g, uncertainty +-30e-10 69 1 : constexpr double atomic_mass_unit = 1.66053906660e-24; 70 : /// The neutron mass, given in grams, uncertainty at 5.7 x 10^-10 level 71 1 : constexpr double neutron_mass = 1.67492749804e-24; 72 : /// The proton mass, given in grams. Uncertainty at 2e-8 level 73 1 : constexpr double proton_mass = 1.672621898e-24; 74 : /// The electron-volt (eV) given in ergs, which is known exactly in SI/cgs 75 1 : constexpr double electron_volt = 1.602176634e-12; 76 : 77 : /*! 78 : * \brief CGS unit of Gauss. 79 : * 80 : * Equals `mass_unit^(1/2) * length_unit^(-1/2) * time_unit^(-1)`. 81 : * 82 : * Conversion rule for electromagnetic fields is 83 : * ``` 84 : * magnetic_field_cgs = magnetic_field_geometric * gauss_unit 85 : * ``` 86 : * or 87 : * ``` 88 : * electric_field_cgs = electric_field_geometric * gauss_unit 89 : * ``` 90 : * 91 : * \warning Before changing units using this value, make sure the unit systems 92 : * you are converting values between are using the same unit convention for 93 : * electromagnetic variables as well. Gaussian and Heaviside-Lorentz unit 94 : * convention (in electromagnetism) have a factor of \f$\sqrt{4\pi}\f$ 95 : * difference in variables. See 96 : * <a href="https://en.wikipedia.org/wiki/Heaviside%E2%80%93Lorentz_units">this 97 : * Wikipedia page</a> for how to convert between different unit systems in 98 : * electromagnetism. 99 : * 100 : * Note that ForceFree and grmhd::ValenciaDivClean evolution systems are 101 : * adopting the geometrized Heaviside-Lorentz unit for magnetic fields. 102 : * 103 : * e.g. Suppose magnetic field has value \f$10^{-5}\f$ with the code unit in the 104 : * ValenciaDivClean evolution system. This corresponds to 105 : * ``` 106 : * 10^(-5) * gauss_unit = 2.3558985e+14 Gauss 107 : * ``` 108 : * in the CGS Heaviside-Lorentz unit. 109 : * 110 : * If one wants to convert it to the usual CGS Gaussian unit, extra factor of 111 : * \f$\sqrt{4\pi}\f$ needs to be multiplied: 112 : * ``` 113 : * 10^(-5) * gauss_unit * sqrt(4pi) = 8.35144274e+14 Gauss 114 : * ``` 115 : */ 116 1 : constexpr double gauss_unit = 2.3558985e+19; 117 : } // namespace cgs 118 : 119 : /*! 120 : * \brief The defining quantities of the nuclear fm-MeV/c^2-fm/c unit system 121 : * 122 : * Constants are defined in terms of cgs units where possible, which are, in 123 : * many cases known exactly due to their relation to SI. 124 : */ 125 1 : namespace nuclear { 126 : /// `mass_nuclear = mass_unit * mass_geometric` 127 : /// Heuristically a solar mass in MeV/c^2 128 1 : constexpr double mass_unit = 129 : cgs::mass_unit / 130 : (1.0e6 * cgs::electron_volt / square(cgs::speed_of_light)); 131 : /// `length_nuclear = length_unit * length_geometric` 132 : /// Heuristically GM_sun/c^2 in fm 133 1 : constexpr double length_unit = cgs::length_unit / (1.0e-13); 134 : /// `time_nuclear = time_unit * time_geometric` 135 : /// Heuristically GM_sun/c^3 in fm/c 136 1 : constexpr double time_unit = 137 : cgs::time_unit / (1.0e-13 / cgs::speed_of_light); 138 : /// `pressure_nuclear = pressure_geometric * pressure_geometric` 139 : /// Heuristically the rest-mass energy density of 140 : /// ~2200 the density of atomic nucli expressed in MeV/fm^3 141 1 : constexpr double pressure_unit = mass_unit / (length_unit * square(time_unit)); 142 : /// `rest_mass_density_nuclear = rest_mass_density_geometric * 143 : /// rest_mass_density_geometric` Heuristically ~2200 the density of atomic nucli 144 : /// expressed in MeV/c^2/fm^3 145 1 : constexpr double rest_mass_density_unit = mass_unit / cube(length_unit); 146 0 : constexpr double neutron_mass = 147 : cgs::neutron_mass / 148 : (1.0e6 * cgs::electron_volt / square(cgs::speed_of_light)); 149 0 : constexpr double atomic_mass_unit = 150 : cgs::atomic_mass_unit / 151 : (1.0e6 * cgs::electron_volt / square(cgs::speed_of_light)); 152 : /// The proton mass in MeV, uncertainty at 5.8eV. 153 1 : constexpr double proton_mass = 154 : cgs::proton_mass / 155 : (1.0e6 * cgs::electron_volt / square(cgs::speed_of_light)); 156 : 157 : /// The saturation number density of baryons in nuclear matter, in 158 : /// units of 1/fm^3. This is a standard value, consistent with e.g. 159 : /// https://journals.aps.org/prc/abstract/10.1103/PhysRevC.102.044321 160 1 : constexpr double saturation_number_density = 0.16; 161 : 162 : } // namespace nuclear 163 : /*! 164 : * \brief Quantities given in terms of geometric units G = c = M_odot = 165 : * 1 166 : * 167 : * All quantities are given in terms of unit systems which are related exactly 168 : * to SI units. The limiting factor in conversions is the poorly known value 169 : * of G; which leads to large uncertainties in the relative value of SI-derived 170 : * masses to the solar mass. For this reason, it is best to avoid using 171 : * geometric units in calculations except where conversion is explicitly needed. 172 : */ 173 1 : namespace geometric { 174 : /// Neutron mass in G = c = M_sun = 1.0 units 175 1 : constexpr double neutron_mass = cgs::neutron_mass / cgs::mass_unit; 176 : /// The rest mass density of matter at the saturation point 177 1 : constexpr double default_saturation_rest_mass_density = 178 : 1 / nuclear::rest_mass_density_unit * 179 : (nuclear::saturation_number_density * nuclear::atomic_mass_unit); 180 : /// The default baryon mass in geometric units. 181 : /// Accepted value of atomic mass unit as expressed in 182 : /// solar masses 183 : /// Limited by precision of knowledge of solar mass. 184 1 : constexpr double default_baryon_mass = cgs::atomic_mass_unit / cgs::mass_unit; 185 : } // namespace geometric 186 : 187 : } // namespace units 188 : } // namespace hydro