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