Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
Constants.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
23
24#include "UnitSystem.hpp"
25#include "constant_table.hpp"
26
27namespace shamunits {
28
33 template<class T>
34 constexpr T pi = 3.141592653589793116;
35
37 template<class T>
38 constexpr T fine_structure = 0.0072973525693;
39
41 template<class T>
42 constexpr T proton_electron_ratio = 1836.1526734311;
43
45 template<class T>
47
57 template<class T>
58 struct Constants {
59
62
64 constexpr explicit Constants(const UnitSystem<T> units) : units(units) {}
65
68 template<Unit u, class Tret = T>
69 constexpr Tret get() const noexcept {
70 return units.template get<u, Tret>();
71 }
72
74 template<class Tret = T, class Tu>
75 constexpr Tret get(Unit<Tu> u) const noexcept {
76 return units.template get<Tret>(u);
77 }
78
80 template<class Tret = T, class Tu>
81 constexpr Tret get(Unit<Tu> u, int power) const noexcept {
82 return units.template get<Tret>(u, power);
83 }
84 };
85
86} // namespace shamunits
A unit system: the values of the seven SI base units in code units.
A unit system, defined by the SI value of its base units.
The table of physical constants: each constant is a Unit (its SI value and dimension).
namespace containing the units library
constexpr T electron_proton_ratio
Mass ration between the electron and proton.
Definition Constants.hpp:46
constexpr T pi
Value of pi Usage : auto pi = shamunits::pi<T>;.
Definition Constants.hpp:34
constexpr T fine_structure
Fine structure constant.
Definition Constants.hpp:38
constexpr T proton_electron_ratio
Mass ration between the proton and electron.
Definition Constants.hpp:42
constexpr Tret get(Unit< Tu > u, int power) const noexcept
get(u) raised to a runtime power: the Python path, Constants(usys).G(power=2)
Definition Constants.hpp:81
constexpr Constants(const UnitSystem< T > units)
Construct the shamunits::Constants class with a unit system.
Definition Constants.hpp:64
constexpr Tret get(Unit< Tu > u) const noexcept
Value of a constant only known at run time, e.g. get(constants::from_name("G")).
Definition Constants.hpp:75
constexpr Tret get() const noexcept
Definition Constants.hpp:69
const UnitSystem< T > units
Current unit system of the constants.
Definition Constants.hpp:61
A unit: its dimension and its magnitude expressed in SI base units, in precision Tscal.
Definition Unit.hpp:89