From 8ddd7e123399d7b7b373aa5ab61abc4ed4d2695c Mon Sep 17 00:00:00 2001 From: rbrugo Date: Tue, 7 Apr 2020 23:20:54 +0200 Subject: [PATCH] Added concentration --- src/include/units/physical/dimensions.h | 6 +++ src/include/units/physical/si.h | 1 + src/include/units/physical/si/concentration.h | 47 +++++++++++++++++++ test/unit_test/runtime/fmt_units_test.cpp | 6 +++ test/unit_test/static/si_test.cpp | 7 ++- 5 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 src/include/units/physical/si/concentration.h diff --git a/src/include/units/physical/dimensions.h b/src/include/units/physical/dimensions.h index 9a6bf108..350d0fcf 100644 --- a/src/include/units/physical/dimensions.h +++ b/src/include/units/physical/dimensions.h @@ -134,6 +134,9 @@ struct dim_absorbed_dose : derived_dimension, exp> {} template I, DimensionOf L> struct dim_current_density : derived_dimension, exp> {}; +template M, DimensionOf L> +struct dim_concentration : derived_dimension, exp> {}; + } // namespace physical template @@ -223,4 +226,7 @@ concept AbsorbedDose = physical::QuantityOf; template concept CurrentDensity = physical::QuantityOf; +template +concept Concentration = physical::QuantityOf; + } // namespace units diff --git a/src/include/units/physical/si.h b/src/include/units/physical/si.h index 8781f985..4269572a 100644 --- a/src/include/units/physical/si.h +++ b/src/include/units/physical/si.h @@ -26,6 +26,7 @@ #include "si/area.h" #include "si/capacitance.h" #include "si/catalytic_activity.h" +#include "si/concentration.h" #include "si/conductance.h" #include "si/constants.h" #include "si/current_density.h" diff --git a/src/include/units/physical/si/concentration.h b/src/include/units/physical/si/concentration.h new file mode 100644 index 00000000..f566b9f3 --- /dev/null +++ b/src/include/units/physical/si/concentration.h @@ -0,0 +1,47 @@ +// 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 + +namespace units::si { + +struct mol_per_metre_cub : unit {}; +struct dim_concentration : physical::dim_concentration {}; + +template +using concentration = quantity; + +inline namespace literals { + +// mol/m³ +constexpr auto operator"" q_mol_per_m3(unsigned long long l) { return concentration(l); } +constexpr auto operator"" q_mol_per_m3(long double l) { return concentration(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 bd7a6c6e..0bfe6bbb 100644 --- a/test/unit_test/runtime/fmt_units_test.cpp +++ b/test/unit_test/runtime/fmt_units_test.cpp @@ -239,6 +239,12 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]") CHECK(fmt::format("{:%Q %Aq}", 1q_A_per_m2) == "1 A/m^2"); } + SECTION("concentration") + { + CHECK(fmt::format("{}", 1q_mol_per_m3) == "1 mol/m³"); + CHECK(fmt::format("{:%Q %Aq}", 1q_mol_per_m3) == "1 mol/m^3"); + } + SECTION("incoherent units with powers") { CHECK(fmt::format("{}", 1q_mi * 1q_mi * 1q_mi) == "1 [15900351812136/3814697265625 × 10⁹] m³"); diff --git a/test/unit_test/static/si_test.cpp b/test/unit_test/static/si_test.cpp index 2a7bb62c..422baa0f 100644 --- a/test/unit_test/static/si_test.cpp +++ b/test/unit_test/static/si_test.cpp @@ -297,8 +297,11 @@ static_assert(detail::unit_text() == "N/m static_assert(12q_A_per_m2 == 60q_A / 5q_m2); static_assert(1q_A_per_m2 == 1q_S * 1q_V / 1q_m2); -/* #warning FIX THIS */ -/* static_assert(detail::unit_text() == basic_symbol_text("A · m²", "A/m^2")); */ +static_assert(detail::unit_text() == basic_symbol_text("A/m²", "A/m^2")); +// concentration + +static_assert(1q_mol_per_m3 == 1q_kg_per_m3 * 1q_mol / 1q_kg); +static_assert(detail::unit_text() == basic_symbol_text("mol/m³", "mol/m^2")); } // namespace