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
IsothermalBulkModulus.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_ISOTHERMAL_BULK_MODULUS_HPP
26#define PHQ_ISOTHERMAL_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/// \brief Isothermal bulk modulus of a material. Not to be confused with the isentropic bulk
38/// modulus; see PhQ::IsentropicBulkModulus. Solid materials usually have very similar isentropic
39/// and isothermal bulk moduli; however, in general, fluid materials have differing isentropic and
40/// isothermal bulk moduli.
41template <typename NumericType = double>
42class IsothermalBulkModulus : public DimensionalScalar<Unit::Pressure, NumericType> {
43public:
44 /// \brief Default constructor. Constructs an isothermal bulk modulus with an uninitialized value.
46
47 /// \brief Constructor. Constructs an isothermal bulk modulus with a given value expressed in a
48 /// given pressure unit.
49 IsothermalBulkModulus(const NumericType value, const Unit::Pressure unit)
50 : DimensionalScalar<Unit::Pressure, NumericType>(value, unit) {}
51
52 /// \brief Destructor. Destroys this isothermal bulk modulus.
53 ~IsothermalBulkModulus() noexcept = default;
54
55 /// \brief Copy constructor. Constructs an isothermal bulk modulus by copying another one.
56 constexpr IsothermalBulkModulus(const IsothermalBulkModulus<NumericType>& other) = default;
57
58 /// \brief Copy constructor. Constructs a isothermal bulk modulus by copying another one.
59 template <typename OtherNumericType>
60 explicit constexpr IsothermalBulkModulus(const IsothermalBulkModulus<OtherNumericType>& other)
61 : IsothermalBulkModulus(static_cast<NumericType>(other.Value())) {}
62
63 /// \brief Move constructor. Constructs an isothermal bulk modulus by moving another one.
64 constexpr IsothermalBulkModulus(IsothermalBulkModulus<NumericType>&& other) noexcept = default;
65
66 /// \brief Copy assignment operator. Assigns this isothermal bulk modulus by copying another one.
68 const IsothermalBulkModulus<NumericType>& other) = default;
69
70 /// \brief Copy assignment operator. Assigns this isothermal bulk modulus by copying another one.
71 template <typename OtherNumericType>
74 this->value = static_cast<NumericType>(other.Value());
75 return *this;
76 }
77
78 /// \brief Move assignment operator. Assigns this isothermal bulk modulus by moving another one.
80 IsothermalBulkModulus<NumericType>&& other) noexcept = default;
81
82 /// \brief Statically creates an isothermal bulk modulus of zero.
83 [[nodiscard]] static constexpr IsothermalBulkModulus<NumericType> Zero() {
84 return IsothermalBulkModulus<NumericType>{static_cast<NumericType>(0)};
85 }
86
87 /// \brief Statically creates an isothermal bulk modulus with a given value expressed in a given
88 /// pressure unit.
89 template <Unit::Pressure Unit>
90 [[nodiscard]] static constexpr IsothermalBulkModulus<NumericType> Create(
91 const NumericType value) {
93 ConvertStatically<Unit::Pressure, Unit, Standard<Unit::Pressure>>(value)};
94 }
95
97 const IsothermalBulkModulus<NumericType>& isothermal_bulk_modulus) const {
98 return IsothermalBulkModulus<NumericType>{this->value + isothermal_bulk_modulus.value};
99 }
100
102 const IsothermalBulkModulus<NumericType>& isothermal_bulk_modulus) const {
103 return IsothermalBulkModulus<NumericType>{this->value - isothermal_bulk_modulus.value};
104 }
105
106 constexpr IsothermalBulkModulus<NumericType> operator*(const NumericType number) const {
107 return IsothermalBulkModulus<NumericType>{this->value * number};
108 }
109
110 constexpr IsothermalBulkModulus<NumericType> operator/(const NumericType number) const {
111 return IsothermalBulkModulus<NumericType>{this->value / number};
112 }
113
114 constexpr NumericType operator/(
115 const IsothermalBulkModulus<NumericType>& isothermal_bulk_modulus) const noexcept {
116 return this->value / isothermal_bulk_modulus.value;
117 }
118
119 constexpr void operator+=(
120 const IsothermalBulkModulus<NumericType>& isothermal_bulk_modulus) noexcept {
121 this->value += isothermal_bulk_modulus.value;
122 }
123
124 constexpr void operator-=(
125 const IsothermalBulkModulus<NumericType>& isothermal_bulk_modulus) noexcept {
126 this->value -= isothermal_bulk_modulus.value;
127 }
128
129 constexpr void operator*=(const NumericType number) noexcept {
130 this->value *= number;
131 }
132
133 constexpr void operator/=(const NumericType number) noexcept {
134 this->value /= number;
135 }
136
137private:
138 /// \brief Constructor. Constructs an isothermal bulk modulus with a given value expressed in the
139 /// standard pressure unit.
140 explicit constexpr IsothermalBulkModulus(const NumericType value)
141 : DimensionalScalar<Unit::Pressure, NumericType>(value) {}
142};
143
144template <typename NumericType>
145inline constexpr bool operator==(const IsothermalBulkModulus<NumericType>& left,
146 const IsothermalBulkModulus<NumericType>& right) noexcept {
147 return left.Value() == right.Value();
148}
149
150template <typename NumericType>
151inline constexpr bool operator!=(const IsothermalBulkModulus<NumericType>& left,
152 const IsothermalBulkModulus<NumericType>& right) noexcept {
153 return left.Value() != right.Value();
154}
155
156template <typename NumericType>
157inline constexpr bool operator<(const IsothermalBulkModulus<NumericType>& left,
158 const IsothermalBulkModulus<NumericType>& right) noexcept {
159 return left.Value() < right.Value();
160}
161
162template <typename NumericType>
163inline constexpr bool operator>(const IsothermalBulkModulus<NumericType>& left,
164 const IsothermalBulkModulus<NumericType>& right) noexcept {
165 return left.Value() > right.Value();
166}
167
168template <typename NumericType>
169inline constexpr bool operator<=(const IsothermalBulkModulus<NumericType>& left,
170 const IsothermalBulkModulus<NumericType>& right) noexcept {
171 return left.Value() <= right.Value();
172}
173
174template <typename NumericType>
175inline constexpr bool operator>=(const IsothermalBulkModulus<NumericType>& left,
176 const IsothermalBulkModulus<NumericType>& right) noexcept {
177 return left.Value() >= right.Value();
178}
179
180template <typename NumericType>
181inline std::ostream& operator<<(
182 std::ostream& stream, const IsothermalBulkModulus<NumericType>& isothermal_bulk_modulus) {
183 stream << isothermal_bulk_modulus.Print();
184 return stream;
185}
186
187template <typename NumericType>
189 const NumericType number, const IsothermalBulkModulus<NumericType>& isothermal_bulk_modulus) {
190 return isothermal_bulk_modulus * number;
191}
192
193} // namespace PhQ
194
195namespace std {
196
197template <typename NumericType>
198struct hash<PhQ::IsothermalBulkModulus<NumericType>> {
199 inline size_t operator()(
200 const PhQ::IsothermalBulkModulus<NumericType>& isothermal_bulk_modulus) const {
201 return hash<NumericType>()(isothermal_bulk_modulus.Value());
202 }
203};
204
205} // namespace std
206
207#endif // PHQ_ISOTHERMAL_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...
Isothermal bulk modulus of a material. Not to be confused with the isentropic bulk modulus; see PhQ::...
constexpr IsothermalBulkModulus< NumericType > operator-(const IsothermalBulkModulus< NumericType > &isothermal_bulk_modulus) const
~IsothermalBulkModulus() noexcept=default
Destructor. Destroys this isothermal bulk modulus.
static constexpr IsothermalBulkModulus< NumericType > Zero()
Statically creates an isothermal bulk modulus of zero.
constexpr void operator-=(const IsothermalBulkModulus< NumericType > &isothermal_bulk_modulus) noexcept
constexpr IsothermalBulkModulus< NumericType > & operator=(IsothermalBulkModulus< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this isothermal bulk modulus by moving another one.
constexpr void operator*=(const NumericType number) noexcept
constexpr IsothermalBulkModulus< NumericType > operator*(const NumericType number) const
IsothermalBulkModulus(const NumericType value, const Unit::Pressure unit)
Constructor. Constructs an isothermal bulk modulus with a given value expressed in a given pressure u...
static constexpr IsothermalBulkModulus< NumericType > Create(const NumericType value)
Statically creates an isothermal bulk modulus with a given value expressed in a given pressure unit.
constexpr IsothermalBulkModulus< NumericType > operator+(const IsothermalBulkModulus< NumericType > &isothermal_bulk_modulus) const
constexpr IsothermalBulkModulus(IsothermalBulkModulus< NumericType > &&other) noexcept=default
Move constructor. Constructs an isothermal bulk modulus by moving another one.
constexpr IsothermalBulkModulus(const NumericType value)
Constructor. Constructs an isothermal bulk modulus with a given value expressed in the standard press...
constexpr void operator+=(const IsothermalBulkModulus< NumericType > &isothermal_bulk_modulus) noexcept
constexpr NumericType operator/(const IsothermalBulkModulus< NumericType > &isothermal_bulk_modulus) const noexcept
constexpr void operator/=(const NumericType number) noexcept
IsothermalBulkModulus()=default
Default constructor. Constructs an isothermal bulk modulus with an uninitialized value.
constexpr IsothermalBulkModulus< NumericType > operator/(const NumericType number) const
constexpr IsothermalBulkModulus< NumericType > & operator=(const IsothermalBulkModulus< NumericType > &other)=default
Copy assignment operator. Assigns this isothermal bulk modulus by copying another one.
constexpr IsothermalBulkModulus< NumericType > & operator=(const IsothermalBulkModulus< OtherNumericType > &other)
Copy assignment operator. Assigns this isothermal bulk modulus by copying 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