From c60f7c1cfe744948930883017ca8749c7f37d031 Mon Sep 17 00:00:00 2001 From: nholthaus Date: Sun, 7 Feb 2016 14:04:30 -0500 Subject: [PATCH] physical constants are in and tested. --- include/units.h | 18 ++++++++++++++---- unitTests/main.cpp | 27 ++++++++++++++++++++------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/include/units.h b/include/units.h index 92d31fd5..d5e3bd5e 100644 --- a/include/units.h +++ b/include/units.h @@ -2479,12 +2479,22 @@ namespace units static const double PI = 3.14159265358979323846264338327950288419716939937510; static const unit_t, dimensionless::scalar, std::ratio<1>>> pi(1.0); ///< Ratio of a circle's circumference to its diameter. - static const unit_t, length::meters>, inverse>> c(1.0); ///< Speed of light in vacuum. + static const velocity::meters_per_second_t c(299792458.0); ///< Speed of light in vacuum. static const unit_t, inverse, inverse>>> G(6.67408e-11); ///< Newtonian constant of gravitation. static const unit_t> h(6.626070040e-34); ///< Planck constant. - static const unit_t, compound_unit>>, std::ratio<1>>> mu0(1.0); ///< vacuum permeability. - static const auto epsilon0 = 1.0 / (mu0 * units::pow<2>(c)); ///< vacuum permitivity. - + static const unit_t>>> mu0(4.0e-7 * PI); ///< vacuum permeability. + static const unit_t>> epsilon0(1.0 / (mu0 * units::pow<2>(c))); ///< vacuum permitivity. + static const impedance::ohm_t Z0(mu0 * c); ///< characteristic impedance of vacuum. + static const unit_t>>> k_e(1.0 / (4 * pi * epsilon0)); ///< Coulomb's constant. + static const charge::coulomb_t e(1.602176565e-19); ///< elementary charge. + static const mass::kilogram_t m_e(9.10938291e-31); ///< electron mass. + static const mass::kilogram_t m_p(1.672621777e-27); ///< proton mass. + static const unit_t>> mu_B(e * h / (4 * pi *m_e)); ///< Bohr magneton. + static const unit_t> N_A(6.02214129e23); ///< Avagadro's Number. + static const unit_t, inverse>> R(8.3144621); ///< Gas constant. + static const unit_t>> k_B(R / N_A); ///< Boltzmann constant. + static const unit_t>> F(N_A * e); ///< Faraday constnat. + static const unit_t, inverse>>>> sigma((2 * pow<5>(pi) * pow<4>(R)) / (15 * pow<3>(h) * pow<2>(c) * pow<4>(N_A))); ///< Stefan-Boltzmann constant. } }; // end namespace units diff --git a/unitTests/main.cpp b/unitTests/main.cpp index 4bca0616..be7624b9 100644 --- a/unitTests/main.cpp +++ b/unitTests/main.cpp @@ -1380,22 +1380,35 @@ TEST_F(UnitTest, concentrationConversion) TEST_F(UnitTest, testConstants) { - EXPECT_NEAR(299792458, meters_per_second_t(constants::c)(), 5.0e-9); + // scalar constants EXPECT_NEAR(3.14159, constants::pi, 5.0e-6); -// EXPECT_NEAR(6.67408e-11, constants::G, 5.0e-17); -// EXPECT_NEAR(6.626070040e-34, constants::h, 5.0e-44); -// EXPECT_NEAR(8.854e-12, unit_t<>(constants::epsilon0()), 5.0e-15); + + // constants with units + EXPECT_NEAR(299792458, constants::c(), 5.0e-9); + EXPECT_NEAR(6.67408e-11, constants::G(), 5.0e-17); + EXPECT_NEAR(6.626070040e-34, constants::h(), 5.0e-44); + EXPECT_NEAR(1.256637061e-6, constants::mu0(), 5.0e-16); + EXPECT_NEAR(8.854187817e-12, constants::epsilon0(), 5.0e-21); + EXPECT_NEAR(376.73031346177, constants::Z0(), 5.0e-12); + EXPECT_NEAR(8.987551787e9, constants::k_e(), 5.0e-1); + EXPECT_NEAR(1.602176565e-19, constants::e(), 5.0e-29); + EXPECT_NEAR(9.10938291e-31, constants::m_e(), 5.0e-40); + EXPECT_NEAR(1.672621777e-27, constants::m_p(), 5.0e-37); + EXPECT_NEAR(9.27400968e-24, constants::mu_B(), 5.0e-30); + EXPECT_NEAR(6.02214129e23, constants::N_A(), 5.0e14); + EXPECT_NEAR(8.3144621, constants::R(), 5.0e-8); + EXPECT_NEAR(1.3806488e-23, constants::k_B(), 5.0e-31); + EXPECT_NEAR(96485.3365, constants::F(), 5.0e-5); + EXPECT_NEAR(5.670373e-8, constants::sigma(), 5.0e-14); } TEST_F(UnitTest, radarRangeEquation) { - using Boltzmann = unit_t, inverse>>; watt_t P_t; // transmit power scalar_t G; // gain meter_t lambda; // wavelength square_meter_t sigma; // radar cross section - const Boltzmann k(1.38e-23); // Boltzmann constant meter_t R; // range kelvin_t T_s; // system noise temp hertz_t B_n; // bandwidth @@ -1411,7 +1424,7 @@ TEST_F(UnitTest, radarRangeEquation) L = dB_t(8.0); scalar_t SNR = (P_t * units::pow<2>(G) * units::pow<2>(lambda) * sigma) / - (units::pow<3>(4 * constants::pi) * units::pow<4>(R) * k * T_s * B_n * L); + (units::pow<3>(4 * constants::pi) * units::pow<4>(R) * constants::k_B * T_s * B_n * L); EXPECT_NEAR(1.535, SNR(), 5.0e-4); }