Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
Loading...
Searching...
No Matches
HeatCapacity.hpp
Go to the documentation of this file.
1// Copyright © 2020-2024 Alexandre Coderre-Chabot
2//
3// This file is part of Physical Quantities (PhQ), a C++ library of physical quantities, physical
4// models, and units of measure for scientific computing.
5//
6// Physical Quantities is hosted at:
7// https://github.com/acodcha/phq
8//
9// Physical Quantities is licensed under the MIT License:
10// https://mit-license.org
11//
12// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
13// associated documentation files (the "Software"), to deal in the Software without restriction,
14// including without limitation the rights to use, copy, modify, merge, publish, distribute,
15// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
16// furnished to do so, subject to the following conditions:
17// - The above copyright notice and this permission notice shall be included in all copies or
18// substantial portions of the Software.
19// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
20// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM
23// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25#ifndef PHQ_UNIT_HEAT_CAPACITY_HPP
26#define PHQ_UNIT_HEAT_CAPACITY_HPP
27
28#include <cstddef>
29#include <cstdint>
30#include <functional>
31#include <map>
32#include <ostream>
33#include <string_view>
34#include <unordered_map>
35
36#include "../Base.hpp"
37#include "../Dimension/ElectricCurrent.hpp"
38#include "../Dimension/Length.hpp"
39#include "../Dimension/LuminousIntensity.hpp"
40#include "../Dimension/Mass.hpp"
41#include "../Dimension/SubstanceAmount.hpp"
42#include "../Dimension/Temperature.hpp"
43#include "../Dimension/Time.hpp"
44#include "../Dimensions.hpp"
45#include "../Unit.hpp"
46#include "../UnitSystem.hpp"
47
48namespace PhQ {
49
50namespace Unit {
51
52/// \brief Heat capacity units.
53enum class HeatCapacity : int8_t {
54 /// \brief Joule per kelvin (J/K) heat capacity unit.
56
57 /// \brief Nanojoule per kelvin (nJ/K) heat capacity unit.
59
60 /// \brief Foot-pound per degree Rankine (ft·lbf/°R) heat capacity unit.
62
63 /// \brief Inch-pound per degree Rankine (in·lbf/°R) heat capacity unit.
65};
66
67} // namespace Unit
68
69/// \brief Standard heat capacity unit: joule per kelvin (J/K).
70template <>
71inline constexpr const Unit::
72 HeatCapacity Standard<Unit::HeatCapacity>{Unit::HeatCapacity::JoulePerKelvin};
73
74/// \brief Physical dimension set of heat capacity units.
75template <>
76inline constexpr const Dimensions RelatedDimensions<Unit::HeatCapacity>{
77 Dimensions{Dimension::Time{-2}, Dimension::Length{2}, Dimension::Mass{1},
78 Dimension::ElectricCurrent{0}, Dimension::Temperature{-1},
79 Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
80};
81
82inline std::ostream& operator<<(std::ostream& stream, const Unit::HeatCapacity unit) {
83 stream << Abbreviation(unit);
84 return stream;
85}
86
87namespace Internal {
88
89template <>
90inline const std::map<UnitSystem, Unit::HeatCapacity> ConsistentUnits<Unit::HeatCapacity>{
95};
96
97template <>
98inline const std::map<Unit::HeatCapacity, UnitSystem> RelatedUnitSystems<Unit::HeatCapacity>{
103};
104
105// clang-format off
106
107template <>
108inline const std::map<Unit::HeatCapacity, std::string_view> Abbreviations<Unit::HeatCapacity>{
113};
114
115template <>
116inline const std::unordered_map<std::string_view, Unit::HeatCapacity> Spellings<Unit::HeatCapacity>{
120 {"kg·m^2/s^2/K", Unit::HeatCapacity::JoulePerKelvin },
121 {"kg*m^2/s^2/K", Unit::HeatCapacity::JoulePerKelvin },
122 {"kg·m2/s2/K", Unit::HeatCapacity::JoulePerKelvin },
123 {"kg*m2/s2/K", Unit::HeatCapacity::JoulePerKelvin },
124 {"kg·m^2/(s^2·K)", Unit::HeatCapacity::JoulePerKelvin },
125 {"kg*m^2/(s^2*K)", Unit::HeatCapacity::JoulePerKelvin },
126 {"kg·m2/(s2·K)", Unit::HeatCapacity::JoulePerKelvin },
127 {"kg*m2/(s2*K)", Unit::HeatCapacity::JoulePerKelvin },
133 {"g·mm^2/s^2/K", Unit::HeatCapacity::NanojoulePerKelvin },
137 {"g·mm^2/(s^2·K)", Unit::HeatCapacity::NanojoulePerKelvin },
138 {"g*mm^2/(s^2*K)", Unit::HeatCapacity::NanojoulePerKelvin },
139 {"g·mm2/(s2·K)", Unit::HeatCapacity::NanojoulePerKelvin },
157};
158
159// clang-format on
160
161template <>
162template <typename NumericType>
163inline constexpr void Conversion<Unit::HeatCapacity, Unit::HeatCapacity::JoulePerKelvin>::
164 FromStandard(NumericType& /*value*/) noexcept {}
165
166template <>
167template <typename NumericType>
168inline constexpr void Conversion<Unit::HeatCapacity, Unit::HeatCapacity::JoulePerKelvin>::
169 ToStandard(NumericType& /*value*/) noexcept {}
170
171template <>
172template <typename NumericType>
173inline constexpr void Conversion<Unit::HeatCapacity, Unit::HeatCapacity::NanojoulePerKelvin>::
174 FromStandard(NumericType& value) noexcept {
175 value *= static_cast<NumericType>(1000000000.0L);
176}
177
178template <>
179template <typename NumericType>
180inline constexpr void Conversion<Unit::HeatCapacity, Unit::HeatCapacity::NanojoulePerKelvin>::
181 ToStandard(NumericType& value) noexcept {
182 value *= static_cast<NumericType>(0.000000001L);
183}
184
185template <>
186template <typename NumericType>
187inline constexpr void Conversion<Unit::HeatCapacity, Unit::HeatCapacity::FootPoundPerRankine>::
188 FromStandard(NumericType& value) noexcept {
189 value /= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.45359237L)
190 * static_cast<NumericType>(9.80665L) * static_cast<NumericType>(1.8L);
191}
192
193template <>
194template <typename NumericType>
195inline constexpr void Conversion<Unit::HeatCapacity, Unit::HeatCapacity::FootPoundPerRankine>::
196 ToStandard(NumericType& value) noexcept {
197 value *= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.45359237L)
198 * static_cast<NumericType>(9.80665L) * static_cast<NumericType>(1.8L);
199}
200
201template <>
202template <typename NumericType>
203inline constexpr void Conversion<Unit::HeatCapacity, Unit::HeatCapacity::InchPoundPerRankine>::
204 FromStandard(NumericType& value) noexcept {
205 value /= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.45359237L)
206 * static_cast<NumericType>(9.80665L) * static_cast<NumericType>(1.8L);
207}
208
209template <>
210template <typename NumericType>
211inline constexpr void Conversion<Unit::HeatCapacity, Unit::HeatCapacity::InchPoundPerRankine>::
212 ToStandard(NumericType& value) noexcept {
213 value *= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.45359237L)
214 * static_cast<NumericType>(9.80665L) * static_cast<NumericType>(1.8L);
215}
216
217template <typename NumericType>
218inline const std::
219 map<Unit::HeatCapacity, std::function<void(NumericType* values, const std::size_t size)>>
220 MapOfConversionsFromStandard<Unit::HeatCapacity, NumericType>{
222 Conversions<Unit::HeatCapacity, Unit::HeatCapacity::JoulePerKelvin>::
223 FromStandard<NumericType>},
225 Conversions<Unit::HeatCapacity, Unit::HeatCapacity::NanojoulePerKelvin>::
226 FromStandard<NumericType>},
228 Conversions<Unit::HeatCapacity, Unit::HeatCapacity::FootPoundPerRankine>::
229 FromStandard<NumericType>},
231 Conversions<Unit::HeatCapacity, Unit::HeatCapacity::InchPoundPerRankine>::
232 FromStandard<NumericType>},
233};
234
235template <typename NumericType>
236inline const std::
237 map<Unit::HeatCapacity, std::function<void(NumericType* const values, const std::size_t size)>>
238 MapOfConversionsToStandard<Unit::HeatCapacity, NumericType>{
240 Conversions<Unit::HeatCapacity, Unit::HeatCapacity::JoulePerKelvin>::
241 ToStandard<NumericType>},
243 Conversions<Unit::HeatCapacity, Unit::HeatCapacity::NanojoulePerKelvin>::
244 ToStandard<NumericType>},
246 Conversions<Unit::HeatCapacity, Unit::HeatCapacity::FootPoundPerRankine>::
247 ToStandard<NumericType>},
249 Conversions<Unit::HeatCapacity, Unit::HeatCapacity::InchPoundPerRankine>::
250 ToStandard<NumericType>},
251};
252
253} // namespace Internal
254
255} // namespace PhQ
256
257#endif // PHQ_UNIT_HEAT_CAPACITY_HPP
HeatCapacity
Heat capacity units.
@ NanojoulePerKelvin
Nanojoule per kelvin (nJ/K) heat capacity unit.
@ InchPoundPerRankine
Inch-pound per degree Rankine (in·lbf/°R) heat capacity unit.
@ FootPoundPerRankine
Foot-pound per degree Rankine (ft·lbf/°R) heat capacity unit.
@ JoulePerKelvin
Joule per kelvin (J/K) heat capacity unit.
Namespace that encompasses all of the Physical Quantities library's content.
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)
@ FootPoundSecondRankine
Foot-pound-second-rankine (ft·lbf·s·°R) system.
@ MillimetreGramSecondKelvin
Millimetre-gram-second-kelvin (mm·g·s·K) system.
@ MetreKilogramSecondKelvin
Metre-kilogram-second-kelvin (m·kg·s·K) system.
@ InchPoundSecondRankine
Inch-pound-second-rankine (in·lbf·s·°R) system.
std::string_view Abbreviation(const Enumeration enumeration)
Returns the abbreviation of a given enumeration value. For example, PhQ::Abbreviation(PhQ::Unit::Time...
Definition Base.hpp:89