IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 143848b5 authored by ralfulrich's avatar ralfulrich
Browse files

this closes issue 26

parent 7940843b
No related branches found
No related tags found
No related merge requests found
......@@ -8,11 +8,8 @@
#include <typeinfo>
#include <cstdlib>
using namespace phys::units;
using namespace phys::units::io; // support stream << unit
using namespace phys::units::literals; // support unit literals like 5_m;
using namespace fwk;
using namespace fwk::literals; // support unit literals like 5_m;
int main()
{
......@@ -29,7 +26,7 @@ int main()
Point const p1(root, {0_m, 0_m, 0_m}); // the origin of the root CS
Point const p2(cs2, {0_m, 0_m, 0_m}); // the origin of cs2
Vector<length_d> const diff = p2 - p1; // the distance between the points, basically the translation vector given above
Vector<fwk::length_d> const diff = p2 - p1; // the distance between the points, basically the translation vector given above
auto const norm = diff.squaredNorm(); // squared length with the right dimension
// print the components of the vector as given in the different CS
......@@ -46,8 +43,8 @@ int main()
// let's try parallel projections:
auto const v1 = Vector<length_d>(root, {1_m, 1_m, 0_m});
auto const v2 = Vector<length_d>(root, {1_m, 0_m, 0_m});
auto const v1 = Vector<fwk::length_d>(root, {1_m, 1_m, 0_m});
auto const v2 = Vector<fwk::length_d>(root, {1_m, 0_m, 0_m});
auto const v3 = v1.parallelProjectionOnto(v2);
......
......@@ -8,9 +8,8 @@
#include <cstdlib>
#include <iostream>
using namespace phys::units;
using namespace phys::units::io; // support stream << unit
using namespace phys::units::literals; // support unit literals like 5_m;
using namespace fwk;
using namespace fwk::literals; // support unit literals like 5_m;
int main() {
fwk::CoordinateSystem root;
......
......@@ -43,7 +43,7 @@ namespace fwk {
}
auto constexpr GetElectricCharge(Code const p) {
return GetElectricChargeNumber(p) * (phys::units::e);
return GetElectricChargeNumber(p) * (fwk::constants::e);
}
auto const GetName(Code const p) {
......
......@@ -278,7 +278,7 @@ def gen_classes(pythia_db):
string += " public:\n"
string += " static Code GetCode() { return Type; }\n"
string += " static quantity<energy_d> GetMass() { return masses[TypeIndex]; }\n"
string += " static quantity<electric_charge_d> GetCharge() { return phys::units::e*electric_charge[TypeIndex]/3; }\n"
string += " static quantity<electric_charge_d> GetCharge() { return fwk::constants::e*electric_charge[TypeIndex]/3; }\n"
string += " static int GetChargeNumber() { return electric_charge[TypeIndex]/3; }\n"
string += " static std::string GetName() { return names[TypeIndex]; }\n"
string += " static Code GetAntiParticle() { return AntiType; }\n"
......@@ -303,9 +303,8 @@ def inc_start():
string += "#include <array>\n"
string += "#include <cstdint>\n"
# string += "#include <iostream>\n\n"
string += "using namespace phys::units;\n"
string += "using namespace phys::units::literals;\n\n"
string += "namespace fwk { \n\n"
string += "using namespace literals; \n"
string += "namespace particle { \n\n"
string += "typedef int16_t PDGCode;\n\n"
return string
......
......@@ -6,9 +6,7 @@
#include <fwk/ParticleProperties.h>
// using namespace phys::units;
// using namespace phys::units::literals;
using namespace fwk::literals;
using namespace fwk::particle;
TEST_CASE("Particles", "[Particles]") {
......@@ -18,9 +16,9 @@ TEST_CASE("Particles", "[Particles]") {
SECTION("Data") {
REQUIRE(Electron::GetMass() / 0.511_MeV == Approx(1));
REQUIRE(Electron::GetMass() / GetMass(Code::Electron) == Approx(1));
REQUIRE(Electron::GetCharge() / phys::units::e == Approx(-1));
REQUIRE(Positron::GetCharge() / phys::units::e == Approx(+1));
REQUIRE(GetElectricCharge(Positron::GetAntiParticle()) / phys::units::e ==
REQUIRE(Electron::GetCharge() / fwk::constants::e == Approx(-1));
REQUIRE(Positron::GetCharge() / fwk::constants::e == Approx(+1));
REQUIRE(GetElectricCharge(Positron::GetAntiParticle()) / fwk::constants::e ==
Approx(-1));
REQUIRE(Electron::GetName() == "e-");
}
......
......@@ -64,13 +64,12 @@ namespace phys {
namespace fwk {
using namespace phys;
// using namespace phys;
using namespace phys::units;
namespace constants = phys::units::constants;
} // namespace fwk
#endif // PHYS_UNITS_PHYSICAL_CONSTANTS_HPP_INCLUDED
/*
* end of file
*/
#ifndef _include_PhysicalUnits_h_
#define _include_PhysicalUnits_h_
#include <fwk/PhysicalConstants.h>
#include <phys/units/io.hpp>
#include <phys/units/physical_constants.hpp>
#include <phys/units/quantity.hpp>
/**
......@@ -11,29 +12,27 @@
* Define _XeV literals, alowing 10_GeV in the code.
*/
/*using namespace phys::units::io;
using namespace phys::units::literals;*/
namespace phys {
namespace units {
namespace literals {
QUANTITY_DEFINE_SCALING_LITERALS(eV, energy_d, magnitude(eV))
QUANTITY_DEFINE_SCALING_LITERALS(eV, energy_d, magnitude(constants::eV))
}
} // namespace units
} // namespace phys
namespace fwk {
using namespace phys;
using namespace phys::units;
// using namespace phys::units::literals;
//namespace literals = phys::units::literals;
using Length = phys::units::quantity<phys::units::length_d, double>;
using Time = phys::units::quantity<phys::units::time_interval_d, double>;
using Speed = phys::units::quantity<phys::units::speed_d, double>;
using Frequency = phys::units::quantity<phys::units::frequency_d, double>;
using ElectricCharge = phys::units::quantity<phys::units::electric_charge_d, double>;
using Energy = phys::units::quantity<phys::units::energy_d, double>;
//namespace quantity {
using Length = phys::units::quantity<phys::units::length_d, double>;
using Time = phys::units::quantity<phys::units::time_interval_d, double>;
using Speed = phys::units::quantity<phys::units::speed_d, double>;
using Frequency = phys::units::quantity<phys::units::frequency_d, double>;
using ElectricCharge = phys::units::quantity<phys::units::electric_charge_d, double>;
using Energy = phys::units::quantity<phys::units::energy_d, double>;
//} // namespace quantity
} // end namespace fwk
......
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one
// cpp file
#include <catch2/catch.hpp>
#include <fwk/PhysicalUnits.h>
#include <array>
using namespace phys::units;
using namespace phys::units::literals;
using namespace fwk;
using namespace fwk::literals;
TEST_CASE( "PhysicalUnits", "[Units]" ) {
TEST_CASE("PhysicalUnits", "[Units]") {
SECTION("Consistency") {
REQUIRE( 1_m/1_m == Approx(1) );
//REQUIRE_FALSE( 1_m/1_s == 1 ); // static assert
REQUIRE(1_m / 1_m == Approx(1));
// REQUIRE_FALSE( 1_m/1_s == 1 ); // static assert
}
SECTION("Constructors") {
auto E1 = 10_GeV;
REQUIRE( E1==10_GeV );
REQUIRE(E1 == 10_GeV);
quantity<phys::units::length_d> l1 = 10_nm;
quantity<phys::units::length_d> arr0[5];
fwk::Length l1 = 10_nm;
fwk::Length arr0[5];
arr0[0] = 5_m;
quantity<phys::units::length_d> arr1[2] = { {1_mm}, {2_cm} };
std::array<quantity<phys::units::energy_d>, 4> arr2; // empty array
std::array<quantity<phys::units::energy_d>, 4> arr3 = { 1_GeV, 1_eV, 5_MeV };
fwk::Length arr1[2] = {{1_mm}, {2_cm}};
std::array<fwk::Energy, 4> arr2; // empty array
std::array<fwk::Energy, 4> arr3 = {1_GeV, 1_eV, 5_MeV};
}
SECTION("Powers in literal units") {
REQUIRE( 1_s/1_ds == Approx(1e1) );
REQUIRE( 1_m/1_cm == Approx(1e2) );
REQUIRE( 1_m/1_mm == Approx(1e3) );
REQUIRE( 1_V/1_uV == Approx(1e6) );
REQUIRE( 1_s/1_ns == Approx(1e9) );
REQUIRE( 1_eV/1_peV == Approx(1e12) );
REQUIRE( 1_A/1_fA == Approx(1e15) );
REQUIRE( 1_mol/1_amol == Approx(1e18) );
REQUIRE( 1_K/1_zK == Approx(1e21) );
REQUIRE( 1_K/1_yK == Approx(1e24) );
REQUIRE( 1_A/1_hA == Approx(1e-2) );
REQUIRE( 1_m/1_km == Approx(1e-3) );
REQUIRE( 1_m/1_Mm == Approx(1e-6) );
REQUIRE( 1_V/1_GV == Approx(1e-9) );
REQUIRE( 1_s/1_Ts == Approx(1e-12) );
REQUIRE( 1_eV/1_PeV == Approx(1e-15) );
REQUIRE( 1_A/1_EA == Approx(1e-18) );
REQUIRE( 1_K/1_ZK == Approx(1e-21) );
REQUIRE( 1_mol/1_Ymol == Approx(1e-24) );
REQUIRE(1_s / 1_ds == Approx(1e1));
REQUIRE(1_m / 1_cm == Approx(1e2));
REQUIRE(1_m / 1_mm == Approx(1e3));
REQUIRE(1_V / 1_uV == Approx(1e6));
REQUIRE(1_s / 1_ns == Approx(1e9));
REQUIRE(1_eV / 1_peV == Approx(1e12));
REQUIRE(1_A / 1_fA == Approx(1e15));
REQUIRE(1_mol / 1_amol == Approx(1e18));
REQUIRE(1_K / 1_zK == Approx(1e21));
REQUIRE(1_K / 1_yK == Approx(1e24));
REQUIRE(1_A / 1_hA == Approx(1e-2));
REQUIRE(1_m / 1_km == Approx(1e-3));
REQUIRE(1_m / 1_Mm == Approx(1e-6));
REQUIRE(1_V / 1_GV == Approx(1e-9));
REQUIRE(1_s / 1_Ts == Approx(1e-12));
REQUIRE(1_eV / 1_PeV == Approx(1e-15));
REQUIRE(1_A / 1_EA == Approx(1e-18));
REQUIRE(1_K / 1_ZK == Approx(1e-21));
REQUIRE(1_mol / 1_Ymol == Approx(1e-24));
}
SECTION("Powers and units") {
REQUIRE( 1 * ampere / 1_A == Approx(1e0) );
REQUIRE( mega * bar / bar == Approx(1e6) );
REQUIRE(1 * ampere / 1_A == Approx(1e0));
REQUIRE(mega * bar / bar == Approx(1e6));
}
SECTION("Formulas") {
const quantity<phys::units::energy_d> E2 = 20_GeV * 2;
REQUIRE( E2==40_GeV );
const double lgE = log10(E2/1_GeV);
REQUIRE( lgE==Approx(log10(40.)) );
const fwk::Energy E2 = 20_GeV * 2;
REQUIRE(E2 == 40_GeV);
const double lgE = log10(E2 / 1_GeV);
REQUIRE(lgE == Approx(log10(40.)));
const auto E3 = E2 + 100_GeV + pow(10, lgE) * 1_GeV;
REQUIRE( E3==180_GeV );
REQUIRE(E3 == 180_GeV);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment