diff --git a/src/include/units/physical/dimensions.h b/src/include/units/physical/dimensions.h index 0099dcd6..e8bf69de 100644 --- a/src/include/units/physical/dimensions.h +++ b/src/include/units/physical/dimensions.h @@ -143,6 +143,12 @@ struct dim_luminance : derived_dimension, exp> {}; template P, DimensionOf T> struct dim_dynamic_viscosity : derived_dimension, exp> {}; +template E, DimensionOf T> +struct dim_heat_capacity : derived_dimension, exp> {}; + +template C, DimensionOf M> +struct dim_specific_heat_capacity : derived_dimension, exp> {}; + } // namespace physical template @@ -241,4 +247,10 @@ concept Luminance = physical::QuantityOf; template concept DynamicViscosity = physical::QuantityOf; +template +concept HeatCapacity = physical::QuantityOf; + +template +concept SpecificHeatCapacity = physical::QuantityOf; + } // namespace units diff --git a/src/include/units/physical/si.h b/src/include/units/physical/si.h index 5403fc04..7a9db42b 100644 --- a/src/include/units/physical/si.h +++ b/src/include/units/physical/si.h @@ -33,6 +33,7 @@ #include "si/density.h" #include "si/dynamic_viscosity.h" #include "si/frequency.h" +#include "si/heat_capacity.h" #include "si/inductance.h" #include "si/luminance.h" #include "si/magnetic_flux.h" diff --git a/src/include/units/physical/si/heat_capacity.h b/src/include/units/physical/si/heat_capacity.h new file mode 100644 index 00000000..4baf04dd --- /dev/null +++ b/src/include/units/physical/si/heat_capacity.h @@ -0,0 +1,58 @@ +// 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 +#include + +namespace units::si { + +struct joule_per_kelvin : unit {}; +struct joule_per_kilogram_kelvin : unit {}; + +struct dim_heat_capacity : physical::dim_heat_capacity {}; +struct dim_specific_heat_capacity : physical::dim_specific_heat_capacity {}; + +template +using heat_capacity = quantity; + +template +using specific_heat_capacity = quantity; + +inline namespace literals { + +// J/K +constexpr auto operator"" q_J_per_K(unsigned long long l) { return heat_capacity(l); } +constexpr auto operator"" q_J_per_K(long double l) { return heat_capacity(l); } + +// J/(kg·K) +constexpr auto operator"" q_J_per_kg_K(unsigned long long l) { return specific_heat_capacity(l); } +constexpr auto operator"" q_J_per_kg_K(long double l) { return specific_heat_capacity(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 e035b012..f98d1787 100644 --- a/test/unit_test/runtime/fmt_units_test.cpp +++ b/test/unit_test/runtime/fmt_units_test.cpp @@ -257,6 +257,17 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]") CHECK(fmt::format("{:%Q %Aq}", 1q_Pa_s) == "1 Pa s"); } + SECTION("heat capacity") + { + CHECK(fmt::format("{}", 1q_J_per_K) == "1 J/K"); + } + + SECTION("specific heat capacity") + { + CHECK(fmt::format("{}", 1q_J_per_kg_K) == "1 J ⋅ K⁻¹ ⋅ kg⁻¹"); + CHECK(fmt::format("{:%Q %Aq}", 1q_J_per_kg_K) == "1 J K^-1 kg^-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 a9353140..8221302a 100644 --- a/test/unit_test/static/si_test.cpp +++ b/test/unit_test/static/si_test.cpp @@ -314,4 +314,12 @@ static_assert(detail::unit_text() == basic_ static_assert(1q_Pa_s == 1q_N * 1q_s / 1q_m2); static_assert(detail::unit_text() == basic_symbol_text("Pa ⋅ s", "Pa s")); +// [specific] heath capacity + +static_assert(1q_J_per_K == 1q_J_per_kg_K * 1q_kg); +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")); + } // namespace