From 15138286e5863a67b1853668e7978dee220e71e8 Mon Sep 17 00:00:00 2001 From: rbrugo Date: Wed, 8 Apr 2020 00:36:44 +0200 Subject: [PATCH] Added thermal conductivity --- src/include/units/physical/dimensions.h | 6 +++ src/include/units/physical/si.h | 1 + .../units/physical/si/thermal_conductivity.h | 47 +++++++++++++++++++ test/unit_test/runtime/fmt_units_test.cpp | 6 +++ test/unit_test/static/si_test.cpp | 5 ++ 5 files changed, 65 insertions(+) create mode 100644 src/include/units/physical/si/thermal_conductivity.h diff --git a/src/include/units/physical/dimensions.h b/src/include/units/physical/dimensions.h index e8bf69de..270cfecc 100644 --- a/src/include/units/physical/dimensions.h +++ b/src/include/units/physical/dimensions.h @@ -149,6 +149,9 @@ struct dim_heat_capacity : derived_dimension, exp> {} template C, DimensionOf M> struct dim_specific_heat_capacity : derived_dimension, exp> {}; +template P, DimensionOf L, DimensionOf T> +struct dim_thermal_conductivity : derived_dimension, exp, exp> {}; + } // namespace physical template @@ -253,4 +256,7 @@ concept HeatCapacity = physical::QuantityOf; template concept SpecificHeatCapacity = physical::QuantityOf; +template +concept ThermalConductivity = physical::QuantityOf; + } // namespace units diff --git a/src/include/units/physical/si.h b/src/include/units/physical/si.h index 7a9db42b..53ce7629 100644 --- a/src/include/units/physical/si.h +++ b/src/include/units/physical/si.h @@ -43,6 +43,7 @@ #include "si/pressure.h" #include "si/resistance.h" #include "si/surface_tension.h" +#include "si/thermal_conductivity.h" #include "si/velocity.h" #include "si/voltage.h" #include "si/volume.h" diff --git a/src/include/units/physical/si/thermal_conductivity.h b/src/include/units/physical/si/thermal_conductivity.h new file mode 100644 index 00000000..6ff60219 --- /dev/null +++ b/src/include/units/physical/si/thermal_conductivity.h @@ -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 +#include +#include +#include + +namespace units::si { + +struct watt_per_metre_kelvin : unit {}; + +struct dim_thermal_conductivity : physical::dim_thermal_conductivity {}; + +template +using thermal_conductivity = quantity; + +inline namespace literals { + +// J/K +constexpr auto operator"" q_W_per_m_K(unsigned long long l) { return thermal_conductivity(l); } +constexpr auto operator"" q_W_per_m_K(long double l) { return thermal_conductivity(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 f98d1787..4472b543 100644 --- a/test/unit_test/runtime/fmt_units_test.cpp +++ b/test/unit_test/runtime/fmt_units_test.cpp @@ -268,6 +268,12 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]") CHECK(fmt::format("{:%Q %Aq}", 1q_J_per_kg_K) == "1 J K^-1 kg^-1"); } + SECTION("thermal conductivity") + { + CHECK(fmt::format("{}", 1q_W_per_m_K) == "1 W ⋅ m⁻¹ ⋅ K⁻¹"); + CHECK(fmt::format("{:%Q %Aq}", 1q_W_per_m_K) == "1 W m^-1 K^-1"); + } + 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 8221302a..0c4d563c 100644 --- a/test/unit_test/static/si_test.cpp +++ b/test/unit_test/static/si_test.cpp @@ -322,4 +322,9 @@ static_assert(1q_J_per_K * 1q_K == 1q_s * 1q_N * 1q_m_per_s); static_assert(detail::unit_text() == "J/K"); static_assert(detail::unit_text() == basic_symbol_text("J ⋅ K⁻¹ ⋅ kg⁻¹", "J kg^-1 K^-1")); +// thermal conductivity + +static_assert(20q_W_per_m_K * 10q_m * 300q_K == 60'000q_W); +static_assert(detail::unit_text() == basic_symbol_text("W ⋅ m⁻¹ ⋅ K⁻¹", "W m^-1 K^-1")); + } // namespace