diff --git a/src/include/units/physical/dimensions.h b/src/include/units/physical/dimensions.h index 7ade3a2d..2ec529ec 100644 --- a/src/include/units/physical/dimensions.h +++ b/src/include/units/physical/dimensions.h @@ -113,6 +113,9 @@ struct dim_pressure : derived_dimension, exp> {}; template V, DimensionOf T, DimensionOf L> struct dim_magnetic_induction : derived_dimension, exp, exp> {}; +template B, DimensionOf A> +struct dim_magnetic_flux : derived_dimension, exp> {}; + } // namespace physical template @@ -181,4 +184,7 @@ concept Pressure = physical::QuantityOf; template concept MagneticInduction = physical::QuantityOf; +template +concept MagneticFlux = physical::QuantityOf; + } // namespace units diff --git a/src/include/units/physical/si/magnetic_flux.h b/src/include/units/physical/si/magnetic_flux.h new file mode 100644 index 00000000..2e520144 --- /dev/null +++ b/src/include/units/physical/si/magnetic_flux.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 weber : named_unit {}; + +struct milliweber : prefixed_unit {}; +struct microweber : prefixed_unit {}; +struct nanoweber : prefixed_unit {}; +struct picoweber : prefixed_unit {}; + +struct dim_magnetic_flux : physical::dim_magnetic_flux {}; + +template +using magnetic_flux = quantity; + +inline namespace literals { + +// Wb +constexpr auto operator"" q_Wb(unsigned long long l) { return magnetic_flux(l); } +constexpr auto operator"" q_Wb(long double l) { return magnetic_flux(l); } + +// mWb +constexpr auto operator"" q_mWb(unsigned long long l) { return magnetic_flux(l); } +constexpr auto operator"" q_mWb(long double l) { return magnetic_flux(l); } + +// µWb +constexpr auto operator"" q_uWb(unsigned long long l) { return magnetic_flux(l); } +constexpr auto operator"" q_uWb(long double l) { return magnetic_flux(l); } + +// nWb +constexpr auto operator"" q_nWb(unsigned long long l) { return magnetic_flux(l); } +constexpr auto operator"" q_nWb(long double l) { return magnetic_flux(l); } + +// pWb +constexpr auto operator"" q_pWb(unsigned long long l) { return magnetic_flux(l); } +constexpr auto operator"" q_pWb(long double l) { return magnetic_flux(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 7ee86de3..5c6ebfb5 100644 --- a/test/unit_test/runtime/fmt_units_test.cpp +++ b/test/unit_test/runtime/fmt_units_test.cpp @@ -40,6 +40,7 @@ #include "units/physical/si/resistance.h" #include "units/physical/si/voltage.h" #include "units/physical/si/magnetic_induction.h" +#include "units/physical/si/magnetic_flux.h" #include "units/format.h" #include @@ -208,6 +209,11 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]") CHECK(fmt::format("{}", 1q_T) == "1 T"); } + SECTION("magnetic flux") + { + CHECK(fmt::format("{}", 1q_Wb) == "1 Wb"); + } + 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 1f73440d..076b3714 100644 --- a/test/unit_test/static/si_test.cpp +++ b/test/unit_test/static/si_test.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include namespace { @@ -199,6 +200,18 @@ static_assert(10q_N / (1q_A * 1q_m) == 10q_T); static_assert(millitesla::symbol == "mT"); static_assert(microtesla::symbol == basic_symbol_text("µT", "uT")); static_assert(nanotesla::symbol == "nT"); +static_assert(picotesla::symbol == "pT"); + +// magnetic flux + +static_assert(1q_Wb == 1q_T * 1q_m2); +static_assert(1q_J == 1q_Wb * 1q_A); +static_assert(1q_N * 1q_s == 1q_Wb * 1q_C / 1q_m); + +static_assert(milliweber::symbol == "mWb"); +static_assert(microweber::symbol == basic_symbol_text("µWb", "uWb")); +static_assert(nanoweber::symbol == "nWb"); +static_assert(picoweber::symbol == "pWb"); /* ************** DERIVED DIMENSIONS IN TERMS OF BASE UNITS **************** */