From 45888ac44e9fdeda18321fc4a61b77699cb05e18 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 17 Mar 2020 17:13:18 +0100 Subject: [PATCH] Physical constants support redesigned --- example/box_example.cpp | 2 +- example/total_energy.cpp | 8 ++-- .../units/physical/natural/constants.h | 3 +- src/include/units/physical/si/constants.h | 40 ++++++++++++++----- 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/example/box_example.cpp b/example/box_example.cpp index 17f59401..1bc7a5ba 100644 --- a/example/box_example.cpp +++ b/example/box_example.cpp @@ -20,7 +20,7 @@ using N = si::newton; using m3 = si::cubic_metre; using kgpm3 = si::kilogram_per_metre_cub; -inline constexpr auto g = si::standard_gravity; +inline constexpr auto g = si::si2019::standard_gravity<>; } // namespace diff --git a/example/total_energy.cpp b/example/total_energy.cpp index f4120879..79d59e52 100644 --- a/example/total_energy.cpp +++ b/example/total_energy.cpp @@ -42,12 +42,12 @@ void si_example() using namespace si; using GeV = gigaelectronvolt; - constexpr Velocity AUTO c = speed_of_light; + constexpr Velocity AUTO c = si2019::speed_of_light<>; std::cout << "\n*** SI units (c = " << c << ") ***\n"; - const Momentum AUTO p = 4.q_GeV / speed_of_light; - const Mass AUTO m = 3.q_GeV / pow<2>(speed_of_light); + const Momentum AUTO p = 4.q_GeV / c; + const Mass AUTO m = 3.q_GeV / pow<2>(c); const Energy AUTO E = total_energy(p, m, c); std::cout << "[in GeV]\n" @@ -73,7 +73,7 @@ void natural_example() using namespace natural; using GeV = gigaelectronvolt; - constexpr Velocity AUTO c = speed_of_light; + constexpr Velocity AUTO c = speed_of_light<>; const momentum p(4); const mass m(3); const Energy AUTO E = total_energy(p, m, c); diff --git a/src/include/units/physical/natural/constants.h b/src/include/units/physical/natural/constants.h index 4de79f28..e8350da8 100644 --- a/src/include/units/physical/natural/constants.h +++ b/src/include/units/physical/natural/constants.h @@ -26,6 +26,7 @@ namespace units::natural { -inline constexpr auto speed_of_light = velocity(1); +template +inline constexpr auto speed_of_light = velocity(1); } // namespace units::natural diff --git a/src/include/units/physical/si/constants.h b/src/include/units/physical/si/constants.h index 7135aad1..ed19febd 100644 --- a/src/include/units/physical/si/constants.h +++ b/src/include/units/physical/si/constants.h @@ -23,24 +23,44 @@ #pragma once #include -#include #include +#include #include #include -#include #include +#include namespace units::si { -inline constexpr auto planck_constant = 6.62607015e-34q_J * 1q_s; -inline constexpr auto reduced_planck_constant = 6.582119569e-10q_GeV * 1q_s; -inline constexpr auto elementary_charge = 1.602176634e-19q_C; -inline constexpr auto boltzmann_constant = 1.380649e-23q_J / 1q_K; -inline constexpr auto avogadro_constant = 6.02214076e23 / 1q_mol; -inline constexpr auto speed_of_light = 299792458q_m_per_s; -inline constexpr auto hyperfine_structure_transition_frequency = 9192631770q_Hz; +namespace si2019 { + +template +inline constexpr auto planck_constant = energy(6.62607015e-34) * time(1); + +template +inline constexpr auto reduced_planck_constant = energy(6.582119569e-10) * time(1); + +template +inline constexpr auto elementary_charge = electric_charge(1.602176634e-19); + +template +inline constexpr auto boltzmann_constant = energy(1.380649e-23) / temperature(1); + +template +inline constexpr auto avogadro_constant = Rep(6.02214076e23) / substance(1); + +template +inline constexpr auto speed_of_light = velocity(299792458); + +template +inline constexpr auto hyperfine_structure_transition_frequency = frequency(9192631770); + +// template // inline constexpr auto luminous_efficacy = 683q_lm / 1q_W; -inline constexpr auto standard_gravity = 9.80665q_m_per_s2; +template +inline constexpr auto standard_gravity = acceleration(9.80665); + +} // namespace si2019 } // namespace units::si