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
IsobaricHeatCapacity.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_ISOBARIC_HEAT_CAPACITY_HPP
26#define PHQ_ISOBARIC_HEAT_CAPACITY_HPP
27
28#include <cstddef>
29#include <functional>
30#include <ostream>
31
32#include "DimensionalScalar.hpp"
33#include "HeatCapacityRatio.hpp"
35#include "Unit/HeatCapacity.hpp"
36
37namespace PhQ {
38
39/// \brief Isobaric heat capacity, also known as heat capacity at constant pressure. For the
40/// mass-specific isobaric heat capacity, see PhQ::SpecificIsobaricHeatCapacity.
41template <typename NumericType = double>
42class IsobaricHeatCapacity : public DimensionalScalar<Unit::HeatCapacity, NumericType> {
43public:
44 /// \brief Default constructor. Constructs an isobaric heat capacity with an uninitialized value.
46
47 /// \brief Constructor. Constructs an isobaric heat capacity with a given value expressed in a
48 /// given heat capacity unit.
49 IsobaricHeatCapacity(const NumericType value, const Unit::HeatCapacity unit)
50 : DimensionalScalar<Unit::HeatCapacity, NumericType>(value, unit) {}
51
52 /// \brief Constructor. Constructs an isobaric heat capacity from a given gas constant and
53 /// isochoric heat capacity using Mayer's relation.
54 constexpr IsobaricHeatCapacity(const IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity,
55 const GasConstant<NumericType>& gas_constant);
56
57 /// \brief Constructor. Constructs an isobaric heat capacity from a given gas constant and heat
58 /// capacity ratio using the definition of the heat capacity ratio and Mayer's relation.
59 constexpr IsobaricHeatCapacity(const HeatCapacityRatio<NumericType>& heat_capacity_ratio,
60 const GasConstant<NumericType>& gas_constant);
61
62 /// \brief Constructor. Constructs an isobaric heat capacity from a given isochoric heat capacity
63 /// and heat capacity ratio using the definition of the specific heat ratio.
64 constexpr IsobaricHeatCapacity(const HeatCapacityRatio<NumericType>& heat_capacity_ratio,
65 const IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity)
66 : IsobaricHeatCapacity<NumericType>(
67 heat_capacity_ratio.Value() * isochoric_heat_capacity.Value()) {}
68
69 /// \brief Constructor. Constructs an isobaric heat capacity from a given specific isobaric heat
70 /// capacity and mass using the definition of the specific isobaric heat capacity.
71 constexpr IsobaricHeatCapacity(
72 const SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity,
73 const Mass<NumericType>& mass);
74
75 /// \brief Destructor. Destroys this isobaric heat capacity.
76 ~IsobaricHeatCapacity() noexcept = default;
77
78 /// \brief Copy constructor. Constructs an isobaric heat capacity by copying another one.
79 constexpr IsobaricHeatCapacity(const IsobaricHeatCapacity<NumericType>& other) = default;
80
81 /// \brief Copy constructor. Constructs a isobaric heat capacity by copying another one.
82 template <typename OtherNumericType>
83 explicit constexpr IsobaricHeatCapacity(const IsobaricHeatCapacity<OtherNumericType>& other)
84 : IsobaricHeatCapacity(static_cast<NumericType>(other.Value())) {}
85
86 /// \brief Move constructor. Constructs an isobaric heat capacity by moving another one.
87 constexpr IsobaricHeatCapacity(IsobaricHeatCapacity<NumericType>&& other) noexcept = default;
88
89 /// \brief Copy assignment operator. Assigns this isobaric heat capacity by copying another one.
91 const IsobaricHeatCapacity<NumericType>& other) = default;
92
93 /// \brief Copy assignment operator. Assigns this isobaric heat capacity by copying another one.
94 template <typename OtherNumericType>
97 this->value = static_cast<NumericType>(other.Value());
98 return *this;
99 }
100
101 /// \brief Move assignment operator. Assigns this isobaric heat capacity by moving another one.
103 IsobaricHeatCapacity<NumericType>&& other) noexcept = default;
104
105 /// \brief Statically creates an isobaric heat capacity of zero.
106 [[nodiscard]] static constexpr IsobaricHeatCapacity<NumericType> Zero() {
107 return IsobaricHeatCapacity<NumericType>{static_cast<NumericType>(0)};
108 }
109
110 /// \brief Statically creates an isobaric heat capacity with a given value expressed in a given
111 /// heat capacity unit.
112 template <Unit::HeatCapacity Unit>
113 [[nodiscard]] static constexpr IsobaricHeatCapacity<NumericType> Create(const NumericType value) {
115 ConvertStatically<Unit::HeatCapacity, Unit, Standard<Unit::HeatCapacity>>(value)};
116 }
117
119 const IsobaricHeatCapacity<NumericType>& isobaric_heat_capacity) const {
120 return IsobaricHeatCapacity<NumericType>{this->value + isobaric_heat_capacity.value};
121 }
122
124 const IsobaricHeatCapacity<NumericType>& isobaric_heat_capacity) const {
125 return IsobaricHeatCapacity<NumericType>{this->value - isobaric_heat_capacity.value};
126 }
127
129 const IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity) const;
130
132 const GasConstant<NumericType>& gas_constant) const;
133
134 constexpr IsobaricHeatCapacity<NumericType> operator*(const NumericType number) const {
135 return IsobaricHeatCapacity<NumericType>{this->value * number};
136 }
137
138 constexpr IsobaricHeatCapacity<NumericType> operator/(const NumericType number) const {
139 return IsobaricHeatCapacity<NumericType>{this->value / number};
140 }
141
142 constexpr NumericType operator/(
143 const IsobaricHeatCapacity<NumericType>& isobaric_heat_capacity) const noexcept {
144 return this->value / isobaric_heat_capacity.value;
145 }
146
148 const Mass<NumericType>& mass) const;
149
151 const SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity) const;
152
154 const IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity) const {
155 return HeatCapacityRatio<NumericType>{*this, isochoric_heat_capacity};
156 }
157
159 const HeatCapacityRatio<NumericType>& heat_capacity_ratio) const {
160 return IsochoricHeatCapacity<NumericType>{*this, heat_capacity_ratio};
161 }
162
163 constexpr void operator+=(
164 const IsobaricHeatCapacity<NumericType>& isobaric_heat_capacity) noexcept {
165 this->value += isobaric_heat_capacity.value;
166 }
167
168 constexpr void operator-=(
169 const IsobaricHeatCapacity<NumericType>& isobaric_heat_capacity) noexcept {
170 this->value -= isobaric_heat_capacity.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 an isobaric heat capacity with a given value expressed in the
183 /// standard heat capacity unit.
184 explicit constexpr IsobaricHeatCapacity(const NumericType value)
185 : DimensionalScalar<Unit::HeatCapacity, NumericType>(value) {}
186};
187
188template <typename NumericType>
189inline constexpr bool operator==(const IsobaricHeatCapacity<NumericType>& left,
190 const IsobaricHeatCapacity<NumericType>& right) noexcept {
191 return left.Value() == right.Value();
192}
193
194template <typename NumericType>
195inline constexpr bool operator!=(const IsobaricHeatCapacity<NumericType>& left,
196 const IsobaricHeatCapacity<NumericType>& right) noexcept {
197 return left.Value() != right.Value();
198}
199
200template <typename NumericType>
201inline constexpr bool operator<(const IsobaricHeatCapacity<NumericType>& left,
202 const IsobaricHeatCapacity<NumericType>& right) noexcept {
203 return left.Value() < right.Value();
204}
205
206template <typename NumericType>
207inline constexpr bool operator>(const IsobaricHeatCapacity<NumericType>& left,
208 const IsobaricHeatCapacity<NumericType>& right) noexcept {
209 return left.Value() > right.Value();
210}
211
212template <typename NumericType>
213inline constexpr bool operator<=(const IsobaricHeatCapacity<NumericType>& left,
214 const IsobaricHeatCapacity<NumericType>& right) noexcept {
215 return left.Value() <= right.Value();
216}
217
218template <typename NumericType>
219inline constexpr bool operator>=(const IsobaricHeatCapacity<NumericType>& left,
220 const IsobaricHeatCapacity<NumericType>& right) noexcept {
221 return left.Value() >= right.Value();
222}
223
224template <typename NumericType>
225inline std::ostream& operator<<(
226 std::ostream& stream, const IsobaricHeatCapacity<NumericType>& isobaric_heat_capacity) {
227 stream << isobaric_heat_capacity.Print();
228 return stream;
229}
230
231template <typename NumericType>
233 const NumericType number, const IsobaricHeatCapacity<NumericType>& isobaric_heat_capacity) {
234 return isobaric_heat_capacity * number;
235}
236
237template <typename NumericType>
239 const IsobaricHeatCapacity<NumericType>& isobaric_heat_capacity,
240 const IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity)
241 : HeatCapacityRatio<NumericType>(
242 isobaric_heat_capacity.Value() / isochoric_heat_capacity.Value()) {}
243
244template <typename NumericType>
246 const IsobaricHeatCapacity<NumericType>& isobaric_heat_capacity,
247 const HeatCapacityRatio<NumericType>& heat_capacity_ratio)
248 : IsochoricHeatCapacity<NumericType>(
249 isobaric_heat_capacity.Value() / heat_capacity_ratio.Value()) {}
250
251template <typename NumericType>
253 const IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity) const {
254 return IsobaricHeatCapacity<NumericType>{*this, isochoric_heat_capacity};
255}
256
257template <typename NumericType>
259 const HeatCapacityRatio<NumericType>& heat_capacity_ratio) const {
260 return IsobaricHeatCapacity<NumericType>{heat_capacity_ratio, *this};
261}
262
263} // namespace PhQ
264
265namespace std {
266
267template <typename NumericType>
268struct hash<PhQ::IsobaricHeatCapacity<NumericType>> {
269 inline size_t operator()(
270 const PhQ::IsobaricHeatCapacity<NumericType>& isobaric_heat_capacity) const {
271 return hash<NumericType>()(isobaric_heat_capacity.Value());
272 }
273};
274
275} // namespace std
276
277#endif // PHQ_ISOBARIC_HEAT_CAPACITY_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.
Heat capacity ratio, also known as ratio of specific heats, adiabatic index, or Laplace's coefficient...
constexpr HeatCapacityRatio< NumericType > operator*(const NumericType number) const
HeatCapacityRatio()=default
Default constructor. Constructs a heat capacity ratio ratio with an uninitialized value.
Isobaric heat capacity, also known as heat capacity at constant pressure. For the mass-specific isoba...
constexpr IsobaricHeatCapacity< NumericType > operator+(const IsobaricHeatCapacity< NumericType > &isobaric_heat_capacity) const
IsobaricHeatCapacity()=default
Default constructor. Constructs an isobaric heat capacity with an uninitialized value.
constexpr HeatCapacityRatio< NumericType > operator/(const IsochoricHeatCapacity< NumericType > &isochoric_heat_capacity) const
constexpr IsobaricHeatCapacity(IsobaricHeatCapacity< NumericType > &&other) noexcept=default
Move constructor. Constructs an isobaric heat capacity by moving another one.
constexpr IsobaricHeatCapacity< NumericType > operator-(const IsobaricHeatCapacity< NumericType > &isobaric_heat_capacity) const
constexpr IsobaricHeatCapacity< NumericType > & operator=(const IsobaricHeatCapacity< OtherNumericType > &other)
Copy assignment operator. Assigns this isobaric heat capacity by copying another one.
constexpr IsobaricHeatCapacity(const HeatCapacityRatio< NumericType > &heat_capacity_ratio, const IsochoricHeatCapacity< NumericType > &isochoric_heat_capacity)
Constructor. Constructs an isobaric heat capacity from a given isochoric heat capacity and heat capac...
constexpr IsobaricHeatCapacity< NumericType > & operator=(const IsobaricHeatCapacity< NumericType > &other)=default
Copy assignment operator. Assigns this isobaric heat capacity by copying another one.
constexpr IsobaricHeatCapacity< NumericType > operator/(const NumericType number) const
constexpr void operator/=(const NumericType number) noexcept
static constexpr IsobaricHeatCapacity< NumericType > Zero()
Statically creates an isobaric heat capacity of zero.
constexpr void operator-=(const IsobaricHeatCapacity< NumericType > &isobaric_heat_capacity) noexcept
~IsobaricHeatCapacity() noexcept=default
Destructor. Destroys this isobaric heat capacity.
constexpr void operator*=(const NumericType number) noexcept
constexpr NumericType operator/(const IsobaricHeatCapacity< NumericType > &isobaric_heat_capacity) const noexcept
constexpr IsobaricHeatCapacity< NumericType > operator*(const NumericType number) const
constexpr IsochoricHeatCapacity< NumericType > operator/(const HeatCapacityRatio< NumericType > &heat_capacity_ratio) const
static constexpr IsobaricHeatCapacity< NumericType > Create(const NumericType value)
Statically creates an isobaric heat capacity with a given value expressed in a given heat capacity un...
constexpr void operator+=(const IsobaricHeatCapacity< NumericType > &isobaric_heat_capacity) noexcept
IsobaricHeatCapacity(const NumericType value, const Unit::HeatCapacity unit)
Constructor. Constructs an isobaric heat capacity with a given value expressed in a given heat capaci...
constexpr IsobaricHeatCapacity< NumericType > & operator=(IsobaricHeatCapacity< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this isobaric heat capacity by moving another one.
constexpr IsobaricHeatCapacity(const NumericType value)
Constructor. Constructs an isobaric heat capacity with a given value expressed in the standard heat c...
Isochoric heat capacity, also known as heat capacity at constant volume. For the mass-specific isocho...
IsochoricHeatCapacity()=default
Default constructor. Constructs an isochoric heat capacity with an uninitialized value.
constexpr IsochoricHeatCapacity< NumericType > operator*(const NumericType number) const
Mass. For the time rate of change of mass, see PhQ::MassRate; see also PhQ::Time and PhQ::Frequency.
Definition Mass.hpp:100
Mass-specific isobaric heat capacity, also known as mass-specific heat capacity at constant pressure,...
HeatCapacity
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