From 1f27646d4cf51ee23944357406e39abacab374bd Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sun, 27 Jun 2021 11:31:54 +0200 Subject: [PATCH 1/9] extended is_quantity to support quantity-derived classes N.B. inheritance is preferred to composition/delegate class to avoid duplication and also inherent the various required operators ('+','-',..., '+=', ...) for details see discussion #271 --- src/core/include/units/bits/basic_concepts.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/include/units/bits/basic_concepts.h b/src/core/include/units/bits/basic_concepts.h index 4ec56115..94425df1 100644 --- a/src/core/include/units/bits/basic_concepts.h +++ b/src/core/include/units/bits/basic_concepts.h @@ -269,7 +269,7 @@ concept Reference = detail::is_reference; namespace detail { template -inline constexpr bool is_quantity = false; +inline constexpr bool is_quantity = requires { typename T::dimension; typename T::unit; typename T::rep;}; template inline constexpr bool is_quantity_point = false; From 7baaefe813e3fecb306f21ea8e4d77d106f57374 Mon Sep 17 00:00:00 2001 From: "Ralph J. Steinhagen" Date: Sun, 27 Jun 2021 13:42:55 +0200 Subject: [PATCH 2/9] added inheritance unit-test and made is_quantity more specific --- src/core/include/units/bits/basic_concepts.h | 2 +- src/core/include/units/quantity.h | 11 +++++++++++ test/unit_test/static/quantity_test.cpp | 12 ++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/core/include/units/bits/basic_concepts.h b/src/core/include/units/bits/basic_concepts.h index 94425df1..4ec56115 100644 --- a/src/core/include/units/bits/basic_concepts.h +++ b/src/core/include/units/bits/basic_concepts.h @@ -269,7 +269,7 @@ concept Reference = detail::is_reference; namespace detail { template -inline constexpr bool is_quantity = requires { typename T::dimension; typename T::unit; typename T::rep;}; +inline constexpr bool is_quantity = false; template inline constexpr bool is_quantity_point = false; diff --git a/src/core/include/units/quantity.h b/src/core/include/units/quantity.h index 4ed10cf9..3e96e8ba 100644 --- a/src/core/include/units/quantity.h +++ b/src/core/include/units/quantity.h @@ -465,6 +465,17 @@ namespace detail { template inline constexpr bool is_quantity> = true; +template +requires units::is_derived_from_specialization_of && + requires { + typename T::dimension; + typename T::unit; + typename T::rep; + requires Dimension; + requires Unit; + requires Representation; } +inline constexpr bool is_quantity = true; + } // namespace detail } // namespace units diff --git a/test/unit_test/static/quantity_test.cpp b/test/unit_test/static/quantity_test.cpp index 507c6382..13ea23aa 100644 --- a/test/unit_test/static/quantity_test.cpp +++ b/test/unit_test/static/quantity_test.cpp @@ -234,6 +234,18 @@ static_assert(length(2_q_km).number() == 2); static_assert(length(2_q_km).number() == 2000); static_assert(length(1500_q_m).number() == 1.5); +/////////////////////////////////////// +// derived quantities +/////////////////////////////////////// + +template +struct derived_quantity : quantity { + using dimension = typename Q::dimension; + using unit = typename Q::unit; + using rep = Rep; +}; + +static_assert(units::detail::is_quantity, "NTTP type description">>); ///////// // CTAD From 5a1fe99a8edc02daea950679cf202f092ce3c1ca Mon Sep 17 00:00:00 2001 From: "Ralph J. Steinhagen" Date: Tue, 29 Jun 2021 17:33:17 +0200 Subject: [PATCH 3/9] removed superfluous `requires` statement in is_quantity --- src/core/include/units/quantity.h | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/core/include/units/quantity.h b/src/core/include/units/quantity.h index 3e96e8ba..e4a17536 100644 --- a/src/core/include/units/quantity.h +++ b/src/core/include/units/quantity.h @@ -466,14 +466,7 @@ template inline constexpr bool is_quantity> = true; template -requires units::is_derived_from_specialization_of && - requires { - typename T::dimension; - typename T::unit; - typename T::rep; - requires Dimension; - requires Unit; - requires Representation; } +requires units::is_derived_from_specialization_of inline constexpr bool is_quantity = true; } // namespace detail From 0188aa265c184fee7fad59c132ac63de79af978c Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Wed, 28 Jul 2021 11:45:02 +0200 Subject: [PATCH 4/9] build: `force_host_context=True` added for `build_requires` --- conanfile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conanfile.py b/conanfile.py index e3f2cbd8..83df621e 100644 --- a/conanfile.py +++ b/conanfile.py @@ -74,8 +74,8 @@ class UnitsConan(ConanFile): def build_requirements(self): if self._run_tests: - self.build_requires("catch2/2.13.4") - self.build_requires("linear_algebra/0.7.1@conan-oss/stable") + self.build_requires("catch2/2.13.4", force_host_context=True) + self.build_requires("linear_algebra/0.7.1@conan-oss/stable", force_host_context=True) if self.options.build_docs: self.build_requires("doxygen/1.9.1") From 942009f4f0e106374430f13afb0eb73e4c0db69e Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Wed, 28 Jul 2021 13:09:54 +0200 Subject: [PATCH 5/9] ci: "Ubuntu GCC 10.1.0" removed and "10.2.0" renamed to "10.3.0" "Ubuntu GCC 10.1.0" is no longer provided on `ubuntu-18.04` image --- .github/workflows/ci-conan.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index 84052ef7..569d4458 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -44,13 +44,7 @@ jobs: compiler: { type: VISUAL, version: 16, cc: "cl", cxx: "cl" } } - { - name: "Ubuntu GCC 10.1.0", - os: ubuntu-18.04, - compiler: { type: GCC, version: 10, cc: "gcc-10", cxx: "g++-10" }, - lib: "libstdc++11" - } - - { - name: "Ubuntu GCC 10.2.0", + name: "Ubuntu GCC 10.3.0", os: ubuntu-20.04, compiler: { type: GCC, version: 10, cc: "gcc-10", cxx: "g++-10" }, lib: "libstdc++11" From 1cd3c4bafb07c5c8aa7ff4c6b93fb25802358ebf Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Wed, 28 Jul 2021 13:11:11 +0200 Subject: [PATCH 6/9] ci: The same changes applied to "CMake Test Package CI" workflow --- .github/workflows/ci-test-package-cmake.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/ci-test-package-cmake.yml b/.github/workflows/ci-test-package-cmake.yml index be5e46f7..e97c43fa 100644 --- a/.github/workflows/ci-test-package-cmake.yml +++ b/.github/workflows/ci-test-package-cmake.yml @@ -48,13 +48,7 @@ jobs: compiler: { type: VISUAL, version: 16, cc: "", cxx: "" } } - { - name: "Ubuntu GCC 10.1.0", - os: ubuntu-18.04, - compiler: { type: GCC, version: 10, cc: "gcc-10", cxx: "g++-10" }, - lib: "libstdc++11" - } - - { - name: "Ubuntu GCC 10.2.0", + name: "Ubuntu GCC 10.3.0", os: ubuntu-20.04, compiler: { type: GCC, version: 10, cc: "gcc-10", cxx: "g++-10" }, lib: "libstdc++11" From 322cde70b948e184c987dd3fa3eb2aef61b119f5 Mon Sep 17 00:00:00 2001 From: "Ralph J. Steinhagen" Date: Mon, 2 Aug 2021 22:15:54 +0200 Subject: [PATCH 7/9] added HEP specific units and definitions in accordance with https://www.bipm.org/documents/20126/41483022/SI-Brochure-9.pdf#page=147 see also disccusion thread #292 --- src/systems/si/include/units/isq/si/area.h | 33 ++++++++++ src/systems/si/include/units/isq/si/energy.h | 48 ++++++++++++++ src/systems/si/include/units/isq/si/mass.h | 63 +++++++++++++++++++ .../si/include/units/isq/si/momentum.h | 48 ++++++++++++++ test/unit_test/static/quantity_test.cpp | 25 +++++++- 5 files changed, 215 insertions(+), 2 deletions(-) diff --git a/src/systems/si/include/units/isq/si/area.h b/src/systems/si/include/units/isq/si/area.h index 13d21a1a..fe401eae 100644 --- a/src/systems/si/include/units/isq/si/area.h +++ b/src/systems/si/include/units/isq/si/area.h @@ -59,10 +59,22 @@ struct square_zettametre : derived_unit struct square_yottametre : derived_unit {}; struct hectare : alias_unit {}; +struct barn : named_scaled_unit {}; template U, Representation Rep = double> using area = quantity; +namespace hep { +struct yocto_barn : prefixed_unit {}; +struct zepto_barn : prefixed_unit {}; +struct atto_barn : prefixed_unit {}; +struct femto_barn : prefixed_unit {}; +struct pico_barn : prefixed_unit {}; +struct nano_barn : prefixed_unit {}; +struct micro_barn : prefixed_unit {}; +struct milli_barn : prefixed_unit {}; +} + #ifndef UNITS_NO_LITERALS inline namespace literals { @@ -157,6 +169,27 @@ constexpr auto operator"" _q_ha(long double l) { return area(l)); return area(static_cast(l)); } +constexpr auto operator"" _q_yb(long double l) { return area(l); } +constexpr auto operator"" _q_zb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } +constexpr auto operator"" _q_zb(long double l) { return area(l); } +constexpr auto operator"" _q_ab(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } +constexpr auto operator"" _q_ab(long double l) { return area(l); } +constexpr auto operator"" _q_fb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } +constexpr auto operator"" _q_fb(long double l) { return area(l); } +constexpr auto operator"" _q_pb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } +constexpr auto operator"" _q_pb(long double l) { return area(l); } +constexpr auto operator"" _q_nb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } +constexpr auto operator"" _q_nb(long double l) { return area(l); } +constexpr auto operator"" _q_ub(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } +constexpr auto operator"" _q_ub(long double l) { return area(l); } +constexpr auto operator"" _q_mb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } +constexpr auto operator"" _q_mb(long double l) { return area(l); } +constexpr auto operator"" _q_b(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } +constexpr auto operator"" _q_b(long double l) { return area(l); } +} // namespace hep::literals + #endif // UNITS_NO_LITERALS #ifndef UNITS_NO_REFERENCES diff --git a/src/systems/si/include/units/isq/si/energy.h b/src/systems/si/include/units/isq/si/energy.h index ddcbb270..1a17cfeb 100644 --- a/src/systems/si/include/units/isq/si/energy.h +++ b/src/systems/si/include/units/isq/si/energy.h @@ -53,6 +53,7 @@ struct exajoule : prefixed_unit {}; struct zettajoule : prefixed_unit {}; struct yottajoule : prefixed_unit {}; +// N.B. electron charge (and eV) is an exact constant: https://www.bipm.org/documents/20126/41483022/SI-Brochure-9.pdf#page=147 struct electronvolt : named_scaled_unit {}; struct gigaelectronvolt : prefixed_unit {}; @@ -61,6 +62,21 @@ struct dim_energy : isq::dim_energy {} template U, Representation Rep = double> using energy = quantity; +namespace hep { +struct feV : prefixed_unit {}; +struct peV : prefixed_unit {}; +struct neV : prefixed_unit {}; +struct ueV : prefixed_unit {}; +struct meV : prefixed_unit {}; +struct keV : prefixed_unit {}; +struct MeV : prefixed_unit {}; +using GeV = gigaelectronvolt; +struct TeV : prefixed_unit {}; +struct PeV : prefixed_unit {}; +struct EeV : prefixed_unit {}; +struct YeV : prefixed_unit {}; +} + #ifndef UNITS_NO_LITERALS inline namespace literals { @@ -143,6 +159,38 @@ constexpr auto operator"" _q_GeV(long double l) { return energy(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_feV(long double l) { return energy(l); } +constexpr auto operator"" _q_peV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_peV(long double l) { return energy(l); } +constexpr auto operator"" _q_neV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_neV(long double l) { return energy(l); } +constexpr auto operator"" _q_ueV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_ueV(long double l) { return energy(l); } +constexpr auto operator"" _q_meV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_meV(long double l) { return energy(l); } + +constexpr auto operator"" _q_eV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_eV(long double l) { return energy(l); } + +constexpr auto operator"" _q_keV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_keV(long double l) { return energy(l); } +constexpr auto operator"" _q_MeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_MeV(long double l) { return energy(l); } +constexpr auto operator"" _q_GeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_GeV(long double l) { return energy(l); } +constexpr auto operator"" _q_TeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_TeV(long double l) { return energy(l); } +constexpr auto operator"" _q_PeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_PeV(long double l) { return energy(l); } +constexpr auto operator"" _q_EeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_EeV(long double l) { return energy(l); } +constexpr auto operator"" _q_YeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_YeV(long double l) { return energy(l); } +} // hep::literals + #endif // UNITS_NO_LITERALS #ifndef UNITS_NO_REFERENCES diff --git a/src/systems/si/include/units/isq/si/mass.h b/src/systems/si/include/units/isq/si/mass.h index a13c4047..8966fffb 100644 --- a/src/systems/si/include/units/isq/si/mass.h +++ b/src/systems/si/include/units/isq/si/mass.h @@ -85,6 +85,25 @@ struct dim_mass : isq::dim_mass {}; template U, Representation Rep = double> using mass = quantity; +namespace hep { +struct eV_per_c2 : named_scaled_unit {}; +struct feV_per_c2 : prefixed_unit {}; +struct peV_per_c2 : prefixed_unit {}; +struct neV_per_c2 : prefixed_unit {}; +struct ueV_per_c2 : prefixed_unit {}; +struct meV_per_c2 : prefixed_unit {}; // approximate mass of an electron/positron (0.511 MeV/c2) +struct keV_per_c2 : prefixed_unit {}; +struct MeV_per_c2 : prefixed_unit {}; +struct GeV_per_c2 : prefixed_unit {}; // approximate mass of a proton (0.938 GeV/c2) or neutron +struct TeV_per_c2 : prefixed_unit {}; +struct PeV_per_c2 : prefixed_unit {}; +struct EeV_per_c2 : prefixed_unit {}; +struct YeV_per_c2 : prefixed_unit {}; +struct electron_mass : named_scaled_unit {}; +struct proton_mass : named_scaled_unit {}; +struct neutron_mass : named_scaled_unit {}; +} // namespace hep + #ifndef UNITS_NO_LITERALS inline namespace literals { @@ -262,8 +281,52 @@ constexpr auto operator"" _q_Yt(long double l) { return mass(l)); return mass(static_cast(l)); } constexpr auto operator"" _q_Da(long double l) { return mass(l); } +namespace units::isq::inline si::inline hep::literals { + +} + } // namespace literals +namespace hep::literals { +constexpr auto operator"" _q_feV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_feV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_peV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_peV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_neV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_neV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_ueV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_ueV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_meV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_meV_per_c2(long double l) { return mass(l); } + +// eV_per_c2 +constexpr auto operator"" _q_eV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_eV_per_c2(long double l) { return mass(l); } + +constexpr auto operator"" _q_keV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_keV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_MeV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_MeV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_GeV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_GeV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_TeV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_TeV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_PeV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_PeV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_EeV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_EeV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_YeV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_YeV_per_c2(long double l) { return mass(l); } + +// special HEP masses +constexpr auto operator"" _q_electron_mass(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_electron_mass(long double l) { return mass(l); } +constexpr auto operator"" _q_proton_mass(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_proton_mass(long double l) { return mass(l); } +constexpr auto operator"" _q_neutron_mass(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_neutron_mass(long double l) { return mass(l); } +} // namespace hep::literals + #endif // UNITS_NO_LITERALS #ifndef UNITS_NO_REFERENCES diff --git a/src/systems/si/include/units/isq/si/momentum.h b/src/systems/si/include/units/isq/si/momentum.h index 28151b6f..9c74f513 100644 --- a/src/systems/si/include/units/isq/si/momentum.h +++ b/src/systems/si/include/units/isq/si/momentum.h @@ -40,6 +40,22 @@ struct dim_momentum : isq::dim_momentum U, Representation Rep = double> using momentum = quantity; +namespace hep { +struct eV_per_c : named_scaled_unit {}; +struct feV_per_c : prefixed_unit {}; +struct peV_per_c : prefixed_unit {}; +struct neV_per_c : prefixed_unit {}; +struct ueV_per_c : prefixed_unit {}; +struct meV_per_c : prefixed_unit {}; +struct keV_per_c : prefixed_unit {}; +struct MeV_per_c : prefixed_unit {}; +struct GeV_per_c : prefixed_unit {}; +struct TeV_per_c : prefixed_unit {}; +struct PeV_per_c : prefixed_unit {}; +struct EeV_per_c : prefixed_unit {}; +struct YeV_per_c : prefixed_unit {}; +} + #ifndef UNITS_NO_LITERALS inline namespace literals { @@ -50,6 +66,38 @@ constexpr auto operator"" _q_kg_m_per_s(long double l) { return momentum(l)); return momentum(static_cast(l)); } + constexpr auto operator"" _q_feV_per_c(long double l) { return momentum(l); } + constexpr auto operator"" _q_peV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } + constexpr auto operator"" _q_peV_per_c(long double l) { return momentum(l); } + constexpr auto operator"" _q_neV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } + constexpr auto operator"" _q_neV_per_c(long double l) { return momentum(l); } + constexpr auto operator"" _q_ueV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } + constexpr auto operator"" _q_ueV_per_c(long double l) { return momentum(l); } + constexpr auto operator"" _q_meV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } + constexpr auto operator"" _q_meV_per_c(long double l) { return momentum(l); } + +// eV_per_c + constexpr auto operator"" _q_eV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } + constexpr auto operator"" _q_eV_per_c(long double l) { return momentum(l); } + + constexpr auto operator"" _q_keV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } + constexpr auto operator"" _q_keV_per_c(long double l) { return momentum(l); } + constexpr auto operator"" _q_MeV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } + constexpr auto operator"" _q_MeV_per_c(long double l) { return momentum(l); } + constexpr auto operator"" _q_GeV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } + constexpr auto operator"" _q_GeV_per_c(long double l) { return momentum(l); } + constexpr auto operator"" _q_TeV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } + constexpr auto operator"" _q_TeV_per_c(long double l) { return momentum(l); } + constexpr auto operator"" _q_PeV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } + constexpr auto operator"" _q_PeV_per_c(long double l) { return momentum(l); } + constexpr auto operator"" _q_EeV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } + constexpr auto operator"" _q_EeV_per_c(long double l) { return momentum(l); } + constexpr auto operator"" _q_YeV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } + constexpr auto operator"" _q_YeV_per_c(long double l) { return momentum(l); } +} // namespace hep::literals + #endif // UNITS_NO_LITERALS } // namespace units::isq::si diff --git a/test/unit_test/static/quantity_test.cpp b/test/unit_test/static/quantity_test.cpp index c0b458f6..81d94a86 100644 --- a/test/unit_test/static/quantity_test.cpp +++ b/test/unit_test/static/quantity_test.cpp @@ -238,14 +238,35 @@ static_assert(length(1500_q_m).number() == 1.5); // derived quantities /////////////////////////////////////// -template +template struct derived_quantity : quantity { using dimension = typename Q::dimension; using unit = typename Q::unit; using rep = Rep; + using R = quantity; + + constexpr derived_quantity() : R(){}; + constexpr explicit(!std::is_trivial_v) derived_quantity(const R& t) : R(t) {} + constexpr explicit(!std::is_trivial_v) derived_quantity(R&& t) : R(std::move(t)) {} + + constexpr derived_quantity& operator=(const R& t) { R::operator=(t); return *this; } + constexpr derived_quantity& operator=(R&& t) { R::operator=(std::move(t)); return *this; } + + constexpr operator R&() & noexcept { return *this; } + constexpr operator const R&() const & noexcept { return *this; } + constexpr operator R&&() && noexcept { return *this; } + constexpr operator const R&&() const && noexcept { return *this; } }; -static_assert(units::detail::is_quantity, "NTTP type description">>); +static_assert(detail::is_quantity, "NTTP type description">>); +constexpr isq::Length auto get_length_derived_quantity() noexcept { + derived_quantity, "NTTP type description"> a; + a += 1_q_m; + a = a + 1_q_m; + a *= 0.5; + return a; +} +static_assert(get_length_derived_quantity() == 1_q_m); ///////// // CTAD From cc5318e5cca782e57c0ccfe703bbc60d2818a9ad Mon Sep 17 00:00:00 2001 From: rstein Date: Wed, 4 Aug 2021 13:42:50 +0200 Subject: [PATCH 8/9] refactored HEP units into separate files and corrected namespace where necessary --- src/systems/CMakeLists.txt | 2 + src/systems/si-hep/CMakeLists.txt | 25 +++ .../si-hep/include/units/isq/si/hep/area.h | 104 +++++++++++++ .../si-hep/include/units/isq/si/hep/energy.h | 142 ++++++++++++++++++ .../si-hep/include/units/isq/si/hep/hep.h | 30 ++++ .../si-hep/include/units/isq/si/hep/mass.h | 129 ++++++++++++++++ .../include/units/isq/si/hep/momentum.h | 105 +++++++++++++ src/systems/si/include/units/isq/si/area.h | 33 ---- src/systems/si/include/units/isq/si/energy.h | 47 ------ src/systems/si/include/units/isq/si/mass.h | 63 -------- .../si/include/units/isq/si/momentum.h | 48 ------ test/unit_test/static/CMakeLists.txt | 1 + test/unit_test/static/si_hep_test.cpp | 70 +++++++++ 13 files changed, 608 insertions(+), 191 deletions(-) create mode 100644 src/systems/si-hep/CMakeLists.txt create mode 100644 src/systems/si-hep/include/units/isq/si/hep/area.h create mode 100644 src/systems/si-hep/include/units/isq/si/hep/energy.h create mode 100644 src/systems/si-hep/include/units/isq/si/hep/hep.h create mode 100644 src/systems/si-hep/include/units/isq/si/hep/mass.h create mode 100644 src/systems/si-hep/include/units/isq/si/hep/momentum.h create mode 100644 test/unit_test/static/si_hep_test.cpp diff --git a/src/systems/CMakeLists.txt b/src/systems/CMakeLists.txt index 0b10673c..1285ea83 100644 --- a/src/systems/CMakeLists.txt +++ b/src/systems/CMakeLists.txt @@ -29,6 +29,7 @@ add_subdirectory(isq-natural) add_subdirectory(si) add_subdirectory(si-cgs) add_subdirectory(si-fps) +add_subdirectory(si-hep) add_subdirectory(si-iau) add_subdirectory(si-imperial) add_subdirectory(si-international) @@ -44,6 +45,7 @@ target_link_libraries(mp-units-systems INTERFACE mp-units::si mp-units::si-cgs mp-units::si-fps + mp-units::si-hep mp-units::si-iau mp-units::si-imperial mp-units::si-international diff --git a/src/systems/si-hep/CMakeLists.txt b/src/systems/si-hep/CMakeLists.txt new file mode 100644 index 00000000..0403a82b --- /dev/null +++ b/src/systems/si-hep/CMakeLists.txt @@ -0,0 +1,25 @@ +# The MIT License (MIT) +# +# Copyright (c) 2021 Mateusz Pusz +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +cmake_minimum_required(VERSION 3.15) + +add_units_module(si-hep mp-units::si) diff --git a/src/systems/si-hep/include/units/isq/si/hep/area.h b/src/systems/si-hep/include/units/isq/si/hep/area.h new file mode 100644 index 00000000..2244ffab --- /dev/null +++ b/src/systems/si-hep/include/units/isq/si/hep/area.h @@ -0,0 +1,104 @@ +// The MIT License (MIT) +// +// Copyright (c) 2021 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +// IWYU pragma: begin_exports +#include +#include +#include +#include +// IWYU pragma: end_exports + +#include +#include + +namespace units::isq::si::hep { + +// effective cross-sectional area according to EU council directive 80/181/EEC +// https://eur-lex.europa.eu/legal-content/EN/TXT/PDF/?uri=CELEX:01980L0181-20090527#page=10 +// https://www.fedlex.admin.ch/eli/cc/1994/3109_3109_3109/de +struct barn : named_scaled_unit {}; +struct yocto_barn : prefixed_unit {}; +struct zepto_barn : prefixed_unit {}; +struct atto_barn : prefixed_unit {}; +struct femto_barn : prefixed_unit {}; +struct pico_barn : prefixed_unit {}; +struct nano_barn : prefixed_unit {}; +struct micro_barn : prefixed_unit {}; +struct milli_barn : prefixed_unit {}; + +//template U, Representation Rep = double> +// using area = quantity; + +#ifndef UNITS_NO_LITERALS + +inline namespace literals { +constexpr auto operator"" _q_yb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } +constexpr auto operator"" _q_yb(long double l) { return area(l); } +constexpr auto operator"" _q_zb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } +constexpr auto operator"" _q_zb(long double l) { return area(l); } +constexpr auto operator"" _q_ab(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } +constexpr auto operator"" _q_ab(long double l) { return area(l); } +constexpr auto operator"" _q_fb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } +constexpr auto operator"" _q_fb(long double l) { return area(l); } +constexpr auto operator"" _q_pb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } +constexpr auto operator"" _q_pb(long double l) { return area(l); } +constexpr auto operator"" _q_nb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } +constexpr auto operator"" _q_nb(long double l) { return area(l); } +constexpr auto operator"" _q_ub(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } +constexpr auto operator"" _q_ub(long double l) { return area(l); } +constexpr auto operator"" _q_mb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } +constexpr auto operator"" _q_mb(long double l) { return area(l); } +constexpr auto operator"" _q_b(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } +constexpr auto operator"" _q_b(long double l) { return area(l); } +} // namespace literals + +#endif // UNITS_NO_LITERALS + +#ifndef UNITS_NO_REFERENCES + +namespace area_references { + +inline constexpr auto barn = reference{}; + +} // namespace area_references + +namespace references { + +using namespace area_references; + +} // namespace references + +#endif // UNITS_NO_REFERENCES + +} // namespace units::isq::si::hep + +#ifndef UNITS_NO_ALIASES + +namespace units::aliases::isq::si::hep::inline area { + +template using barn = units::isq::si::hep::area; + +} // namespace units::aliases::isq::si::hep::inline area + +#endif // UNITS_NO_ALIASES diff --git a/src/systems/si-hep/include/units/isq/si/hep/energy.h b/src/systems/si-hep/include/units/isq/si/hep/energy.h new file mode 100644 index 00000000..7fcf36d3 --- /dev/null +++ b/src/systems/si-hep/include/units/isq/si/hep/energy.h @@ -0,0 +1,142 @@ +// The MIT License (MIT) +// +// Copyright (c) 2021 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +// IWYU pragma: begin_exports +#include +#include +#include +#include +#include +// IWYU pragma: end_exports +#include + +namespace units::isq::si::hep { + +// N.B. electron charge (and eV) is an exact constant: https://www.bipm.org/documents/20126/41483022/SI-Brochure-9.pdf#page=147 +struct electronvolt : named_scaled_unit {}; + +struct yeV : prefixed_unit {}; // N.B. very rarely used +struct zeV : prefixed_unit {}; // N.B. very rarely used +struct aeV : prefixed_unit {}; // N.B. very rarely used +struct feV : prefixed_unit {}; +struct peV : prefixed_unit {}; +struct neV : prefixed_unit {}; +struct ueV : prefixed_unit {}; +struct meV : prefixed_unit {}; +using eV = electronvolt; +struct keV : prefixed_unit {}; +struct MeV : prefixed_unit {}; +struct GeV : prefixed_unit {}; +struct TeV : prefixed_unit {}; +struct PeV : prefixed_unit {}; +struct EeV : prefixed_unit {}; // N.B. very rarely used +struct ZeV : prefixed_unit {}; // N.B. very rarely used +struct YeV : prefixed_unit {}; // N.B. very rarely used + +template U, Representation Rep = double> +using energy = quantity; + +#ifndef UNITS_NO_LITERALS + +inline namespace literals { + +constexpr auto operator"" _q_feV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_feV(long double l) { return energy(l); } +constexpr auto operator"" _q_peV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_peV(long double l) { return energy(l); } +constexpr auto operator"" _q_neV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_neV(long double l) { return energy(l); } +constexpr auto operator"" _q_ueV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_ueV(long double l) { return energy(l); } +constexpr auto operator"" _q_meV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_meV(long double l) { return energy(l); } + +constexpr auto operator"" _q_eV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_eV(long double l) { return energy(l); } + +constexpr auto operator"" _q_keV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_keV(long double l) { return energy(l); } +constexpr auto operator"" _q_MeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_MeV(long double l) { return energy(l); } +constexpr auto operator"" _q_GeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_GeV(long double l) { return energy(l); } +constexpr auto operator"" _q_TeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_TeV(long double l) { return energy(l); } +constexpr auto operator"" _q_PeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_PeV(long double l) { return energy(l); } +constexpr auto operator"" _q_EeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_EeV(long double l) { return energy(l); } +constexpr auto operator"" _q_ZeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_ZeV(long double l) { return energy(l); } +constexpr auto operator"" _q_YeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } +constexpr auto operator"" _q_YeV(long double l) { return energy(l); } +} // namespace literals + +#endif // UNITS_NO_LITERALS + +#ifndef UNITS_NO_REFERENCES + +namespace energy_references { + +inline constexpr auto eV = reference{}; + +} // namespace energy_references + +namespace references { + +using namespace energy_references; + +} // namespace references + +#endif // UNITS_NO_REFERENCES + +} // namespace units::isq::si::hep + +#ifndef UNITS_NO_ALIASES + +namespace units::aliases::isq::si::hep::inline energy { + +template using yeV = units::isq::si::hep::energy; +template using zeV = units::isq::si::hep::energy; +template using aeV = units::isq::si::hep::energy; +template using feV = units::isq::si::hep::energy; +template using peV = units::isq::si::hep::energy; +template using neV = units::isq::si::hep::energy; +template using ueV = units::isq::si::hep::energy; +template using meV = units::isq::si::hep::energy; + +template using eV = units::isq::si::hep::energy; + +template using keV = units::isq::si::hep::energy; +template using MeV = units::isq::si::hep::energy; +template using GeV = units::isq::si::hep::energy; +template using TeV = units::isq::si::hep::energy; +template using PeV = units::isq::si::hep::energy; +template using EeV = units::isq::si::hep::energy; +template using ZeV = units::isq::si::hep::energy; +template using YeV = units::isq::si::hep::energy; + +} // namespace units::aliases::isq::si::hep::inline energy + +#endif // UNITS_NO_ALIASES diff --git a/src/systems/si-hep/include/units/isq/si/hep/hep.h b/src/systems/si-hep/include/units/isq/si/hep/hep.h new file mode 100644 index 00000000..3cfb0fa5 --- /dev/null +++ b/src/systems/si-hep/include/units/isq/si/hep/hep.h @@ -0,0 +1,30 @@ +// The MIT License (MIT) +// +// Copyright (c) 2021 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +// IWYU pragma: begin_exports +#include +#include +#include +#include +// IWYU pragma: end_exports diff --git a/src/systems/si-hep/include/units/isq/si/hep/mass.h b/src/systems/si-hep/include/units/isq/si/hep/mass.h new file mode 100644 index 00000000..237d2d74 --- /dev/null +++ b/src/systems/si-hep/include/units/isq/si/hep/mass.h @@ -0,0 +1,129 @@ +// The MIT License (MIT) +// +// Copyright (c) 2021 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +// IWYU pragma: begin_exports +#include +#include +#include +#include +// IWYU pragma: end_exports + +#include +#include + +namespace units::isq::si::hep { + +struct eV_per_c2 : named_scaled_unit {}; +struct feV_per_c2 : prefixed_unit {}; +struct peV_per_c2 : prefixed_unit {}; +struct neV_per_c2 : prefixed_unit {}; +struct ueV_per_c2 : prefixed_unit {}; +struct meV_per_c2 : prefixed_unit {}; // approximate mass of an electron/positron (0.511 MeV/c2) +struct keV_per_c2 : prefixed_unit {}; +struct MeV_per_c2 : prefixed_unit {}; +struct GeV_per_c2 : prefixed_unit {}; // approximate mass of a proton (0.938 GeV/c2) or neutron +struct TeV_per_c2 : prefixed_unit {}; +struct PeV_per_c2 : prefixed_unit {}; +struct EeV_per_c2 : prefixed_unit {}; +struct YeV_per_c2 : prefixed_unit {}; +struct electron_mass : named_scaled_unit {}; +struct proton_mass : named_scaled_unit {}; +struct neutron_mass : named_scaled_unit {}; + +struct dim_mass : isq::dim_mass {}; + +template U, Representation Rep = double> +using mass = quantity; + +#ifndef UNITS_NO_LITERALS + +inline namespace literals { +constexpr auto operator"" _q_feV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_feV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_peV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_peV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_neV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_neV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_ueV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_ueV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_meV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_meV_per_c2(long double l) { return mass(l); } + +// eV_per_c2 +constexpr auto operator"" _q_eV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_eV_per_c2(long double l) { return mass(l); } + +constexpr auto operator"" _q_keV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_keV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_MeV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_MeV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_GeV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_GeV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_TeV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_TeV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_PeV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_PeV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_EeV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_EeV_per_c2(long double l) { return mass(l); } +constexpr auto operator"" _q_YeV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_YeV_per_c2(long double l) { return mass(l); } + +// special HEP masses +constexpr auto operator"" _q_electron_mass(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_electron_mass(long double l) { return mass(l); } +constexpr auto operator"" _q_proton_mass(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_proton_mass(long double l) { return mass(l); } +constexpr auto operator"" _q_neutron_mass(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } +constexpr auto operator"" _q_neutron_mass(long double l) { return mass(l); } +} // namespace literals + +#endif // UNITS_NO_LITERALS + +#ifndef UNITS_NO_REFERENCES + +namespace mass_references { + +inline constexpr auto eV_per_c2 = reference{}; + +} // namespace mass_references + +namespace references { + +using namespace mass_references; + +} // namespace references + +#endif // UNITS_NO_REFERENCES + +} // namespace units::isq::si::hep + +#ifndef UNITS_NO_ALIASES + +namespace units::aliases::isq::si::hep::inline mass { + +template using eV_per_c2g = units::isq::si::hep::mass; + +} // namespace units::aliases::isq::si::hep::inline mass + +#endif // UNITS_NO_ALIASES diff --git a/src/systems/si-hep/include/units/isq/si/hep/momentum.h b/src/systems/si-hep/include/units/isq/si/hep/momentum.h new file mode 100644 index 00000000..aaece772 --- /dev/null +++ b/src/systems/si-hep/include/units/isq/si/hep/momentum.h @@ -0,0 +1,105 @@ +// The MIT License (MIT) +// +// Copyright (c) 2021 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +// IWYU pragma: begin_exports +#include +#include +#include +#include +// IWYU pragma: end_exports + +#include +#include +#include + +namespace units::isq::si::hep { + +struct eV_per_c : named_scaled_unit {}; +struct feV_per_c : prefixed_unit {}; +struct peV_per_c : prefixed_unit {}; +struct neV_per_c : prefixed_unit {}; +struct ueV_per_c : prefixed_unit {}; +struct meV_per_c : prefixed_unit {}; +struct keV_per_c : prefixed_unit {}; +struct MeV_per_c : prefixed_unit {}; +struct GeV_per_c : prefixed_unit {}; +struct TeV_per_c : prefixed_unit {}; +struct PeV_per_c : prefixed_unit {}; +struct EeV_per_c : prefixed_unit {}; +struct YeV_per_c : prefixed_unit {}; + +struct dim_momentum : isq::dim_momentum {}; + +template U, Representation Rep = double> +using momentum = quantity; + +#ifndef UNITS_NO_LITERALS + +inline namespace literals { + +constexpr auto operator"" _q_feV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } +constexpr auto operator"" _q_feV_per_c(long double l) { return momentum(l); } +constexpr auto operator"" _q_peV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } +constexpr auto operator"" _q_peV_per_c(long double l) { return momentum(l); } +constexpr auto operator"" _q_neV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } +constexpr auto operator"" _q_neV_per_c(long double l) { return momentum(l); } +constexpr auto operator"" _q_ueV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } +constexpr auto operator"" _q_ueV_per_c(long double l) { return momentum(l); } +constexpr auto operator"" _q_meV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } +constexpr auto operator"" _q_meV_per_c(long double l) { return momentum(l); } + +// eV_per_c +constexpr auto operator"" _q_eV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } +constexpr auto operator"" _q_eV_per_c(long double l) { return momentum(l); } + +constexpr auto operator"" _q_keV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } +constexpr auto operator"" _q_keV_per_c(long double l) { return momentum(l); } +constexpr auto operator"" _q_MeV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } +constexpr auto operator"" _q_MeV_per_c(long double l) { return momentum(l); } +constexpr auto operator"" _q_GeV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } +constexpr auto operator"" _q_GeV_per_c(long double l) { return momentum(l); } +constexpr auto operator"" _q_TeV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } +constexpr auto operator"" _q_TeV_per_c(long double l) { return momentum(l); } +constexpr auto operator"" _q_PeV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } +constexpr auto operator"" _q_PeV_per_c(long double l) { return momentum(l); } +constexpr auto operator"" _q_EeV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } +constexpr auto operator"" _q_EeV_per_c(long double l) { return momentum(l); } +constexpr auto operator"" _q_YeV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } +constexpr auto operator"" _q_YeV_per_c(long double l) { return momentum(l); } + +} // namespace literals + +#endif // UNITS_NO_LITERALS + +} // namespace units::isq::si + +#ifndef UNITS_NO_ALIASES + +namespace units::aliases::isq::si::inline momentum { + +template using eV_per_c = units::isq::si::hep::momentum; + +} // namespace units::aliases::isq::si::inline momentum + +#endif // UNITS_NO_ALIASES diff --git a/src/systems/si/include/units/isq/si/area.h b/src/systems/si/include/units/isq/si/area.h index fe401eae..13d21a1a 100644 --- a/src/systems/si/include/units/isq/si/area.h +++ b/src/systems/si/include/units/isq/si/area.h @@ -59,22 +59,10 @@ struct square_zettametre : derived_unit struct square_yottametre : derived_unit {}; struct hectare : alias_unit {}; -struct barn : named_scaled_unit {}; template U, Representation Rep = double> using area = quantity; -namespace hep { -struct yocto_barn : prefixed_unit {}; -struct zepto_barn : prefixed_unit {}; -struct atto_barn : prefixed_unit {}; -struct femto_barn : prefixed_unit {}; -struct pico_barn : prefixed_unit {}; -struct nano_barn : prefixed_unit {}; -struct micro_barn : prefixed_unit {}; -struct milli_barn : prefixed_unit {}; -} - #ifndef UNITS_NO_LITERALS inline namespace literals { @@ -169,27 +157,6 @@ constexpr auto operator"" _q_ha(long double l) { return area(l)); return area(static_cast(l)); } -constexpr auto operator"" _q_yb(long double l) { return area(l); } -constexpr auto operator"" _q_zb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } -constexpr auto operator"" _q_zb(long double l) { return area(l); } -constexpr auto operator"" _q_ab(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } -constexpr auto operator"" _q_ab(long double l) { return area(l); } -constexpr auto operator"" _q_fb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } -constexpr auto operator"" _q_fb(long double l) { return area(l); } -constexpr auto operator"" _q_pb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } -constexpr auto operator"" _q_pb(long double l) { return area(l); } -constexpr auto operator"" _q_nb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } -constexpr auto operator"" _q_nb(long double l) { return area(l); } -constexpr auto operator"" _q_ub(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } -constexpr auto operator"" _q_ub(long double l) { return area(l); } -constexpr auto operator"" _q_mb(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } -constexpr auto operator"" _q_mb(long double l) { return area(l); } -constexpr auto operator"" _q_b(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return area(static_cast(l)); } -constexpr auto operator"" _q_b(long double l) { return area(l); } -} // namespace hep::literals - #endif // UNITS_NO_LITERALS #ifndef UNITS_NO_REFERENCES diff --git a/src/systems/si/include/units/isq/si/energy.h b/src/systems/si/include/units/isq/si/energy.h index 1a17cfeb..99350d2c 100644 --- a/src/systems/si/include/units/isq/si/energy.h +++ b/src/systems/si/include/units/isq/si/energy.h @@ -62,21 +62,6 @@ struct dim_energy : isq::dim_energy {} template U, Representation Rep = double> using energy = quantity; -namespace hep { -struct feV : prefixed_unit {}; -struct peV : prefixed_unit {}; -struct neV : prefixed_unit {}; -struct ueV : prefixed_unit {}; -struct meV : prefixed_unit {}; -struct keV : prefixed_unit {}; -struct MeV : prefixed_unit {}; -using GeV = gigaelectronvolt; -struct TeV : prefixed_unit {}; -struct PeV : prefixed_unit {}; -struct EeV : prefixed_unit {}; -struct YeV : prefixed_unit {}; -} - #ifndef UNITS_NO_LITERALS inline namespace literals { @@ -159,38 +144,6 @@ constexpr auto operator"" _q_GeV(long double l) { return energy(l)); return energy(static_cast(l)); } -constexpr auto operator"" _q_feV(long double l) { return energy(l); } -constexpr auto operator"" _q_peV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } -constexpr auto operator"" _q_peV(long double l) { return energy(l); } -constexpr auto operator"" _q_neV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } -constexpr auto operator"" _q_neV(long double l) { return energy(l); } -constexpr auto operator"" _q_ueV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } -constexpr auto operator"" _q_ueV(long double l) { return energy(l); } -constexpr auto operator"" _q_meV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } -constexpr auto operator"" _q_meV(long double l) { return energy(l); } - -constexpr auto operator"" _q_eV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } -constexpr auto operator"" _q_eV(long double l) { return energy(l); } - -constexpr auto operator"" _q_keV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } -constexpr auto operator"" _q_keV(long double l) { return energy(l); } -constexpr auto operator"" _q_MeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } -constexpr auto operator"" _q_MeV(long double l) { return energy(l); } -constexpr auto operator"" _q_GeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } -constexpr auto operator"" _q_GeV(long double l) { return energy(l); } -constexpr auto operator"" _q_TeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } -constexpr auto operator"" _q_TeV(long double l) { return energy(l); } -constexpr auto operator"" _q_PeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } -constexpr auto operator"" _q_PeV(long double l) { return energy(l); } -constexpr auto operator"" _q_EeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } -constexpr auto operator"" _q_EeV(long double l) { return energy(l); } -constexpr auto operator"" _q_YeV(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return energy(static_cast(l)); } -constexpr auto operator"" _q_YeV(long double l) { return energy(l); } -} // hep::literals - #endif // UNITS_NO_LITERALS #ifndef UNITS_NO_REFERENCES diff --git a/src/systems/si/include/units/isq/si/mass.h b/src/systems/si/include/units/isq/si/mass.h index 8966fffb..a13c4047 100644 --- a/src/systems/si/include/units/isq/si/mass.h +++ b/src/systems/si/include/units/isq/si/mass.h @@ -85,25 +85,6 @@ struct dim_mass : isq::dim_mass {}; template U, Representation Rep = double> using mass = quantity; -namespace hep { -struct eV_per_c2 : named_scaled_unit {}; -struct feV_per_c2 : prefixed_unit {}; -struct peV_per_c2 : prefixed_unit {}; -struct neV_per_c2 : prefixed_unit {}; -struct ueV_per_c2 : prefixed_unit {}; -struct meV_per_c2 : prefixed_unit {}; // approximate mass of an electron/positron (0.511 MeV/c2) -struct keV_per_c2 : prefixed_unit {}; -struct MeV_per_c2 : prefixed_unit {}; -struct GeV_per_c2 : prefixed_unit {}; // approximate mass of a proton (0.938 GeV/c2) or neutron -struct TeV_per_c2 : prefixed_unit {}; -struct PeV_per_c2 : prefixed_unit {}; -struct EeV_per_c2 : prefixed_unit {}; -struct YeV_per_c2 : prefixed_unit {}; -struct electron_mass : named_scaled_unit {}; -struct proton_mass : named_scaled_unit {}; -struct neutron_mass : named_scaled_unit {}; -} // namespace hep - #ifndef UNITS_NO_LITERALS inline namespace literals { @@ -281,52 +262,8 @@ constexpr auto operator"" _q_Yt(long double l) { return mass(l)); return mass(static_cast(l)); } constexpr auto operator"" _q_Da(long double l) { return mass(l); } -namespace units::isq::inline si::inline hep::literals { - -} - } // namespace literals -namespace hep::literals { -constexpr auto operator"" _q_feV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } -constexpr auto operator"" _q_feV_per_c2(long double l) { return mass(l); } -constexpr auto operator"" _q_peV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } -constexpr auto operator"" _q_peV_per_c2(long double l) { return mass(l); } -constexpr auto operator"" _q_neV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } -constexpr auto operator"" _q_neV_per_c2(long double l) { return mass(l); } -constexpr auto operator"" _q_ueV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } -constexpr auto operator"" _q_ueV_per_c2(long double l) { return mass(l); } -constexpr auto operator"" _q_meV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } -constexpr auto operator"" _q_meV_per_c2(long double l) { return mass(l); } - -// eV_per_c2 -constexpr auto operator"" _q_eV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } -constexpr auto operator"" _q_eV_per_c2(long double l) { return mass(l); } - -constexpr auto operator"" _q_keV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } -constexpr auto operator"" _q_keV_per_c2(long double l) { return mass(l); } -constexpr auto operator"" _q_MeV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } -constexpr auto operator"" _q_MeV_per_c2(long double l) { return mass(l); } -constexpr auto operator"" _q_GeV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } -constexpr auto operator"" _q_GeV_per_c2(long double l) { return mass(l); } -constexpr auto operator"" _q_TeV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } -constexpr auto operator"" _q_TeV_per_c2(long double l) { return mass(l); } -constexpr auto operator"" _q_PeV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } -constexpr auto operator"" _q_PeV_per_c2(long double l) { return mass(l); } -constexpr auto operator"" _q_EeV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } -constexpr auto operator"" _q_EeV_per_c2(long double l) { return mass(l); } -constexpr auto operator"" _q_YeV_per_c2(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } -constexpr auto operator"" _q_YeV_per_c2(long double l) { return mass(l); } - -// special HEP masses -constexpr auto operator"" _q_electron_mass(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } -constexpr auto operator"" _q_electron_mass(long double l) { return mass(l); } -constexpr auto operator"" _q_proton_mass(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } -constexpr auto operator"" _q_proton_mass(long double l) { return mass(l); } -constexpr auto operator"" _q_neutron_mass(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return mass(static_cast(l)); } -constexpr auto operator"" _q_neutron_mass(long double l) { return mass(l); } -} // namespace hep::literals - #endif // UNITS_NO_LITERALS #ifndef UNITS_NO_REFERENCES diff --git a/src/systems/si/include/units/isq/si/momentum.h b/src/systems/si/include/units/isq/si/momentum.h index 9c74f513..28151b6f 100644 --- a/src/systems/si/include/units/isq/si/momentum.h +++ b/src/systems/si/include/units/isq/si/momentum.h @@ -40,22 +40,6 @@ struct dim_momentum : isq::dim_momentum U, Representation Rep = double> using momentum = quantity; -namespace hep { -struct eV_per_c : named_scaled_unit {}; -struct feV_per_c : prefixed_unit {}; -struct peV_per_c : prefixed_unit {}; -struct neV_per_c : prefixed_unit {}; -struct ueV_per_c : prefixed_unit {}; -struct meV_per_c : prefixed_unit {}; -struct keV_per_c : prefixed_unit {}; -struct MeV_per_c : prefixed_unit {}; -struct GeV_per_c : prefixed_unit {}; -struct TeV_per_c : prefixed_unit {}; -struct PeV_per_c : prefixed_unit {}; -struct EeV_per_c : prefixed_unit {}; -struct YeV_per_c : prefixed_unit {}; -} - #ifndef UNITS_NO_LITERALS inline namespace literals { @@ -66,38 +50,6 @@ constexpr auto operator"" _q_kg_m_per_s(long double l) { return momentum(l)); return momentum(static_cast(l)); } - constexpr auto operator"" _q_feV_per_c(long double l) { return momentum(l); } - constexpr auto operator"" _q_peV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } - constexpr auto operator"" _q_peV_per_c(long double l) { return momentum(l); } - constexpr auto operator"" _q_neV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } - constexpr auto operator"" _q_neV_per_c(long double l) { return momentum(l); } - constexpr auto operator"" _q_ueV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } - constexpr auto operator"" _q_ueV_per_c(long double l) { return momentum(l); } - constexpr auto operator"" _q_meV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } - constexpr auto operator"" _q_meV_per_c(long double l) { return momentum(l); } - -// eV_per_c - constexpr auto operator"" _q_eV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } - constexpr auto operator"" _q_eV_per_c(long double l) { return momentum(l); } - - constexpr auto operator"" _q_keV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } - constexpr auto operator"" _q_keV_per_c(long double l) { return momentum(l); } - constexpr auto operator"" _q_MeV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } - constexpr auto operator"" _q_MeV_per_c(long double l) { return momentum(l); } - constexpr auto operator"" _q_GeV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } - constexpr auto operator"" _q_GeV_per_c(long double l) { return momentum(l); } - constexpr auto operator"" _q_TeV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } - constexpr auto operator"" _q_TeV_per_c(long double l) { return momentum(l); } - constexpr auto operator"" _q_PeV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } - constexpr auto operator"" _q_PeV_per_c(long double l) { return momentum(l); } - constexpr auto operator"" _q_EeV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } - constexpr auto operator"" _q_EeV_per_c(long double l) { return momentum(l); } - constexpr auto operator"" _q_YeV_per_c(unsigned long long l) { gsl_ExpectsAudit(std::in_range(l)); return momentum(static_cast(l)); } - constexpr auto operator"" _q_YeV_per_c(long double l) { return momentum(l); } -} // namespace hep::literals - #endif // UNITS_NO_LITERALS } // namespace units::isq::si diff --git a/test/unit_test/static/CMakeLists.txt b/test/unit_test/static/CMakeLists.txt index 0c5b3d9c..2e8d40fe 100644 --- a/test/unit_test/static/CMakeLists.txt +++ b/test/unit_test/static/CMakeLists.txt @@ -57,6 +57,7 @@ add_library(unit_tests_static si_test.cpp si_cgs_test.cpp si_fps_test.cpp + si_hep_test.cpp symbol_text_test.cpp type_list_test.cpp unit_test.cpp diff --git a/test/unit_test/static/si_hep_test.cpp b/test/unit_test/static/si_hep_test.cpp new file mode 100644 index 00000000..b51bd19a --- /dev/null +++ b/test/unit_test/static/si_hep_test.cpp @@ -0,0 +1,70 @@ +// The MIT License (MIT) +// +// Copyright (c) 2021 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include +#include +#include +#include +#include +#include + +namespace { + +using namespace units::isq; + +static_assert(units::detail::quantity_ratio> == units::ratio(1)); + +// mass +static_assert(si::hep::mass(1'000) == si::hep::mass(1)); +static_assert(si::hep::mass(1'000) == si::mass(1)); +static_assert(si::mass(1'000) == si::hep::mass(1)); + +// momentum +static_assert(si::hep::momentum(1'000'000) == si::hep::momentum(1)); +static_assert(si::hep::momentum(1'000'000) == si::momentum(1)); +static_assert(si::momentum(1'000'000) == si::hep::momentum(1)); + +// area +static_assert(si::area(1e28) == si::area(1)); +//static_assert(si::area(1) == si::area(1e-28)); // numeric rounding issues on some platforms + + +namespace hep_literal_test { + +using namespace units::isq::si::hep::literals; + +static_assert(si::hep::energy(1'000) == 1_q_keV); +static_assert(si::hep::energy(1'000'000) == 1_q_MeV); + +static_assert(si::hep::mass(1'000) == 1_q_keV_per_c2); +static_assert(si::hep::mass(1'000'000) == 1_q_MeV_per_c2); + +static_assert(si::hep::momentum(1'000) == 1_q_keV_per_c); +static_assert(si::hep::momentum(1'000'000) == 1_q_MeV_per_c); + +static_assert(si::area(1e-28L) == 1_q_b); +//static_assert(si::hep::area(1e-4L) == 1_q_b); // numeric rounding issues on some platforms +static_assert(si::area(1e-43) == 1_q_fb); + +} + +} From 157da0d068d3f27e7f57c0b2b68055749a7db97c Mon Sep 17 00:00:00 2001 From: "Ralph J. Steinhagen" Date: Sat, 14 Aug 2021 19:57:32 +0200 Subject: [PATCH 9/9] added fixes to address review comments * removed commented code in hep/area.h * added dependency to si-hep in conanfile.py * removed redundant electronvolt definition in hep/energy.h (+ last-minute bug/typo fix) --- conanfile.py | 3 ++- src/systems/si-hep/include/units/isq/si/hep/area.h | 3 --- src/systems/si-hep/include/units/isq/si/hep/energy.h | 6 ++---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/conanfile.py b/conanfile.py index 83df621e..dce9b515 100644 --- a/conanfile.py +++ b/conanfile.py @@ -144,10 +144,11 @@ class UnitsConan(ConanFile): self.cpp_info.components["si"].requires = ["isq"] self.cpp_info.components["si-cgs"].requires = ["si"] self.cpp_info.components["si-fps"].requires = ["si"] + self.cpp_info.components["si-hep"].requires = ["si"] self.cpp_info.components["si-iau"].requires = ["si"] self.cpp_info.components["si-imperial"].requires = ["si"] self.cpp_info.components["si-international"].requires = ["si"] self.cpp_info.components["si-typographic"].requires = ["si"] self.cpp_info.components["si-uscs"].requires = ["si"] self.cpp_info.components["isq-iec80000"].requires = ["si"] - self.cpp_info.components["systems"].requires = ["isq", "isq-natural", "si", "si-cgs", "si-fps", "si-iau", "si-imperial", "si-international", "si-typographic", "si-uscs", "isq-iec80000"] + self.cpp_info.components["systems"].requires = ["isq", "isq-natural", "si", "si-cgs", "si-fps", "si-hep", "si-iau", "si-imperial", "si-international", "si-typographic", "si-uscs", "isq-iec80000"] diff --git a/src/systems/si-hep/include/units/isq/si/hep/area.h b/src/systems/si-hep/include/units/isq/si/hep/area.h index 2244ffab..fa5d8bdb 100644 --- a/src/systems/si-hep/include/units/isq/si/hep/area.h +++ b/src/systems/si-hep/include/units/isq/si/hep/area.h @@ -47,9 +47,6 @@ struct nano_barn : prefixed_unit {}; struct micro_barn : prefixed_unit {}; struct milli_barn : prefixed_unit {}; -//template U, Representation Rep = double> -// using area = quantity; - #ifndef UNITS_NO_LITERALS inline namespace literals { diff --git a/src/systems/si-hep/include/units/isq/si/hep/energy.h b/src/systems/si-hep/include/units/isq/si/hep/energy.h index 7fcf36d3..87f8e9dd 100644 --- a/src/systems/si-hep/include/units/isq/si/hep/energy.h +++ b/src/systems/si-hep/include/units/isq/si/hep/energy.h @@ -32,9 +32,7 @@ #include namespace units::isq::si::hep { - -// N.B. electron charge (and eV) is an exact constant: https://www.bipm.org/documents/20126/41483022/SI-Brochure-9.pdf#page=147 -struct electronvolt : named_scaled_unit {}; +using units::isq::si::electronvolt; struct yeV : prefixed_unit {}; // N.B. very rarely used struct zeV : prefixed_unit {}; // N.B. very rarely used @@ -47,7 +45,7 @@ struct meV : prefixed_unit {}; using eV = electronvolt; struct keV : prefixed_unit {}; struct MeV : prefixed_unit {}; -struct GeV : prefixed_unit {}; +struct GeV : prefixed_unit {}; struct TeV : prefixed_unit {}; struct PeV : prefixed_unit {}; struct EeV : prefixed_unit {}; // N.B. very rarely used