Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
Strain.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_STRAIN_HPP
26 #define PHQ_STRAIN_HPP
27 
28 #include <array>
29 #include <cstddef>
30 #include <functional>
31 #include <ostream>
32 
34 #include "ScalarStrain.hpp"
35 #include "SymmetricDyad.hpp"
36 
37 namespace PhQ {
38 
39 // Forward declaration for class PhQ::Strain.
40 template <typename NumericType>
41 class DisplacementGradient;
42 
43 // Forward declaration for class PhQ::Strain.
44 template <typename NumericType>
45 class Time;
46 
47 // Forward declaration for class PhQ::Strain.
48 template <typename NumericType>
49 class Frequency;
50 
51 // Forward declaration for class PhQ::Strain.
52 template <typename NumericType>
53 class StrainRate;
54 
55 // Forward declaration for class PhQ::Strain.
56 template <typename NumericType>
58 
59 // Forward declaration for class PhQ::Strain.
60 template <typename NumericType>
61 class VolumetricThermalExpansionCoefficient;
62 
63 /// \brief Three-dimensional Euclidean strain symmetric dyadic tensor. Contains six components in
64 /// Cartesian coordinates: xx, xy = yx, xz = zx, yy, yz = zy, and zz. For the scalar components or
65 /// resultants of a strain tensor, see PhQ::ScalarStrain. For the time rate of change of strain, see
66 /// PhQ::StrainRate, PhQ::Time, and PhQ::Frequency.
67 template <typename NumericType = double>
68 class Strain : public DimensionlessSymmetricDyad<NumericType> {
69 public:
70  /// \brief Default constructor. Constructs a strain tensor with an uninitialized value.
71  Strain() = default;
72 
73  /// \brief Constructor. Constructs a strain tensor whose value has the given xx, xy, xz, yy, yz,
74  /// and zz Cartesian components.
75  constexpr Strain(const NumericType xx, const NumericType xy, const NumericType xz,
76  const NumericType yy, const NumericType yz, const NumericType zz)
77  : DimensionlessSymmetricDyad<NumericType>(xx, xy, xz, yy, yz, zz) {}
78 
79  /// \brief Constructor. Constructs a strain tensor from a given array representing its value's xx,
80  /// xy, xz, yy, yz, and zz Cartesian components.
81  explicit constexpr Strain(const std::array<NumericType, 6>& xx_xy_xz_yy_yz_zz)
82  : DimensionlessSymmetricDyad<NumericType>(xx_xy_xz_yy_yz_zz) {}
83 
84  /// \brief Constructor. Constructs a strain tensor with a given value.
85  explicit constexpr Strain(const SymmetricDyad<NumericType>& value)
86  : DimensionlessSymmetricDyad<NumericType>(value) {}
87 
88  /// \brief Constructor. Constructs a strain tensor from a given strain rate tensor and time using
89  /// the definition of the strain rate tensor.
90  constexpr Strain(const StrainRate<NumericType>& strain_rate, const Time<NumericType>& time);
91 
92  /// \brief Constructor. Constructs a strain tensor from a given strain rate tensor and frequency
93  /// using the definition of the strain rate tensor.
94  constexpr Strain(
95  const StrainRate<NumericType>& strain_rate, const Frequency<NumericType>& frequency);
96 
97  /// \brief Constructor. Constructs a strain tensor from a given displacement gradient using the
98  /// definition of the strain tensor.
99  explicit constexpr Strain(const DisplacementGradient<NumericType>& displacement_gradient);
100 
101  /// \brief Constructor. Constructs a strain tensor from a given volumetric thermal expansion
102  /// coefficient and temperature difference using the definition of the volumetric thermal
103  /// expansion coefficient.
105  volumetric_thermal_expansion_coefficient,
106  const TemperatureDifference<NumericType>& temperature_difference);
107 
108  /// \brief Destructor. Destroys this strain tensor.
109  ~Strain() noexcept = default;
110 
111  /// \brief Copy constructor. Constructs a strain tensor by copying another one.
112  constexpr Strain(const Strain<NumericType>& other) = default;
113 
114  /// \brief Copy constructor. Constructs a strain tensor by copying another one.
115  template <typename OtherNumericType>
116  explicit constexpr Strain(const Strain<OtherNumericType>& other)
117  : Strain(static_cast<SymmetricDyad<NumericType>>(other.Value())) {}
118 
119  /// \brief Move constructor. Constructs a strain tensor by moving another one.
120  constexpr Strain(Strain<NumericType>&& other) noexcept = default;
121 
122  /// \brief Copy assignment operator. Assigns this strain tensor by copying another one.
123  constexpr Strain<NumericType>& operator=(const Strain<NumericType>& other) = default;
124 
125  /// \brief Copy assignment operator. Assigns this strain tensor by copying another one.
126  template <typename OtherNumericType>
128  this->value = static_cast<SymmetricDyad<NumericType>>(other.Value());
129  return *this;
130  }
131 
132  /// \brief Move assignment operator. Assigns this strain tensor by moving another one.
133  constexpr Strain<NumericType>& operator=(Strain<NumericType>&& other) noexcept = default;
134 
135  /// \brief Statically creates a strain tensor of zero.
136  [[nodiscard]] static constexpr Strain<NumericType> Zero() {
138  }
139 
140  /// \brief Returns the xx Cartesian component of this strain tensor.
141  [[nodiscard]] constexpr ScalarStrain<NumericType> xx() const noexcept {
142  return ScalarStrain<NumericType>{this->value.xx()};
143  }
144 
145  /// \brief Returns the xy = yx Cartesian component of this strain tensor.
146  [[nodiscard]] constexpr ScalarStrain<NumericType> xy() const noexcept {
147  return ScalarStrain<NumericType>{this->value.xy()};
148  }
149 
150  /// \brief Returns the xz = zx Cartesian component of this strain tensor.
151  [[nodiscard]] constexpr ScalarStrain<NumericType> xz() const noexcept {
152  return ScalarStrain<NumericType>{this->value.xz()};
153  }
154 
155  /// \brief Returns the yx = xy Cartesian component of this strain tensor.
156  [[nodiscard]] constexpr ScalarStrain<NumericType> yx() const noexcept {
157  return ScalarStrain<NumericType>{this->value.yx()};
158  }
159 
160  /// \brief Returns the yy Cartesian component of this strain tensor.
161  [[nodiscard]] constexpr ScalarStrain<NumericType> yy() const noexcept {
162  return ScalarStrain<NumericType>{this->value.yy()};
163  }
164 
165  /// \brief Returns the yz = zy Cartesian component of this strain tensor.
166  [[nodiscard]] constexpr ScalarStrain<NumericType> yz() const noexcept {
167  return ScalarStrain<NumericType>{this->value.yz()};
168  }
169 
170  /// \brief Returns the zx = xz Cartesian component of this strain tensor.
171  [[nodiscard]] constexpr ScalarStrain<NumericType> zx() const noexcept {
172  return ScalarStrain<NumericType>{this->value.zx()};
173  }
174 
175  /// \brief Returns the zy = yz Cartesian component of this strain tensor.
176  [[nodiscard]] constexpr ScalarStrain<NumericType> zy() const noexcept {
177  return ScalarStrain<NumericType>{this->value.zy()};
178  }
179 
180  /// \brief Returns the zz Cartesian component of this strain tensor.
181  [[nodiscard]] constexpr ScalarStrain<NumericType> zz() const noexcept {
182  return ScalarStrain<NumericType>{this->value.zz()};
183  }
184 
185  constexpr Strain<NumericType> operator+(const Strain<NumericType>& strain) const {
186  return Strain<NumericType>{this->value + strain.value};
187  }
188 
189  constexpr Strain<NumericType> operator-(const Strain<NumericType>& strain) const {
190  return Strain<NumericType>{this->value - strain.value};
191  }
192 
193  constexpr Strain<NumericType> operator*(const NumericType number) const {
194  return Strain<NumericType>{this->value * number};
195  }
196 
197  constexpr StrainRate<NumericType> operator*(const Frequency<NumericType>& frequency) const;
198 
199  constexpr Strain<NumericType> operator/(const NumericType number) const {
200  return Strain<NumericType>{this->value / number};
201  }
202 
203  constexpr StrainRate<NumericType> operator/(const Time<NumericType>& time) const;
204 
205  constexpr void operator+=(const Strain<NumericType>& strain) noexcept {
206  this->value += strain.value;
207  }
208 
209  constexpr void operator-=(const Strain<NumericType>& strain) noexcept {
210  this->value -= strain.value;
211  }
212 
213  constexpr void operator*=(const NumericType number) noexcept {
214  this->value *= number;
215  }
216 
217  constexpr void operator/=(const NumericType number) noexcept {
218  this->value /= number;
219  }
220 };
221 
222 template <typename NumericType>
223 inline constexpr bool operator==(
224  const Strain<NumericType>& left, const Strain<NumericType>& right) noexcept {
225  return left.Value() == right.Value();
226 }
227 
228 template <typename NumericType>
229 inline constexpr bool operator!=(
230  const Strain<NumericType>& left, const Strain<NumericType>& right) noexcept {
231  return left.Value() != right.Value();
232 }
233 
234 template <typename NumericType>
235 inline constexpr bool operator<(
236  const Strain<NumericType>& left, const Strain<NumericType>& right) noexcept {
237  return left.Value() < right.Value();
238 }
239 
240 template <typename NumericType>
241 inline constexpr bool operator>(
242  const Strain<NumericType>& left, const Strain<NumericType>& right) noexcept {
243  return left.Value() > right.Value();
244 }
245 
246 template <typename NumericType>
247 inline constexpr bool operator<=(
248  const Strain<NumericType>& left, const Strain<NumericType>& right) noexcept {
249  return left.Value() <= right.Value();
250 }
251 
252 template <typename NumericType>
253 inline constexpr bool operator>=(
254  const Strain<NumericType>& left, const Strain<NumericType>& right) noexcept {
255  return left.Value() >= right.Value();
256 }
257 
258 template <typename NumericType>
259 inline std::ostream& operator<<(std::ostream& stream, const Strain<NumericType>& strain) {
260  stream << strain.Print();
261  return stream;
262 }
263 
264 template <typename NumericType>
266  const NumericType number, const Strain<NumericType>& strain) {
267  return strain * number;
268 }
269 
270 } // namespace PhQ
271 
272 namespace std {
273 
274 template <typename NumericType>
275 struct hash<PhQ::Strain<NumericType>> {
276  inline size_t operator()(const PhQ::Strain<NumericType>& strain) const {
277  return hash<PhQ::SymmetricDyad<NumericType>>()(strain.Value());
278  }
279 };
280 
281 } // namespace std
282 
283 #endif // PHQ_STRAIN_HPP
Abstract base class that represents any dimensionless symmetric dyadic tensor physical quantity....
constexpr const PhQ::SymmetricDyad< double > & Value() const noexcept
Value of this physical quantity.
std::string Print() const
Prints this physical quantity as a string.
PhQ::SymmetricDyad< double > value
Value of this physical quantity.
Three-dimensional Euclidean displacement gradient dyadic tensor. Gradient of the displacement vector....
Frequency. Inverse of a time duration. See also PhQ::Time.
Definition: Frequency.hpp:40
Scalar component or resultant of a three-dimensional Euclidean strain symmetric dyadic tensor....
Three-dimensional Euclidean strain rate symmetric dyadic tensor. Time rate of change of strain....
Definition: StrainRate.hpp:51
Three-dimensional Euclidean strain symmetric dyadic tensor. Contains six components in Cartesian coor...
Definition: Strain.hpp:68
constexpr Strain< NumericType > & operator=(const Strain< NumericType > &other)=default
Copy assignment operator. Assigns this strain tensor by copying another one.
constexpr ScalarStrain< NumericType > yy() const noexcept
Returns the yy Cartesian component of this strain tensor.
Definition: Strain.hpp:161
constexpr ScalarStrain< NumericType > zx() const noexcept
Returns the zx = xz Cartesian component of this strain tensor.
Definition: Strain.hpp:171
static constexpr Strain< NumericType > Zero()
Statically creates a strain tensor of zero.
Definition: Strain.hpp:136
constexpr ScalarStrain< NumericType > zy() const noexcept
Returns the zy = yz Cartesian component of this strain tensor.
Definition: Strain.hpp:176
constexpr Strain(const SymmetricDyad< NumericType > &value)
Constructor. Constructs a strain tensor with a given value.
Definition: Strain.hpp:85
constexpr ScalarStrain< NumericType > yx() const noexcept
Returns the yx = xy Cartesian component of this strain tensor.
Definition: Strain.hpp:156
constexpr Strain< NumericType > operator+(const Strain< NumericType > &strain) const
Definition: Strain.hpp:185
Strain()=default
Default constructor. Constructs a strain tensor with an uninitialized value.
constexpr Strain< NumericType > & operator=(const Strain< OtherNumericType > &other)
Copy assignment operator. Assigns this strain tensor by copying another one.
Definition: Strain.hpp:127
constexpr Strain(const std::array< NumericType, 6 > &xx_xy_xz_yy_yz_zz)
Constructor. Constructs a strain tensor from a given array representing its value's xx,...
Definition: Strain.hpp:81
constexpr Strain< NumericType > operator*(const NumericType number) const
Definition: Strain.hpp:193
constexpr Strain(Strain< NumericType > &&other) noexcept=default
Move constructor. Constructs a strain tensor by moving another one.
constexpr ScalarStrain< NumericType > xx() const noexcept
Returns the xx Cartesian component of this strain tensor.
Definition: Strain.hpp:141
constexpr void operator/=(const NumericType number) noexcept
Definition: Strain.hpp:217
constexpr Strain(const NumericType xx, const NumericType xy, const NumericType xz, const NumericType yy, const NumericType yz, const NumericType zz)
Constructor. Constructs a strain tensor whose value has the given xx, xy, xz, yy, yz,...
Definition: Strain.hpp:75
~Strain() noexcept=default
Destructor. Destroys this strain tensor.
constexpr ScalarStrain< NumericType > zz() const noexcept
Returns the zz Cartesian component of this strain tensor.
Definition: Strain.hpp:181
constexpr Strain< NumericType > operator/(const NumericType number) const
Definition: Strain.hpp:199
constexpr Strain< NumericType > & operator=(Strain< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this strain tensor by moving another one.
constexpr ScalarStrain< NumericType > xz() const noexcept
Returns the xz = zx Cartesian component of this strain tensor.
Definition: Strain.hpp:151
constexpr Strain< NumericType > operator-(const Strain< NumericType > &strain) const
Definition: Strain.hpp:189
constexpr ScalarStrain< NumericType > yz() const noexcept
Returns the yz = zy Cartesian component of this strain tensor.
Definition: Strain.hpp:166
constexpr void operator-=(const Strain< NumericType > &strain) noexcept
Definition: Strain.hpp:209
constexpr void operator*=(const NumericType number) noexcept
Definition: Strain.hpp:213
constexpr ScalarStrain< NumericType > xy() const noexcept
Returns the xy = yx Cartesian component of this strain tensor.
Definition: Strain.hpp:146
constexpr void operator+=(const Strain< NumericType > &strain) noexcept
Definition: Strain.hpp:205
Symmetric three-dimensional Euclidean dyadic tensor. Contains six components in Cartesian coordinates...
constexpr NumericType xy() const noexcept
Returns this three-dimensional symmetric dyadic tensor's xy = yx Cartesian component.
constexpr NumericType xx() const noexcept
Returns this three-dimensional symmetric dyadic tensor's xx Cartesian component.
constexpr NumericType zx() const noexcept
Returns this three-dimensional symmetric dyadic tensor's zx = xz Cartesian component.
constexpr NumericType zz() const noexcept
Returns this three-dimensional symmetric dyadic tensor's zz Cartesian component.
constexpr NumericType yx() const noexcept
Returns this three-dimensional symmetric dyadic tensor's yx = xy Cartesian component.
constexpr NumericType yy() const noexcept
Returns this three-dimensional symmetric dyadic tensor's yy Cartesian component.
static constexpr SymmetricDyad< NumericType > Zero()
Statically creates a three-dimensional symmetric dyadic tensor with its xx, xy, xz,...
constexpr NumericType xz() const noexcept
Returns this three-dimensional symmetric dyadic tensor's xz = zx Cartesian component.
constexpr NumericType yz() const noexcept
Returns this three-dimensional symmetric dyadic tensor's yz = zy Cartesian component.
constexpr NumericType zy() const noexcept
Returns this three-dimensional symmetric dyadic tensor's zy = yz Cartesian component.
Temperature difference. Not to be confused with temperature; see PhQ::Temperature....
Time. Can represent either a point in time, a time duration, or a period. For the inverse of time,...
Definition: Time.hpp:172
Volumetric thermal expansion coefficient. Not to be confused with the linear thermal expansion coeffi...
Frequency
Frequency units.
Definition: Frequency.hpp:53
Time
Time units.
Definition: Time.hpp:53
TemperatureDifference
Temperature difference units. Not to be confused with temperature units. For example,...
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)