Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
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 
35 namespace PhQ {
36 
37 // Forward declaration for class PhQ::IsentropicBulkModulus.
38 template <typename NumericType>
39 class MassDensity;
40 
41 // Forward declaration for class PhQ::IsentropicBulkModulus.
42 template <typename NumericType>
43 class 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.
49 template <typename NumericType = double>
50 class IsentropicBulkModulus : public DimensionalScalar<Unit::Pressure, NumericType> {
51 public:
52  /// \brief Default constructor. Constructs an isentropic bulk modulus with an uninitialized value.
53  IsentropicBulkModulus() = default;
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 
150 private:
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 
157 template <typename NumericType>
158 inline constexpr bool operator==(const IsentropicBulkModulus<NumericType>& left,
159  const IsentropicBulkModulus<NumericType>& right) noexcept {
160  return left.Value() == right.Value();
161 }
162 
163 template <typename NumericType>
164 inline constexpr bool operator!=(const IsentropicBulkModulus<NumericType>& left,
165  const IsentropicBulkModulus<NumericType>& right) noexcept {
166  return left.Value() != right.Value();
167 }
168 
169 template <typename NumericType>
170 inline constexpr bool operator<(const IsentropicBulkModulus<NumericType>& left,
171  const IsentropicBulkModulus<NumericType>& right) noexcept {
172  return left.Value() < right.Value();
173 }
174 
175 template <typename NumericType>
176 inline constexpr bool operator>(const IsentropicBulkModulus<NumericType>& left,
177  const IsentropicBulkModulus<NumericType>& right) noexcept {
178  return left.Value() > right.Value();
179 }
180 
181 template <typename NumericType>
182 inline constexpr bool operator<=(const IsentropicBulkModulus<NumericType>& left,
183  const IsentropicBulkModulus<NumericType>& right) noexcept {
184  return left.Value() <= right.Value();
185 }
186 
187 template <typename NumericType>
188 inline constexpr bool operator>=(const IsentropicBulkModulus<NumericType>& left,
189  const IsentropicBulkModulus<NumericType>& right) noexcept {
190  return left.Value() >= right.Value();
191 }
192 
193 template <typename NumericType>
194 inline std::ostream& operator<<(
195  std::ostream& stream, const IsentropicBulkModulus<NumericType>& isentropic_bulk_modulus) {
196  stream << isentropic_bulk_modulus.Print();
197  return stream;
198 }
199 
200 template <typename NumericType>
202  const NumericType number, const IsentropicBulkModulus<NumericType>& isentropic_bulk_modulus) {
203  return isentropic_bulk_modulus * number;
204 }
205 
206 } // namespace PhQ
207 
208 namespace std {
209 
210 template <typename NumericType>
211 struct 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...
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...
Isentropic bulk modulus. Not to be confused with the isothermal bulk modulus; see PhQ::IsothermalBulk...
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 IsentropicBulkModulus< NumericType > & operator=(const IsentropicBulkModulus< OtherNumericType > &other)
Copy assignment operator. Assigns this isentropic bulk modulus by copying another one.
constexpr void operator/=(const NumericType number) noexcept
constexpr IsentropicBulkModulus< NumericType > operator*(const NumericType number) const
static constexpr IsentropicBulkModulus< NumericType > Zero()
Statically creates an isentropic bulk modulus of zero.
constexpr IsentropicBulkModulus< NumericType > operator+(const IsentropicBulkModulus< NumericType > &isentropic_bulk_modulus) const
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 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< NumericType > &other)=default
Copy assignment operator. Assigns this isentropic bulk modulus by copying another one.
constexpr IsentropicBulkModulus< NumericType > & operator=(IsentropicBulkModulus< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this isentropic bulk modulus by moving another one.
Mass density. Mass per unit volume; see PhQ::Mass and PhQ::Volume.
Definition: MassDensity.hpp:83
Speed of sound. Applies to any deformable material, including fluids and deformable solids....
Definition: SoundSpeed.hpp:56
MassDensity
Mass density units.
Definition: MassDensity.hpp:54
Pressure
Pressure units.
Definition: Pressure.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)