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
TotalKinematicPressure.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_KINEMATIC_PRESSURE_HPP
26#define PHQ_TOTAL_KINEMATIC_PRESSURE_HPP
27
28#include <cstddef>
29#include <functional>
30#include <ostream>
31
32#include "DimensionalScalar.hpp"
34#include "MassDensity.hpp"
36#include "TotalPressure.hpp"
38
39namespace PhQ {
40
41/// \brief Total kinematic pressure, which is total pressure divided by mass density; see
42/// PhQ::TotalPressure and PhQ::MassDensity.
43template <typename NumericType = double>
44class TotalKinematicPressure : public DimensionalScalar<Unit::SpecificEnergy, NumericType> {
45public:
46 /// \brief Default constructor. Constructs a total kinematic pressure with an uninitialized value.
48
49 /// \brief Constructor. Constructs a total kinematic pressure with a given value expressed in a
50 /// given specific energy unit.
51 TotalKinematicPressure(const NumericType value, const Unit::SpecificEnergy unit)
52 : DimensionalScalar<Unit::SpecificEnergy, NumericType>(value, unit) {}
53
54 /// \brief Constructor. Constructs a total kinematic pressure from a given static kinematic
55 /// pressure and dynamic kinematic pressure using the definition of total kinematic pressure.
57 const StaticKinematicPressure<NumericType>& static_kinematic_pressure,
58 const DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure)
59 : TotalKinematicPressure<NumericType>(
60 static_kinematic_pressure.Value() + dynamic_kinematic_pressure.Value()) {}
61
62 /// \brief Constructor. Constructs a total kinematic pressure from a given total pressure and mass
63 /// density using the definition of total kinematic pressure.
64 constexpr TotalKinematicPressure(const TotalPressure<NumericType>& total_pressure,
65 const MassDensity<NumericType>& mass_density)
66 : TotalKinematicPressure<NumericType>(total_pressure.Value() / mass_density.Value()) {}
67
68 /// \brief Destructor. Destroys this total kinematic pressure.
69 ~TotalKinematicPressure() noexcept = default;
70
71 /// \brief Copy constructor. Constructs a total kinematic pressure by copying another one.
72 constexpr TotalKinematicPressure(const TotalKinematicPressure<NumericType>& other) = default;
73
74 /// \brief Copy constructor. Constructs a total kinematic pressure by copying another one.
75 template <typename OtherNumericType>
76 explicit constexpr TotalKinematicPressure(const TotalKinematicPressure<OtherNumericType>& other)
77 : TotalKinematicPressure(static_cast<NumericType>(other.Value())) {}
78
79 /// \brief Move constructor. Constructs a total kinematic pressure by moving another one.
80 constexpr TotalKinematicPressure(TotalKinematicPressure<NumericType>&& other) noexcept = default;
81
82 /// \brief Copy assignment operator. Assigns this total kinematic pressure by copying another one.
84 const TotalKinematicPressure<NumericType>& other) = default;
85
86 /// \brief Copy assignment operator. Assigns this total kinematic pressure by copying another one.
87 template <typename OtherNumericType>
90 this->value = static_cast<NumericType>(other.Value());
91 return *this;
92 }
93
94 /// \brief Move assignment operator. Assigns this total kinematic pressure by moving another one.
96 TotalKinematicPressure<NumericType>&& other) noexcept = default;
97
98 /// \brief Statically creates a total kinematic pressure of zero.
99 [[nodiscard]] static constexpr TotalKinematicPressure<NumericType> Zero() {
100 return TotalKinematicPressure<NumericType>{static_cast<NumericType>(0)};
101 }
102
103 /// \brief Statically creates a total kinematic pressure with a given value expressed in a given
104 /// specific energy unit.
105 template <Unit::SpecificEnergy Unit>
106 [[nodiscard]] static constexpr TotalKinematicPressure<NumericType> Create(
107 const NumericType value) {
109 ConvertStatically<Unit::SpecificEnergy, Unit, Standard<Unit::SpecificEnergy>>(value)};
110 }
111
113 const TotalKinematicPressure<NumericType>& total_kinematic_pressure) const {
114 return TotalKinematicPressure<NumericType>{this->value + total_kinematic_pressure.value};
115 }
116
118 const TotalKinematicPressure<NumericType>& total_kinematic_pressure) const {
119 return TotalKinematicPressure<NumericType>{this->value - total_kinematic_pressure.value};
120 }
121
123 const StaticKinematicPressure<NumericType>& static_kinematic_pressure) const {
124 return DynamicKinematicPressure<NumericType>{*this, static_kinematic_pressure};
125 }
126
128 const DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure) const {
129 return StaticKinematicPressure<NumericType>{*this, dynamic_kinematic_pressure};
130 }
131
132 constexpr TotalKinematicPressure<NumericType> operator*(const NumericType number) const {
133 return TotalKinematicPressure<NumericType>{this->value * number};
134 }
135
136 constexpr TotalKinematicPressure<NumericType> operator/(const NumericType number) const {
137 return TotalKinematicPressure<NumericType>{this->value / number};
138 }
139
140 constexpr NumericType operator/(
141 const TotalKinematicPressure<NumericType>& total_kinematic_pressure) const noexcept {
142 return this->value / total_kinematic_pressure.value;
143 }
144
145 constexpr void operator+=(
146 const TotalKinematicPressure<NumericType>& total_kinematic_pressure) noexcept {
147 this->value += total_kinematic_pressure.value;
148 }
149
150 constexpr void operator-=(
151 const TotalKinematicPressure<NumericType>& total_kinematic_pressure) noexcept {
152 this->value -= total_kinematic_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 total kinematic pressure with a given value expressed in the
165 /// standard specific energy unit.
166 explicit constexpr TotalKinematicPressure(const NumericType value)
167 : DimensionalScalar<Unit::SpecificEnergy, NumericType>(value) {}
168};
169
170template <typename NumericType>
171inline constexpr bool operator==(const TotalKinematicPressure<NumericType>& left,
172 const TotalKinematicPressure<NumericType>& right) noexcept {
173 return left.Value() == right.Value();
174}
175
176template <typename NumericType>
177inline constexpr bool operator!=(const TotalKinematicPressure<NumericType>& left,
178 const TotalKinematicPressure<NumericType>& right) noexcept {
179 return left.Value() != right.Value();
180}
181
182template <typename NumericType>
183inline constexpr bool operator<(const TotalKinematicPressure<NumericType>& left,
184 const TotalKinematicPressure<NumericType>& right) noexcept {
185 return left.Value() < right.Value();
186}
187
188template <typename NumericType>
189inline constexpr bool operator>(const TotalKinematicPressure<NumericType>& left,
190 const TotalKinematicPressure<NumericType>& right) noexcept {
191 return left.Value() > right.Value();
192}
193
194template <typename NumericType>
195inline constexpr bool operator<=(const TotalKinematicPressure<NumericType>& left,
196 const TotalKinematicPressure<NumericType>& right) noexcept {
197 return left.Value() <= right.Value();
198}
199
200template <typename NumericType>
201inline constexpr bool operator>=(const TotalKinematicPressure<NumericType>& left,
202 const TotalKinematicPressure<NumericType>& right) noexcept {
203 return left.Value() >= right.Value();
204}
205
206template <typename NumericType>
207inline std::ostream& operator<<(
208 std::ostream& stream, const TotalKinematicPressure<NumericType>& total_kinematic_pressure) {
209 stream << total_kinematic_pressure.Print();
210 return stream;
211}
212
213template <typename NumericType>
215 const NumericType number, const TotalKinematicPressure<NumericType>& total_kinematic_pressure) {
216 return total_kinematic_pressure * number;
217}
218
219template <typename NumericType>
221 const MassDensity<NumericType>& mass_density,
222 const TotalKinematicPressure<NumericType>& total_kinematic_pressure)
223 : TotalPressure<NumericType>(mass_density.Value() * total_kinematic_pressure.Value()) {}
224
225template <typename NumericType>
227 const TotalKinematicPressure<NumericType>& total_kinematic_pressure,
228 const DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure)
229 : StaticKinematicPressure<NumericType>(
230 total_kinematic_pressure.Value() - dynamic_kinematic_pressure.Value()) {}
231
232template <typename NumericType>
234 const TotalKinematicPressure<NumericType>& total_kinematic_pressure,
235 const StaticKinematicPressure<NumericType>& static_kinematic_pressure)
236 : DynamicKinematicPressure<NumericType>(
237 total_kinematic_pressure.Value() - static_kinematic_pressure.Value()) {}
238
239template <typename NumericType>
241operator+(const DynamicKinematicPressure<NumericType>& dynamic_kinematic_pressure) const {
242 return TotalKinematicPressure<NumericType>{*this, dynamic_kinematic_pressure};
243}
244
245template <typename NumericType>
247operator+(const StaticKinematicPressure<NumericType>& static_kinematic_pressure) const {
248 return TotalKinematicPressure<NumericType>{static_kinematic_pressure, *this};
249}
250
251template <typename NumericType>
253 const MassDensity<NumericType>& mass_density) const {
254 return TotalKinematicPressure<NumericType>{*this, mass_density};
255}
256
257} // namespace PhQ
258
259namespace std {
260
261template <typename NumericType>
262struct hash<PhQ::TotalKinematicPressure<NumericType>> {
263 inline size_t operator()(
264 const PhQ::TotalKinematicPressure<NumericType>& total_kinematic_pressure) const {
265 return hash<NumericType>()(total_kinematic_pressure.Value());
266 }
267};
268
269} // namespace std
270
271#endif // PHQ_TOTAL_KINEMATIC_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...
constexpr DynamicKinematicPressure< NumericType > operator+(const DynamicKinematicPressure< NumericType > &dynamic_kinematic_pressure) const
DynamicKinematicPressure()=default
Default constructor. Constructs a dynamic kinematic pressure with an uninitialized value.
Mass density. Mass per unit volume; see PhQ::Mass and PhQ::Volume.
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
StaticKinematicPressure()=default
Default constructor. Constructs a static kinematic pressure with an uninitialized value.
Total kinematic pressure, which is total pressure divided by mass density; see PhQ::TotalPressure and...
TotalKinematicPressure()=default
Default constructor. Constructs a total kinematic pressure with an uninitialized value.
constexpr DynamicKinematicPressure< NumericType > operator-(const StaticKinematicPressure< NumericType > &static_kinematic_pressure) const
constexpr TotalKinematicPressure< NumericType > operator+(const TotalKinematicPressure< NumericType > &total_kinematic_pressure) const
constexpr TotalKinematicPressure(const NumericType value)
Constructor. Constructs a total kinematic pressure with a given value expressed in the standard speci...
constexpr void operator*=(const NumericType number) noexcept
constexpr void operator+=(const TotalKinematicPressure< NumericType > &total_kinematic_pressure) noexcept
TotalKinematicPressure(const NumericType value, const Unit::SpecificEnergy unit)
Constructor. Constructs a total kinematic pressure with a given value expressed in a given specific e...
constexpr TotalKinematicPressure(TotalKinematicPressure< NumericType > &&other) noexcept=default
Move constructor. Constructs a total kinematic pressure by moving another one.
static constexpr TotalKinematicPressure< NumericType > Zero()
Statically creates a total kinematic pressure of zero.
~TotalKinematicPressure() noexcept=default
Destructor. Destroys this total kinematic pressure.
constexpr TotalKinematicPressure< NumericType > & operator=(const TotalKinematicPressure< OtherNumericType > &other)
Copy assignment operator. Assigns this total kinematic pressure by copying another one.
constexpr StaticKinematicPressure< NumericType > operator-(const DynamicKinematicPressure< NumericType > &dynamic_kinematic_pressure) const
constexpr NumericType operator/(const TotalKinematicPressure< NumericType > &total_kinematic_pressure) const noexcept
constexpr TotalKinematicPressure< NumericType > & operator=(TotalKinematicPressure< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this total kinematic pressure by moving another one.
constexpr TotalKinematicPressure< NumericType > & operator=(const TotalKinematicPressure< NumericType > &other)=default
Copy assignment operator. Assigns this total kinematic pressure by copying another one.
constexpr void operator/=(const NumericType number) noexcept
constexpr void operator-=(const TotalKinematicPressure< NumericType > &total_kinematic_pressure) noexcept
constexpr TotalKinematicPressure(const TotalPressure< NumericType > &total_pressure, const MassDensity< NumericType > &mass_density)
Constructor. Constructs a total kinematic pressure from a given total pressure and mass density using...
constexpr TotalKinematicPressure< NumericType > operator/(const NumericType number) const
static constexpr TotalKinematicPressure< NumericType > Create(const NumericType value)
Statically creates a total kinematic pressure with a given value expressed in a given specific energy...
constexpr TotalKinematicPressure< NumericType > operator*(const NumericType number) const
constexpr TotalKinematicPressure(const StaticKinematicPressure< NumericType > &static_kinematic_pressure, const DynamicKinematicPressure< NumericType > &dynamic_kinematic_pressure)
Constructor. Constructs a total kinematic pressure from a given static kinematic pressure and dynamic...
constexpr TotalKinematicPressure< NumericType > operator-(const TotalKinematicPressure< NumericType > &total_kinematic_pressure) const
Total pressure, which is the sum of static pressure and dynamic pressure; see PhQ::StaticPressure and...
constexpr TotalPressure< NumericType > operator/(const NumericType number) const
TotalPressure()=default
Default constructor. Constructs a total pressure with an uninitialized value.
SpecificEnergy
Mass-specific energy units.
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