diff --git a/conanfile.py b/conanfile.py index 80e3a1a0..e25ccb17 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/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..fa5d8bdb --- /dev/null +++ b/src/systems/si-hep/include/units/isq/si/hep/area.h @@ -0,0 +1,101 @@ +// 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 {}; + +#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..87f8e9dd --- /dev/null +++ b/src/systems/si-hep/include/units/isq/si/hep/energy.h @@ -0,0 +1,140 @@ +// 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 { +using units::isq::si::electronvolt; + +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/energy.h b/src/systems/si/include/units/isq/si/energy.h index ddcbb270..99350d2c 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 {}; 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/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 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); + +} + +}