forked from mpusz/mp-units
Added inductance
This commit is contained in:
@@ -116,6 +116,9 @@ struct dim_magnetic_induction : derived_dimension<Child, U, exp<V, 1>, exp<T, 1>
|
||||
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>> {};
|
||||
|
||||
template<typename Child, Unit U, DimensionOf<dim_magnetic_flux> F, DimensionOf<dim_electric_current> I>
|
||||
struct dim_inductance : derived_dimension<Child, U, exp<F, 1>, exp<I, -1>> {};
|
||||
|
||||
} // namespace physical
|
||||
|
||||
template<typename T>
|
||||
@@ -187,4 +190,7 @@ concept MagneticInduction = physical::QuantityOf<T, physical::dim_magnetic_induc
|
||||
template <typename T>
|
||||
concept MagneticFlux = physical::QuantityOf<T, physical::dim_magnetic_flux>;
|
||||
|
||||
template <typename T>
|
||||
concept Inductance = physical::QuantityOf<T, physical::dim_inductance>;
|
||||
|
||||
} // namespace units
|
||||
|
68
src/include/units/physical/si/inductance.h
Normal file
68
src/include/units/physical/si/inductance.h
Normal 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_flux.h>
|
||||
#include <units/physical/si/current.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
namespace units::si {
|
||||
|
||||
struct henry : named_unit<henry, "H", prefix> {};
|
||||
|
||||
struct millihenry : prefixed_unit<millihenry, milli, henry> {};
|
||||
struct microhenry : prefixed_unit<microhenry, micro, henry> {};
|
||||
struct nanohenry : prefixed_unit<nanohenry, nano, henry> {};
|
||||
struct picohenry : prefixed_unit<picohenry, pico, henry> {};
|
||||
|
||||
struct dim_inductance : physical::dim_inductance<dim_inductance, henry, dim_magnetic_flux, dim_electric_current> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
using inductance = quantity<dim_inductance, U, Rep>;
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// H
|
||||
constexpr auto operator"" q_H(unsigned long long l) { return inductance<henry, std::int64_t>(l); }
|
||||
constexpr auto operator"" q_H(long double l) { return inductance<henry, long double>(l); }
|
||||
|
||||
// mH
|
||||
constexpr auto operator"" q_mH(unsigned long long l) { return inductance<millihenry, std::int64_t>(l); }
|
||||
constexpr auto operator"" q_mH(long double l) { return inductance<millihenry, long double>(l); }
|
||||
|
||||
// µH
|
||||
constexpr auto operator"" q_uH(unsigned long long l) { return inductance<microhenry, std::int64_t>(l); }
|
||||
constexpr auto operator"" q_uH(long double l) { return inductance<microhenry, long double>(l); }
|
||||
|
||||
// nH
|
||||
constexpr auto operator"" q_nH(unsigned long long l) { return inductance<nanohenry, std::int64_t>(l); }
|
||||
constexpr auto operator"" q_nH(long double l) { return inductance<nanohenry, long double>(l); }
|
||||
|
||||
// pH
|
||||
constexpr auto operator"" q_pH(unsigned long long l) { return inductance<picohenry, std::int64_t>(l); }
|
||||
constexpr auto operator"" q_pH(long double l) { return inductance<picohenry, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
} // namespace units::si
|
@@ -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 <catch2/catch.hpp>
|
||||
|
||||
@@ -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")
|
||||
|
@@ -42,6 +42,7 @@
|
||||
#include <units/physical/si/volume.h>
|
||||
#include <units/physical/si/magnetic_induction.h>
|
||||
#include <units/physical/si/magnetic_flux.h>
|
||||
#include <units/physical/si/inductance.h>
|
||||
#include <utility>
|
||||
|
||||
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
|
||||
|
Reference in New Issue
Block a user