From cc5318e5cca782e57c0ccfe703bbc60d2818a9ad Mon Sep 17 00:00:00 2001 From: rstein Date: Wed, 4 Aug 2021 13:42:50 +0200 Subject: [PATCH] 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); + +} + +}