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
HeatCapacityRatio.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_HEAT_CAPACITY_RATIO_HPP
26#define PHQ_HEAT_CAPACITY_RATIO_HPP
27
28#include <cstddef>
29#include <functional>
30#include <ostream>
31
33
34namespace PhQ {
35
36// Forward declaration for class PhQ::HeatCapacityRatio.
37template <typename NumericType>
38class GasConstant;
39
40// Forward declaration for class PhQ::HeatCapacityRatio.
41template <typename NumericType>
42class IsobaricHeatCapacity;
43
44// Forward declaration for class PhQ::HeatCapacityRatio.
45template <typename NumericType>
46class IsochoricHeatCapacity;
47
48// Forward declaration for class PhQ::HeatCapacityRatio.
49template <typename NumericType>
50class Mass;
51
52// Forward declaration for class PhQ::HeatCapacityRatio.
53template <typename NumericType>
54class SpecificGasConstant;
55
56// Forward declaration for class PhQ::HeatCapacityRatio.
57template <typename NumericType>
58class SpecificIsobaricHeatCapacity;
59
60// Forward declaration for class PhQ::HeatCapacityRatio.
61template <typename NumericType>
62class SpecificIsochoricHeatCapacity;
63
64/// \brief Heat capacity ratio, also known as ratio of specific heats, adiabatic index, or Laplace's
65/// coefficient. A material's heat capacity ratio is the ratio of its isobaric heat capacity to its
66/// isochoric heat capacity; see PhQ::IsobaricHeatCapacity and PhQ::IsochoricHeatCapacity.
67template <typename NumericType = double>
68class HeatCapacityRatio : public DimensionlessScalar<NumericType> {
69public:
70 /// \brief Default constructor. Constructs a heat capacity ratio ratio with an uninitialized
71 /// value.
72 HeatCapacityRatio() = default;
73
74 /// \brief Constructor. Constructs a heat capacity ratio with a given value.
75 explicit constexpr HeatCapacityRatio(const NumericType value)
76 : DimensionlessScalar<NumericType>(value) {}
77
78 /// \brief Constructor. Constructs a heat capacity ratio from a given specific gas constant and
79 /// specific isobaric heat capacity using Mayer's relation and the definition of the heat capacity
80 /// ratio.
81 constexpr HeatCapacityRatio(
82 const SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity,
83 const SpecificGasConstant<NumericType>& specific_gas_constant);
84
85 /// \brief Constructor. Constructs a heat capacity ratio from a given specific gas constant and
86 /// specific isochoric heat capacity using Mayer's relation and the definition of the heat
87 /// capacity ratio.
88 constexpr HeatCapacityRatio(
89 const SpecificGasConstant<NumericType>& specific_gas_constant,
90 const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity);
91
92 /// \brief Constructor. Constructs a heat capacity ratio from a given specific isobaric heat
93 /// capacity and specific isochoric heat capacity using the definition of the heat capacity ratio.
94 constexpr HeatCapacityRatio(
95 const SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity,
96 const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity);
97
98 /// \brief Constructor. Constructs a heat capacity ratio from a given gas constant and isobaric
99 /// heat capacity using Mayer's relation and the definition of the heat capacity ratio.
100 constexpr HeatCapacityRatio(const IsobaricHeatCapacity<NumericType>& isobaric_heat_capacity,
101 const GasConstant<NumericType>& gas_constant);
102
103 /// \brief Constructor. Constructs a heat capacity ratio from a given gas constant and isochoric
104 /// heat capacity using Mayer's relation and the definition of the heat capacity ratio.
105 constexpr HeatCapacityRatio(const GasConstant<NumericType>& gas_constant,
106 const IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity);
107
108 /// \brief Constructor. Constructs a heat capacity ratio from a given isobaric heat capacity and
109 /// isochoric heat capacity using the definition of the specific heat ratio.
110 constexpr HeatCapacityRatio(const IsobaricHeatCapacity<NumericType>& isobaric_heat_capacity,
111 const IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity);
112
113 /// \brief Destructor. Destroys this heat capacity ratio.
114 ~HeatCapacityRatio() noexcept = default;
115
116 /// \brief Copy constructor. Constructs a heat capacity ratio by copying another one.
117 constexpr HeatCapacityRatio(const HeatCapacityRatio<NumericType>& other) = default;
118
119 /// \brief Copy constructor. Constructs a heat capacity ratio by copying another one.
120 template <typename OtherNumericType>
121 explicit constexpr HeatCapacityRatio(const HeatCapacityRatio<OtherNumericType>& other)
122 : HeatCapacityRatio(static_cast<NumericType>(other.Value())) {}
123
124 /// \brief Move constructor. Constructs a heat capacity ratio by moving another one.
125 constexpr HeatCapacityRatio(HeatCapacityRatio<NumericType>&& other) noexcept = default;
126
127 /// \brief Copy assignment operator. Assigns this heat capacity ratio by copying another one.
129 const HeatCapacityRatio<NumericType>& other) = default;
130
131 /// \brief Copy assignment operator. Assigns this heat capacity ratio by copying another one.
132 template <typename OtherNumericType>
135 this->value = static_cast<NumericType>(other.Value());
136 return *this;
137 }
138
139 /// \brief Move assignment operator. Assigns this heat capacity ratio by moving another one.
141 HeatCapacityRatio<NumericType>&& other) noexcept = default;
142
143 /// \brief Statically creates a heat capacity ratio of zero.
144 [[nodiscard]] static constexpr HeatCapacityRatio<NumericType> Zero() {
145 return HeatCapacityRatio<NumericType>{static_cast<NumericType>(0)};
146 }
147
149 const HeatCapacityRatio<NumericType>& heat_capacity_ratio) const {
150 return HeatCapacityRatio<NumericType>{this->value + heat_capacity_ratio.value};
151 }
152
154 const HeatCapacityRatio<NumericType>& heat_capacity_ratio) const {
155 return HeatCapacityRatio<NumericType>{this->value - heat_capacity_ratio.value};
156 }
157
158 constexpr HeatCapacityRatio<NumericType> operator*(const NumericType number) const {
159 return HeatCapacityRatio<NumericType>{this->value * number};
160 }
161
163 const IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity) const;
164
166 const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity) const;
167
168 constexpr HeatCapacityRatio<NumericType> operator/(const NumericType number) const {
169 return HeatCapacityRatio<NumericType>{this->value / number};
170 }
171
172 constexpr NumericType operator/(
173 const HeatCapacityRatio<NumericType>& heat_capacity_ratio) const noexcept {
174 return this->value / heat_capacity_ratio.value;
175 }
176
177 constexpr void operator+=(const HeatCapacityRatio<NumericType>& heat_capacity_ratio) noexcept {
178 this->value += heat_capacity_ratio.value;
179 }
180
181 constexpr void operator-=(const HeatCapacityRatio<NumericType>& heat_capacity_ratio) noexcept {
182 this->value -= heat_capacity_ratio.value;
183 }
184
185 constexpr void operator*=(const NumericType number) noexcept {
186 this->value *= number;
187 }
188
189 constexpr void operator/=(const NumericType number) noexcept {
190 this->value /= number;
191 }
192};
193
194template <typename NumericType>
195inline constexpr bool operator==(const HeatCapacityRatio<NumericType>& left,
196 const HeatCapacityRatio<NumericType>& right) noexcept {
197 return left.Value() == right.Value();
198}
199
200template <typename NumericType>
201inline constexpr bool operator!=(const HeatCapacityRatio<NumericType>& left,
202 const HeatCapacityRatio<NumericType>& right) noexcept {
203 return left.Value() != right.Value();
204}
205
206template <typename NumericType>
207inline constexpr bool operator<(const HeatCapacityRatio<NumericType>& left,
208 const HeatCapacityRatio<NumericType>& right) noexcept {
209 return left.Value() < right.Value();
210}
211
212template <typename NumericType>
213inline constexpr bool operator>(const HeatCapacityRatio<NumericType>& left,
214 const HeatCapacityRatio<NumericType>& right) noexcept {
215 return left.Value() > right.Value();
216}
217
218template <typename NumericType>
219inline constexpr bool operator<=(const HeatCapacityRatio<NumericType>& left,
220 const HeatCapacityRatio<NumericType>& right) noexcept {
221 return left.Value() <= right.Value();
222}
223
224template <typename NumericType>
225inline constexpr bool operator>=(const HeatCapacityRatio<NumericType>& left,
226 const HeatCapacityRatio<NumericType>& right) noexcept {
227 return left.Value() >= right.Value();
228}
229
230template <typename NumericType>
231inline std::ostream& operator<<(
232 std::ostream& stream, const HeatCapacityRatio<NumericType>& heat_capacity_ratio) {
233 stream << heat_capacity_ratio.Print();
234 return stream;
235}
236
237template <typename NumericType>
239 const NumericType number, const HeatCapacityRatio<NumericType>& heat_capacity_ratio) {
240 return HeatCapacityRatio<NumericType>{number * heat_capacity_ratio.Value()};
241}
242
243} // namespace PhQ
244
245namespace std {
246
247template <typename NumericType>
248struct hash<PhQ::HeatCapacityRatio<NumericType>> {
249 inline size_t operator()(const PhQ::HeatCapacityRatio<NumericType>& heat_capacity_ratio) const {
250 return hash<NumericType>()(heat_capacity_ratio.Value());
251 }
252};
253
254} // namespace std
255
256#endif // PHQ_HEAT_CAPACITY_RATIO_HPP
Abstract base class that represents any dimensionless scalar physical quantity. Such a physical quant...
constexpr NumericType Value() const noexcept
Value of this physical quantity.
NumericType value
Value of this physical quantity.
std::string Print() const
Prints this physical quantity as a string.
Gas constant of a gas. For the mass-specific gas constant, see PhQ::SpecificGasConstant.
Heat capacity ratio, also known as ratio of specific heats, adiabatic index, or Laplace's coefficient...
constexpr void operator*=(const NumericType number) noexcept
constexpr HeatCapacityRatio< NumericType > operator*(const NumericType number) const
constexpr HeatCapacityRatio(const NumericType value)
Constructor. Constructs a heat capacity ratio with a given value.
constexpr HeatCapacityRatio< NumericType > operator+(const HeatCapacityRatio< NumericType > &heat_capacity_ratio) const
constexpr void operator+=(const HeatCapacityRatio< NumericType > &heat_capacity_ratio) noexcept
constexpr HeatCapacityRatio< NumericType > & operator=(const HeatCapacityRatio< OtherNumericType > &other)
Copy assignment operator. Assigns this heat capacity ratio by copying another one.
constexpr NumericType operator/(const HeatCapacityRatio< NumericType > &heat_capacity_ratio) const noexcept
static constexpr HeatCapacityRatio< NumericType > Zero()
Statically creates a heat capacity ratio of zero.
constexpr HeatCapacityRatio< NumericType > & operator=(const HeatCapacityRatio< NumericType > &other)=default
Copy assignment operator. Assigns this heat capacity ratio by copying another one.
constexpr void operator/=(const NumericType number) noexcept
~HeatCapacityRatio() noexcept=default
Destructor. Destroys this heat capacity ratio.
constexpr HeatCapacityRatio< NumericType > operator/(const NumericType number) const
constexpr HeatCapacityRatio(HeatCapacityRatio< NumericType > &&other) noexcept=default
Move constructor. Constructs a heat capacity ratio by moving another one.
HeatCapacityRatio()=default
Default constructor. Constructs a heat capacity ratio ratio with an uninitialized value.
constexpr HeatCapacityRatio< NumericType > operator-(const HeatCapacityRatio< NumericType > &heat_capacity_ratio) const
constexpr HeatCapacityRatio< NumericType > & operator=(HeatCapacityRatio< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this heat capacity ratio by moving another one.
constexpr void operator-=(const HeatCapacityRatio< NumericType > &heat_capacity_ratio) noexcept
Isobaric heat capacity, also known as heat capacity at constant pressure. For the mass-specific isoba...
Isochoric heat capacity, also known as heat capacity at constant volume. For the mass-specific isocho...
Mass-specific gas constant of a gas. Gas constant per unit mass; see PhQ::GasConstant and PhQ::Mass....
Mass-specific isobaric heat capacity, also known as mass-specific heat capacity at constant pressure,...
Mass-specific isochoric heat capacity, also known as mass-specific heat capacity at constant volume,...
Mass
Mass units.
Definition Mass.hpp:53
Namespace that encompasses all of the Physical Quantities library's content.
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)
constexpr bool operator<(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr bool operator<=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr bool operator>(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr Acceleration< NumericType > operator*(const NumericType number, const Acceleration< NumericType > &acceleration)
constexpr bool operator==(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr bool operator>=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr bool operator!=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept