Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
IsochoricHeatCapacity.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_ISOCHORIC_HEAT_CAPACITY_HPP
26 #define PHQ_ISOCHORIC_HEAT_CAPACITY_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 
32 #include "DimensionalScalar.hpp"
33 #include "HeatCapacityRatio.hpp"
34 #include "Unit/HeatCapacity.hpp"
35 
36 namespace PhQ {
37 
38 /// \brief Isochoric heat capacity, also known as heat capacity at constant volume. For the
39 /// mass-specific isochoric heat capacity, see PhQ::SpecificIsochoricHeatCapacity.
40 template <typename NumericType = double>
41 class IsochoricHeatCapacity : public DimensionalScalar<Unit::HeatCapacity, NumericType> {
42 public:
43  /// \brief Default constructor. Constructs an isochoric heat capacity with an uninitialized value.
44  IsochoricHeatCapacity() = default;
45 
46  /// \brief Constructor. Constructs an isochoric heat capacity with a given value expressed in a
47  /// given heat capacity unit.
48  IsochoricHeatCapacity(const NumericType value, const Unit::HeatCapacity unit)
49  : DimensionalScalar<Unit::HeatCapacity, NumericType>(value, unit) {}
50 
51  /// \brief Constructor. Constructs an isochoric heat capacity from a given gas constant and
52  /// isobaric heat capacity using Mayer's relation.
53  constexpr IsochoricHeatCapacity(const IsobaricHeatCapacity<NumericType>& isobaric_heat_capacity,
54  const GasConstant<NumericType>& gas_constant);
55 
56  /// \brief Constructor. Constructs an isochoric heat capacity from a given gas constant and heat
57  /// capacity ratio using the definition of the specific heat ratio and Mayer's relation.
58  constexpr IsochoricHeatCapacity(const GasConstant<NumericType>& gas_constant,
59  const HeatCapacityRatio<NumericType>& heat_capacity_ratio);
60 
61  /// \brief Constructor. Constructs an isochoric heat capacity from a given isobaric heat capacity
62  /// and heat capacity ratio using the definition of the specific heat ratio.
63  constexpr IsochoricHeatCapacity(const IsobaricHeatCapacity<NumericType>& isobaric_heat_capacity,
64  const HeatCapacityRatio<NumericType>& heat_capacity_ratio);
65 
66  /// \brief Constructor. Constructs an isochoric heat capacity from a given specific isochoric heat
67  /// capacity and mass using the definition of the specific isochoric heat capacity.
68  constexpr IsochoricHeatCapacity(
69  const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity,
70  const Mass<NumericType>& mass);
71 
72  /// \brief Destructor. Destroys this isochoric heat capacity.
73  ~IsochoricHeatCapacity() noexcept = default;
74 
75  /// \brief Copy constructor. Constructs an isochoric heat capacity by copying another one.
76  constexpr IsochoricHeatCapacity(const IsochoricHeatCapacity<NumericType>& other) = default;
77 
78  /// \brief Copy constructor. Constructs a isochoric heat capacity by copying another one.
79  template <typename OtherNumericType>
80  explicit constexpr IsochoricHeatCapacity(const IsochoricHeatCapacity<OtherNumericType>& other)
81  : IsochoricHeatCapacity(static_cast<NumericType>(other.Value())) {}
82 
83  /// \brief Move constructor. Constructs an isochoric heat capacity by moving another one.
84  constexpr IsochoricHeatCapacity(IsochoricHeatCapacity<NumericType>&& other) noexcept = default;
85 
86  /// \brief Copy assignment operator. Assigns this isochoric heat capacity by copying another one.
88  const IsochoricHeatCapacity<NumericType>& other) = default;
89 
90  /// \brief Copy assignment operator. Assigns this isochoric heat capacity by copying another one.
91  template <typename OtherNumericType>
94  this->value = static_cast<NumericType>(other.Value());
95  return *this;
96  }
97 
98  /// \brief Move assignment operator. Assigns this isochoric heat capacity by moving another one.
100  IsochoricHeatCapacity<NumericType>&& other) noexcept = default;
101 
102  /// \brief Statically creates an isochoric heat capacity of zero.
103  [[nodiscard]] static constexpr IsochoricHeatCapacity<NumericType> Zero() {
104  return IsochoricHeatCapacity<NumericType>{static_cast<NumericType>(0)};
105  }
106 
107  /// \brief Statically creates an isochoric heat capacity with a given value expressed in a given
108  /// heat capacity unit.
109  template <Unit::HeatCapacity Unit>
110  [[nodiscard]] static constexpr IsochoricHeatCapacity<NumericType> Create(
111  const NumericType value) {
113  ConvertStatically<Unit::HeatCapacity, Unit, Standard<Unit::HeatCapacity>>(value)};
114  }
115 
117  const IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity) const {
118  return IsochoricHeatCapacity<NumericType>{this->value + isochoric_heat_capacity.value};
119  }
120 
122  const GasConstant<NumericType>& gas_constant) const;
123 
125  const IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity) const {
126  return IsochoricHeatCapacity<NumericType>{this->value - isochoric_heat_capacity.value};
127  }
128 
129  constexpr IsochoricHeatCapacity<NumericType> operator*(const NumericType number) const {
130  return IsochoricHeatCapacity<NumericType>{this->value * number};
131  }
132 
134  const HeatCapacityRatio<NumericType>& heat_capacity_ratio) const;
135 
136  constexpr IsochoricHeatCapacity<NumericType> operator/(const NumericType number) const {
137  return IsochoricHeatCapacity<NumericType>{this->value / number};
138  }
139 
141  const Mass<NumericType>& mass) const;
142 
143  constexpr Mass<NumericType> operator/(
144  const SpecificIsochoricHeatCapacity<NumericType>& specific_isochoric_heat_capacity) const;
145 
146  constexpr NumericType operator/(
147  const IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity) const noexcept {
148  return this->value / isochoric_heat_capacity.value;
149  }
150 
151  constexpr void operator+=(
152  const IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity) noexcept {
153  this->value += isochoric_heat_capacity.value;
154  }
155 
156  constexpr void operator-=(
157  const IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity) noexcept {
158  this->value -= isochoric_heat_capacity.value;
159  }
160 
161  constexpr void operator*=(const NumericType number) noexcept {
162  this->value *= number;
163  }
164 
165  constexpr void operator/=(const NumericType number) noexcept {
166  this->value /= number;
167  }
168 
169 private:
170  /// \brief Constructor. Constructs an isochoric heat capacity with a given value expressed in the
171  /// standard heat capacity unit.
172  explicit constexpr IsochoricHeatCapacity(const NumericType value)
173  : DimensionalScalar<Unit::HeatCapacity, NumericType>(value) {}
174 };
175 
176 template <typename NumericType>
177 inline constexpr bool operator==(const IsochoricHeatCapacity<NumericType>& left,
178  const IsochoricHeatCapacity<NumericType>& right) noexcept {
179  return left.Value() == right.Value();
180 }
181 
182 template <typename NumericType>
183 inline constexpr bool operator!=(const IsochoricHeatCapacity<NumericType>& left,
184  const IsochoricHeatCapacity<NumericType>& right) noexcept {
185  return left.Value() != right.Value();
186 }
187 
188 template <typename NumericType>
189 inline constexpr bool operator<(const IsochoricHeatCapacity<NumericType>& left,
190  const IsochoricHeatCapacity<NumericType>& right) noexcept {
191  return left.Value() < right.Value();
192 }
193 
194 template <typename NumericType>
195 inline constexpr bool operator>(const IsochoricHeatCapacity<NumericType>& left,
196  const IsochoricHeatCapacity<NumericType>& right) noexcept {
197  return left.Value() > right.Value();
198 }
199 
200 template <typename NumericType>
201 inline constexpr bool operator<=(const IsochoricHeatCapacity<NumericType>& left,
202  const IsochoricHeatCapacity<NumericType>& right) noexcept {
203  return left.Value() <= right.Value();
204 }
205 
206 template <typename NumericType>
207 inline constexpr bool operator>=(const IsochoricHeatCapacity<NumericType>& left,
208  const IsochoricHeatCapacity<NumericType>& right) noexcept {
209  return left.Value() >= right.Value();
210 }
211 
212 template <typename NumericType>
213 inline std::ostream& operator<<(
214  std::ostream& stream, const IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity) {
215  stream << isochoric_heat_capacity.Print();
216  return stream;
217 }
218 
219 template <typename NumericType>
221  const NumericType number, const IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity) {
222  return isochoric_heat_capacity * number;
223 }
224 
225 } // namespace PhQ
226 
227 namespace std {
228 
229 template <typename NumericType>
230 struct hash<PhQ::IsochoricHeatCapacity<NumericType>> {
231  inline size_t operator()(
232  const PhQ::IsochoricHeatCapacity<NumericType>& isochoric_heat_capacity) const {
233  return hash<NumericType>()(isochoric_heat_capacity.Value());
234  }
235 };
236 
237 } // namespace std
238 
239 #endif // PHQ_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::HeatCapacity 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.
Definition: GasConstant.hpp:46
Heat capacity ratio, also known as ratio of specific heats, adiabatic index, or Laplace's coefficient...
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...
static constexpr IsochoricHeatCapacity< NumericType > Create(const NumericType value)
Statically creates an isochoric heat capacity with a given value expressed in a given heat capacity u...
constexpr IsochoricHeatCapacity< NumericType > & operator=(const IsochoricHeatCapacity< OtherNumericType > &other)
Copy assignment operator. Assigns this isochoric heat capacity by copying another one.
constexpr IsochoricHeatCapacity< NumericType > operator+(const IsochoricHeatCapacity< NumericType > &isochoric_heat_capacity) const
constexpr IsochoricHeatCapacity< NumericType > operator-(const IsochoricHeatCapacity< NumericType > &isochoric_heat_capacity) const
constexpr void operator+=(const IsochoricHeatCapacity< NumericType > &isochoric_heat_capacity) noexcept
~IsochoricHeatCapacity() noexcept=default
Destructor. Destroys this isochoric heat capacity.
constexpr void operator-=(const IsochoricHeatCapacity< NumericType > &isochoric_heat_capacity) noexcept
IsochoricHeatCapacity()=default
Default constructor. Constructs an isochoric heat capacity with an uninitialized value.
IsochoricHeatCapacity(const NumericType value, const Unit::HeatCapacity unit)
Constructor. Constructs an isochoric heat capacity with a given value expressed in a given heat capac...
constexpr IsochoricHeatCapacity(IsochoricHeatCapacity< NumericType > &&other) noexcept=default
Move constructor. Constructs an isochoric heat capacity by moving another one.
constexpr void operator*=(const NumericType number) noexcept
constexpr IsochoricHeatCapacity< NumericType > operator*(const NumericType number) const
constexpr IsochoricHeatCapacity< NumericType > & operator=(const IsochoricHeatCapacity< NumericType > &other)=default
Copy assignment operator. Assigns this isochoric heat capacity by copying another one.
constexpr void operator/=(const NumericType number) noexcept
static constexpr IsochoricHeatCapacity< NumericType > Zero()
Statically creates an isochoric heat capacity of zero.
constexpr IsochoricHeatCapacity< NumericType > & operator=(IsochoricHeatCapacity< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this isochoric heat capacity by moving another one.
constexpr IsochoricHeatCapacity(const NumericType value)
Constructor. Constructs an isochoric heat capacity with a given value expressed in the standard heat ...
constexpr IsochoricHeatCapacity< NumericType > operator/(const NumericType number) const
constexpr NumericType operator/(const IsochoricHeatCapacity< NumericType > &isochoric_heat_capacity) const noexcept
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 isochoric heat capacity, also known as mass-specific heat capacity at constant volume,...
HeatCapacity
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)