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