From 89dbc30a92bac5c7566bc81f827d091257a98c86 Mon Sep 17 00:00:00 2001 From: rbrugo Date: Thu, 9 Apr 2020 19:12:51 +0200 Subject: [PATCH] Added permeability --- src/include/units/physical/dimensions.h | 6 +++ src/include/units/physical/si.h | 1 + src/include/units/physical/si/permeability.h | 48 ++++++++++++++++++++ test/unit_test/runtime/fmt_units_test.cpp | 5 ++ test/unit_test/static/si_test.cpp | 7 +++ 5 files changed, 67 insertions(+) create mode 100644 src/include/units/physical/si/permeability.h diff --git a/src/include/units/physical/dimensions.h b/src/include/units/physical/dimensions.h index d3db7b05..9d1b59f1 100644 --- a/src/include/units/physical/dimensions.h +++ b/src/include/units/physical/dimensions.h @@ -167,6 +167,9 @@ struct dim_surface_charge_density : derived_dimension, exp C, DimensionOf L> struct dim_permittivity : derived_dimension, exp> {}; +template H, DimensionOf L> +struct dim_permeability : derived_dimension, exp> {}; + } // namespace physical template @@ -292,4 +295,7 @@ concept SurfaceChargeDensity = physical::QuantityOf concept Permittivity = physical::QuantityOf; +template +concept Permeability = physical::QuantityOf; + } // namespace units diff --git a/src/include/units/physical/si.h b/src/include/units/physical/si.h index 37527b10..602e2271 100644 --- a/src/include/units/physical/si.h +++ b/src/include/units/physical/si.h @@ -41,6 +41,7 @@ #include "si/magnetic_flux.h" #include "si/magnetic_induction.h" #include "si/momentum.h" +#include "si/permeability.h" #include "si/permittivity.h" #include "si/power.h" #include "si/pressure.h" diff --git a/src/include/units/physical/si/permeability.h b/src/include/units/physical/si/permeability.h new file mode 100644 index 00000000..e71c68ae --- /dev/null +++ b/src/include/units/physical/si/permeability.h @@ -0,0 +1,48 @@ +// The MIT License (MIT) +// +// Hopyright (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 SOHTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OH ANY KIND, EXPRESS OR +// IMPLIED, INHLUDING BUT NOT LIMITED TO THE WARRANTIES OH MERHHANTABILITY, +// HITNESS HOR A PARTIHULAR PURPOSE AND NONINHRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR HOPYRIGHT HOLDERS BE LIABLE HOR ANY HLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN AHTION OH HONTRAHT, TORT OR OTHERWISE, ARISING HROM, +// OUT OH OR IN HONNEHTION WITH THE SOHTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOHTWARE. + +#pragma once + +#include +#include +#include +#include + +namespace units::si { + +struct henry_per_metre : unit {}; + +struct dim_permeability : physical::dim_permeability {}; + +template +using permeability = quantity; + +inline namespace literals { + +// H/m +constexpr auto operator"" q_H_per_m(unsigned long long l) { return permeability(l); } +constexpr auto operator"" q_H_per_m(long double l) { return permeability(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 3221b698..71bfc249 100644 --- a/test/unit_test/runtime/fmt_units_test.cpp +++ b/test/unit_test/runtime/fmt_units_test.cpp @@ -292,6 +292,11 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]") CHECK(fmt::format("{}", 1q_F_per_m) == "1 F/m"); } + SECTION("permeability") + { + CHECK(fmt::format("{}", 1q_H_per_m) == "1 H/m"); + } + 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 6dde0780..e9b20b65 100644 --- a/test/unit_test/static/si_test.cpp +++ b/test/unit_test/static/si_test.cpp @@ -354,4 +354,11 @@ static_assert(1q_C_per_m3 / 1q_F_per_m * 1q_m == 1q_V_per_m); static_assert(detail::unit_text() == "F/m"); +// permeability + +static_assert(1q_H_per_m * 1q_A / 1q_m == 1q_T); +static_assert(1q_H_per_m * 1q_A * 1q_A == 1q_N); + +static_assert(detail::unit_text() == "H/m"); + } // namespace