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