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
SpecificGasConstant.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_SPECIFIC_GAS_CONSTANT_HPP
26#define PHQ_SPECIFIC_GAS_CONSTANT_HPP
27
28#include <cstddef>
29#include <functional>
30#include <ostream>
31
32#include "DimensionalScalar.hpp"
33#include "GasConstant.hpp"
34#include "HeatCapacityRatio.hpp"
35#include "Mass.hpp"
39
40namespace PhQ {
41
42/// \brief Mass-specific gas constant of a gas. Gas constant per unit mass; see PhQ::GasConstant and
43/// PhQ::Mass. PhQ::Mass.
44template <typename NumericType = double>
45class SpecificGasConstant : public DimensionalScalar<Unit::SpecificHeatCapacity, NumericType> {
46public:
47 /// \brief Default constructor. Constructs a specific gas constant with an uninitialized value.
49
50 /// \brief Constructor. Constructs a specific gas constant with a given value expressed in a given
51 /// specific heat capacity unit.
53 : DimensionalScalar<Unit::SpecificHeatCapacity, NumericType>(value, unit) {}
54
55 /// \brief Constructor. Constructs a specific gas constant from a given specific isobaric heat
56 /// capacity and specific isochoric heat capacity using Mayer's relation.
58 const SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity,
59 const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity)
60 : SpecificGasConstant<NumericType>(
61 specific_isobaric_heat_capacity.Value() - specific_isochoric_heat_capacity.Value()) {}
62
63 /// \brief Constructor. Constructs a specific gas constant from a given specific isobaric heat
64 /// capacity and heat capacity ratio using the definition of the heat capacity ratio and Mayer's
65 /// relation.
67 const HeatCapacityRatio<NumericType>& heat_capacity_ratio,
68 const SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity)
69 : SpecificGasConstant<NumericType>(
70 (1.0 - 1.0 / heat_capacity_ratio.Value()) * specific_isobaric_heat_capacity.Value()) {}
71
72 /// \brief Constructor. Constructs a specific gas constant from a given specific isochoric heat
73 /// capacity and heat capacity ratio using the definition of the heat capacity ratio and Mayer's
74 /// relation.
76 const HeatCapacityRatio<NumericType>& heat_capacity_ratio,
77 const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity)
78 : SpecificGasConstant<NumericType>(
79 (heat_capacity_ratio.Value() - 1.0) * specific_isochoric_heat_capacity.Value()) {}
80
81 /// \brief Constructor. Constructs a specific gas constant from a given gas constant and mass
82 /// using the definition of the specific gas constant.
84 const GasConstant<NumericType>& gas_constant, const Mass<NumericType>& mass)
85 : SpecificGasConstant<NumericType>(gas_constant.Value() / mass.Value()) {}
86
87 /// \brief Destructor. Destroys this specific gas constant.
88 ~SpecificGasConstant() noexcept = default;
89
90 /// \brief Copy constructor. Constructs a specific gas constant by copying another one.
91 constexpr SpecificGasConstant(const SpecificGasConstant<NumericType>& other) = default;
92
93 /// \brief Copy constructor. Constructs a specific gas constant by copying another one.
94 template <typename OtherNumericType>
95 explicit constexpr SpecificGasConstant(const SpecificGasConstant<OtherNumericType>& other)
96 : SpecificGasConstant(static_cast<NumericType>(other.Value())) {}
97
98 /// \brief Move constructor. Constructs a specific gas constant by moving another one.
99 constexpr SpecificGasConstant(SpecificGasConstant<NumericType>&& other) noexcept = default;
100
101 /// \brief Copy assignment operator. Assigns this specific gas constant by copying another one.
103 const SpecificGasConstant<NumericType>& other) = default;
104
105 /// \brief Copy assignment operator. Assigns this specific gas constant by copying another one.
106 template <typename OtherNumericType>
109 this->value = static_cast<NumericType>(other.Value());
110 return *this;
111 }
112
113 /// \brief Move assignment operator. Assigns this specific gas constant by moving another one.
115 SpecificGasConstant<NumericType>&& other) noexcept = default;
116
117 /// \brief Statically creates a specific gas constant of zero.
118 [[nodiscard]] static constexpr SpecificGasConstant<NumericType> Zero() {
119 return SpecificGasConstant<NumericType>{static_cast<NumericType>(0)};
120 }
121
122 /// \brief Statically creates a specific gas constant with a given value expressed in a given
123 /// specific heat capacity unit.
124 template <Unit::SpecificHeatCapacity Unit>
125 [[nodiscard]] static constexpr SpecificGasConstant<NumericType> Create(const NumericType value) {
127 ConvertStatically<Unit::SpecificHeatCapacity, Unit, Standard<Unit::SpecificHeatCapacity>>(
128 value)};
129 }
130
132 const SpecificGasConstant<NumericType>& specific_gas_constant) const {
133 return SpecificGasConstant<NumericType>{this->value + specific_gas_constant.value};
134 }
135
137 const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity) const {
138 return SpecificIsobaricHeatCapacity<NumericType>{specific_isochoric_heat_capacity, *this};
139 }
140
142 const SpecificGasConstant<NumericType>& specific_gas_constant) const {
143 return SpecificGasConstant<NumericType>{this->value - specific_gas_constant.value};
144 }
145
146 constexpr SpecificGasConstant<NumericType> operator*(const NumericType number) const {
147 return SpecificGasConstant<NumericType>{this->value * number};
148 }
149
151 return GasConstant<NumericType>{*this, mass};
152 }
153
154 constexpr SpecificGasConstant<NumericType> operator/(const NumericType number) const {
155 return SpecificGasConstant<NumericType>{this->value / number};
156 }
157
158 constexpr NumericType operator/(
159 const SpecificGasConstant<NumericType>& specific_gas_constant) const noexcept {
160 return this->value / specific_gas_constant.value;
161 }
162
163 constexpr void operator+=(
164 const SpecificGasConstant<NumericType>& specific_gas_constant) noexcept {
165 this->value += specific_gas_constant.value;
166 }
167
168 constexpr void operator-=(
169 const SpecificGasConstant<NumericType>& specific_gas_constant) noexcept {
170 this->value -= specific_gas_constant.value;
171 }
172
173 constexpr void operator*=(const NumericType number) noexcept {
174 this->value *= number;
175 }
176
177 constexpr void operator/=(const NumericType number) noexcept {
178 this->value /= number;
179 }
180
181private:
182 /// \brief Constructor. Constructs a specific gas constant with a given value expressed in the
183 /// standard specific heat capacity unit.
184 explicit constexpr SpecificGasConstant(const NumericType value)
185 : DimensionalScalar<Unit::SpecificHeatCapacity, NumericType>(value) {}
186};
187
188template <typename NumericType>
189inline constexpr bool operator==(const SpecificGasConstant<NumericType>& left,
190 const SpecificGasConstant<NumericType>& right) noexcept {
191 return left.Value() == right.Value();
192}
193
194template <typename NumericType>
195inline constexpr bool operator!=(const SpecificGasConstant<NumericType>& left,
196 const SpecificGasConstant<NumericType>& right) noexcept {
197 return left.Value() != right.Value();
198}
199
200template <typename NumericType>
201inline constexpr bool operator<(const SpecificGasConstant<NumericType>& left,
202 const SpecificGasConstant<NumericType>& right) noexcept {
203 return left.Value() < right.Value();
204}
205
206template <typename NumericType>
207inline constexpr bool operator>(const SpecificGasConstant<NumericType>& left,
208 const SpecificGasConstant<NumericType>& right) noexcept {
209 return left.Value() > right.Value();
210}
211
212template <typename NumericType>
213inline constexpr bool operator<=(const SpecificGasConstant<NumericType>& left,
214 const SpecificGasConstant<NumericType>& right) noexcept {
215 return left.Value() <= right.Value();
216}
217
218template <typename NumericType>
219inline constexpr bool operator>=(const SpecificGasConstant<NumericType>& left,
220 const SpecificGasConstant<NumericType>& right) noexcept {
221 return left.Value() >= right.Value();
222}
223
224template <typename NumericType>
225inline std::ostream& operator<<(
226 std::ostream& stream, const SpecificGasConstant<NumericType>& specific_gas_constant) {
227 stream << specific_gas_constant.Print();
228 return stream;
229}
230
231template <typename NumericType>
233 const NumericType number, const SpecificGasConstant<NumericType>& specific_gas_constant) {
234 return specific_gas_constant * number;
235}
236
237template <typename NumericType>
239 const SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity,
240 const SpecificGasConstant<NumericType>& specific_gas_constant)
241 : HeatCapacityRatio<NumericType>(
242 specific_isobaric_heat_capacity.Value()
243 / (specific_isobaric_heat_capacity.Value() - specific_gas_constant.Value())) {}
244
245template <typename NumericType>
247 const SpecificGasConstant<NumericType>& specific_gas_constant,
248 const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity)
249 : HeatCapacityRatio<NumericType>(
250 specific_gas_constant.Value() / specific_isochoric_heat_capacity.Value() + 1.0) {}
251
252template <typename NumericType>
253inline constexpr Mass<NumericType>::Mass(
254 const GasConstant<NumericType>& gas_constant,
255 const SpecificGasConstant<NumericType>& specific_gas_constant)
256 : Mass<NumericType>(gas_constant.Value() / specific_gas_constant.Value()) {}
257
258template <typename NumericType>
260 const SpecificGasConstant<NumericType>& specific_gas_constant, const Mass<NumericType>& mass)
261 : GasConstant<NumericType>(specific_gas_constant.Value() * mass.Value()) {}
262
263template <typename NumericType>
265 const SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity,
266 const SpecificGasConstant<NumericType>& specific_gas_constant)
267 : SpecificIsochoricHeatCapacity<NumericType>(
268 specific_isobaric_heat_capacity.Value() - specific_gas_constant.Value()) {}
269
270template <typename NumericType>
272 const SpecificGasConstant<NumericType>& specific_gas_constant,
273 const HeatCapacityRatio<NumericType>& heat_capacity_ratio)
274 : SpecificIsochoricHeatCapacity<NumericType>(
275 specific_gas_constant.Value() / (heat_capacity_ratio.Value() - 1.0)) {}
276
277template <typename NumericType>
279 const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity,
280 const SpecificGasConstant<NumericType>& specific_gas_constant)
281 : SpecificIsobaricHeatCapacity<NumericType>(
282 specific_isochoric_heat_capacity.Value() + specific_gas_constant.Value()) {}
283
284template <typename NumericType>
286 const HeatCapacityRatio<NumericType>& heat_capacity_ratio,
287 const SpecificGasConstant<NumericType>& specific_gas_constant)
288 : SpecificIsobaricHeatCapacity<NumericType>(
289 heat_capacity_ratio.Value() * specific_gas_constant.Value()
290 / (heat_capacity_ratio.Value() - 1.0)) {}
291
292template <typename NumericType>
295 const SpecificGasConstant<NumericType>& specific_gas_constant) const {
296 return SpecificIsobaricHeatCapacity<NumericType>{*this, specific_gas_constant};
297}
298
299template <typename NumericType>
302 const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity) const {
303 return SpecificGasConstant<NumericType>{*this, specific_isochoric_heat_capacity};
304}
305
306template <typename NumericType>
309 const SpecificGasConstant<NumericType>& specific_gas_constant) const {
310 return SpecificIsochoricHeatCapacity<NumericType>{*this, specific_gas_constant};
311}
312
313template <typename NumericType>
315 const SpecificGasConstant<NumericType>& specific_gas_constant) const {
316 return GasConstant<NumericType>{specific_gas_constant, *this};
317}
318
319template <typename NumericType>
324
325template <typename NumericType>
327 const SpecificGasConstant<NumericType>& specific_gas_constant) const {
328 return Mass<NumericType>{*this, specific_gas_constant};
329}
330
331} // namespace PhQ
332
333namespace std {
334
335template <typename NumericType>
336struct hash<PhQ::SpecificGasConstant<NumericType>> {
337 inline size_t operator()(
338 const PhQ::SpecificGasConstant<NumericType>& specific_gas_constant) const {
339 return hash<NumericType>()(specific_gas_constant.Value());
340 }
341};
342
343} // namespace std
344
345#endif // PHQ_SPECIFIC_GAS_CONSTANT_HPP
Abstract base class that represents any dimensional scalar physical quantity. Such a physical quantit...
NumericType value
Value of this physical quantity expressed in its standard unit of measure.
constexpr NumericType Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
static constexpr UnitType Unit()
Standard unit of measure for this physical quantity. This physical quantity's value is stored interna...
std::string Print() const
Prints this physical quantity as a string. This physical quantity's value is expressed in its standar...
Gas constant of a gas. For the mass-specific gas constant, see PhQ::SpecificGasConstant.
constexpr GasConstant< NumericType > operator/(const NumericType number) const
GasConstant()=default
Default constructor. Constructs a gas constant with an uninitialized value.
Heat capacity ratio, also known as ratio of specific heats, adiabatic index, or Laplace's coefficient...
HeatCapacityRatio()=default
Default constructor. Constructs a heat capacity ratio ratio with an uninitialized value.
Mass. For the time rate of change of mass, see PhQ::MassRate; see also PhQ::Time and PhQ::Frequency.
Definition Mass.hpp:100
Mass()=default
Default constructor. Constructs a mass with an uninitialized value.
constexpr Mass< NumericType > operator*(const NumericType number) const
Definition Mass.hpp:192
Mass-specific gas constant of a gas. Gas constant per unit mass; see PhQ::GasConstant and PhQ::Mass....
constexpr void operator+=(const SpecificGasConstant< NumericType > &specific_gas_constant) noexcept
static constexpr SpecificGasConstant< NumericType > Create(const NumericType value)
Statically creates a specific gas constant with a given value expressed in a given specific heat capa...
constexpr SpecificGasConstant< NumericType > operator-(const SpecificGasConstant< NumericType > &specific_gas_constant) const
constexpr SpecificGasConstant(const SpecificIsobaricHeatCapacity< NumericType > &specific_isobaric_heat_capacity, const SpecificIsochoricHeatCapacity< NumericType > &specific_isochoric_heat_capacity)
Constructor. Constructs a specific gas constant from a given specific isobaric heat capacity and spec...
constexpr SpecificGasConstant(const GasConstant< NumericType > &gas_constant, const Mass< NumericType > &mass)
Constructor. Constructs a specific gas constant from a given gas constant and mass using the definiti...
constexpr SpecificGasConstant< NumericType > operator*(const NumericType number) const
constexpr SpecificGasConstant< NumericType > & operator=(const SpecificGasConstant< NumericType > &other)=default
Copy assignment operator. Assigns this specific gas constant by copying another one.
constexpr SpecificIsobaricHeatCapacity< NumericType > operator+(const SpecificIsochoricHeatCapacity< NumericType > &specific_isochoric_heat_capacity) const
constexpr SpecificGasConstant(const HeatCapacityRatio< NumericType > &heat_capacity_ratio, const SpecificIsobaricHeatCapacity< NumericType > &specific_isobaric_heat_capacity)
Constructor. Constructs a specific gas constant from a given specific isobaric heat capacity and heat...
constexpr GasConstant< NumericType > operator*(const Mass< NumericType > &mass) const
constexpr void operator*=(const NumericType number) noexcept
constexpr void operator/=(const NumericType number) noexcept
constexpr SpecificGasConstant< NumericType > & operator=(SpecificGasConstant< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this specific gas constant by moving another one.
constexpr SpecificGasConstant< NumericType > operator+(const SpecificGasConstant< NumericType > &specific_gas_constant) const
SpecificGasConstant()=default
Default constructor. Constructs a specific gas constant with an uninitialized value.
constexpr void operator-=(const SpecificGasConstant< NumericType > &specific_gas_constant) noexcept
static constexpr SpecificGasConstant< NumericType > Zero()
Statically creates a specific gas constant of zero.
~SpecificGasConstant() noexcept=default
Destructor. Destroys this specific gas constant.
constexpr SpecificGasConstant< NumericType > operator/(const NumericType number) const
constexpr SpecificGasConstant(SpecificGasConstant< NumericType > &&other) noexcept=default
Move constructor. Constructs a specific gas constant by moving another one.
constexpr SpecificGasConstant< NumericType > & operator=(const SpecificGasConstant< OtherNumericType > &other)
Copy assignment operator. Assigns this specific gas constant by copying another one.
constexpr SpecificGasConstant(const NumericType value)
Constructor. Constructs a specific gas constant with a given value expressed in the standard specific...
constexpr NumericType operator/(const SpecificGasConstant< NumericType > &specific_gas_constant) const noexcept
constexpr SpecificGasConstant(const HeatCapacityRatio< NumericType > &heat_capacity_ratio, const SpecificIsochoricHeatCapacity< NumericType > &specific_isochoric_heat_capacity)
Constructor. Constructs a specific gas constant from a given specific isochoric heat capacity and hea...
SpecificGasConstant(const NumericType value, const Unit::SpecificHeatCapacity unit)
Constructor. Constructs a specific gas constant with a given value expressed in a given specific heat...
Mass-specific isobaric heat capacity, also known as mass-specific heat capacity at constant pressure,...
SpecificIsobaricHeatCapacity()=default
Default constructor. Constructs a specific isobaric heat capacity with an uninitialized value.
constexpr SpecificIsobaricHeatCapacity< NumericType > operator-(const SpecificIsobaricHeatCapacity< NumericType > &specific_isobaric_heat_capacity) const
Mass-specific isochoric heat capacity, also known as mass-specific heat capacity at constant volume,...
SpecificIsochoricHeatCapacity()=default
Default constructor. Constructs a specific isochoric heat capacity with an uninitialized value.
constexpr SpecificIsochoricHeatCapacity< NumericType > operator+(const SpecificIsochoricHeatCapacity< NumericType > &specific_isochoric_heat_capacity) const
SpecificHeatCapacity
Mass-specific heat capacity units.
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