Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
Loading...
Searching...
No Matches
DynamicPressure.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_PRESSURE_HPP
26#define PHQ_DYNAMIC_PRESSURE_HPP
27
28#include <cstddef>
29#include <functional>
30#include <ostream>
31
32#include "DimensionalScalar.hpp"
33#include "MassDensity.hpp"
34#include "Speed.hpp"
35#include "StaticPressure.hpp"
36
37namespace PhQ {
38
39// Forward declaration for class PhQ::DynamicPressure.
40template <typename NumericType>
41class DynamicKinematicPressure;
42
43/// \brief Dynamic pressure, which is the additional pressure arising from a flowing fluid's kinetic
44/// energy. Dynamic pressure can be thought of as a flowing fluid's kinetic energy per unit volume.
45/// Not to be confused with static pressure or total pressure; see PhQ::StaticPressure and
46/// PhQ::TotalPressure. For dynamic kinematic pressure, see PhQ::DynamicKinematicPressure.
47template <typename NumericType = double>
48class DynamicPressure : public DimensionalScalar<Unit::Pressure, NumericType> {
49public:
50 /// \brief Default constructor. Constructs a dynamic pressure with an uninitialized value.
51 DynamicPressure() = default;
52
53 /// \brief Constructor. Constructs a dynamic pressure with a given value expressed in a given
54 /// pressure unit.
55 DynamicPressure(const NumericType value, const Unit::Pressure unit)
56 : DimensionalScalar<Unit::Pressure, NumericType>(value, unit) {}
57
58 /// \brief Constructor. Constructs a dynamic pressure from a given mass density and speed using
59 /// the definition of dynamic pressure.
60 constexpr DynamicPressure(
61 const MassDensity<NumericType>& mass_density, const Speed<NumericType>& speed)
62 : DynamicPressure<NumericType>(0.5 * mass_density.Value() * std::pow(speed.Value(), 2)) {}
63
64 /// \brief Constructor. Constructs a dynamic pressure from a given total pressure and static
65 /// pressure using the definition of total pressure.
66 constexpr DynamicPressure(const TotalPressure<NumericType>& total_pressure,
67 const StaticPressure<NumericType>& static_pressure);
68
69 /// \brief Constructor. Constructs a dynamic pressure from a given mass density and dynamic
70 /// kinematic pressure using the definition of dynamic kinematic pressure.
71 constexpr DynamicPressure(
72 const MassDensity<NumericType>& mass_density,
73 const DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure);
74
75 /// \brief Destructor. Destroys this dynamic pressure.
76 ~DynamicPressure() noexcept = default;
77
78 /// \brief Copy constructor. Constructs a dynamic pressure by copying another one.
79 constexpr DynamicPressure(const DynamicPressure<NumericType>& other) = default;
80
81 /// \brief Copy constructor. Constructs a dynamic pressure by copying another one.
82 template <typename OtherNumericType>
83 explicit constexpr DynamicPressure(const DynamicPressure<OtherNumericType>& other)
84 : DynamicPressure(static_cast<NumericType>(other.Value())) {}
85
86 /// \brief Move constructor. Constructs a dynamic pressure by moving another one.
87 constexpr DynamicPressure(DynamicPressure<NumericType>&& other) noexcept = default;
88
89 /// \brief Copy assignment operator. Assigns this dynamic pressure by copying another one.
91 const DynamicPressure<NumericType>& other) = default;
92
93 /// \brief Copy assignment operator. Assigns this dynamic pressure by copying another one.
94 template <typename OtherNumericType>
97 this->value = static_cast<NumericType>(other.Value());
98 return *this;
99 }
100
101 /// \brief Move assignment operator. Assigns this dynamic pressure by moving another one.
103 DynamicPressure<NumericType>&& other) noexcept = default;
104
105 /// \brief Statically creates a dynamic pressure of zero.
106 [[nodiscard]] static constexpr DynamicPressure<NumericType> Zero() {
107 return DynamicPressure<NumericType>{static_cast<NumericType>(0)};
108 }
109
110 /// \brief Statically creates a dynamic pressure with a given value expressed in a given pressure
111 /// unit.
112 template <Unit::Pressure Unit>
113 [[nodiscard]] static constexpr DynamicPressure<NumericType> Create(const NumericType value) {
115 ConvertStatically<Unit::Pressure, Unit, Standard<Unit::Pressure>>(value)};
116 }
117
119 const DynamicPressure<NumericType>& dynamic_pressure) const {
120 return DynamicPressure<NumericType>{this->value + dynamic_pressure.value};
121 }
122
124 const StaticPressure<NumericType>& static_pressure) const;
125
127 const DynamicPressure<NumericType>& dynamic_pressure) const {
128 return DynamicPressure<NumericType>{this->value - dynamic_pressure.value};
129 }
130
131 constexpr DynamicPressure<NumericType> operator*(const NumericType number) const {
132 return DynamicPressure<NumericType>{this->value * number};
133 }
134
135 constexpr DynamicPressure<NumericType> operator/(const NumericType number) const {
136 return DynamicPressure<NumericType>{this->value / number};
137 }
138
139 constexpr NumericType operator/(
140 const DynamicPressure<NumericType>& dynamic_pressure) const noexcept {
141 return this->value / dynamic_pressure.value;
142 }
143
145 const MassDensity<NumericType>& mass_density) const;
146
147 constexpr void operator+=(const DynamicPressure<NumericType>& dynamic_pressure) noexcept {
148 this->value += dynamic_pressure.value;
149 }
150
151 constexpr void operator-=(const DynamicPressure<NumericType>& dynamic_pressure) noexcept {
152 this->value -= dynamic_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
163private:
164 /// \brief Constructor. Constructs a dynamic pressure with a given value expressed in the standard
165 /// pressure unit.
166 explicit constexpr DynamicPressure(const NumericType value)
167 : DimensionalScalar<Unit::Pressure, NumericType>(value) {}
168};
169
170template <typename NumericType>
171inline constexpr bool operator==(
172 const DynamicPressure<NumericType>& left, const DynamicPressure<NumericType>& right) noexcept {
173 return left.Value() == right.Value();
174}
175
176template <typename NumericType>
177inline constexpr bool operator!=(
178 const DynamicPressure<NumericType>& left, const DynamicPressure<NumericType>& right) noexcept {
179 return left.Value() != right.Value();
180}
181
182template <typename NumericType>
183inline constexpr bool operator<(
184 const DynamicPressure<NumericType>& left, const DynamicPressure<NumericType>& right) noexcept {
185 return left.Value() < right.Value();
186}
187
188template <typename NumericType>
189inline constexpr bool operator>(
190 const DynamicPressure<NumericType>& left, const DynamicPressure<NumericType>& right) noexcept {
191 return left.Value() > right.Value();
192}
193
194template <typename NumericType>
195inline constexpr bool operator<=(
196 const DynamicPressure<NumericType>& left, const DynamicPressure<NumericType>& right) noexcept {
197 return left.Value() <= right.Value();
198}
199
200template <typename NumericType>
201inline constexpr bool operator>=(
202 const DynamicPressure<NumericType>& left, const DynamicPressure<NumericType>& right) noexcept {
203 return left.Value() >= right.Value();
204}
205
206template <typename NumericType>
207inline std::ostream& operator<<(
208 std::ostream& stream, const DynamicPressure<NumericType>& dynamic_pressure) {
209 stream << dynamic_pressure.Print();
210 return stream;
211}
212
213template <typename NumericType>
215 const NumericType number, const DynamicPressure<NumericType>& dynamic_pressure) {
216 return dynamic_pressure * number;
217}
218
219template <typename NumericType>
221 const DynamicPressure<NumericType>& dynamic_pressure, const Speed<NumericType>& speed)
222 : MassDensity<NumericType>(2.0 * dynamic_pressure.Value() / (speed.Value() * speed.Value())) {}
223
224template <typename NumericType>
226 const MassDensity<NumericType>& mass_density)
227 : Speed<NumericType>(std::sqrt(2.0 * dynamic_pressure.Value() / mass_density.Value())) {}
228
229} // namespace PhQ
230
231namespace std {
232
233template <typename NumericType>
234struct hash<PhQ::DynamicPressure<NumericType>> {
235 inline size_t operator()(const PhQ::DynamicPressure<NumericType>& dynamic_pressure) const {
236 return hash<NumericType>()(dynamic_pressure.Value());
237 }
238};
239
240} // namespace std
241
242#endif // PHQ_DYNAMIC_PRESSURE_HPP
Abstract base class that represents any dimensional scalar physical quantity. Such a physical quantit...
NumericType value
Value of this physical quantity expressed in its standard unit of measure.
constexpr NumericType Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
static constexpr UnitType 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...
Dynamic pressure, which is the additional pressure arising from a flowing fluid's kinetic energy....
constexpr DynamicPressure< NumericType > operator+(const DynamicPressure< NumericType > &dynamic_pressure) const
constexpr void operator*=(const NumericType number) noexcept
static constexpr DynamicPressure< NumericType > Create(const NumericType value)
Statically creates a dynamic pressure with a given value expressed in a given pressure unit.
constexpr DynamicPressure< NumericType > operator-(const DynamicPressure< NumericType > &dynamic_pressure) const
constexpr DynamicPressure< NumericType > operator/(const NumericType number) const
constexpr DynamicPressure(const NumericType value)
Constructor. Constructs a dynamic pressure with a given value expressed in the standard pressure unit...
constexpr DynamicPressure(DynamicPressure< NumericType > &&other) noexcept=default
Move constructor. Constructs a dynamic pressure by moving another one.
constexpr void operator+=(const DynamicPressure< NumericType > &dynamic_pressure) noexcept
static constexpr DynamicPressure< NumericType > Zero()
Statically creates a dynamic pressure of zero.
constexpr DynamicPressure< NumericType > & operator=(const DynamicPressure< OtherNumericType > &other)
Copy assignment operator. Assigns this dynamic pressure by copying another one.
constexpr void operator-=(const DynamicPressure< NumericType > &dynamic_pressure) noexcept
constexpr void operator/=(const NumericType number) noexcept
constexpr DynamicPressure(const MassDensity< NumericType > &mass_density, const Speed< NumericType > &speed)
Constructor. Constructs a dynamic pressure from a given mass density and speed using the definition o...
constexpr DynamicPressure< NumericType > & operator=(DynamicPressure< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this dynamic pressure by moving another one.
DynamicPressure()=default
Default constructor. Constructs a dynamic pressure with an uninitialized value.
~DynamicPressure() noexcept=default
Destructor. Destroys this dynamic pressure.
constexpr DynamicPressure< NumericType > & operator=(const DynamicPressure< NumericType > &other)=default
Copy assignment operator. Assigns this dynamic pressure by copying another one.
constexpr NumericType operator/(const DynamicPressure< NumericType > &dynamic_pressure) const noexcept
DynamicPressure(const NumericType value, const Unit::Pressure unit)
Constructor. Constructs a dynamic pressure with a given value expressed in a given pressure unit.
constexpr DynamicPressure< NumericType > operator*(const NumericType number) const
Mass density. Mass per unit volume; see PhQ::Mass and PhQ::Volume.
MassDensity()=default
Default constructor. Constructs a mass density with an uninitialized value.
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 pressure. Pressure of a fluid at rest. Not to be confused with dynamic pressure,...
Total pressure, which is the sum of static pressure and dynamic pressure; see PhQ::StaticPressure and...
Pressure
Pressure units.
Definition Pressure.hpp:53
Namespace that encompasses all of the Physical Quantities library's content.
std::ostream & operator<<(std::ostream &stream, 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 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