Added magnetic flux

This commit is contained in:
rbrugo
2020-04-05 12:58:39 +02:00
committed by Mateusz Pusz
parent 608a75b61f
commit 86eefe1b0d
4 changed files with 93 additions and 0 deletions

View File

@@ -113,6 +113,9 @@ struct dim_pressure : derived_dimension<Child, U, exp<F, 1>, exp<A, -1>> {};
template <typename Child, Unit U, DimensionOf<dim_voltage> V, DimensionOf<dim_time> T, DimensionOf<dim_length> L>
struct dim_magnetic_induction : derived_dimension<Child, U, exp<V, 1>, exp<T, 1>, exp<L, -2>> {};
template<typename Child, Unit U, DimensionOf<dim_magnetic_induction> B, DimensionOf<dim_area> A>
struct dim_magnetic_flux : derived_dimension<Child, U, exp<B, 1>, exp<A, 1>> {};
} // namespace physical
template<typename T>
@@ -181,4 +184,7 @@ concept Pressure = physical::QuantityOf<T, physical::dim_pressure>;
template<typename T>
concept MagneticInduction = physical::QuantityOf<T, physical::dim_magnetic_induction>;
template <typename T>
concept MagneticFlux = physical::QuantityOf<T, physical::dim_magnetic_flux>;
} // namespace units

View File

@@ -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 <units/physical/dimensions.h>
#include <units/physical/si/magnetic_induction.h>
#include <units/physical/si/area.h>
#include <units/quantity.h>
namespace units::si {
struct weber : named_unit<weber, "Wb", prefix> {};
struct milliweber : prefixed_unit<milliweber, milli, weber> {};
struct microweber : prefixed_unit<microweber, micro, weber> {};
struct nanoweber : prefixed_unit<nanoweber, nano, weber> {};
struct picoweber : prefixed_unit<picoweber, pico, weber> {};
struct dim_magnetic_flux : physical::dim_magnetic_flux<dim_magnetic_flux, weber, dim_magnetic_induction, dim_area> {};
template<Unit U, Scalar Rep = double>
using magnetic_flux = quantity<dim_magnetic_flux, U, Rep>;
inline namespace literals {
// Wb
constexpr auto operator"" q_Wb(unsigned long long l) { return magnetic_flux<weber, std::int64_t>(l); }
constexpr auto operator"" q_Wb(long double l) { return magnetic_flux<weber, long double>(l); }
// mWb
constexpr auto operator"" q_mWb(unsigned long long l) { return magnetic_flux<milliweber, std::int64_t>(l); }
constexpr auto operator"" q_mWb(long double l) { return magnetic_flux<milliweber, long double>(l); }
// µWb
constexpr auto operator"" q_uWb(unsigned long long l) { return magnetic_flux<microweber, std::int64_t>(l); }
constexpr auto operator"" q_uWb(long double l) { return magnetic_flux<microweber, long double>(l); }
// nWb
constexpr auto operator"" q_nWb(unsigned long long l) { return magnetic_flux<nanoweber, std::int64_t>(l); }
constexpr auto operator"" q_nWb(long double l) { return magnetic_flux<nanoweber, long double>(l); }
// pWb
constexpr auto operator"" q_pWb(unsigned long long l) { return magnetic_flux<picoweber, std::int64_t>(l); }
constexpr auto operator"" q_pWb(long double l) { return magnetic_flux<picoweber, long double>(l); }
} // namespace literals
} // namespace units::si

View File

@@ -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 <catch2/catch.hpp>
@@ -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");

View File

@@ -41,6 +41,7 @@
#include <units/physical/si/voltage.h>
#include <units/physical/si/volume.h>
#include <units/physical/si/magnetic_induction.h>
#include <units/physical/si/magnetic_flux.h>
#include <utility>
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 **************** */