mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-05 05:04:27 +02:00
Added current density
This commit is contained in:
@@ -131,6 +131,9 @@ struct dim_catalytic_activity : derived_dimension<Child, U, exp<T, -1>, exp<M, 1
|
||||
template<typename Child, Unit U, DimensionOf<dim_energy> E, DimensionOf<dim_mass> M>
|
||||
struct dim_absorbed_dose : derived_dimension<Child, U, exp<E, 1>, exp<M, -1>> {};
|
||||
|
||||
template<typename Child, Unit U, DimensionOf<dim_electric_current> I, DimensionOf<dim_area> A>
|
||||
struct dim_current_density : derived_dimension<Child, U, exp<I, 1>, exp<A, -1>> {};
|
||||
|
||||
} // namespace physical
|
||||
|
||||
template<typename T>
|
||||
@@ -217,4 +220,7 @@ concept CatalyticActivity = physical::QuantityOf<T, physical::dim_catalytic_acti
|
||||
template<typename T>
|
||||
concept AbsorbedDose = physical::QuantityOf<T, physical::dim_absorbed_dose>;
|
||||
|
||||
template<typename T>
|
||||
concept CurrentDensity = physical::QuantityOf<T, physical::dim_current_density>;
|
||||
|
||||
} // namespace units
|
||||
|
@@ -22,20 +22,23 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "units/physical/si/area.h"
|
||||
#include "units/physical/si/constants.h"
|
||||
#include "units/physical/si/frequency.h"
|
||||
#include "units/physical/si/momentum.h"
|
||||
#include "units/physical/si/power.h"
|
||||
#include "units/physical/si/velocity.h"
|
||||
#include "units/physical/si/volume.h"
|
||||
#include "units/physical/si/surface_tension.h"
|
||||
#include "units/physical/si/density.h"
|
||||
#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/physical/si/inductance.h"
|
||||
#include "units/physical/si/conductance.h"
|
||||
#include "units/physical/si/catalytic_activity.h"
|
||||
#include "units/physical/si/absorbed_dose.h"
|
||||
#include "si/area.h"
|
||||
#include "si/constants.h"
|
||||
#include "si/frequency.h"
|
||||
#include "si/momentum.h"
|
||||
#include "si/power.h"
|
||||
#include "si/velocity.h"
|
||||
#include "si/volume.h"
|
||||
#include "si/surface_tension.h"
|
||||
#include "si/pressure.h"
|
||||
#include "si/density.h"
|
||||
#include "si/resistance.h"
|
||||
#include "si/voltage.h"
|
||||
#include "si/capacitance.h"
|
||||
#include "si/magnetic_induction.h"
|
||||
#include "si/magnetic_flux.h"
|
||||
#include "si/inductance.h"
|
||||
#include "si/conductance.h"
|
||||
#include "si/catalytic_activity.h"
|
||||
#include "si/absorbed_dose.h"
|
||||
#include "si/current_density.h"
|
||||
|
47
src/include/units/physical/si/current_density.h
Normal file
47
src/include/units/physical/si/current_density.h
Normal file
@@ -0,0 +1,47 @@
|
||||
// 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/current.h>
|
||||
#include <units/physical/si/area.h>
|
||||
#include <units/physical/si/prefixes.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
namespace units::si {
|
||||
|
||||
struct ampere_per_metre_sq : unit<ampere_per_metre_sq> {};
|
||||
|
||||
struct dim_current_density : physical::dim_current_density<dim_current_density, ampere_per_metre_sq, dim_electric_current, dim_area> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
using current_density = quantity<dim_current_density, U, Rep>;
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
constexpr auto operator"" q_A_per_m2(unsigned long long l) { return current_density<ampere_per_metre_sq, std::int64_t>(l); }
|
||||
constexpr auto operator"" q_A_per_m2(long double l) { return current_density<ampere_per_metre_sq, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
} // namespace units::si
|
@@ -20,14 +20,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include "units/physical/si/area.h"
|
||||
#include "units/physical/si/constants.h"
|
||||
#include "units/physical/si/frequency.h"
|
||||
#include "units/physical/si/momentum.h"
|
||||
#include "units/physical/si/power.h"
|
||||
#include "units/physical/si/velocity.h"
|
||||
#include "units/physical/si/volume.h"
|
||||
#include "units/physical/si/surface_tension.h"
|
||||
#include "units/physical/si.h"
|
||||
#include "units/physical/us/length.h"
|
||||
#include "units/physical/imperial/length.h"
|
||||
#include "units/physical/international/length.h"
|
||||
@@ -36,15 +29,6 @@
|
||||
#include "units/physical/international/velocity.h"
|
||||
#include "units/physical/iau/length.h"
|
||||
#include "units/physical/typographic/length.h"
|
||||
#include "units/physical/si/density.h"
|
||||
#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/physical/si/inductance.h"
|
||||
#include "units/physical/si/conductance.h"
|
||||
#include "units/physical/si/catalytic_activity.h"
|
||||
#include "units/physical/si/absorbed_dose.h"
|
||||
#include "units/format.h"
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
@@ -249,6 +233,12 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]")
|
||||
CHECK(fmt::format("{}", 1q_in + 1q_yd) == "37 in");
|
||||
}
|
||||
|
||||
SECTION("current density")
|
||||
{
|
||||
CHECK(fmt::format("{}", 1q_A_per_m2) == "1 A/m²");
|
||||
CHECK(fmt::format("{:%q %AQ}", 1q_A_per_m2) == "1 A/m^2");
|
||||
}
|
||||
|
||||
SECTION("incoherent units with powers")
|
||||
{
|
||||
CHECK(fmt::format("{}", 1q_mi * 1q_mi * 1q_mi) == "1 [15900351812136/3814697265625 × 10⁹] m³");
|
||||
|
@@ -20,32 +20,7 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/physical/si/acceleration.h>
|
||||
#include <units/physical/si/area.h>
|
||||
#include <units/physical/si/capacitance.h>
|
||||
#include <units/physical/si/current.h>
|
||||
#include <units/physical/si/electric_charge.h>
|
||||
#include <units/physical/si/energy.h>
|
||||
#include <units/physical/si/force.h>
|
||||
#include <units/physical/si/frequency.h>
|
||||
#include <units/physical/si/length.h>
|
||||
#include <units/physical/si/luminous_intensity.h>
|
||||
#include <units/physical/si/mass.h>
|
||||
#include <units/physical/si/power.h>
|
||||
#include <units/physical/si/pressure.h>
|
||||
#include <units/physical/si/substance.h>
|
||||
#include <units/physical/si/surface_tension.h>
|
||||
#include <units/physical/si/temperature.h>
|
||||
#include <units/physical/si/time.h>
|
||||
#include <units/physical/si/velocity.h>
|
||||
#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 <units/physical/si/inductance.h>
|
||||
#include <units/physical/si/conductance.h>
|
||||
#include <units/physical/si/catalytic_activity.h>
|
||||
#include <units/physical/si/absorbed_dose.h>
|
||||
#include <units/physical/si.h>
|
||||
#include <utility>
|
||||
|
||||
namespace {
|
||||
@@ -317,4 +292,13 @@ static_assert(2q_m * 5q_N_per_m == 10q_N);
|
||||
|
||||
static_assert(detail::unit_text<dim_surface_tension, newton_per_metre>() == "N/m");
|
||||
|
||||
// current density
|
||||
|
||||
static_assert(12q_A_per_m2 == 60q_A / 5q_m2);
|
||||
static_assert(1q_A_per_m2 == 1q_S * 1q_V / 1q_m2);
|
||||
|
||||
/* #warning FIX THIS */
|
||||
/* static_assert(detail::unit_text<dim_current_density, ampere_per_metre_sq>() == basic_symbol_text("A · m²", "A/m^2")); */
|
||||
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user