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