From 63463e7a35f5de69c00c6cdfdd5396033fcd205e Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 24 Feb 2020 20:46:21 +0100 Subject: [PATCH] Total energy example slightly refactored --- example/total_energy.cpp | 41 ++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/example/total_energy.cpp b/example/total_energy.cpp index 5eb4e732..f4120879 100644 --- a/example/total_energy.cpp +++ b/example/total_energy.cpp @@ -40,38 +40,47 @@ Energy AUTO total_energy(Momentum AUTO p, Mass AUTO m, Velocity AUTO c) void si_example() { using namespace si; + using GeV = gigaelectronvolt; + + constexpr Velocity AUTO c = speed_of_light; + + std::cout << "\n*** SI units (c = " << c << ") ***\n"; const Momentum AUTO p = 4.q_GeV / speed_of_light; - const momentum p_si = p; const Mass AUTO m = 3.q_GeV / pow<2>(speed_of_light); - const mass m_si = m; - const Velocity AUTO c = speed_of_light; const Energy AUTO E = total_energy(p, m, c); + + std::cout << "[in GeV]\n" + << "p = " << p << "\n" + << "m = " << m << "\n" + << "E = " << E << "\n"; + + const momentum p_si = p; + const mass m_si = m; const energy E_si = total_energy(p_si, m_si, c); - std::cout << "p = " << p << "\n" - << "p_si = " << p_si << "\n" - << "m = " << m << "\n" - << "m_si = " << m_si << "\n" - << "c = " << c << "\n" - << "E = " << E << "\n" - << "E_si = " << E_si << "\n" - << "E_GeV = " << quantity_cast(E_si) << "\n"; + std::cout << "\n[in SI units]\n" + << "p = " << p_si << "\n" + << "m = " << m_si << "\n" + << "E = " << E_si << "\n"; + + std::cout << "\n[converted from SI units back to GeV]\n" + << "E = " << quantity_cast(E_si) << "\n"; } void natural_example() { using namespace natural; + using GeV = gigaelectronvolt; - const momentum p(4); - const mass m(3); - const 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); - std::cout << "\nNatural units:\n" + std::cout << "\n*** Natural units (c = " << c << ") ***\n" << "p = " << p << "\n" << "m = " << m << "\n" - << "c = " << c << "\n" << "E = " << E << "\n"; }