forked from mpusz/mp-units
Added conductance
This commit is contained in:
@@ -119,6 +119,9 @@ 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>> {};
|
||||
|
||||
template<typename Child, Unit U, DimensionOf<dim_resistance> R>
|
||||
struct dim_conductance : derived_dimension<Child, U, exp<R, -1>> {};
|
||||
|
||||
} // namespace physical
|
||||
|
||||
template<typename T>
|
||||
@@ -193,4 +196,7 @@ concept MagneticFlux = physical::QuantityOf<T, physical::dim_magnetic_flux>;
|
||||
template <typename T>
|
||||
concept Inductance = physical::QuantityOf<T, physical::dim_inductance>;
|
||||
|
||||
template <typename T>
|
||||
concept Conductance = physical::QuantityOf<T, physical::dim_inductance>;
|
||||
|
||||
} // namespace units
|
||||
|
63
src/include/units/physical/si/conductance.h
Normal file
63
src/include/units/physical/si/conductance.h
Normal file
@@ -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 <units/physical/dimensions.h>
|
||||
#include <units/physical/si/resistance.h>
|
||||
#include <units/physical/si/prefixes.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
namespace units::si {
|
||||
|
||||
struct siemens : named_unit<siemens, {"S", "siemens"}, prefix> {};
|
||||
struct millisiemens : prefixed_unit<millisiemens, milli, siemens> {};
|
||||
struct microsiemens : prefixed_unit<microsiemens, micro, siemens> {};
|
||||
struct nanosiemens : prefixed_unit<nanosiemens, nano, siemens> {};
|
||||
|
||||
struct dim_conductance : physical::dim_conductance<dim_conductance, siemens, dim_resistance> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
using conductance = quantity<dim_conductance, U, Rep>;
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// R
|
||||
constexpr auto operator"" q_S(unsigned long long l) { return conductance<siemens, std::int64_t>(l); }
|
||||
constexpr auto operator"" q_S(long double l) { return conductance<siemens, long double>(l); }
|
||||
|
||||
// mS
|
||||
constexpr auto operator"" q_mS(unsigned long long l) { return conductance<millisiemens, std::int64_t>(l); }
|
||||
constexpr auto operator"" q_mS(long double l) { return conductance<millisiemens, long double>(l); }
|
||||
|
||||
// µS
|
||||
constexpr auto operator"" q_uS(unsigned long long l) { return conductance<microsiemens, std::int64_t>(l); }
|
||||
constexpr auto operator"" q_uS(long double l) { return conductance<microsiemens, long double>(l); }
|
||||
|
||||
// nS
|
||||
constexpr auto operator"" q_nS(unsigned long long l) { return conductance<nanosiemens, std::int64_t>(l); }
|
||||
constexpr auto operator"" q_nS(long double l) { return conductance<nanosiemens, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
} // namespace units::si
|
||||
|
@@ -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 <catch2/catch.hpp>
|
||||
|
||||
@@ -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");
|
||||
|
@@ -43,6 +43,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 <utility>
|
||||
|
||||
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
|
||||
|
Reference in New Issue
Block a user