Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
StaticPressure.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_PRESSURE_HPP
26 #define PHQ_STATIC_PRESSURE_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 
32 #include "Area.hpp"
33 #include "DimensionalScalar.hpp"
34 #include "ScalarForce.hpp"
35 #include "Unit/Pressure.hpp"
36 
37 namespace PhQ {
38 
39 // Forward declaration for class PhQ::StaticPressure.
40 template <typename NumericType>
41 class Direction;
42 
43 // Forward declaration for class PhQ::StaticPressure.
44 template <typename NumericType>
45 class DynamicPressure;
46 
47 // Forward declaration for class PhQ::StaticPressure.
48 template <typename NumericType>
49 class MassDensity;
50 
51 // Forward declaration for class PhQ::StaticPressure.
52 template <typename NumericType>
53 class StaticKinematicPressure;
54 
55 // Forward declaration for class PhQ::StaticPressure.
56 template <typename NumericType>
57 class Stress;
58 
59 // Forward declaration for class PhQ::StaticPressure.
60 template <typename NumericType>
61 class TotalPressure;
62 
63 /// \brief Static pressure. Pressure of a fluid at rest. Not to be confused with dynamic pressure,
64 /// which is the additional pressure resulting from the kinetic energy of a flowing fluid, or total
65 /// pressure, which is the sum of static pressure and dynamic pressure. See PhQ::DynamicPressure and
66 /// PhQ::TotalPressure. Can represent either an absolute static pressure or a static pressure
67 /// difference relative to another static pressure. For static kinematic pressure, see
68 /// PhQ::StaticKinematicPressure.
69 template <typename NumericType = double>
70 class StaticPressure : public DimensionalScalar<Unit::Pressure, NumericType> {
71 public:
72  /// \brief Default constructor. Constructs a static pressure with an uninitialized value.
73  StaticPressure() = default;
74 
75  /// \brief Constructor. Constructs a static pressure with a given value expressed in a given
76  /// pressure unit.
77  StaticPressure(const NumericType value, const Unit::Pressure unit)
78  : DimensionalScalar<Unit::Pressure, NumericType>(value, unit) {}
79 
80  /// \brief Constructor. Constructs a static pressure from a given scalar force magnitude and area
81  /// using the definition of pressure.
82  constexpr StaticPressure(
83  const ScalarForce<NumericType>& scalar_force, const Area<NumericType>& area)
84  : StaticPressure<NumericType>(scalar_force.Value() / area.Value()) {}
85 
86  /// \brief Constructor. Constructs a static pressure from a given total pressure and dynamic
87  /// pressure using the definition of total pressure.
88  constexpr StaticPressure(const TotalPressure<NumericType>& total_pressure,
89  const DynamicPressure<NumericType>& dynamic_pressure);
90 
91  /// \brief Constructor. Constructs a static pressure from a given mass density and static
92  /// kinematic pressure using the definition of static kinematic pressure.
93  constexpr StaticPressure(const MassDensity<NumericType>& mass_density,
94  const StaticKinematicPressure<NumericType>& static_kinematic_pressure);
95 
96  /// \brief Destructor. Destroys this static pressure.
97  ~StaticPressure() noexcept = default;
98 
99  /// \brief Copy constructor. Constructs a static pressure by copying another one.
100  constexpr StaticPressure(const StaticPressure<NumericType>& other) = default;
101 
102  /// \brief Copy constructor. Constructs a static pressure by copying another one.
103  template <typename OtherNumericType>
104  explicit constexpr StaticPressure(const StaticPressure<OtherNumericType>& other)
105  : StaticPressure(static_cast<NumericType>(other.Value())) {}
106 
107  /// \brief Move constructor. Constructs a static pressure by moving another one.
108  constexpr StaticPressure(StaticPressure<NumericType>&& other) noexcept = default;
109 
110  /// \brief Copy assignment operator. Assigns this static pressure by copying another one.
112  const StaticPressure<NumericType>& other) = default;
113 
114  /// \brief Copy assignment operator. Assigns this static pressure by copying another one.
115  template <typename OtherNumericType>
117  this->value = static_cast<NumericType>(other.Value());
118  return *this;
119  }
120 
121  /// \brief Move assignment operator. Assigns this static pressure by moving another one.
123  StaticPressure<NumericType>&& other) noexcept = default;
124 
125  /// \brief Statically creates a static pressure of zero.
126  [[nodiscard]] static constexpr StaticPressure<NumericType> Zero() {
127  return StaticPressure<NumericType>{static_cast<NumericType>(0)};
128  }
129 
130  /// \brief Statically creates a static pressure with a given value expressed in a given pressure
131  /// unit.
132  template <Unit::Pressure Unit>
133  [[nodiscard]] static constexpr StaticPressure<NumericType> Create(const NumericType value) {
135  ConvertStatically<Unit::Pressure, Unit, Standard<Unit::Pressure>>(value)};
136  }
137 
138  [[nodiscard]] constexpr PhQ::Stress<NumericType> Stress() const;
139 
141  return StaticPressure<NumericType>{this->value + other.value};
142  }
143 
145  const DynamicPressure<NumericType>& dynamic_pressure) const;
146 
148  return StaticPressure<NumericType>{this->value - other.value};
149  }
150 
151  constexpr StaticPressure<NumericType> operator*(const NumericType number) const {
152  return StaticPressure<NumericType>{this->value * number};
153  }
154 
155  constexpr ScalarForce<NumericType> operator*(const Area<NumericType>& area) const {
156  return ScalarForce<NumericType>{*this, area};
157  }
158 
159  constexpr StaticPressure<NumericType> operator/(const NumericType number) const {
160  return StaticPressure<NumericType>{this->value / number};
161  }
162 
164  const MassDensity<NumericType>& mass_density) const;
165 
166  constexpr NumericType operator/(const StaticPressure<NumericType>& other) const noexcept {
167  return this->value / other.value;
168  }
169 
170  constexpr void operator+=(const StaticPressure<NumericType>& other) noexcept {
171  this->value += other.value;
172  }
173 
174  constexpr void operator-=(const StaticPressure<NumericType>& other) noexcept {
175  this->value -= other.value;
176  }
177 
178  constexpr void operator*=(const NumericType number) noexcept {
179  this->value *= number;
180  }
181 
182  constexpr void operator/=(const NumericType number) noexcept {
183  this->value /= number;
184  }
185 
186 private:
187  /// \brief Constructor. Constructs a static pressure with a given value expressed in the standard
188  /// pressure unit.
189  explicit constexpr StaticPressure(const NumericType value)
190  : DimensionalScalar<Unit::Pressure, NumericType>(value) {}
191 };
192 
193 template <typename NumericType>
194 inline constexpr bool operator==(
195  const StaticPressure<NumericType>& left, const StaticPressure<NumericType>& right) noexcept {
196  return left.Value() == right.Value();
197 }
198 
199 template <typename NumericType>
200 inline constexpr bool operator!=(
201  const StaticPressure<NumericType>& left, const StaticPressure<NumericType>& right) noexcept {
202  return left.Value() != right.Value();
203 }
204 
205 template <typename NumericType>
206 inline constexpr bool operator<(
207  const StaticPressure<NumericType>& left, const StaticPressure<NumericType>& right) noexcept {
208  return left.Value() < right.Value();
209 }
210 
211 template <typename NumericType>
212 inline constexpr bool operator>(
213  const StaticPressure<NumericType>& left, const StaticPressure<NumericType>& right) noexcept {
214  return left.Value() > right.Value();
215 }
216 
217 template <typename NumericType>
218 inline constexpr bool operator<=(
219  const StaticPressure<NumericType>& left, const StaticPressure<NumericType>& right) noexcept {
220  return left.Value() <= right.Value();
221 }
222 
223 template <typename NumericType>
224 inline constexpr bool operator>=(
225  const StaticPressure<NumericType>& left, const StaticPressure<NumericType>& right) noexcept {
226  return left.Value() >= right.Value();
227 }
228 
229 template <typename NumericType>
230 inline std::ostream& operator<<(
231  std::ostream& stream, const StaticPressure<NumericType>& static_pressure) {
232  stream << static_pressure.Print();
233  return stream;
234 }
235 
236 template <typename NumericType>
238  const NumericType number, const StaticPressure<NumericType>& static_pressure) {
239  return static_pressure * number;
240 }
241 
242 template <typename NumericType>
243 inline constexpr Area<NumericType>::Area(const ScalarForce<NumericType>& scalar_force,
244  const StaticPressure<NumericType>& static_pressure)
245  : Area<NumericType>(scalar_force.Value() / static_pressure.Value()) {}
246 
247 template <typename NumericType>
249  const StaticPressure<NumericType>& static_pressure, const Area<NumericType>& area)
250  : ScalarForce<NumericType>(static_pressure.Value() * area.Value()) {}
251 
252 template <typename NumericType>
254  const StaticPressure<NumericType>& static_pressure) const {
255  return ScalarForce<NumericType>{static_pressure, *this};
256 }
257 
258 template <typename NumericType>
260  const Area<NumericType>& area) const {
261  return StaticPressure<NumericType>{*this, area};
262 }
263 
264 } // namespace PhQ
265 
266 namespace std {
267 
268 template <typename NumericType>
269 struct hash<PhQ::StaticPressure<NumericType>> {
270  inline size_t operator()(const PhQ::StaticPressure<NumericType>& static_pressure) const {
271  return hash<NumericType>()(static_pressure.Value());
272  }
273 };
274 
275 } // namespace std
276 
277 #endif // PHQ_STATIC_PRESSURE_HPP
Surface area or cross-sectional area. Can also represent a scalar component of a vector area or the m...
Definition: Area.hpp:71
constexpr Area< NumericType > operator*(const NumericType number) const
Definition: Area.hpp:143
Area()=default
Default constructor. Constructs an area with an uninitialized value.
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::Pressure 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 pressure, which is the additional pressure arising from a flowing fluid's kinetic energy....
Mass density. Mass per unit volume; see PhQ::Mass and PhQ::Volume.
Definition: MassDensity.hpp:83
Scalar force component or magnitude of a force vector. For a three-dimensional Euclidean force vector...
Definition: ScalarForce.hpp:66
constexpr ScalarForce< NumericType > operator/(const NumericType number) const
Static kinematic pressure, which is static pressure divided by mass density; see PhQ::StaticPressure ...
Static pressure. Pressure of a fluid at rest. Not to be confused with dynamic pressure,...
constexpr void operator/=(const NumericType number) noexcept
constexpr StaticPressure< NumericType > operator+(const StaticPressure< NumericType > &other) const
constexpr NumericType operator/(const StaticPressure< NumericType > &other) const noexcept
constexpr StaticPressure(const NumericType value)
Constructor. Constructs a static pressure with a given value expressed in the standard pressure unit.
constexpr void operator-=(const StaticPressure< NumericType > &other) noexcept
constexpr void operator*=(const NumericType number) noexcept
constexpr ScalarForce< NumericType > operator*(const Area< NumericType > &area) const
constexpr StaticPressure(const ScalarForce< NumericType > &scalar_force, const Area< NumericType > &area)
Constructor. Constructs a static pressure from a given scalar force magnitude and area using the defi...
constexpr StaticPressure< NumericType > operator-(const StaticPressure< NumericType > &other) const
constexpr StaticPressure< NumericType > operator/(const NumericType number) const
static constexpr StaticPressure< NumericType > Create(const NumericType value)
Statically creates a static pressure with a given value expressed in a given pressure unit.
constexpr StaticPressure< NumericType > operator*(const NumericType number) const
StaticPressure(const NumericType value, const Unit::Pressure unit)
Constructor. Constructs a static pressure with a given value expressed in a given pressure unit.
constexpr StaticPressure< NumericType > & operator=(const StaticPressure< OtherNumericType > &other)
Copy assignment operator. Assigns this static pressure by copying another one.
~StaticPressure() noexcept=default
Destructor. Destroys this static pressure.
constexpr StaticPressure< NumericType > & operator=(const StaticPressure< NumericType > &other)=default
Copy assignment operator. Assigns this static pressure by copying another one.
constexpr PhQ::Stress< NumericType > Stress() const
Definition: Stress.hpp:307
static constexpr StaticPressure< NumericType > Zero()
Statically creates a static pressure of zero.
constexpr void operator+=(const StaticPressure< NumericType > &other) noexcept
StaticPressure()=default
Default constructor. Constructs a static pressure with an uninitialized value.
constexpr StaticPressure(StaticPressure< NumericType > &&other) noexcept=default
Move constructor. Constructs a static pressure by moving another one.
constexpr StaticPressure< NumericType > & operator=(StaticPressure< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this static pressure by moving another one.
Three-dimensional Euclidean Cauchy stress symmetric dyadic tensor. Contains six components in Cartesi...
Definition: Stress.hpp:50
Total pressure, which is the sum of static pressure and dynamic pressure; see PhQ::StaticPressure and...
MassDensity
Mass density units.
Definition: MassDensity.hpp:54
Pressure
Pressure units.
Definition: Pressure.hpp:53
Area
Area units.
Definition: Area.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)