Skip to content

Commit

Permalink
physical constants are in and tested.
Browse files Browse the repository at this point in the history
  • Loading branch information
nholthaus committed Feb 7, 2016
1 parent 1eb678d commit c60f7c1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
18 changes: 14 additions & 4 deletions include/units.h
Original file line number Diff line number Diff line change
Expand Up @@ -2479,12 +2479,22 @@ namespace units
static const double PI = 3.14159265358979323846264338327950288419716939937510;

static const unit_t<unit<std::ratio<1>, dimensionless::scalar, std::ratio<1>>> pi(1.0); ///< Ratio of a circle's circumference to its diameter.
static const unit_t<compound_unit<unit<std::ratio<299792458>, length::meters>, inverse<time::seconds>>> 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<compound_unit<cubed<length::meters>, inverse<mass::kilogram>, inverse<squared<time::seconds>>>> G(6.67408e-11); ///< Newtonian constant of gravitation.
static const unit_t<compound_unit<energy::joule, time::seconds>> h(6.626070040e-34); ///< Planck constant.
static const unit_t<unit<std::ratio<4, 10000000>, compound_unit<force::newton, inverse<squared<current::ampere>>>, 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<compound_unit<force::newtons, inverse<squared<current::ampere>>>> mu0(4.0e-7 * PI); ///< vacuum permeability.
static const unit_t<compound_unit<capacitance::farad, inverse<length::meter>>> 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<compound_unit<force::newtons, area::square_meter, inverse<squared<charge::coulomb>>>> 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<compound_unit<energy::joules, inverse<magnetic_field_strength::tesla>>> mu_B(e * h / (4 * pi *m_e)); ///< Bohr magneton.
static const unit_t<inverse<substance::mol>> N_A(6.02214129e23); ///< Avagadro's Number.
static const unit_t<compound_unit<energy::joules, inverse<temperature::kelvin>, inverse<substance::moles>>> R(8.3144621); ///< Gas constant.
static const unit_t<compound_unit<energy::joules, inverse<temperature::kelvin>>> k_B(R / N_A); ///< Boltzmann constant.
static const unit_t<compound_unit<charge::coulomb, inverse<substance::mol>>> F(N_A * e); ///< Faraday constnat.
static const unit_t<compound_unit<power::watts, inverse<area::square_meters>, inverse<squared<squared<temperature::kelvin>>>>> 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
Expand Down
27 changes: 20 additions & 7 deletions unitTests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<compound_unit<watts, inverse<hertz>, inverse<kelvin>>>;

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
Expand All @@ -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);
}
Expand Down

0 comments on commit c60f7c1

Please sign in to comment.