Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
constant_table.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
22
23#include "shamunits/Unit.hpp"
26#include <string_view>
27#include <array>
28
29namespace shamunits::details {
31 inline constexpr double pi = 3.141592653589793116;
32} // namespace shamunits::details
33
34namespace shamunits::constants {
35
36 // SI defining constants
37 inline constexpr Unit<> delta_nu_cs = 9192631770. * units::hertz;
38 inline constexpr Unit<> c = 299792458. * units::metre / units::second;
39 inline constexpr Unit<> h = 6.62607015e-34 * units::joule * units::second;
40 inline constexpr Unit<> e = 1.602176634e-19 * units::coulomb;
41 inline constexpr Unit<> k = 1.380649e-23 * units::joule / units::kelvin;
42 // NOLINTNEXTLINE(readability-identifier-naming): physics symbol, also the Python method name
43 inline constexpr Unit<> Na = 6.02214076e23 / units::mole;
44 // NOLINTNEXTLINE(readability-identifier-naming): physics symbol, also the Python method name
45 inline constexpr Unit<> Kcd = 683. * units::lumen / units::watt;
46
47 // Times
48 inline constexpr Unit<> second = units::second;
49 inline constexpr Unit<> minute = units::minute;
50 inline constexpr Unit<> hour = units::hour;
51 inline constexpr Unit<> day = units::day;
52 inline constexpr Unit<> year = units::year;
53
54 // Lengths
56 inline constexpr Unit<> au = units::astronomical_unit;
57 inline constexpr Unit<> light_year = units::light_year;
58 inline constexpr Unit<> parsec = units::parsec;
61 inline constexpr Unit<> planck_length = 1.61625518e-35 * units::metre;
62
63 // Masses
64 inline constexpr Unit<> proton_mass = 1.67262192e-27 * units::kilogram;
66 inline constexpr Unit<> electron_mass = proton_mass * (1. / 1836.1526734311);
67 inline constexpr Unit<> earth_mass = 5.9722e24 * units::kilogram;
68 inline constexpr Unit<> jupiter_mass = 1.898e27 * units::kilogram;
69 inline constexpr Unit<> sol_mass = units::solar_mass;
70 inline constexpr Unit<> planck_mass = 2.17643424e-8 * units::kilogram;
71 inline constexpr Unit<> dalton = 1.66053906892e-27 * units::kilogram;
72
73 // Densities
75 inline constexpr Unit<> guiness_density
76 = (1.017 * 1000.) * units::kilogram / upow(units::metre, 3);
77
78 // Derived constants
79 // NOLINTNEXTLINE(readability-identifier-naming): physics symbol, also the Python method name
80 inline constexpr Unit<> G
81 = 6.6743015e-11 * units::newton * upow(units::metre, 2) / upow(units::kilogram, 2);
82 inline constexpr Unit<> hbar = h / (2. * details::pi);
83 inline constexpr Unit<> mu_0
84 = 1.2566370621219e-6 * units::newton / upow(units::ampere, 2);
85 // NOLINTNEXTLINE(readability-identifier-naming): physics symbol, also the Python method name
86 inline constexpr Unit<> Z_0 = mu_0 * c;
87 inline constexpr Unit<> epsilon_0 = 1. / (Z_0 * c);
88 inline constexpr Unit<> ke = 1. / (4. * details::pi * epsilon_0);
89 inline constexpr Unit<> kb
90 = 1.380649e-23 * units::joule / units::kelvin;
92 inline constexpr Unit<> sigma
93 = 5.670374419e-8 * units::watt / upow(units::metre, 2) / upow(units::kelvin, 4);
94
97 inline constexpr auto registry = std::to_array<NamedUnit>({
98 {"delta_nu_cs", "delta_nu_cs", delta_nu_cs},
99 {"c", "c", c},
100 {"h", "h", h},
101 {"e", "e", e},
102 {"k", "k", k},
103 {"Na", "Na", Na},
104 {"Kcd", "Kcd", Kcd},
105 {"second", "second", second},
106 {"minute", "minute", minute},
107 {"hour", "hour", hour},
108 {"day", "day", day},
109 {"year", "year", year},
110 {"au", "au", au},
111 {"astronomical_unit", "astronomical_unit", astronomical_unit},
112 {"light_year", "light_year", light_year},
113 {"parsec", "parsec", parsec},
114 {"solar_radius", "solar_radius", solar_radius},
115 {"earth_radius", "earth_radius", earth_radius},
116 {"planck_length", "planck_length", planck_length},
117 {"proton_mass", "proton_mass", proton_mass},
118 {"electron_mass", "electron_mass", electron_mass},
119 {"earth_mass", "earth_mass", earth_mass},
120 {"jupiter_mass", "jupiter_mass", jupiter_mass},
121 {"sol_mass", "sol_mass", sol_mass},
122 {"planck_mass", "planck_mass", planck_mass},
123 {"dalton", "dalton", dalton},
124 {"guiness_density", "guiness_density", guiness_density},
125 {"G", "G", G},
126 {"hbar", "hbar", hbar},
127 {"mu_0", "mu_0", mu_0},
128 {"Z_0", "Z_0", Z_0},
129 {"epsilon_0", "epsilon_0", epsilon_0},
130 {"ke", "ke", ke},
131 {"kb", "kb", kb},
132 {"sigma", "sigma", sigma},
133 });
134
135 static_assert(details::names_are_valid(registry), "empty or duplicate constant name");
136
137 // Dimension checks: derived constants must land on the expected dimension
138 static_assert(h.dim == (units::joule * units::second).dim && hbar.dim == h.dim);
139 static_assert(G.dim == Dimension{.second = -2, .metre = 3, .kilogram = -1});
140 static_assert(mu_0.dim == (units::newton / upow(units::ampere, 2)).dim);
141 static_assert(Z_0.dim == units::ohm.dim);
142 static_assert(epsilon_0.dim == (units::farad / units::metre).dim);
143 static_assert(ke.dim == (units::newton * upow(units::metre, 2) / upow(units::coulomb, 2)).dim);
144 static_assert(sigma.dim == (units::watt / upow(units::metre, 2) / upow(units::kelvin, 4)).dim);
145 static_assert(Kcd.dim == (units::lumen / units::watt).dim && Na.dim == (1. / units::mole).dim);
146 static_assert(guiness_density.dim == (units::kilogram / upow(units::metre, 3)).dim);
147 static_assert(k == kb && au == astronomical_unit);
148
150 inline Unit<> from_name(std::string_view name) {
151 return shamunits::details::unit_from_name(registry, name, "constant");
152 }
153
154} // namespace shamunits::constants
A physical unit as a value: its SI dimension and its magnitude in SI base units.
constexpr Unit c
speed of light
Unit from_name(std::string_view name)
Constant from its name; throws std::invalid_argument if unknown.
constexpr Unit h
Planck constant.
constexpr double pi
pi, as a plain number for building constants (same value as shamunits::pi<double>)
constexpr Unit dalton
atomic mass unit
constexpr Unit solar_radius
solar radius
constexpr auto registry
constexpr Unit planck_length
Planck length.
constexpr Unit earth_radius
Earth equatorial radius.
constexpr Unit sol_mass
solar mass
constexpr Unit mu_0
vacuum permeability
constexpr Unit epsilon_0
vacuum permittivity
constexpr Unit minute
minute
constexpr Unit light_year
light year
constexpr Unit jupiter_mass
Jupiter mass.
constexpr Unit guiness_density
density of Guinness, 1.017 g.cm-3
constexpr Unit sigma
Stefan-Boltzmann constant.
constexpr Unit proton_mass
constexpr Unit Z_0
vacuum impedance
constexpr Unit earth_mass
Earth mass.
constexpr Unit astronomical_unit
au
constexpr Unit day
day
constexpr Unit year
Julian year.
constexpr Unit au
alias of astronomical_unit
constexpr Unit parsec
parsec
constexpr Unit hour
hour
constexpr Unit Na
Avogadro constant.
constexpr Unit k
Boltzmann constant.
constexpr Unit planck_mass
Planck mass.
constexpr Unit hbar
reduced Planck
constexpr Unit delta_nu_cs
Cs hyperfine frequency.
constexpr Unit e
elementary charge
constexpr Unit second
second
constexpr Unit Kcd
luminous efficacy
constexpr Unit ke
Coulomb constant.
constexpr Unit electron_mass
electron mass, from the proton/electron mass ratio
constexpr Unit< T > upow(Unit< T > u, int n) noexcept
Integer power of a unit.
Definition Unit.hpp:147
Name tables mapping long and short names to units, with constexpr lookup.
Unit unit_from_name(std::span< const NamedUnit > registry, std::string_view name, std::string_view kind="unit")
Unit named name in registry; throws std::invalid_argument when unknown.
Definition registry.hpp:58
constexpr bool names_are_valid(std::span< const NamedUnit > registry) noexcept
True when no name is empty and no name appears twice, long and short names together.
Definition registry.hpp:70
Exponents of the seven SI base dimensions.
Definition Unit.hpp:35
A unit: its dimension and its magnitude expressed in SI base units, in precision Tscal.
Definition Unit.hpp:89
Dimension dim
SI dimension.
Definition Unit.hpp:90
The table of units: one constexpr Unit per unit, plus its name registry.
constexpr Unit light_year
ly
constexpr Unit hertz
Hz = s-1.
constexpr Unit solar_radius
rsol
constexpr Unit kilogram
kg
constexpr Unit mole
mol
constexpr Unit kelvin
K.
constexpr Unit earth_radius
rearth (equatorial)
constexpr Unit newton
N = kg.m.s-2.
constexpr Unit hour
hr
constexpr Unit solar_mass
sol_mass
constexpr Unit lumen
lm = cd.sr
constexpr Unit joule
J = N.m.
constexpr Unit watt
W = J.s-1.
constexpr Unit second
s
constexpr Unit ampere
A.
constexpr Unit minute
mn
constexpr Unit metre
m
constexpr Unit parsec
pc
constexpr Unit year
yr (Julian)
constexpr Unit coulomb
C = s.A.
constexpr Unit astronomical_unit
au
constexpr Unit day
dy