Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
DynamicKinematicPressure.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_DYNAMIC_KINEMATIC_PRESSURE_HPP
26 #define PHQ_DYNAMIC_KINEMATIC_PRESSURE_HPP
27 
28 #include <cmath>
29 #include <cstddef>
30 #include <functional>
31 #include <ostream>
32 
33 #include "DimensionalScalar.hpp"
34 #include "DynamicPressure.hpp"
35 #include "MassDensity.hpp"
36 #include "Speed.hpp"
38 #include "Unit/SpecificEnergy.hpp"
39 
40 namespace PhQ {
41 
42 /// \brief Dynamic kinematic pressure, which is dynamic pressure divided by mass density; see
43 /// PhQ::DynamicPressure and PhQ::MassDensity.
44 template <typename NumericType = double>
45 class DynamicKinematicPressure : public DimensionalScalar<Unit::SpecificEnergy, NumericType> {
46 public:
47  /// \brief Default constructor. Constructs a dynamic kinematic pressure with an uninitialized
48  /// value.
50 
51  /// \brief Constructor. Constructs a dynamic kinematic pressure with a given value expressed in a
52  /// given specific energy unit.
53  DynamicKinematicPressure(const NumericType value, const Unit::SpecificEnergy unit)
54  : DimensionalScalar<Unit::SpecificEnergy, NumericType>(value, unit) {}
55 
56  /// \brief Constructor. Constructs a dynamic kinematic pressure from a given speed using the
57  /// definition of dynamic kinematic pressure.
58  explicit constexpr DynamicKinematicPressure(const Speed<NumericType>& speed)
59  : DynamicKinematicPressure<NumericType>(0.5 * std::pow(speed.Value(), 2)) {}
60 
61  /// \brief Constructor. Constructs a dynamic kinematic pressure from a given total kinematic
62  /// pressure and static kinematic pressure using the definition of total kinematic pressure.
63  constexpr DynamicKinematicPressure(
64  const TotalKinematicPressure<NumericType>& total_kinematic_pressure,
65  const StaticKinematicPressure<NumericType>& static_kinematic_pressure);
66 
67  /// \brief Constructor. Constructs a dynamic kinematic pressure from a given dynamic pressure and
68  /// mass density using the definition of dynamic kinematic pressure.
69  constexpr DynamicKinematicPressure(const DynamicPressure<NumericType>& dynamic_pressure,
70  const MassDensity<NumericType>& mass_density)
71  : DynamicKinematicPressure<NumericType>(dynamic_pressure.Value() / mass_density.Value()) {}
72 
73  /// \brief Destructor. Destroys this dynamic kinematic pressure.
74  ~DynamicKinematicPressure() noexcept = default;
75 
76  /// \brief Copy constructor. Constructs a dynamic kinematic pressure by copying another one.
77  constexpr DynamicKinematicPressure(const DynamicKinematicPressure<NumericType>& other) = default;
78 
79  /// \brief Copy constructor. Constructs a dynamic kinematic pressure by copying another one.
80  template <typename OtherNumericType>
81  explicit constexpr DynamicKinematicPressure(
82  const DynamicKinematicPressure<OtherNumericType>& other)
83  : DynamicKinematicPressure(static_cast<NumericType>(other.Value())) {}
84 
85  /// \brief Move constructor. Constructs a dynamic kinematic pressure by moving another one.
87  DynamicKinematicPressure<NumericType>&& other) noexcept = default;
88 
89  /// \brief Copy assignment operator. Assigns this dynamic kinematic pressure by copying another
90  /// one.
92  const DynamicKinematicPressure<NumericType>& other) = default;
93 
94  /// \brief Copy assignment operator. Assigns this dynamic kinematic pressure by copying another
95  /// one.
96  template <typename OtherNumericType>
99  this->value = static_cast<NumericType>(other.Value());
100  return *this;
101  }
102 
103  /// \brief Move assignment operator. Assigns this dynamic kinematic pressure by moving another
104  /// one.
106  DynamicKinematicPressure<NumericType>&& other) noexcept = default;
107 
108  /// \brief Statically creates a dynamic kinematic pressure of zero.
109  [[nodiscard]] static constexpr DynamicKinematicPressure<NumericType> Zero() {
110  return DynamicKinematicPressure<NumericType>{static_cast<NumericType>(0)};
111  }
112 
113  /// \brief Statically creates a dynamic kinematic pressure with a given value expressed in a given
114  /// specific energy unit.
115  template <Unit::SpecificEnergy Unit>
116  [[nodiscard]] static constexpr DynamicKinematicPressure<NumericType> Create(
117  const NumericType value) {
119  ConvertStatically<Unit::SpecificEnergy, Unit, Standard<Unit::SpecificEnergy>>(value)};
120  }
121 
123  const DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure) const {
124  return DynamicKinematicPressure<NumericType>{this->value + dynamic_kinematic_pressure.value};
125  }
126 
128  const StaticKinematicPressure<NumericType>& static_kinematic_pressure) const;
129 
131  const DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure) const {
132  return DynamicKinematicPressure<NumericType>{this->value - dynamic_kinematic_pressure.value};
133  }
134 
135  constexpr DynamicKinematicPressure<NumericType> operator*(const NumericType number) const {
136  return DynamicKinematicPressure<NumericType>{this->value * number};
137  }
138 
139  constexpr DynamicKinematicPressure<NumericType> operator/(const NumericType number) const {
140  return DynamicKinematicPressure<NumericType>{this->value / number};
141  }
142 
143  constexpr NumericType operator/(
144  const DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure) const noexcept {
145  return this->value / dynamic_kinematic_pressure.value;
146  }
147 
148  constexpr void operator+=(
149  const DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure) noexcept {
150  this->value += dynamic_kinematic_pressure.value;
151  }
152 
153  constexpr void operator-=(
154  const DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure) noexcept {
155  this->value -= dynamic_kinematic_pressure.value;
156  }
157 
158  constexpr void operator*=(const NumericType number) noexcept {
159  this->value *= number;
160  }
161 
162  constexpr void operator/=(const NumericType number) noexcept {
163  this->value /= number;
164  }
165 
166 private:
167  /// \brief Constructor. Constructs a dynamic kinematic pressure with a given value expressed in
168  /// the standard specific energy unit.
169  explicit constexpr DynamicKinematicPressure(const NumericType value)
170  : DimensionalScalar<Unit::SpecificEnergy, NumericType>(value) {}
171 };
172 
173 template <typename NumericType>
174 inline constexpr bool operator==(const DynamicKinematicPressure<NumericType>& left,
175  const DynamicKinematicPressure<NumericType>& right) noexcept {
176  return left.Value() == right.Value();
177 }
178 
179 template <typename NumericType>
180 inline constexpr bool operator!=(const DynamicKinematicPressure<NumericType>& left,
181  const DynamicKinematicPressure<NumericType>& right) noexcept {
182  return left.Value() != right.Value();
183 }
184 
185 template <typename NumericType>
186 inline constexpr bool operator<(const DynamicKinematicPressure<NumericType>& left,
187  const DynamicKinematicPressure<NumericType>& right) noexcept {
188  return left.Value() < right.Value();
189 }
190 
191 template <typename NumericType>
192 inline constexpr bool operator>(const DynamicKinematicPressure<NumericType>& left,
193  const DynamicKinematicPressure<NumericType>& right) noexcept {
194  return left.Value() > right.Value();
195 }
196 
197 template <typename NumericType>
198 inline constexpr bool operator<=(const DynamicKinematicPressure<NumericType>& left,
199  const DynamicKinematicPressure<NumericType>& right) noexcept {
200  return left.Value() <= right.Value();
201 }
202 
203 template <typename NumericType>
204 inline constexpr bool operator>=(const DynamicKinematicPressure<NumericType>& left,
205  const DynamicKinematicPressure<NumericType>& right) noexcept {
206  return left.Value() >= right.Value();
207 }
208 
209 template <typename NumericType>
210 inline std::ostream& operator<<(
211  std::ostream& stream, const DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure) {
212  stream << dynamic_kinematic_pressure.Print();
213  return stream;
214 }
215 
216 template <typename NumericType>
218  const NumericType number,
219  const DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure) {
220  return dynamic_kinematic_pressure * number;
221 }
222 
223 template <typename NumericType>
225  const DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure)
226  : Speed<NumericType>(std::sqrt(2.0 * dynamic_kinematic_pressure.Value())) {}
227 
228 template <typename NumericType>
230  const MassDensity<NumericType>& mass_density,
231  const DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure)
232  : DynamicPressure<NumericType>(mass_density.Value() * dynamic_kinematic_pressure.Value()) {}
233 
234 template <typename NumericType>
236  const MassDensity<NumericType>& mass_density) const {
237  return DynamicKinematicPressure<NumericType>{*this, mass_density};
238 }
239 
240 } // namespace PhQ
241 
242 namespace std {
243 
244 template <typename NumericType>
245 struct hash<PhQ::DynamicKinematicPressure<NumericType>> {
246  inline size_t operator()(
247  const PhQ::DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure) const {
248  return hash<NumericType>()(dynamic_kinematic_pressure.Value());
249  }
250 };
251 
252 } // namespace std
253 
254 #endif // PHQ_DYNAMIC_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...
~DynamicKinematicPressure() noexcept=default
Destructor. Destroys this dynamic kinematic pressure.
constexpr DynamicKinematicPressure< NumericType > & operator=(const DynamicKinematicPressure< NumericType > &other)=default
Copy assignment operator. Assigns this dynamic kinematic pressure by copying another one.
static constexpr DynamicKinematicPressure< NumericType > Zero()
Statically creates a dynamic kinematic pressure of zero.
constexpr DynamicKinematicPressure< NumericType > operator+(const DynamicKinematicPressure< NumericType > &dynamic_kinematic_pressure) const
constexpr DynamicKinematicPressure< NumericType > & operator=(DynamicKinematicPressure< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this dynamic kinematic pressure by moving another one.
constexpr DynamicKinematicPressure(const DynamicPressure< NumericType > &dynamic_pressure, const MassDensity< NumericType > &mass_density)
Constructor. Constructs a dynamic kinematic pressure from a given dynamic pressure and mass density u...
constexpr DynamicKinematicPressure< NumericType > & operator=(const DynamicKinematicPressure< OtherNumericType > &other)
Copy assignment operator. Assigns this dynamic kinematic pressure by copying another one.
constexpr void operator+=(const DynamicKinematicPressure< NumericType > &dynamic_kinematic_pressure) noexcept
constexpr void operator/=(const NumericType number) noexcept
static constexpr DynamicKinematicPressure< NumericType > Create(const NumericType value)
Statically creates a dynamic kinematic pressure with a given value expressed in a given specific ener...
constexpr DynamicKinematicPressure< NumericType > operator-(const DynamicKinematicPressure< NumericType > &dynamic_kinematic_pressure) const
constexpr DynamicKinematicPressure< NumericType > operator*(const NumericType number) const
DynamicKinematicPressure(const NumericType value, const Unit::SpecificEnergy unit)
Constructor. Constructs a dynamic kinematic pressure with a given value expressed in a given specific...
constexpr DynamicKinematicPressure(DynamicKinematicPressure< NumericType > &&other) noexcept=default
Move constructor. Constructs a dynamic kinematic pressure by moving another one.
constexpr void operator-=(const DynamicKinematicPressure< NumericType > &dynamic_kinematic_pressure) noexcept
constexpr DynamicKinematicPressure< NumericType > operator/(const NumericType number) const
constexpr DynamicKinematicPressure(const NumericType value)
Constructor. Constructs a dynamic kinematic pressure with a given value expressed in the standard spe...
DynamicKinematicPressure()=default
Default constructor. Constructs a dynamic kinematic pressure with an uninitialized value.
constexpr NumericType operator/(const DynamicKinematicPressure< NumericType > &dynamic_kinematic_pressure) const noexcept
constexpr DynamicKinematicPressure(const Speed< NumericType > &speed)
Constructor. Constructs a dynamic kinematic pressure from a given speed using the definition of dynam...
constexpr void operator*=(const NumericType number) noexcept
Dynamic pressure, which is the additional pressure arising from a flowing fluid's kinetic energy....
constexpr DynamicPressure< NumericType > operator/(const NumericType number) const
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.
Scalar velocity component or magnitude of a velocity vector. For a three-dimensional Euclidean veloci...
Definition: Speed.hpp:100
Speed()=default
Default constructor. Constructs a speed with an uninitialized value.
Static kinematic pressure, which is static pressure divided by mass density; see PhQ::StaticPressure ...
Total kinematic pressure, which is total pressure divided by mass density; see PhQ::TotalPressure and...
SpecificEnergy
Mass-specific energy units.
Speed
Speed units.
Definition: Speed.hpp:53
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)