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
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
40namespace PhQ {
41
42// Forward declaration for class PhQ::StrainRate.
43template <typename NumericType>
44class 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.
50template <typename NumericType = double>
51class StrainRate : public DimensionalSymmetricDyad<Unit::Frequency, NumericType> {
52public:
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.
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
230private:
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
237template <typename NumericType>
238inline constexpr bool operator==(
239 const StrainRate<NumericType>& left, const StrainRate<NumericType>& right) noexcept {
240 return left.Value() == right.Value();
241}
242
243template <typename NumericType>
244inline constexpr bool operator!=(
245 const StrainRate<NumericType>& left, const StrainRate<NumericType>& right) noexcept {
246 return left.Value() != right.Value();
247}
248
249template <typename NumericType>
250inline constexpr bool operator<(
251 const StrainRate<NumericType>& left, const StrainRate<NumericType>& right) noexcept {
252 return left.Value() < right.Value();
253}
254
255template <typename NumericType>
256inline constexpr bool operator>(
257 const StrainRate<NumericType>& left, const StrainRate<NumericType>& right) noexcept {
258 return left.Value() > right.Value();
259}
260
261template <typename NumericType>
262inline constexpr bool operator<=(
263 const StrainRate<NumericType>& left, const StrainRate<NumericType>& right) noexcept {
264 return left.Value() <= right.Value();
265}
266
267template <typename NumericType>
268inline constexpr bool operator>=(
269 const StrainRate<NumericType>& left, const StrainRate<NumericType>& right) noexcept {
270 return left.Value() >= right.Value();
271}
272
273template <typename NumericType>
274inline std::ostream& operator<<(std::ostream& stream, const StrainRate<NumericType>& strain_rate) {
275 stream << strain_rate.Print();
276 return stream;
277}
278
279template <typename NumericType>
281 const NumericType number, const StrainRate<NumericType>& strain_rate) {
282 return strain_rate * number;
283}
284
285template <typename NumericType>
287 const StrainRate<NumericType>& strain_rate, const Time<NumericType>& time)
288 : Strain<NumericType>(strain_rate.Value() * time.Value()) {}
289
290template <typename NumericType>
292 const StrainRate<NumericType>& strain_rate, const Frequency<NumericType>& frequency)
293 : Strain<NumericType>(strain_rate.Value() / frequency.Value()) {}
294
295template <typename NumericType>
297 const Frequency<NumericType>& frequency) const {
298 return StrainRate<NumericType>{*this, frequency};
299}
300
301template <typename NumericType>
303 const Time<NumericType>& time) const {
304 return StrainRate<NumericType>{*this, time};
305}
306
307template <typename NumericType>
309 const StrainRate<NumericType>& strain_rate) const {
310 return Strain<NumericType>{strain_rate, *this};
311}
312
313template <typename NumericType>
315 const Strain<NumericType>& strain) const {
316 return StrainRate<NumericType>{strain, *this};
317}
318
319} // namespace PhQ
320
321namespace std {
322
323template <typename NumericType>
324struct 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
constexpr NumericType Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
Abstract base class that represents any dimensional symmetric dyadic tensor physical quantity....
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...
PhQ::SymmetricDyad< NumericType > value
Value of this physical quantity expressed in its standard unit of measure.
constexpr const PhQ::SymmetricDyad< NumericType > & Value() const noexcept
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
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....
constexpr StrainRate operator+(const StrainRate< NumericType > &strain_rate) const
constexpr ScalarStrainRate< NumericType > xx() const noexcept
Returns the xx Cartesian component of this strain rate tensor.
constexpr ScalarStrainRate< NumericType > zy() const noexcept
Returns the zy = yz Cartesian component of this strain rate tensor.
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.
constexpr StrainRate< NumericType > operator-(const StrainRate< NumericType > &strain_rate) const
~StrainRate() noexcept=default
Destructor. Destroys this strain rate tensor.
constexpr StrainRate< NumericType > & operator=(StrainRate< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this strain rate tensor by moving another one.
constexpr ScalarStrainRate< NumericType > yy() const noexcept
Returns the yy Cartesian component of this strain rate tensor.
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.
constexpr ScalarStrainRate< NumericType > xz() const noexcept
Returns the xz = zx Cartesian component of this strain rate tensor.
constexpr StrainRate< NumericType > & operator=(const StrainRate< OtherNumericType > &other)
Copy assignment operator. Assigns this strain rate tensor by copying another one.
constexpr ScalarStrainRate< NumericType > zz() const noexcept
Returns the zz Cartesian component of this strain rate tensor.
static constexpr StrainRate< NumericType > Zero()
Statically creates a strain rate tensor of zero.
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...
constexpr ScalarStrainRate< NumericType > yz() const noexcept
Returns the yz = zy Cartesian component of this strain rate tensor.
constexpr Strain< NumericType > operator/(const Frequency< NumericType > &frequency) const
StrainRate()=default
Default constructor. Constructs a strain rate tensor with an uninitialized value.
constexpr ScalarStrainRate< NumericType > xy() const noexcept
Returns the xy = yx Cartesian component of this strain rate tensor.
constexpr StrainRate< NumericType > operator/(const NumericType number) const
constexpr StrainRate< NumericType > & operator=(const StrainRate< NumericType > &other)=default
Copy assignment operator. Assigns this strain rate tensor by copying another one.
constexpr StrainRate< NumericType > operator*(const NumericType number) const
constexpr void operator/=(const NumericType number) noexcept
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...
constexpr StrainRate(const SymmetricDyad< NumericType > &value)
Constructor. Constructs a strain rate tensor with a given value expressed in the standard frequency u...
constexpr void operator-=(const StrainRate< NumericType > &strain_rate) noexcept
constexpr ScalarStrainRate< NumericType > zx() const noexcept
Returns the zx = xz Cartesian component of this strain rate tensor.
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
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...
StrainRate(const SymmetricDyad< NumericType > &value, Unit::Frequency unit)
Constructor. Constructs a strain rate tensor with a given value expressed in a given frequency unit.
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...
constexpr Strain< NumericType > operator*(const Time< NumericType > &time) const
constexpr void operator+=(const StrainRate< NumericType > &strain_rate) noexcept
constexpr ScalarStrainRate< NumericType > yx() const noexcept
Returns the yx = xy Cartesian component of this strain rate tensor.
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...
static constexpr SymmetricDyad< NumericType > Zero()
Statically creates a three-dimensional symmetric dyadic tensor with its xx, xy, xz,...
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.
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