Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
SpecificHeatCapacity.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_SPECIFIC_HEAT_CAPACITY_HPP
26 #define PHQ_UNIT_SPECIFIC_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 
48 namespace PhQ {
49 
50 namespace Unit {
51 
52 /// \brief Mass-specific heat capacity units.
53 enum class SpecificHeatCapacity : int8_t {
54  /// \brief Joule per kilogram per kelvin (J/kg/K) specific heat capacity unit.
56 
57  /// \brief Nanojoule per gram per kelvin (nJ/g/K) specific heat capacity unit.
59 
60  /// \brief Foot-pound per slug per degree Rankine (ft·lbf/slug/°R) specific heat capacity unit.
62 
63  /// \brief Inch-pound per slinch per degree Rankine (in·lbf/slinch/°R) specific heat capacity
64  /// unit.
66 };
67 
68 } // namespace Unit
69 
70 /// \brief Standard mass-specific heat capacity unit: joule per kilogram per kelvin (J/kg/K).
71 template <>
72 inline constexpr const Unit::SpecificHeatCapacity Standard<Unit::SpecificHeatCapacity>{
74 
75 /// \brief Physical dimension set of mass-specific heat capacity units.
76 template <>
77 inline constexpr const Dimensions RelatedDimensions<Unit::SpecificHeatCapacity>{
78  Dimensions{Dimension::Time{-2}, Dimension::Length{2}, Dimension::Mass{0},
80  Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
81 };
82 
83 inline std::ostream& operator<<(std::ostream& stream, const Unit::SpecificHeatCapacity unit) {
84  stream << Abbreviation(unit);
85  return stream;
86 }
87 
88 namespace Internal {
89 
90 template <>
91 inline const std::map<UnitSystem, Unit::SpecificHeatCapacity> ConsistentUnits<
97 };
98 
99 template <>
100 inline const std::map<Unit::SpecificHeatCapacity, UnitSystem> RelatedUnitSystems<
106 };
107 
108 // clang-format off
109 
110 template <>
111 inline const std::map<Unit::SpecificHeatCapacity, std::string_view>
112  Abbreviations<Unit::SpecificHeatCapacity>{
117 };
118 
119 template <>
120 inline const std::unordered_map<std::string_view, Unit::SpecificHeatCapacity> Spellings<
424 };
425 
426 // clang-format on
427 
428 template <>
429 template <typename NumericType>
430 inline constexpr void
431 Conversion<Unit::SpecificHeatCapacity, Unit::SpecificHeatCapacity::JoulePerKilogramPerKelvin>::
432  FromStandard(NumericType& /*value*/) noexcept {}
433 
434 template <>
435 template <typename NumericType>
436 inline constexpr void
437 Conversion<Unit::SpecificHeatCapacity, Unit::SpecificHeatCapacity::JoulePerKilogramPerKelvin>::
438  ToStandard(NumericType& /*value*/) noexcept {}
439 
440 template <>
441 template <typename NumericType>
442 inline constexpr void
443 Conversion<Unit::SpecificHeatCapacity, Unit::SpecificHeatCapacity::NanojoulePerGramPerKelvin>::
444  FromStandard(NumericType& value) noexcept {
445  value *= static_cast<NumericType>(1000000.0L);
446 }
447 
448 template <>
449 template <typename NumericType>
450 inline constexpr void
451 Conversion<Unit::SpecificHeatCapacity, Unit::SpecificHeatCapacity::NanojoulePerGramPerKelvin>::
452  ToStandard(NumericType& value) noexcept {
453  value *= static_cast<NumericType>(0.000001L);
454 }
455 
456 template <>
457 template <typename NumericType>
458 inline constexpr void
459 Conversion<Unit::SpecificHeatCapacity, Unit::SpecificHeatCapacity::FootPoundPerSlugPerRankine>::
460  FromStandard(NumericType& value) noexcept {
461  value /= static_cast<NumericType>(1.8L) * static_cast<NumericType>(0.3048L)
462  * static_cast<NumericType>(0.3048L);
463 }
464 
465 template <>
466 template <typename NumericType>
467 inline constexpr void
468 Conversion<Unit::SpecificHeatCapacity, Unit::SpecificHeatCapacity::FootPoundPerSlugPerRankine>::
469  ToStandard(NumericType& value) noexcept {
470  value *= static_cast<NumericType>(1.8L) * static_cast<NumericType>(0.3048L)
471  * static_cast<NumericType>(0.3048L);
472 }
473 
474 template <>
475 template <typename NumericType>
476 inline constexpr void
477 Conversion<Unit::SpecificHeatCapacity, Unit::SpecificHeatCapacity::InchPoundPerSlinchPerRankine>::
478  FromStandard(NumericType& value) noexcept {
479  value /= static_cast<NumericType>(1.8L) * static_cast<NumericType>(0.0254L)
480  * static_cast<NumericType>(0.0254L);
481 }
482 
483 template <>
484 template <typename NumericType>
485 inline constexpr void
486 Conversion<Unit::SpecificHeatCapacity, Unit::SpecificHeatCapacity::InchPoundPerSlinchPerRankine>::
487  ToStandard(NumericType& value) noexcept {
488  value *= static_cast<NumericType>(1.8L) * static_cast<NumericType>(0.0254L)
489  * static_cast<NumericType>(0.0254L);
490 }
491 
492 template <typename NumericType>
493 inline const std::map<Unit::SpecificHeatCapacity,
494  std::function<void(NumericType* values, const std::size_t size)>>
495  MapOfConversionsFromStandard<Unit::SpecificHeatCapacity, NumericType>{
497  Conversions<
499  Unit::SpecificHeatCapacity::JoulePerKilogramPerKelvin>::FromStandard<NumericType> },
501  Conversions<
503  Unit::SpecificHeatCapacity::NanojoulePerGramPerKelvin>::FromStandard<NumericType> },
505  Conversions<
507  Unit::SpecificHeatCapacity::FootPoundPerSlugPerRankine>::FromStandard<NumericType> },
509  Conversions<
512 };
513 
514 template <typename NumericType>
515 inline const std::map<Unit::SpecificHeatCapacity,
516  std::function<void(NumericType* const values, const std::size_t size)>>
517  MapOfConversionsToStandard<Unit::SpecificHeatCapacity, NumericType>{
519  Conversions<
521  Unit::SpecificHeatCapacity::JoulePerKilogramPerKelvin>::ToStandard<NumericType> },
523  Conversions<
525  Unit::SpecificHeatCapacity::NanojoulePerGramPerKelvin>::ToStandard<NumericType> },
527  Conversions<
529  Unit::SpecificHeatCapacity::FootPoundPerSlugPerRankine>::ToStandard<NumericType> },
531  Conversions<
534 };
535 
536 } // namespace Internal
537 
538 } // namespace PhQ
539 
540 #endif // PHQ_UNIT_SPECIFIC_HEAT_CAPACITY_HPP
ElectricCurrent
Electric current units.
Mass
Mass units.
Definition: Mass.hpp:53
SpecificHeatCapacity
Mass-specific heat capacity units.
@ NanojoulePerGramPerKelvin
Nanojoule per gram per kelvin (nJ/g/K) specific heat capacity unit.
@ InchPoundPerSlinchPerRankine
Inch-pound per slinch per degree Rankine (in·lbf/slinch/°R) specific heat capacity unit.
@ JoulePerKilogramPerKelvin
Joule per kilogram per kelvin (J/kg/K) specific heat capacity unit.
@ FootPoundPerSlugPerRankine
Foot-pound per slug per degree Rankine (ft·lbf/slug/°R) specific heat capacity unit.
Length
Length units.
Definition: Length.hpp:53
SubstanceAmount
Amount of substance units.
Temperature
Temperature units. Not to be confused with temperature difference units. For example,...
Definition: Temperature.hpp:55
Time
Time units.
Definition: Time.hpp:53
Namespace that encompasses all of the Physical Quantities library's content.
@ 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
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)