Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
TotalKinematicPressure.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_TOTAL_KINEMATIC_PRESSURE_HPP
26 #define PHQ_TOTAL_KINEMATIC_PRESSURE_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 
32 #include "DimensionalScalar.hpp"
34 #include "MassDensity.hpp"
36 #include "TotalPressure.hpp"
37 #include "Unit/SpecificEnergy.hpp"
38 
39 namespace PhQ {
40 
41 /// \brief Total kinematic pressure, which is total pressure divided by mass density; see
42 /// PhQ::TotalPressure and PhQ::MassDensity.
43 template <typename NumericType = double>
44 class TotalKinematicPressure : public DimensionalScalar<Unit::SpecificEnergy, NumericType> {
45 public:
46  /// \brief Default constructor. Constructs a total kinematic pressure with an uninitialized value.
48 
49  /// \brief Constructor. Constructs a total kinematic pressure with a given value expressed in a
50  /// given specific energy unit.
51  TotalKinematicPressure(const NumericType value, const Unit::SpecificEnergy unit)
52  : DimensionalScalar<Unit::SpecificEnergy, NumericType>(value, unit) {}
53 
54  /// \brief Constructor. Constructs a total kinematic pressure from a given static kinematic
55  /// pressure and dynamic kinematic pressure using the definition of total kinematic pressure.
57  const StaticKinematicPressure<NumericType>& static_kinematic_pressure,
58  const DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure)
59  : TotalKinematicPressure<NumericType>(
60  static_kinematic_pressure.Value() + dynamic_kinematic_pressure.Value()) {}
61 
62  /// \brief Constructor. Constructs a total kinematic pressure from a given total pressure and mass
63  /// density using the definition of total kinematic pressure.
64  constexpr TotalKinematicPressure(const TotalPressure<NumericType>& total_pressure,
65  const MassDensity<NumericType>& mass_density)
66  : TotalKinematicPressure<NumericType>(total_pressure.Value() / mass_density.Value()) {}
67 
68  /// \brief Destructor. Destroys this total kinematic pressure.
69  ~TotalKinematicPressure() noexcept = default;
70 
71  /// \brief Copy constructor. Constructs a total kinematic pressure by copying another one.
72  constexpr TotalKinematicPressure(const TotalKinematicPressure<NumericType>& other) = default;
73 
74  /// \brief Copy constructor. Constructs a total kinematic pressure by copying another one.
75  template <typename OtherNumericType>
76  explicit constexpr TotalKinematicPressure(const TotalKinematicPressure<OtherNumericType>& other)
77  : TotalKinematicPressure(static_cast<NumericType>(other.Value())) {}
78 
79  /// \brief Move constructor. Constructs a total kinematic pressure by moving another one.
80  constexpr TotalKinematicPressure(TotalKinematicPressure<NumericType>&& other) noexcept = default;
81 
82  /// \brief Copy assignment operator. Assigns this total kinematic pressure by copying another one.
84  const TotalKinematicPressure<NumericType>& other) = default;
85 
86  /// \brief Copy assignment operator. Assigns this total kinematic pressure by copying another one.
87  template <typename OtherNumericType>
90  this->value = static_cast<NumericType>(other.Value());
91  return *this;
92  }
93 
94  /// \brief Move assignment operator. Assigns this total kinematic pressure by moving another one.
96  TotalKinematicPressure<NumericType>&& other) noexcept = default;
97 
98  /// \brief Statically creates a total kinematic pressure of zero.
99  [[nodiscard]] static constexpr TotalKinematicPressure<NumericType> Zero() {
100  return TotalKinematicPressure<NumericType>{static_cast<NumericType>(0)};
101  }
102 
103  /// \brief Statically creates a total kinematic pressure with a given value expressed in a given
104  /// specific energy unit.
105  template <Unit::SpecificEnergy Unit>
106  [[nodiscard]] static constexpr TotalKinematicPressure<NumericType> Create(
107  const NumericType value) {
109  ConvertStatically<Unit::SpecificEnergy, Unit, Standard<Unit::SpecificEnergy>>(value)};
110  }
111 
113  const TotalKinematicPressure<NumericType>& total_kinematic_pressure) const {
114  return TotalKinematicPressure<NumericType>{this->value + total_kinematic_pressure.value};
115  }
116 
118  const TotalKinematicPressure<NumericType>& total_kinematic_pressure) const {
119  return TotalKinematicPressure<NumericType>{this->value - total_kinematic_pressure.value};
120  }
121 
123  const StaticKinematicPressure<NumericType>& static_kinematic_pressure) const {
124  return DynamicKinematicPressure<NumericType>{*this, static_kinematic_pressure};
125  }
126 
128  const DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure) const {
129  return StaticKinematicPressure<NumericType>{*this, dynamic_kinematic_pressure};
130  }
131 
132  constexpr TotalKinematicPressure<NumericType> operator*(const NumericType number) const {
133  return TotalKinematicPressure<NumericType>{this->value * number};
134  }
135 
136  constexpr TotalKinematicPressure<NumericType> operator/(const NumericType number) const {
137  return TotalKinematicPressure<NumericType>{this->value / number};
138  }
139 
140  constexpr NumericType operator/(
141  const TotalKinematicPressure<NumericType>& total_kinematic_pressure) const noexcept {
142  return this->value / total_kinematic_pressure.value;
143  }
144 
145  constexpr void operator+=(
146  const TotalKinematicPressure<NumericType>& total_kinematic_pressure) noexcept {
147  this->value += total_kinematic_pressure.value;
148  }
149 
150  constexpr void operator-=(
151  const TotalKinematicPressure<NumericType>& total_kinematic_pressure) noexcept {
152  this->value -= total_kinematic_pressure.value;
153  }
154 
155  constexpr void operator*=(const NumericType number) noexcept {
156  this->value *= number;
157  }
158 
159  constexpr void operator/=(const NumericType number) noexcept {
160  this->value /= number;
161  }
162 
163 private:
164  /// \brief Constructor. Constructs a total kinematic pressure with a given value expressed in the
165  /// standard specific energy unit.
166  explicit constexpr TotalKinematicPressure(const NumericType value)
167  : DimensionalScalar<Unit::SpecificEnergy, NumericType>(value) {}
168 };
169 
170 template <typename NumericType>
171 inline constexpr bool operator==(const TotalKinematicPressure<NumericType>& left,
172  const TotalKinematicPressure<NumericType>& right) noexcept {
173  return left.Value() == right.Value();
174 }
175 
176 template <typename NumericType>
177 inline constexpr bool operator!=(const TotalKinematicPressure<NumericType>& left,
178  const TotalKinematicPressure<NumericType>& right) noexcept {
179  return left.Value() != right.Value();
180 }
181 
182 template <typename NumericType>
183 inline constexpr bool operator<(const TotalKinematicPressure<NumericType>& left,
184  const TotalKinematicPressure<NumericType>& right) noexcept {
185  return left.Value() < right.Value();
186 }
187 
188 template <typename NumericType>
189 inline constexpr bool operator>(const TotalKinematicPressure<NumericType>& left,
190  const TotalKinematicPressure<NumericType>& right) noexcept {
191  return left.Value() > right.Value();
192 }
193 
194 template <typename NumericType>
195 inline constexpr bool operator<=(const TotalKinematicPressure<NumericType>& left,
196  const TotalKinematicPressure<NumericType>& right) noexcept {
197  return left.Value() <= right.Value();
198 }
199 
200 template <typename NumericType>
201 inline constexpr bool operator>=(const TotalKinematicPressure<NumericType>& left,
202  const TotalKinematicPressure<NumericType>& right) noexcept {
203  return left.Value() >= right.Value();
204 }
205 
206 template <typename NumericType>
207 inline std::ostream& operator<<(
208  std::ostream& stream, const TotalKinematicPressure<NumericType>& total_kinematic_pressure) {
209  stream << total_kinematic_pressure.Print();
210  return stream;
211 }
212 
213 template <typename NumericType>
215  const NumericType number, const TotalKinematicPressure<NumericType>& total_kinematic_pressure) {
216  return total_kinematic_pressure * number;
217 }
218 
219 template <typename NumericType>
221  const MassDensity<NumericType>& mass_density,
222  const TotalKinematicPressure<NumericType>& total_kinematic_pressure)
223  : TotalPressure<NumericType>(mass_density.Value() * total_kinematic_pressure.Value()) {}
224 
225 template <typename NumericType>
227  const TotalKinematicPressure<NumericType>& total_kinematic_pressure,
228  const DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure)
229  : StaticKinematicPressure<NumericType>(
230  total_kinematic_pressure.Value() - dynamic_kinematic_pressure.Value()) {}
231 
232 template <typename NumericType>
234  const TotalKinematicPressure<NumericType>& total_kinematic_pressure,
235  const StaticKinematicPressure<NumericType>& static_kinematic_pressure)
236  : DynamicKinematicPressure<NumericType>(
237  total_kinematic_pressure.Value() - static_kinematic_pressure.Value()) {}
238 
239 template <typename NumericType>
242  const DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure) const {
243  return TotalKinematicPressure<NumericType>{*this, dynamic_kinematic_pressure};
244 }
245 
246 template <typename NumericType>
249  const StaticKinematicPressure<NumericType>& static_kinematic_pressure) const {
250  return TotalKinematicPressure<NumericType>{static_kinematic_pressure, *this};
251 }
252 
253 template <typename NumericType>
255  const MassDensity<NumericType>& mass_density) const {
256  return TotalKinematicPressure<NumericType>{*this, mass_density};
257 }
258 
259 } // namespace PhQ
260 
261 namespace std {
262 
263 template <typename NumericType>
264 struct hash<PhQ::TotalKinematicPressure<NumericType>> {
265  inline size_t operator()(
266  const PhQ::TotalKinematicPressure<NumericType>& total_kinematic_pressure) const {
267  return hash<NumericType>()(total_kinematic_pressure.Value());
268  }
269 };
270 
271 } // namespace std
272 
273 #endif // PHQ_TOTAL_KINEMATIC_PRESSURE_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::SpecificEnergy 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...
Dynamic kinematic pressure, which is dynamic pressure divided by mass density; see PhQ::DynamicPressu...
constexpr DynamicKinematicPressure< NumericType > operator+(const DynamicKinematicPressure< NumericType > &dynamic_kinematic_pressure) const
DynamicKinematicPressure()=default
Default constructor. Constructs a dynamic kinematic pressure with an uninitialized value.
Mass density. Mass per unit volume; see PhQ::Mass and PhQ::Volume.
Definition: MassDensity.hpp:83
Mass-specific energy. Energy per unit mass; see PhQ::Energy and PhQ::Mass.
Static kinematic pressure, which is static pressure divided by mass density; see PhQ::StaticPressure ...
constexpr StaticKinematicPressure< NumericType > operator+(const StaticKinematicPressure< NumericType > &other) const
StaticKinematicPressure()=default
Default constructor. Constructs a static kinematic pressure with an uninitialized value.
Total kinematic pressure, which is total pressure divided by mass density; see PhQ::TotalPressure and...
TotalKinematicPressure()=default
Default constructor. Constructs a total kinematic pressure with an uninitialized value.
constexpr TotalKinematicPressure< NumericType > operator+(const TotalKinematicPressure< NumericType > &total_kinematic_pressure) const
constexpr TotalKinematicPressure< NumericType > operator*(const NumericType number) const
constexpr TotalKinematicPressure(const NumericType value)
Constructor. Constructs a total kinematic pressure with a given value expressed in the standard speci...
constexpr void operator*=(const NumericType number) noexcept
constexpr void operator+=(const TotalKinematicPressure< NumericType > &total_kinematic_pressure) noexcept
static constexpr TotalKinematicPressure< NumericType > Create(const NumericType value)
Statically creates a total kinematic pressure with a given value expressed in a given specific energy...
constexpr TotalKinematicPressure< NumericType > operator-(const TotalKinematicPressure< NumericType > &total_kinematic_pressure) const
TotalKinematicPressure(const NumericType value, const Unit::SpecificEnergy unit)
Constructor. Constructs a total kinematic pressure with a given value expressed in a given specific e...
constexpr TotalKinematicPressure(TotalKinematicPressure< NumericType > &&other) noexcept=default
Move constructor. Constructs a total kinematic pressure by moving another one.
static constexpr TotalKinematicPressure< NumericType > Zero()
Statically creates a total kinematic pressure of zero.
constexpr DynamicKinematicPressure< NumericType > operator-(const StaticKinematicPressure< NumericType > &static_kinematic_pressure) const
~TotalKinematicPressure() noexcept=default
Destructor. Destroys this total kinematic pressure.
constexpr TotalKinematicPressure< NumericType > & operator=(TotalKinematicPressure< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this total kinematic pressure by moving another one.
constexpr NumericType operator/(const TotalKinematicPressure< NumericType > &total_kinematic_pressure) const noexcept
constexpr void operator/=(const NumericType number) noexcept
constexpr void operator-=(const TotalKinematicPressure< NumericType > &total_kinematic_pressure) noexcept
constexpr TotalKinematicPressure(const TotalPressure< NumericType > &total_pressure, const MassDensity< NumericType > &mass_density)
Constructor. Constructs a total kinematic pressure from a given total pressure and mass density using...
constexpr StaticKinematicPressure< NumericType > operator-(const DynamicKinematicPressure< NumericType > &dynamic_kinematic_pressure) const
constexpr TotalKinematicPressure< NumericType > operator/(const NumericType number) const
constexpr TotalKinematicPressure(const StaticKinematicPressure< NumericType > &static_kinematic_pressure, const DynamicKinematicPressure< NumericType > &dynamic_kinematic_pressure)
Constructor. Constructs a total kinematic pressure from a given static kinematic pressure and dynamic...
constexpr TotalKinematicPressure< NumericType > & operator=(const TotalKinematicPressure< OtherNumericType > &other)
Copy assignment operator. Assigns this total kinematic pressure by copying another one.
constexpr TotalKinematicPressure< NumericType > & operator=(const TotalKinematicPressure< NumericType > &other)=default
Copy assignment operator. Assigns this total kinematic pressure by copying another one.
Total pressure, which is the sum of static pressure and dynamic pressure; see PhQ::StaticPressure and...
constexpr TotalPressure< NumericType > operator/(const NumericType number) const
TotalPressure()=default
Default constructor. Constructs a total pressure with an uninitialized value.
SpecificEnergy
Mass-specific energy 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)