Added heat capacity and specific heat capacity

This commit is contained in:
rbrugo
2020-04-08 00:20:37 +02:00
committed by Mateusz Pusz
parent 07b5364c97
commit 017e88ca28
5 changed files with 90 additions and 0 deletions

View File

@@ -143,6 +143,12 @@ struct dim_luminance : derived_dimension<Child, U, exp<I, 1>, exp<L, -2>> {};
template<typename Child, Unit U, DimensionOf<dim_pressure> P, DimensionOf<dim_time> T>
struct dim_dynamic_viscosity : derived_dimension<Child, U, exp<P, 1>, exp<T, 1>> {};
template<typename Child, Unit U, DimensionOf<dim_energy> E, DimensionOf<dim_thermodynamic_temperature> T>
struct dim_heat_capacity : derived_dimension<Child, U, exp<E, 1>, exp<T, -1>> {};
template<typename Child, Unit U, DimensionOf<dim_heat_capacity> C, DimensionOf<dim_mass> M>
struct dim_specific_heat_capacity : derived_dimension<Child, U, exp<C, 1>, exp<M, -1>> {};
} // namespace physical
template<typename T>
@@ -241,4 +247,10 @@ concept Luminance = physical::QuantityOf<T, physical::dim_luminance>;
template<typename T>
concept DynamicViscosity = physical::QuantityOf<T, physical::dim_dynamic_viscosity>;
template<typename T>
concept HeatCapacity = physical::QuantityOf<T, physical::dim_heat_capacity>;
template<typename T>
concept SpecificHeatCapacity = physical::QuantityOf<T, physical::dim_specific_heat_capacity>;
} // namespace units

View File

@@ -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"

View File

@@ -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 <units/physical/dimensions.h>
#include <units/physical/si/temperature.h>
#include <units/physical/si/energy.h>
#include <units/physical/si/mass.h>
#include <units/quantity.h>
namespace units::si {
struct joule_per_kelvin : unit<joule_per_kelvin> {};
struct joule_per_kilogram_kelvin : unit<joule_per_kilogram_kelvin> {};
struct dim_heat_capacity : physical::dim_heat_capacity<dim_heat_capacity, joule_per_kelvin, dim_energy, dim_thermodynamic_temperature> {};
struct dim_specific_heat_capacity : physical::dim_specific_heat_capacity<dim_specific_heat_capacity, joule_per_kilogram_kelvin, dim_heat_capacity, dim_mass> {};
template<Unit U, Scalar Rep = double>
using heat_capacity = quantity<dim_heat_capacity, U, Rep>;
template<Unit U, Scalar Rep = double>
using specific_heat_capacity = quantity<dim_specific_heat_capacity, U, Rep>;
inline namespace literals {
// J/K
constexpr auto operator"" q_J_per_K(unsigned long long l) { return heat_capacity<joule_per_kelvin, std::int64_t>(l); }
constexpr auto operator"" q_J_per_K(long double l) { return heat_capacity<joule_per_kelvin, long double>(l); }
// J/(kg·K)
constexpr auto operator"" q_J_per_kg_K(unsigned long long l) { return specific_heat_capacity<joule_per_kilogram_kelvin, std::int64_t>(l); }
constexpr auto operator"" q_J_per_kg_K(long double l) { return specific_heat_capacity<joule_per_kilogram_kelvin, long double>(l); }
} // namespace literals
} // namespace units::si

View File

@@ -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³");

View File

@@ -314,4 +314,12 @@ static_assert(detail::unit_text<dim_luminance, candela_per_metre_sq>() == basic_
static_assert(1q_Pa_s == 1q_N * 1q_s / 1q_m2);
static_assert(detail::unit_text<dim_dynamic_viscosity, pascal_second>() == 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<dim_heat_capacity, joule_per_kelvin>() == "J/K");
static_assert(detail::unit_text<dim_specific_heat_capacity, joule_per_kilogram_kelvin>() == basic_symbol_text("J ⋅ K⁻¹ ⋅ kg⁻¹", "J kg^-1 K^-1"));
} // namespace