From 14f00ef7759279e89bc7f5459c224b2a08672d11 Mon Sep 17 00:00:00 2001 From: rbrugo Date: Sun, 5 Apr 2020 16:49:19 +0200 Subject: [PATCH] Added inductance --- src/include/units/physical/dimensions.h | 6 ++ src/include/units/physical/si/inductance.h | 68 ++++++++++++++++++++++ test/unit_test/runtime/fmt_units_test.cpp | 8 +++ test/unit_test/static/si_test.cpp | 12 ++++ 4 files changed, 94 insertions(+) create mode 100644 src/include/units/physical/si/inductance.h diff --git a/src/include/units/physical/dimensions.h b/src/include/units/physical/dimensions.h index 2ec529ec..be264f48 100644 --- a/src/include/units/physical/dimensions.h +++ b/src/include/units/physical/dimensions.h @@ -116,6 +116,9 @@ struct dim_magnetic_induction : derived_dimension, exp template B, DimensionOf A> struct dim_magnetic_flux : derived_dimension, exp> {}; +template F, DimensionOf I> +struct dim_inductance : derived_dimension, exp> {}; + } // namespace physical template @@ -187,4 +190,7 @@ concept MagneticInduction = physical::QuantityOf concept MagneticFlux = physical::QuantityOf; +template +concept Inductance = physical::QuantityOf; + } // namespace units diff --git a/src/include/units/physical/si/inductance.h b/src/include/units/physical/si/inductance.h new file mode 100644 index 00000000..d7f13326 --- /dev/null +++ b/src/include/units/physical/si/inductance.h @@ -0,0 +1,68 @@ +// 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 henry : named_unit {}; + +struct millihenry : prefixed_unit {}; +struct microhenry : prefixed_unit {}; +struct nanohenry : prefixed_unit {}; +struct picohenry : prefixed_unit {}; + +struct dim_inductance : physical::dim_inductance {}; + +template +using inductance = quantity; + +inline namespace literals { + +// H +constexpr auto operator"" q_H(unsigned long long l) { return inductance(l); } +constexpr auto operator"" q_H(long double l) { return inductance(l); } + +// mH +constexpr auto operator"" q_mH(unsigned long long l) { return inductance(l); } +constexpr auto operator"" q_mH(long double l) { return inductance(l); } + +// µH +constexpr auto operator"" q_uH(unsigned long long l) { return inductance(l); } +constexpr auto operator"" q_uH(long double l) { return inductance(l); } + +// nH +constexpr auto operator"" q_nH(unsigned long long l) { return inductance(l); } +constexpr auto operator"" q_nH(long double l) { return inductance(l); } + +// pH +constexpr auto operator"" q_pH(unsigned long long l) { return inductance(l); } +constexpr auto operator"" q_pH(long double l) { return inductance(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 5c6ebfb5..91388b8d 100644 --- a/test/unit_test/runtime/fmt_units_test.cpp +++ b/test/unit_test/runtime/fmt_units_test.cpp @@ -41,6 +41,7 @@ #include "units/physical/si/voltage.h" #include "units/physical/si/magnetic_induction.h" #include "units/physical/si/magnetic_flux.h" +#include "units/physical/si/inductance.h" #include "units/format.h" #include @@ -212,6 +213,13 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]") SECTION("magnetic flux") { CHECK(fmt::format("{}", 1q_Wb) == "1 Wb"); + CHECK(fmt::format("{}", 1q_G) == "1 G"); + } + + SECTION("inductance") + { + CHECK(fmt::format("{}", 1q_H) == "1 H"); + CHECK(fmt::format("{}", 1q_mH) == "1 mH"); } SECTION("addition with common ratio") diff --git a/test/unit_test/static/si_test.cpp b/test/unit_test/static/si_test.cpp index 076b3714..dd25f042 100644 --- a/test/unit_test/static/si_test.cpp +++ b/test/unit_test/static/si_test.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include namespace { @@ -213,6 +214,17 @@ static_assert(microweber::symbol == basic_symbol_text("µWb", "uWb")); static_assert(nanoweber::symbol == "nWb"); static_assert(picoweber::symbol == "pWb"); +// inductance + +static_assert(1q_H == 1q_Wb / 1q_A); +static_assert(1q_V == 1q_H * 1q_A / 1q_s); +static_assert(1q_J == 1q_H * 1q_A * 1q_A); + +static_assert(millihenry::symbol == "mH"); +static_assert(microhenry::symbol == basic_symbol_text("µH", "uH")); +static_assert(nanohenry::symbol == "nH"); +static_assert(picohenry::symbol == "pH"); + /* ************** DERIVED DIMENSIONS IN TERMS OF BASE UNITS **************** */ // velocity