From 43f475fb80d0a3238e943374416ef0c0c28fdb70 Mon Sep 17 00:00:00 2001 From: rbrugo Date: Tue, 7 Apr 2020 01:46:23 +0200 Subject: [PATCH] Added absorbed dose --- src/include/units/physical/dimensions.h | 6 ++ src/include/units/physical/si/absorbed_dose.h | 58 +++++++++++++++++++ test/unit_test/runtime/fmt_units_test.cpp | 8 +++ test/unit_test/static/si_test.cpp | 13 +++++ 4 files changed, 85 insertions(+) create mode 100644 src/include/units/physical/si/absorbed_dose.h diff --git a/src/include/units/physical/dimensions.h b/src/include/units/physical/dimensions.h index 496d626a..e7ed11a7 100644 --- a/src/include/units/physical/dimensions.h +++ b/src/include/units/physical/dimensions.h @@ -128,6 +128,9 @@ struct dim_conductance : derived_dimension> {}; template T, DimensionOf M> struct dim_catalytic_activity : derived_dimension, exp> {}; +template E, DimensionOf M> +struct dim_absorbed_dose : derived_dimension, exp> {}; + } // namespace physical template @@ -211,4 +214,7 @@ concept Conductance = physical::QuantityOf; template concept CatalyticActivity = physical::QuantityOf; +template +concept AbsorbedDose = physical::QuantityOf; + } // namespace units diff --git a/src/include/units/physical/si/absorbed_dose.h b/src/include/units/physical/si/absorbed_dose.h new file mode 100644 index 00000000..5ee5b719 --- /dev/null +++ b/src/include/units/physical/si/absorbed_dose.h @@ -0,0 +1,58 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 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 + +#include +#include +#include +#include +#include + +namespace units::si { + +struct gray : named_unit {}; +struct milligray : prefixed_unit {}; +struct kilogray : prefixed_unit {}; + +struct dim_absorbed_dose : physical::dim_absorbed_dose {}; + +template +using absorbed_dose = quantity; + +inline namespace literals { + +// G +constexpr auto operator"" q_Gy(unsigned long long l) { return absorbed_dose(l); } +constexpr auto operator"" q_Gy(long double l) { return absorbed_dose(l); } + +// mGy +constexpr auto operator"" q_mGy(unsigned long long l) { return absorbed_dose(l); } +constexpr auto operator"" q_mGy(long double l) { return absorbed_dose(l); } + +// kGy +constexpr auto operator"" q_kGy(unsigned long long l) { return absorbed_dose(l); } +constexpr auto operator"" q_kGy(long double l) { return absorbed_dose(l); } + +} // namespace literals + +} // namespace units::si diff --git a/test/unit_test/runtime/fmt_units_test.cpp b/test/unit_test/runtime/fmt_units_test.cpp index d1c2bd70..3c1216a6 100644 --- a/test/unit_test/runtime/fmt_units_test.cpp +++ b/test/unit_test/runtime/fmt_units_test.cpp @@ -44,6 +44,7 @@ #include "units/physical/si/inductance.h" #include "units/physical/si/conductance.h" #include "units/physical/si/catalytic_activity.h" +#include "units/physical/si/absorbed_dose.h" #include "units/format.h" #include @@ -236,6 +237,13 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]") CHECK(fmt::format("{}", 1q_U) == "1 U"); } + SECTION("absorbed dose") + { + CHECK(fmt::format("{}", 1q_Gy) == "1 Gy"); + CHECK(fmt::format("{}", 1q_kGy) == "1 kGy"); + CHECK(fmt::format("{}", 1q_mGy) == "1 mGy"); + } + SECTION("addition with common ratio") { CHECK(fmt::format("{}", 1q_in + 1q_yd) == "37 in"); diff --git a/test/unit_test/static/si_test.cpp b/test/unit_test/static/si_test.cpp index 6ebd86a7..1d690718 100644 --- a/test/unit_test/static/si_test.cpp +++ b/test/unit_test/static/si_test.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include namespace { @@ -242,6 +243,18 @@ static_assert(nanosiemens::symbol == "nS"); static_assert(1q_kat == 1q_mol / 1q_s); static_assert(1'000'000q_U == 1q_mol / 1q_min); +static_assert(katal::symbol == "kat"); +static_assert(enzyme_unit::symbol == "U"); + +// absorbed dose + +static_assert(1q_Gy == 1q_J / 1q_kg); +static_assert(9.q_W * 3q_s / 60q_kg == 450q_mGy); + +static_assert(gray::symbol == "Gy"); +static_assert(milligray::symbol == "mGy"); +static_assert(kilogray::symbol == "kGy"); + /* ************** DERIVED DIMENSIONS IN TERMS OF BASE UNITS **************** */ // velocity