Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
StrainRate.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_RATE_HPP
26 #define PHQ_STRAIN_RATE_HPP
27 
28 #include <array>
29 #include <cstddef>
30 #include <functional>
31 #include <ostream>
32 
34 #include "Frequency.hpp"
35 #include "ScalarStrainRate.hpp"
36 #include "Strain.hpp"
37 #include "SymmetricDyad.hpp"
38 #include "Unit/Frequency.hpp"
39 
40 namespace PhQ {
41 
42 // Forward declaration for class PhQ::StrainRate.
43 template <typename NumericType>
44 class VelocityGradient;
45 
46 /// \brief Three-dimensional Euclidean strain rate symmetric dyadic tensor. Time rate of change of
47 /// strain. Contains six components in Cartesian coordinates: xx, xy = yx, xz = zx, yy, yz = zy, and
48 /// zz. For the scalar components or resultants of a strain rate tensor, see PhQ::ScalarStrainRate.
49 /// See also PhQ::Strain, PhQ::Time, and PhQ::Frequency.
50 template <typename NumericType = double>
51 class StrainRate : public DimensionalSymmetricDyad<Unit::Frequency, NumericType> {
52 public:
53  /// \brief Default constructor. Constructs a strain rate tensor with an uninitialized value.
54  StrainRate() = default;
55 
56  /// \brief Constructor. Constructs a strain rate tensor with a given value expressed in a given
57  /// frequency unit.
59  : DimensionalSymmetricDyad<Unit::Frequency, NumericType>(value, unit) {}
60 
61  /// \brief Constructor. Constructs a strain rate tensor from a given set of scalar strain rate
62  /// components.
66  : StrainRate<NumericType>(
67  {xx.Value(), xy.Value(), xz.Value(), yy.Value(), yz.Value(), zz.Value()}) {}
68 
69  /// \brief Constructor. Constructs a strain rate tensor from a given strain tensor and time using
70  /// the definition of the strain rate tensor.
71  constexpr StrainRate(const Strain<NumericType>& strain, const Time<NumericType>& time)
72  : StrainRate<NumericType>(strain.Value() / time.Value()) {}
73 
74  /// \brief Constructor. Constructs a strain rate tensor from a given strain tensor and frequency
75  /// using the definition of the strain rate tensor.
76  constexpr StrainRate(const Strain<NumericType>& strain, const Frequency<NumericType>& frequency)
77  : StrainRate<NumericType>(strain.Value() * frequency.Value()) {}
78 
79  /// \brief Constructor. Constructs a strain rate tensor from a given velocity gradient using the
80  /// definition of the strain rate tensor.
81  explicit constexpr StrainRate(const VelocityGradient<NumericType>& velocity_gradient);
82 
83  /// \brief Destructor. Destroys this strain rate tensor.
84  ~StrainRate() noexcept = default;
85 
86  /// \brief Copy constructor. Constructs a strain rate tensor by copying another one.
87  constexpr StrainRate(const StrainRate<NumericType>& other) = default;
88 
89  /// \brief Copy constructor. Constructs a strain rate tensor by copying another one.
90  template <typename OtherNumericType>
91  explicit constexpr StrainRate(const StrainRate<OtherNumericType>& other)
92  : StrainRate(static_cast<SymmetricDyad<NumericType>>(other.Value())) {}
93 
94  /// \brief Move constructor. Constructs a strain rate tensor by moving another one.
95  constexpr StrainRate(StrainRate<NumericType>&& other) noexcept = default;
96 
97  /// \brief Copy assignment operator. Assigns this strain rate tensor by copying another one.
98  constexpr StrainRate<NumericType>& operator=(const StrainRate<NumericType>& other) = default;
99 
100  /// \brief Copy assignment operator. Assigns this strain rate tensor by copying another one.
101  template <typename OtherNumericType>
103  this->value = static_cast<SymmetricDyad<NumericType>>(other.Value());
104  return *this;
105  }
106 
107  /// \brief Move assignment operator. Assigns this strain rate tensor by moving another one.
108  constexpr StrainRate<NumericType>& operator=(StrainRate<NumericType>&& other) noexcept = default;
109 
110  /// \brief Statically creates a strain rate tensor of zero.
111  [[nodiscard]] static constexpr StrainRate<NumericType> Zero() {
113  }
114 
115  /// \brief Statically creates a strain rate tensor from the given xx, xy, xz, yy, yz, and zz
116  /// Cartesian components expressed in a given frequency unit.
117  template <Unit::Frequency Unit>
118  [[nodiscard]] static constexpr StrainRate<NumericType> Create(
119  const NumericType xx, const NumericType xy, const NumericType xz, const NumericType yy,
120  const NumericType yz, const NumericType zz) {
122  ConvertStatically<Unit::Frequency, Unit, Standard<Unit::Frequency>>(
124  }
125 
126  /// \brief Statically creates a strain rate tensor from the given xx, xy, xz, yy, yz, and zz
127  /// Cartesian components expressed in a given frequency unit.
128  template <Unit::Frequency Unit>
129  [[nodiscard]] static constexpr StrainRate<NumericType> Create(
130  const std::array<NumericType, 6>& xx_xy_xz_yy_yz_zz) {
132  ConvertStatically<Unit::Frequency, Unit, Standard<Unit::Frequency>>(
133  SymmetricDyad<NumericType>{xx_xy_xz_yy_yz_zz})};
134  }
135 
136  /// \brief Statically creates a strain rate tensor with a given value expressed in a given
137  /// frequency unit.
138  template <Unit::Frequency Unit>
139  [[nodiscard]] static constexpr StrainRate<NumericType> Create(
142  ConvertStatically<Unit::Frequency, Unit, Standard<Unit::Frequency>>(value)};
143  }
144 
145  /// \brief Returns the xx Cartesian component of this strain rate tensor.
146  [[nodiscard]] constexpr ScalarStrainRate<NumericType> xx() const noexcept {
147  return ScalarStrainRate<NumericType>{this->value.xx()};
148  }
149 
150  /// \brief Returns the xy = yx Cartesian component of this strain rate tensor.
151  [[nodiscard]] constexpr ScalarStrainRate<NumericType> xy() const noexcept {
152  return ScalarStrainRate<NumericType>{this->value.xy()};
153  }
154 
155  /// \brief Returns the xz = zx Cartesian component of this strain rate tensor.
156  [[nodiscard]] constexpr ScalarStrainRate<NumericType> xz() const noexcept {
157  return ScalarStrainRate<NumericType>{this->value.xz()};
158  }
159 
160  /// \brief Returns the yx = xy Cartesian component of this strain rate tensor.
161  [[nodiscard]] constexpr ScalarStrainRate<NumericType> yx() const noexcept {
162  return ScalarStrainRate<NumericType>{this->value.yx()};
163  }
164 
165  /// \brief Returns the yy Cartesian component of this strain rate tensor.
166  [[nodiscard]] constexpr ScalarStrainRate<NumericType> yy() const noexcept {
167  return ScalarStrainRate<NumericType>{this->value.yy()};
168  }
169 
170  /// \brief Returns the yz = zy Cartesian component of this strain rate tensor.
171  [[nodiscard]] constexpr ScalarStrainRate<NumericType> yz() const noexcept {
172  return ScalarStrainRate<NumericType>{this->value.yz()};
173  }
174 
175  /// \brief Returns the zx = xz Cartesian component of this strain rate tensor.
176  [[nodiscard]] constexpr ScalarStrainRate<NumericType> zx() const noexcept {
177  return ScalarStrainRate<NumericType>{this->value.zx()};
178  }
179 
180  /// \brief Returns the zy = yz Cartesian component of this strain rate tensor.
181  [[nodiscard]] constexpr ScalarStrainRate<NumericType> zy() const noexcept {
182  return ScalarStrainRate<NumericType>{this->value.zy()};
183  }
184 
185  /// \brief Returns the zz Cartesian component of this strain rate tensor.
186  [[nodiscard]] constexpr ScalarStrainRate<NumericType> zz() const noexcept {
187  return ScalarStrainRate<NumericType>{this->value.zz()};
188  }
189 
190  constexpr StrainRate operator+(const StrainRate<NumericType>& strain_rate) const {
191  return StrainRate<NumericType>{this->value + strain_rate.value};
192  }
193 
194  constexpr StrainRate<NumericType> operator-(const StrainRate<NumericType>& strain_rate) const {
195  return StrainRate<NumericType>{this->value - strain_rate.value};
196  }
197 
198  constexpr StrainRate<NumericType> operator*(const NumericType number) const {
199  return StrainRate<NumericType>{this->value * number};
200  }
201 
202  constexpr Strain<NumericType> operator*(const Time<NumericType>& time) const {
203  return Strain<NumericType>{*this, time};
204  }
205 
206  constexpr StrainRate<NumericType> operator/(const NumericType number) const {
207  return StrainRate<NumericType>{this->value / number};
208  }
209 
210  constexpr Strain<NumericType> operator/(const Frequency<NumericType>& frequency) const {
211  return Strain<NumericType>{*this, frequency};
212  }
213 
214  constexpr void operator+=(const StrainRate<NumericType>& strain_rate) noexcept {
215  this->value += strain_rate.value;
216  }
217 
218  constexpr void operator-=(const StrainRate<NumericType>& strain_rate) noexcept {
219  this->value -= strain_rate.value;
220  }
221 
222  constexpr void operator*=(const NumericType number) noexcept {
223  this->value *= number;
224  }
225 
226  constexpr void operator/=(const NumericType number) noexcept {
227  this->value /= number;
228  }
229 
230 private:
231  /// \brief Constructor. Constructs a strain rate tensor with a given value expressed in the
232  /// standard frequency unit.
233  explicit constexpr StrainRate(const SymmetricDyad<NumericType>& value)
234  : DimensionalSymmetricDyad<Unit::Frequency, NumericType>(value) {}
235 };
236 
237 template <typename NumericType>
238 inline constexpr bool operator==(
239  const StrainRate<NumericType>& left, const StrainRate<NumericType>& right) noexcept {
240  return left.Value() == right.Value();
241 }
242 
243 template <typename NumericType>
244 inline constexpr bool operator!=(
245  const StrainRate<NumericType>& left, const StrainRate<NumericType>& right) noexcept {
246  return left.Value() != right.Value();
247 }
248 
249 template <typename NumericType>
250 inline constexpr bool operator<(
251  const StrainRate<NumericType>& left, const StrainRate<NumericType>& right) noexcept {
252  return left.Value() < right.Value();
253 }
254 
255 template <typename NumericType>
256 inline constexpr bool operator>(
257  const StrainRate<NumericType>& left, const StrainRate<NumericType>& right) noexcept {
258  return left.Value() > right.Value();
259 }
260 
261 template <typename NumericType>
262 inline constexpr bool operator<=(
263  const StrainRate<NumericType>& left, const StrainRate<NumericType>& right) noexcept {
264  return left.Value() <= right.Value();
265 }
266 
267 template <typename NumericType>
268 inline constexpr bool operator>=(
269  const StrainRate<NumericType>& left, const StrainRate<NumericType>& right) noexcept {
270  return left.Value() >= right.Value();
271 }
272 
273 template <typename NumericType>
274 inline std::ostream& operator<<(std::ostream& stream, const StrainRate<NumericType>& strain_rate) {
275  stream << strain_rate.Print();
276  return stream;
277 }
278 
279 template <typename NumericType>
281  const NumericType number, const StrainRate<NumericType>& strain_rate) {
282  return strain_rate * number;
283 }
284 
285 template <typename NumericType>
287  const StrainRate<NumericType>& strain_rate, const Time<NumericType>& time)
288  : Strain<NumericType>(strain_rate.Value() * time.Value()) {}
289 
290 template <typename NumericType>
292  const StrainRate<NumericType>& strain_rate, const Frequency<NumericType>& frequency)
293  : Strain<NumericType>(strain_rate.Value() / frequency.Value()) {}
294 
295 template <typename NumericType>
297  const Frequency<NumericType>& frequency) const {
298  return StrainRate<NumericType>{*this, frequency};
299 }
300 
301 template <typename NumericType>
303  const Time<NumericType>& time) const {
304  return StrainRate<NumericType>{*this, time};
305 }
306 
307 template <typename NumericType>
309  const StrainRate<NumericType>& strain_rate) const {
310  return Strain<NumericType>{strain_rate, *this};
311 }
312 
313 template <typename NumericType>
314 inline constexpr StrainRate<NumericType> Frequency<NumericType>::operator*(
315  const Strain<NumericType>& strain) const {
316  return StrainRate<NumericType>{strain, *this};
317 }
318 
319 } // namespace PhQ
320 
321 namespace std {
322 
323 template <typename NumericType>
324 struct hash<PhQ::StrainRate<NumericType>> {
325  inline size_t operator()(const PhQ::StrainRate<NumericType>& strain_rate) const {
326  return hash<PhQ::SymmetricDyad<NumericType>>()(strain_rate.Value());
327  }
328 };
329 
330 } // namespace std
331 
332 #endif // PHQ_STRAIN_RATE_HPP
Abstract base class that represents any dimensional symmetric dyadic tensor physical quantity....
constexpr const PhQ::SymmetricDyad< double > & Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
static constexpr Unit::Frequency 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...
PhQ::SymmetricDyad< double > value
Value of this physical quantity expressed in its standard unit of measure.
Frequency. Inverse of a time duration. See also PhQ::Time.
Definition: Frequency.hpp:40
constexpr Frequency< NumericType > operator*(const NumericType number) const
Definition: Frequency.hpp:154
Scalar component or resultant of a three-dimensional Euclidean strain rate symmetric dyadic tensor....
Three-dimensional Euclidean strain rate symmetric dyadic tensor. Time rate of change of strain....
Definition: StrainRate.hpp:51
constexpr StrainRate operator+(const StrainRate< NumericType > &strain_rate) const
Definition: StrainRate.hpp:190
constexpr StrainRate< NumericType > & operator=(StrainRate< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this strain rate tensor by moving another one.
StrainRate(const ScalarStrainRate< NumericType > &xx, const ScalarStrainRate< NumericType > &xy, const ScalarStrainRate< NumericType > &xz, const ScalarStrainRate< NumericType > &yy, const ScalarStrainRate< NumericType > &yz, const ScalarStrainRate< NumericType > &zz)
Constructor. Constructs a strain rate tensor from a given set of scalar strain rate components.
Definition: StrainRate.hpp:63
constexpr ScalarStrainRate< NumericType > zz() const noexcept
Returns the zz Cartesian component of this strain rate tensor.
Definition: StrainRate.hpp:186
~StrainRate() noexcept=default
Destructor. Destroys this strain rate tensor.
constexpr Strain< NumericType > operator/(const Frequency< NumericType > &frequency) const
Definition: StrainRate.hpp:210
constexpr Strain< NumericType > operator*(const Time< NumericType > &time) const
Definition: StrainRate.hpp:202
constexpr ScalarStrainRate< NumericType > xz() const noexcept
Returns the xz = zx Cartesian component of this strain rate tensor.
Definition: StrainRate.hpp:156
constexpr ScalarStrainRate< NumericType > zx() const noexcept
Returns the zx = xz Cartesian component of this strain rate tensor.
Definition: StrainRate.hpp:176
constexpr StrainRate< NumericType > operator-(const StrainRate< NumericType > &strain_rate) const
Definition: StrainRate.hpp:194
constexpr StrainRate< NumericType > & operator=(const StrainRate< NumericType > &other)=default
Copy assignment operator. Assigns this strain rate tensor by copying another one.
constexpr ScalarStrainRate< NumericType > yz() const noexcept
Returns the yz = zy Cartesian component of this strain rate tensor.
Definition: StrainRate.hpp:171
constexpr ScalarStrainRate< NumericType > yy() const noexcept
Returns the yy Cartesian component of this strain rate tensor.
Definition: StrainRate.hpp:166
constexpr StrainRate(const Strain< NumericType > &strain, const Frequency< NumericType > &frequency)
Constructor. Constructs a strain rate tensor from a given strain tensor and frequency using the defin...
Definition: StrainRate.hpp:76
StrainRate()=default
Default constructor. Constructs a strain rate tensor with an uninitialized value.
constexpr StrainRate< NumericType > operator/(const NumericType number) const
Definition: StrainRate.hpp:206
constexpr ScalarStrainRate< NumericType > xx() const noexcept
Returns the xx Cartesian component of this strain rate tensor.
Definition: StrainRate.hpp:146
constexpr void operator/=(const NumericType number) noexcept
Definition: StrainRate.hpp:226
constexpr ScalarStrainRate< NumericType > xy() const noexcept
Returns the xy = yx Cartesian component of this strain rate tensor.
Definition: StrainRate.hpp:151
static constexpr StrainRate< NumericType > Create(const SymmetricDyad< NumericType > &value)
Statically creates a strain rate tensor with a given value expressed in a given frequency unit.
Definition: StrainRate.hpp:139
constexpr StrainRate< NumericType > & operator=(const StrainRate< OtherNumericType > &other)
Copy assignment operator. Assigns this strain rate tensor by copying another one.
Definition: StrainRate.hpp:102
constexpr StrainRate< NumericType > operator*(const NumericType number) const
Definition: StrainRate.hpp:198
static constexpr StrainRate< NumericType > Create(const std::array< NumericType, 6 > &xx_xy_xz_yy_yz_zz)
Statically creates a strain rate tensor from the given xx, xy, xz, yy, yz, and zz Cartesian component...
Definition: StrainRate.hpp:129
constexpr ScalarStrainRate< NumericType > yx() const noexcept
Returns the yx = xy Cartesian component of this strain rate tensor.
Definition: StrainRate.hpp:161
constexpr StrainRate(const SymmetricDyad< NumericType > &value)
Constructor. Constructs a strain rate tensor with a given value expressed in the standard frequency u...
Definition: StrainRate.hpp:233
constexpr void operator-=(const StrainRate< NumericType > &strain_rate) noexcept
Definition: StrainRate.hpp:218
constexpr StrainRate(StrainRate< NumericType > &&other) noexcept=default
Move constructor. Constructs a strain rate tensor by moving another one.
constexpr void operator*=(const NumericType number) noexcept
Definition: StrainRate.hpp:222
constexpr StrainRate(const Strain< NumericType > &strain, const Time< NumericType > &time)
Constructor. Constructs a strain rate tensor from a given strain tensor and time using the definition...
Definition: StrainRate.hpp:71
static constexpr StrainRate< NumericType > Zero()
Statically creates a strain rate tensor of zero.
Definition: StrainRate.hpp:111
StrainRate(const SymmetricDyad< NumericType > &value, Unit::Frequency unit)
Constructor. Constructs a strain rate tensor with a given value expressed in a given frequency unit.
Definition: StrainRate.hpp:58
constexpr void operator+=(const StrainRate< NumericType > &strain_rate) noexcept
Definition: StrainRate.hpp:214
constexpr ScalarStrainRate< NumericType > zy() const noexcept
Returns the zy = yz Cartesian component of this strain rate tensor.
Definition: StrainRate.hpp:181
static constexpr StrainRate< NumericType > Create(const NumericType xx, const NumericType xy, const NumericType xz, const NumericType yy, const NumericType yz, const NumericType zz)
Statically creates a strain rate tensor from the given xx, xy, xz, yy, yz, and zz Cartesian component...
Definition: StrainRate.hpp:118
Three-dimensional Euclidean strain symmetric dyadic tensor. Contains six components in Cartesian coor...
Definition: Strain.hpp:68
Strain()=default
Default constructor. Constructs a strain tensor with an uninitialized value.
constexpr Strain< NumericType > operator*(const NumericType number) const
Definition: Strain.hpp:193
constexpr Strain< NumericType > operator/(const NumericType number) const
Definition: Strain.hpp:199
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.
Time. Can represent either a point in time, a time duration, or a period. For the inverse of time,...
Definition: Time.hpp:172
constexpr Time< NumericType > operator*(const NumericType number) const
Definition: Time.hpp:278
Three-dimensional Euclidean velocity gradient dyadic tensor. Gradient of the velocity vector....
Frequency
Frequency units.
Definition: Frequency.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)