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