Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
SpecificIsochoricHeatCapacity.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_ISOCHORIC_HEAT_CAPACITY_HPP
26 #define PHQ_SPECIFIC_ISOCHORIC_HEAT_CAPACITY_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 
32 #include "DimensionalScalar.hpp"
33 #include "HeatCapacityRatio.hpp"
35 #include "Mass.hpp"
37 
38 namespace PhQ {
39 
40 /// \brief Mass-specific isochoric heat capacity, also known as mass-specific heat capacity at
41 /// constant volume, or isochoric heat capacity per unit mass; see PhQ::IsochoricHeatCapacity and
42 /// PhQ::Mass.
43 template <typename NumericType = double>
45  : public DimensionalScalar<Unit::SpecificHeatCapacity, NumericType> {
46 public:
47  /// \brief Default constructor. Constructs a specific isochoric heat capacity with an
48  /// uninitialized value.
50 
51  /// \brief Constructor. Constructs a specific isochoric heat capacity with a given value expressed
52  /// in a given specific heat capacity unit.
54  : DimensionalScalar<Unit::SpecificHeatCapacity, NumericType>(value, unit) {}
55 
56  /// \brief Constructor. Constructs a specific isochoric heat capacity from a given specific gas
57  /// constant and specific isobaric heat capacity using Mayer's relation.
59  const SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity,
60  const SpecificGasConstant<NumericType>& specific_gas_constant);
61 
62  /// \brief Constructor. Constructs a specific isochoric heat capacity from a given specific gas
63  /// constant and heat capacity ratio using the definition of the heat capacity ratio and Mayer's
64  /// relation.
66  const SpecificGasConstant<NumericType>& specific_gas_constant,
67  const HeatCapacityRatio<NumericType>& heat_capacity_ratio);
68 
69  /// \brief Constructor. Constructs a specific isochoric heat capacity from a given specific
70  /// isobaric heat capacity and heat capacity ratio using the definition of the heat capacity
71  /// ratio.
73  const SpecificIsobaricHeatCapacity<NumericType>& specific_isobaric_heat_capacity,
74  const HeatCapacityRatio<NumericType>& heat_capacity_ratio);
75 
76  /// \brief Constructor. Constructs a specific isochoric heat capacity from a given isochoric heat
77  /// capacity and mass using the definition of the specific isochoric heat capacity.
79  const IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity,
80  const Mass<NumericType>& mass)
81  : SpecificIsochoricHeatCapacity<NumericType>(isochoric_heat_capacity.Value() / mass.Value()) {}
82 
83  /// \brief Destructor. Destroys this specific isochoric heat capacity.
84  ~SpecificIsochoricHeatCapacity() noexcept = default;
85 
86  /// \brief Copy constructor. Constructs a specific isochoric heat capacity by copying another one.
88  const SpecificIsochoricHeatCapacity<NumericType>& other) = default;
89 
90  /// \brief Copy constructor. Constructs a specific isochoric heat capacity by copying another one.
91  template <typename OtherNumericType>
92  explicit constexpr SpecificIsochoricHeatCapacity(
93  const SpecificIsochoricHeatCapacity<OtherNumericType>& other)
94  : SpecificIsochoricHeatCapacity(static_cast<NumericType>(other.Value())) {}
95 
96  /// \brief Move constructor. Constructs a specific isochoric heat capacity by moving another one.
98  SpecificIsochoricHeatCapacity<NumericType>&& other) noexcept = default;
99 
100  /// \brief Copy assignment operator. Assigns this specific isochoric heat capacity by copying
101  /// another one.
103  const SpecificIsochoricHeatCapacity<NumericType>& other) = default;
104 
105  /// \brief Copy assignment operator. Assigns this specific isochoric heat capacity by copying
106  /// another one.
107  template <typename OtherNumericType>
110  this->value = static_cast<NumericType>(other.Value());
111  return *this;
112  }
113 
114  /// \brief Move assignment operator. Assigns this specific isochoric heat capacity by moving
115  /// another one.
117  SpecificIsochoricHeatCapacity<NumericType>&& other) noexcept = default;
118 
119  /// \brief Statically creates a specific isochoric heat capacity of zero.
120  [[nodiscard]] static constexpr SpecificIsochoricHeatCapacity<NumericType> Zero() {
121  return SpecificIsochoricHeatCapacity<NumericType>{static_cast<NumericType>(0)};
122  }
123 
124  /// \brief Statically creates a specific isochoric heat capacity with a given value expressed in a
125  /// given specific heat capacity unit.
126  template <Unit::SpecificHeatCapacity Unit>
127  [[nodiscard]] static constexpr SpecificIsochoricHeatCapacity<NumericType> Create(
128  const NumericType value) {
130  ConvertStatically<Unit::SpecificHeatCapacity, Unit, Standard<Unit::SpecificHeatCapacity>>(
131  value)};
132  }
133 
135  const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity) const {
137  this->value + specific_isochoric_heat_capacity.value};
138  }
139 
141  const SpecificGasConstant<NumericType>& specific_gas_constant) const;
142 
144  const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity) const {
146  this->value - specific_isochoric_heat_capacity.value};
147  }
148 
149  constexpr SpecificIsochoricHeatCapacity<NumericType> operator*(const NumericType number) const {
150  return SpecificIsochoricHeatCapacity<NumericType>{this->value * number};
151  }
152 
154  return IsochoricHeatCapacity<NumericType>{*this, mass};
155  }
156 
158  const HeatCapacityRatio<NumericType>& heat_capacity_ratio) const;
159 
160  constexpr SpecificIsochoricHeatCapacity<NumericType> operator/(const NumericType number) const {
161  return SpecificIsochoricHeatCapacity<NumericType>{this->value / number};
162  }
163 
164  constexpr NumericType operator/(
165  const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity)
166  const noexcept {
167  return this->value / specific_isochoric_heat_capacity.value;
168  }
169 
170  constexpr void operator+=(
171  const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity) noexcept {
172  this->value += specific_isochoric_heat_capacity.value;
173  }
174 
175  constexpr void operator-=(
176  const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity) noexcept {
177  this->value -= specific_isochoric_heat_capacity.value;
178  }
179 
180  constexpr void operator*=(const NumericType number) noexcept {
181  this->value *= number;
182  }
183 
184  constexpr void operator/=(const NumericType number) noexcept {
185  this->value /= number;
186  }
187 
188 private:
189  /// \brief Constructor. Constructs a specific isochoric heat capacity with a given value expressed
190  /// in the standard specific heat capacity unit.
191  explicit constexpr SpecificIsochoricHeatCapacity(const NumericType value)
192  : DimensionalScalar<Unit::SpecificHeatCapacity, NumericType>(value) {}
193 };
194 
195 template <typename NumericType>
196 inline constexpr bool operator==(const SpecificIsochoricHeatCapacity<NumericType>& left,
197  const SpecificIsochoricHeatCapacity<NumericType>& right) noexcept {
198  return left.Value() == right.Value();
199 }
200 
201 template <typename NumericType>
202 inline constexpr bool operator!=(const SpecificIsochoricHeatCapacity<NumericType>& left,
203  const SpecificIsochoricHeatCapacity<NumericType>& right) noexcept {
204  return left.Value() != right.Value();
205 }
206 
207 template <typename NumericType>
208 inline constexpr bool operator<(const SpecificIsochoricHeatCapacity<NumericType>& left,
209  const SpecificIsochoricHeatCapacity<NumericType>& right) noexcept {
210  return left.Value() < right.Value();
211 }
212 
213 template <typename NumericType>
214 inline constexpr bool operator>(const SpecificIsochoricHeatCapacity<NumericType>& left,
215  const SpecificIsochoricHeatCapacity<NumericType>& right) noexcept {
216  return left.Value() > right.Value();
217 }
218 
219 template <typename NumericType>
220 inline constexpr bool operator<=(const SpecificIsochoricHeatCapacity<NumericType>& left,
221  const SpecificIsochoricHeatCapacity<NumericType>& right) noexcept {
222  return left.Value() <= right.Value();
223 }
224 
225 template <typename NumericType>
226 inline constexpr bool operator>=(const SpecificIsochoricHeatCapacity<NumericType>& left,
227  const SpecificIsochoricHeatCapacity<NumericType>& right) noexcept {
228  return left.Value() >= right.Value();
229 }
230 
231 template <typename NumericType>
232 inline std::ostream& operator<<(
233  std::ostream& stream,
234  const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity) {
235  stream << specific_isochoric_heat_capacity.Print();
236  return stream;
237 }
238 
239 template <typename NumericType>
241  const NumericType number,
242  const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity) {
243  return specific_isochoric_heat_capacity * number;
244 }
245 
246 template <typename NumericType>
247 inline constexpr Mass<NumericType>::Mass(
248  const IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity,
249  const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity)
250  : Mass<NumericType>(isochoric_heat_capacity.Value() / specific_isochoric_heat_capacity.Value()) {}
251 
252 template <typename NumericType>
254  const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity,
255  const Mass<NumericType>& mass)
256  : IsochoricHeatCapacity<NumericType>(specific_isochoric_heat_capacity.Value() * mass.Value()) {}
257 
258 template <typename NumericType>
260  const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity) const {
261  return IsochoricHeatCapacity<NumericType>{specific_isochoric_heat_capacity, *this};
262 }
263 
264 template <typename NumericType>
265 inline constexpr SpecificIsochoricHeatCapacity<NumericType>
267  return SpecificIsochoricHeatCapacity<NumericType>{*this, mass};
268 }
269 
270 template <typename NumericType>
272  const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity) const {
273  return Mass<NumericType>{*this, specific_isochoric_heat_capacity};
274 }
275 
276 } // namespace PhQ
277 
278 namespace std {
279 
280 template <typename NumericType>
281 struct hash<PhQ::SpecificIsochoricHeatCapacity<NumericType>> {
282  inline size_t operator()(
283  const PhQ::SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity)
284  const {
285  return hash<NumericType>()(specific_isochoric_heat_capacity.Value());
286  }
287 };
288 
289 } // namespace std
290 
291 #endif // PHQ_SPECIFIC_ISOCHORIC_HEAT_CAPACITY_HPP
Abstract base class that represents any dimensional scalar physical quantity. Such a physical quantit...
double value
Value of this physical quantity expressed in its standard unit of measure.
constexpr double Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
static constexpr Unit::SpecificHeatCapacity 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...
Heat capacity ratio, also known as ratio of specific heats, adiabatic index, or Laplace's coefficient...
Isochoric heat capacity, also known as heat capacity at constant volume. For the mass-specific isocho...
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()=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....
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,...
constexpr SpecificIsochoricHeatCapacity(const NumericType value)
Constructor. Constructs a specific isochoric heat capacity with a given value expressed in the standa...
constexpr SpecificIsochoricHeatCapacity< NumericType > operator+(const SpecificIsochoricHeatCapacity< NumericType > &specific_isochoric_heat_capacity) const
constexpr void operator/=(const NumericType number) noexcept
constexpr SpecificIsochoricHeatCapacity< NumericType > operator*(const NumericType number) const
constexpr SpecificIsochoricHeatCapacity(SpecificIsochoricHeatCapacity< NumericType > &&other) noexcept=default
Move constructor. Constructs a specific isochoric heat capacity by moving another one.
constexpr void operator*=(const NumericType number) noexcept
constexpr NumericType operator/(const SpecificIsochoricHeatCapacity< NumericType > &specific_isochoric_heat_capacity) const noexcept
static constexpr SpecificIsochoricHeatCapacity< NumericType > Create(const NumericType value)
Statically creates a specific isochoric heat capacity with a given value expressed in a given specifi...
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
constexpr SpecificIsochoricHeatCapacity< NumericType > operator/(const NumericType number) const
constexpr SpecificIsochoricHeatCapacity(const IsochoricHeatCapacity< NumericType > &isochoric_heat_capacity, const Mass< NumericType > &mass)
Constructor. Constructs a specific isochoric heat capacity from a given isochoric heat capacity and m...
constexpr void operator+=(const SpecificIsochoricHeatCapacity< NumericType > &specific_isochoric_heat_capacity) noexcept
constexpr SpecificIsochoricHeatCapacity< NumericType > & operator=(SpecificIsochoricHeatCapacity< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this specific isochoric heat capacity by moving another one.
~SpecificIsochoricHeatCapacity() noexcept=default
Destructor. Destroys this specific isochoric heat capacity.
constexpr SpecificIsochoricHeatCapacity< NumericType > & operator=(const SpecificIsochoricHeatCapacity< OtherNumericType > &other)
Copy assignment operator. Assigns this specific isochoric heat capacity by copying another one.
constexpr void operator-=(const SpecificIsochoricHeatCapacity< NumericType > &specific_isochoric_heat_capacity) noexcept
constexpr IsochoricHeatCapacity< NumericType > operator*(const Mass< NumericType > &mass) const
constexpr SpecificIsochoricHeatCapacity< NumericType > & operator=(const SpecificIsochoricHeatCapacity< NumericType > &other)=default
Copy assignment operator. Assigns this specific isochoric heat capacity by copying another one.
static constexpr SpecificIsochoricHeatCapacity< NumericType > Zero()
Statically creates a specific isochoric heat capacity of zero.
SpecificIsochoricHeatCapacity(const NumericType value, const Unit::SpecificHeatCapacity unit)
Constructor. Constructs a specific isochoric heat capacity with a given value expressed in a given sp...
Mass
Mass units.
Definition: Mass.hpp:53
SpecificHeatCapacity
Mass-specific heat capacity units.
Namespace that encompasses all of the Physical Quantities library's content.
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
constexpr bool operator!=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)