diff --git a/src/include/units/physical/dimensions.h b/src/include/units/physical/dimensions.h index 270cfecc..6298a5a9 100644 --- a/src/include/units/physical/dimensions.h +++ b/src/include/units/physical/dimensions.h @@ -152,6 +152,12 @@ struct dim_specific_heat_capacity : derived_dimension, exp P, DimensionOf L, DimensionOf T> struct dim_thermal_conductivity : derived_dimension, exp, exp> {}; +template E, DimensionOf L> +struct dim_energy_density : derived_dimension, exp> {}; + +template V, DimensionOf L> +struct dim_electric_field_strength : derived_dimension, exp> {}; + } // namespace physical template @@ -199,6 +205,9 @@ concept Momentum = physical::QuantityOf; template concept Energy = physical::QuantityOf; +template +concept Density = physical::QuantityOf; + template concept Power = physical::QuantityOf; @@ -259,4 +268,10 @@ concept SpecificHeatCapacity = physical::QuantityOf concept ThermalConductivity = physical::QuantityOf; +// template +// concept EnergyDensity = physical::QuantityOf; + +template +concept ElectricFieldStrength = physical::QuantityOf; + } // namespace units diff --git a/src/include/units/physical/si.h b/src/include/units/physical/si.h index 53ce7629..c88a0f07 100644 --- a/src/include/units/physical/si.h +++ b/src/include/units/physical/si.h @@ -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" diff --git a/src/include/units/physical/si/electric_field_strength.h b/src/include/units/physical/si/electric_field_strength.h new file mode 100644 index 00000000..1e42301e --- /dev/null +++ b/src/include/units/physical/si/electric_field_strength.h @@ -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 +#include +#include + +namespace units::si { + +struct volt_per_metre : unit {}; +struct dim_electric_field_strength : physical::dim_electric_field_strength {}; + +template +using electric_field_strength = quantity; + +inline namespace literals { + +// V/m +constexpr auto operator"" q_V_per_m(unsigned long long l) { return electric_field_strength(l); } +constexpr auto operator"" q_V_per_m(long double l) { return electric_field_strength(l); } + +} // namespace literals + +} // namespace units::si diff --git a/test/unit_test/runtime/fmt_units_test.cpp b/test/unit_test/runtime/fmt_units_test.cpp index 4472b543..275768ff 100644 --- a/test/unit_test/runtime/fmt_units_test.cpp +++ b/test/unit_test/runtime/fmt_units_test.cpp @@ -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³"); diff --git a/test/unit_test/static/si_test.cpp b/test/unit_test/static/si_test.cpp index 0c4d563c..48f06ea8 100644 --- a/test/unit_test/static/si_test.cpp +++ b/test/unit_test/static/si_test.cpp @@ -327,4 +327,11 @@ static_assert(detail::unit_text() == 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() == "V/m"); + } // namespace