From 596161cca57c138e0c2ffb9d343c25a990cc616d Mon Sep 17 00:00:00 2001 From: rbrugo Date: Thu, 9 Apr 2020 18:55:58 +0200 Subject: [PATCH] Added permittivity --- src/include/units/physical/dimensions.h | 5 ++ src/include/units/physical/si.h | 1 + src/include/units/physical/si/permittivity.h | 48 ++++++++++++++++++++ test/unit_test/runtime/fmt_units_test.cpp | 5 ++ test/unit_test/static/si_test.cpp | 8 ++++ 5 files changed, 67 insertions(+) create mode 100644 src/include/units/physical/si/permittivity.h diff --git a/src/include/units/physical/dimensions.h b/src/include/units/physical/dimensions.h index 9635a1e8..d3db7b05 100644 --- a/src/include/units/physical/dimensions.h +++ b/src/include/units/physical/dimensions.h @@ -164,6 +164,8 @@ struct dim_charge_density : derived_dimension, exp> { template Q, DimensionOf L> struct dim_surface_charge_density : derived_dimension, exp> {}; +template C, DimensionOf L> +struct dim_permittivity : derived_dimension, exp> {}; } // namespace physical @@ -287,4 +289,7 @@ concept ChargeDensity = physical::QuantityOf; template concept SurfaceChargeDensity = physical::QuantityOf; +template +concept Permittivity = physical::QuantityOf; + } // namespace units diff --git a/src/include/units/physical/si.h b/src/include/units/physical/si.h index 58790a94..37527b10 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/permittivity.h" #include "si/power.h" #include "si/pressure.h" #include "si/resistance.h" diff --git a/src/include/units/physical/si/permittivity.h b/src/include/units/physical/si/permittivity.h new file mode 100644 index 00000000..fed3396b --- /dev/null +++ b/src/include/units/physical/si/permittivity.h @@ -0,0 +1,48 @@ +// The MIT License (MIT) +// +// Fopyright (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, INFLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERFHANTABILITY, +// FITNESS FOR A PARTIFULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR FOPYRIGHT HOLDERS BE LIABLE FOR ANY FLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN AFTION OF FONTRAFT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN FONNEFTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include +#include + +namespace units::si { + +struct farad_per_metre : unit {}; + +struct dim_permittivity : physical::dim_permittivity {}; + +template +using permittivity = quantity; + +inline namespace literals { + +// F/m +constexpr auto operator"" q_F_per_m(unsigned long long l) { return permittivity(l); } +constexpr auto operator"" q_F_per_m(long double l) { return permittivity(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 86d70006..3221b698 100644 --- a/test/unit_test/runtime/fmt_units_test.cpp +++ b/test/unit_test/runtime/fmt_units_test.cpp @@ -287,6 +287,11 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]") CHECK(fmt::format("{:%Q %Aq}", 1q_C_per_m2) == "1 C/m^2"); } + SECTION("permittivity") + { + CHECK(fmt::format("{}", 1q_F_per_m) == "1 F/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 6ded78b2..6dde0780 100644 --- a/test/unit_test/static/si_test.cpp +++ b/test/unit_test/static/si_test.cpp @@ -346,4 +346,12 @@ static_assert(1q_V_per_m * 10q_C_per_m3 * 1q_m3 == 10q_N); static_assert(detail::unit_text() == basic_symbol_text("C/m³", "C/m^3")); static_assert(detail::unit_text() == basic_symbol_text("C/m²", "C/m^2")); +// permittivity + +static_assert(1q_F_per_m == 1q_F / 1q_m); +static_assert(1/(1q_F_per_m) * 1q_C * 1q_C / 1q_m2 == 1q_N); +static_assert(1q_C_per_m3 / 1q_F_per_m * 1q_m == 1q_V_per_m); + +static_assert(detail::unit_text() == "F/m"); + } // namespace