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
IsentropicBulkModulus.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_ISENTROPIC_BULK_MODULUS_HPP
26#define PHQ_ISENTROPIC_BULK_MODULUS_HPP
27
28#include <cstddef>
29#include <functional>
30#include <ostream>
31
32#include "DimensionalScalar.hpp"
33#include "Unit/Pressure.hpp"
34
35namespace PhQ {
36
37// Forward declaration for class PhQ::IsentropicBulkModulus.
38template <typename NumericType>
39class MassDensity;
40
41// Forward declaration for class PhQ::IsentropicBulkModulus.
42template <typename NumericType>
43class SoundSpeed;
44
45/// \brief Isentropic bulk modulus. Not to be confused with the isothermal bulk modulus; see
46/// PhQ::IsothermalBulkModulus. Solid materials usually have very similar isentropic and isothermal
47/// bulk moduli; however, in general, fluid materials have differing isentropic and isothermal bulk
48/// moduli.
49template <typename NumericType = double>
50class IsentropicBulkModulus : public DimensionalScalar<Unit::Pressure, NumericType> {
51public:
52 /// \brief Default constructor. Constructs an isentropic bulk modulus with an uninitialized value.
54
55 /// \brief Constructor. Constructs an isentropic bulk modulus with a given value expressed in a
56 /// given pressure unit.
57 IsentropicBulkModulus(const NumericType value, const Unit::Pressure unit)
58 : DimensionalScalar<Unit::Pressure, NumericType>(value, unit) {}
59
60 /// \brief Constructor. Constructs an isentropic bulk modulus from a given mass density and sound
61 /// speed using the definition of the isentropic bulk modulus.
62 constexpr IsentropicBulkModulus(
63 const MassDensity<NumericType>& mass_density, const SoundSpeed<NumericType>& sound_speed);
64
65 /// \brief Destructor. Destroys this isentropic bulk modulus.
66 ~IsentropicBulkModulus() noexcept = default;
67
68 /// \brief Copy constructor. Constructs an isentropic bulk modulus by copying another one.
69 constexpr IsentropicBulkModulus(const IsentropicBulkModulus<NumericType>& other) = default;
70
71 /// \brief Copy constructor. Constructs a isentropic bulk modulus by copying another one.
72 template <typename OtherNumericType>
73 explicit constexpr IsentropicBulkModulus(const IsentropicBulkModulus<OtherNumericType>& other)
74 : IsentropicBulkModulus(static_cast<NumericType>(other.Value())) {}
75
76 /// \brief Move constructor. Constructs an isentropic bulk modulus by moving another one.
77 constexpr IsentropicBulkModulus(IsentropicBulkModulus<NumericType>&& other) noexcept = default;
78
79 /// \brief Copy assignment operator. Assigns this isentropic bulk modulus by copying another one.
81 const IsentropicBulkModulus<NumericType>& other) = default;
82
83 /// \brief Copy assignment operator. Assigns this isentropic bulk modulus by copying another one.
84 template <typename OtherNumericType>
87 this->value = static_cast<NumericType>(other.Value());
88 return *this;
89 }
90
91 /// \brief Move assignment operator. Assigns this isentropic bulk modulus by moving another one.
93 IsentropicBulkModulus<NumericType>&& other) noexcept = default;
94
95 /// \brief Statically creates an isentropic bulk modulus of zero.
96 [[nodiscard]] static constexpr IsentropicBulkModulus<NumericType> Zero() {
97 return IsentropicBulkModulus<NumericType>{static_cast<NumericType>(0)};
98 }
99
100 /// \brief Statically creates an isentropic bulk modulus with a given value expressed in a given
101 /// pressure unit.
102 template <Unit::Pressure Unit>
103 [[nodiscard]] static constexpr IsentropicBulkModulus<NumericType> Create(
104 const NumericType value) {
106 ConvertStatically<Unit::Pressure, Unit, Standard<Unit::Pressure>>(value)};
107 }
108
110 const IsentropicBulkModulus<NumericType>& isentropic_bulk_modulus) const {
111 return IsentropicBulkModulus<NumericType>{this->value + isentropic_bulk_modulus.value};
112 }
113
115 const IsentropicBulkModulus<NumericType>& isentropic_bulk_modulus) const {
116 return IsentropicBulkModulus<NumericType>{this->value - isentropic_bulk_modulus.value};
117 }
118
119 constexpr IsentropicBulkModulus<NumericType> operator*(const NumericType number) const {
120 return IsentropicBulkModulus<NumericType>{this->value * number};
121 }
122
123 constexpr IsentropicBulkModulus<NumericType> operator/(const NumericType number) const {
124 return IsentropicBulkModulus<NumericType>{this->value / number};
125 }
126
127 constexpr NumericType operator/(
128 const IsentropicBulkModulus<NumericType>& isentropic_bulk_modulus) const noexcept {
129 return this->value / isentropic_bulk_modulus.value;
130 }
131
132 constexpr void operator+=(
133 const IsentropicBulkModulus<NumericType>& isentropic_bulk_modulus) noexcept {
134 this->value += isentropic_bulk_modulus.value;
135 }
136
137 constexpr void operator-=(
138 const IsentropicBulkModulus<NumericType>& isentropic_bulk_modulus) noexcept {
139 this->value -= isentropic_bulk_modulus.value;
140 }
141
142 constexpr void operator*=(const NumericType number) noexcept {
143 this->value *= number;
144 }
145
146 constexpr void operator/=(const NumericType number) noexcept {
147 this->value /= number;
148 }
149
150private:
151 /// \brief Constructor. Constructs an isentropic bulk modulus with a given value expressed in the
152 /// standard pressure unit.
153 explicit constexpr IsentropicBulkModulus(const NumericType value)
154 : DimensionalScalar<Unit::Pressure, NumericType>(value) {}
155};
156
157template <typename NumericType>
158inline constexpr bool operator==(const IsentropicBulkModulus<NumericType>& left,
159 const IsentropicBulkModulus<NumericType>& right) noexcept {
160 return left.Value() == right.Value();
161}
162
163template <typename NumericType>
164inline constexpr bool operator!=(const IsentropicBulkModulus<NumericType>& left,
165 const IsentropicBulkModulus<NumericType>& right) noexcept {
166 return left.Value() != right.Value();
167}
168
169template <typename NumericType>
170inline constexpr bool operator<(const IsentropicBulkModulus<NumericType>& left,
171 const IsentropicBulkModulus<NumericType>& right) noexcept {
172 return left.Value() < right.Value();
173}
174
175template <typename NumericType>
176inline constexpr bool operator>(const IsentropicBulkModulus<NumericType>& left,
177 const IsentropicBulkModulus<NumericType>& right) noexcept {
178 return left.Value() > right.Value();
179}
180
181template <typename NumericType>
182inline constexpr bool operator<=(const IsentropicBulkModulus<NumericType>& left,
183 const IsentropicBulkModulus<NumericType>& right) noexcept {
184 return left.Value() <= right.Value();
185}
186
187template <typename NumericType>
188inline constexpr bool operator>=(const IsentropicBulkModulus<NumericType>& left,
189 const IsentropicBulkModulus<NumericType>& right) noexcept {
190 return left.Value() >= right.Value();
191}
192
193template <typename NumericType>
194inline std::ostream& operator<<(
195 std::ostream& stream, const IsentropicBulkModulus<NumericType>& isentropic_bulk_modulus) {
196 stream << isentropic_bulk_modulus.Print();
197 return stream;
198}
199
200template <typename NumericType>
202 const NumericType number, const IsentropicBulkModulus<NumericType>& isentropic_bulk_modulus) {
203 return isentropic_bulk_modulus * number;
204}
205
206} // namespace PhQ
207
208namespace std {
209
210template <typename NumericType>
211struct hash<PhQ::IsentropicBulkModulus<NumericType>> {
212 inline size_t operator()(
213 const PhQ::IsentropicBulkModulus<NumericType>& isentropic_bulk_modulus) const {
214 return hash<NumericType>()(isentropic_bulk_modulus.Value());
215 }
216};
217
218} // namespace std
219
220#endif // PHQ_ISENTROPIC_BULK_MODULUS_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...
Isentropic bulk modulus. Not to be confused with the isothermal bulk modulus; see PhQ::IsothermalBulk...
static constexpr IsentropicBulkModulus< NumericType > Zero()
Statically creates an isentropic bulk modulus of zero.
constexpr NumericType operator/(const IsentropicBulkModulus< NumericType > &isentropic_bulk_modulus) const noexcept
constexpr IsentropicBulkModulus(IsentropicBulkModulus< NumericType > &&other) noexcept=default
Move constructor. Constructs an isentropic bulk modulus by moving another one.
IsentropicBulkModulus()=default
Default constructor. Constructs an isentropic bulk modulus with an uninitialized value.
constexpr void operator*=(const NumericType number) noexcept
constexpr void operator-=(const IsentropicBulkModulus< NumericType > &isentropic_bulk_modulus) noexcept
~IsentropicBulkModulus() noexcept=default
Destructor. Destroys this isentropic bulk modulus.
constexpr void operator/=(const NumericType number) noexcept
constexpr IsentropicBulkModulus< NumericType > & operator=(IsentropicBulkModulus< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this isentropic bulk modulus by moving another one.
constexpr IsentropicBulkModulus< NumericType > & operator=(const IsentropicBulkModulus< NumericType > &other)=default
Copy assignment operator. Assigns this isentropic bulk modulus by copying another one.
constexpr IsentropicBulkModulus(const NumericType value)
Constructor. Constructs an isentropic bulk modulus with a given value expressed in the standard press...
IsentropicBulkModulus(const NumericType value, const Unit::Pressure unit)
Constructor. Constructs an isentropic bulk modulus with a given value expressed in a given pressure u...
constexpr IsentropicBulkModulus< NumericType > operator+(const IsentropicBulkModulus< NumericType > &isentropic_bulk_modulus) const
constexpr IsentropicBulkModulus< NumericType > operator*(const NumericType number) const
constexpr IsentropicBulkModulus< NumericType > operator/(const NumericType number) const
constexpr void operator+=(const IsentropicBulkModulus< NumericType > &isentropic_bulk_modulus) noexcept
static constexpr IsentropicBulkModulus< NumericType > Create(const NumericType value)
Statically creates an isentropic bulk modulus with a given value expressed in a given pressure unit.
constexpr IsentropicBulkModulus< NumericType > & operator=(const IsentropicBulkModulus< OtherNumericType > &other)
Copy assignment operator. Assigns this isentropic bulk modulus by copying another one.
constexpr IsentropicBulkModulus< NumericType > operator-(const IsentropicBulkModulus< NumericType > &isentropic_bulk_modulus) const
Mass density. Mass per unit volume; see PhQ::Mass and PhQ::Volume.
Speed of sound. Applies to any deformable material, including fluids and deformable solids....
MassDensity
Mass density units.
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