Added electric field strength

This commit is contained in:
rbrugo
2020-04-08 01:01:01 +02:00
committed by Mateusz Pusz
parent 15138286e5
commit 7803da0bdf
5 changed files with 73 additions and 0 deletions

View File

@@ -152,6 +152,12 @@ struct dim_specific_heat_capacity : derived_dimension<Child, U, exp<C, 1>, exp<M
template<typename Child, Unit U, DimensionOf<dim_power> P, DimensionOf<dim_length> L, DimensionOf<dim_thermodynamic_temperature> T>
struct dim_thermal_conductivity : derived_dimension<Child, U, exp<P, 1>, exp<L, -1>, exp<T, -1>> {};
template<typename Child, Unit U, DimensionOf<dim_energy> E, DimensionOf<dim_length> L>
struct dim_energy_density : derived_dimension<Child, U, exp<E, 1>, exp<L, -3>> {};
template<typename Child, Unit U, DimensionOf<dim_voltage> V, DimensionOf<dim_length> L>
struct dim_electric_field_strength : derived_dimension<Child, U, exp<V, 1>, exp<L, -1>> {};
} // namespace physical
template<typename T>
@@ -199,6 +205,9 @@ concept Momentum = physical::QuantityOf<T, physical::dim_momentum>;
template<typename T>
concept Energy = physical::QuantityOf<T, physical::dim_energy>;
template<typename T>
concept Density = physical::QuantityOf<T, physical::dim_density>;
template<typename T>
concept Power = physical::QuantityOf<T, physical::dim_power>;
@@ -259,4 +268,10 @@ concept SpecificHeatCapacity = physical::QuantityOf<T, physical::dim_specific_he
template<typename T>
concept ThermalConductivity = physical::QuantityOf<T, physical::dim_thermal_conductivity>;
// template<typename T>
// concept EnergyDensity = physical::QuantityOf<T, physical::dim_energy_density>;
template<typename T>
concept ElectricFieldStrength = physical::QuantityOf<T, physical::dim_electric_field_strength>;
} // namespace units

View File

@@ -32,6 +32,7 @@
#include "si/current_density.h"
#include "si/density.h"
#include "si/dynamic_viscosity.h"
#include "si/electric_field_strength.h"
#include "si/frequency.h"
#include "si/heat_capacity.h"
#include "si/inductance.h"

View File

@@ -0,0 +1,45 @@
// 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/voltage.h>
#include <units/quantity.h>
namespace units::si {
struct volt_per_metre : unit<volt_per_metre> {};
struct dim_electric_field_strength : physical::dim_electric_field_strength<dim_electric_field_strength, volt_per_metre, dim_voltage, dim_length> {};
template<Unit U, Scalar Rep = double>
using electric_field_strength = quantity<dim_electric_field_strength, U, Rep>;
inline namespace literals {
// V/m
constexpr auto operator"" q_V_per_m(unsigned long long l) { return electric_field_strength<volt_per_metre, std::int64_t>(l); }
constexpr auto operator"" q_V_per_m(long double l) { return electric_field_strength<volt_per_metre, long double>(l); }
} // namespace literals
} // namespace units::si

View File

@@ -274,6 +274,11 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]")
CHECK(fmt::format("{:%Q %Aq}", 1q_W_per_m_K) == "1 W m^-1 K^-1");
}
SECTION("electric field strength")
{
CHECK(fmt::format("{}", 1q_V_per_m) == "1 V/m");
}
SECTION("incoherent units with powers")
{
CHECK(fmt::format("{}", 1q_mi * 1q_mi * 1q_mi) == "1 [15900351812136/3814697265625 × 10⁹] m³");

View File

@@ -327,4 +327,11 @@ static_assert(detail::unit_text<dim_specific_heat_capacity, joule_per_kilogram_k
static_assert(20q_W_per_m_K * 10q_m * 300q_K == 60'000q_W);
static_assert(detail::unit_text<dim_thermal_conductivity, watt_per_metre_kelvin>() == basic_symbol_text("W ⋅ m⁻¹ ⋅ K⁻¹", "W m^-1 K^-1"));
// electric field strength
static_assert(100q_N/20q_C == 5q_V_per_m);
static_assert(1q_C * 10q_V_per_m * 3q_m == 30q_J);
static_assert(detail::unit_text<dim_electric_field_strength, volt_per_metre>() == "V/m");
} // namespace