diff --git a/src/include/units/physical/dimensions.h b/src/include/units/physical/dimensions.h index be264f48..eaec5174 100644 --- a/src/include/units/physical/dimensions.h +++ b/src/include/units/physical/dimensions.h @@ -119,6 +119,9 @@ struct dim_magnetic_flux : derived_dimension, exp> {}; template F, DimensionOf I> struct dim_inductance : derived_dimension, exp> {}; +template R> +struct dim_conductance : derived_dimension> {}; + } // namespace physical template @@ -193,4 +196,7 @@ concept MagneticFlux = physical::QuantityOf; template concept Inductance = physical::QuantityOf; +template +concept Conductance = physical::QuantityOf; + } // namespace units diff --git a/src/include/units/physical/si/conductance.h b/src/include/units/physical/si/conductance.h new file mode 100644 index 00000000..44ca2021 --- /dev/null +++ b/src/include/units/physical/si/conductance.h @@ -0,0 +1,63 @@ +// 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 siemens : named_unit {}; +struct millisiemens : prefixed_unit {}; +struct microsiemens : prefixed_unit {}; +struct nanosiemens : prefixed_unit {}; + +struct dim_conductance : physical::dim_conductance {}; + +template +using conductance = quantity; + +inline namespace literals { + +// R +constexpr auto operator"" q_S(unsigned long long l) { return conductance(l); } +constexpr auto operator"" q_S(long double l) { return conductance(l); } + +// mS +constexpr auto operator"" q_mS(unsigned long long l) { return conductance(l); } +constexpr auto operator"" q_mS(long double l) { return conductance(l); } + +// µS +constexpr auto operator"" q_uS(unsigned long long l) { return conductance(l); } +constexpr auto operator"" q_uS(long double l) { return conductance(l); } + +// nS +constexpr auto operator"" q_nS(unsigned long long l) { return conductance(l); } +constexpr auto operator"" q_nS(long double l) { return conductance(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 91388b8d..1b298a8e 100644 --- a/test/unit_test/runtime/fmt_units_test.cpp +++ b/test/unit_test/runtime/fmt_units_test.cpp @@ -42,6 +42,7 @@ #include "units/physical/si/magnetic_induction.h" #include "units/physical/si/magnetic_flux.h" #include "units/physical/si/inductance.h" +#include "units/physical/si/conductance.h" #include "units/format.h" #include @@ -222,6 +223,12 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]") CHECK(fmt::format("{}", 1q_mH) == "1 mH"); } + SECTION("conductance") + { + CHECK(fmt::format("{}", 1q_S) == "1 S"); + CHECK(fmt::format("{}", 1q_nS) == "1 nS"); + } + 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 dd25f042..6720b60f 100644 --- a/test/unit_test/static/si_test.cpp +++ b/test/unit_test/static/si_test.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include namespace { @@ -225,6 +226,16 @@ static_assert(microhenry::symbol == basic_symbol_text("µH", "uH")); static_assert(nanohenry::symbol == "nH"); static_assert(picohenry::symbol == "pH"); +// conductance + +static_assert(1q_S * 1q_R == 1); +static_assert(1q_S == 1q_A / 1q_V); +static_assert(1q_W == 1q_A * 1q_A / 1q_S); + +static_assert(millisiemens::symbol == "mS"); +static_assert(microsiemens::symbol == basic_symbol_text("µS", "uS")); +static_assert(nanosiemens::symbol == "nS"); + /* ************** DERIVED DIMENSIONS IN TERMS OF BASE UNITS **************** */ // velocity