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