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
VelocityGradient.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_VELOCITY_GRADIENT_HPP
26#define PHQ_VELOCITY_GRADIENT_HPP
27
28#include <array>
29#include <cstddef>
30#include <functional>
31#include <ostream>
32
33#include "DimensionalDyad.hpp"
35#include "Dyad.hpp"
36#include "Frequency.hpp"
38#include "StrainRate.hpp"
39#include "Time.hpp"
40#include "Unit/Frequency.hpp"
41
42namespace PhQ {
43
44/// \brief Three-dimensional Euclidean velocity gradient dyadic tensor. Gradient of the velocity
45/// vector. May be symmetric or asymmetric. Contains nine components in Cartesian coordinates: xx,
46/// xy, xz, yx, yy, yz, zx, zy, and zz. For the scalar components or resultants of a velocity
47/// gradient tensor, see PhQ::ScalarVelocityGradient. Can also represent the time rate of change of
48/// a displacement gradient; see PhQ::DisplacementGradient, PhQ::Time, and PhQ::Frequency.
49template <typename NumericType = double>
50class VelocityGradient : public DimensionalDyad<Unit::Frequency, NumericType> {
51public:
52 /// \brief Default constructor. Constructs a velocity gradient tensor with an uninitialized value.
53 VelocityGradient() = default;
54
55 /// \brief Constructor. Constructs a velocity gradient tensor with a given value expressed in a
56 /// given frequency unit.
58 : DimensionalDyad<Unit::Frequency, NumericType>(value, unit) {}
59
60 /// \brief Constructor. Constructs a velocity gradient tensor from a given set of scalar velocity
61 /// gradient components.
70
71 /// \brief Constructor. Constructs a velocity gradient tensor from a given displacement gradient
72 /// tensor and time using the definition of speed.
74 const DisplacementGradient<NumericType>& displacement_gradient, const Time<NumericType>& time)
75 : VelocityGradient<NumericType>(displacement_gradient.Value() / time.Value()) {}
76
77 /// \brief Constructor. Constructs a velocity gradient tensor from a given displacement gradient
78 /// tensor and frequency using the definition of speed.
79 constexpr VelocityGradient(const DisplacementGradient<NumericType>& displacement_gradient,
80 const Frequency<NumericType>& frequency)
81 : VelocityGradient<NumericType>(displacement_gradient.Value() * frequency.Value()) {}
82
83 /// \brief Destructor. Destroys this velocity gradient tensor.
84 ~VelocityGradient() noexcept = default;
85
86 /// \brief Copy constructor. Constructs a velocity gradient tensor by copying another one.
87 constexpr VelocityGradient(const VelocityGradient<NumericType>& other) = default;
88
89 /// \brief Copy constructor. Constructs a velocity gradient tensor by copying another one.
90 template <typename OtherNumericType>
91 explicit constexpr VelocityGradient(const VelocityGradient<OtherNumericType>& other)
92 : VelocityGradient(static_cast<Dyad<NumericType>>(other.Value())) {}
93
94 /// \brief Move constructor. Constructs a velocity gradient tensor by moving another one.
95 constexpr VelocityGradient(VelocityGradient<NumericType>&& other) noexcept = default;
96
97 /// \brief Copy assignment operator. Assigns this velocity gradient tensor by copying another one.
99 const VelocityGradient<NumericType>& other) = default;
100
101 /// \brief Copy assignment operator. Assigns this velocity gradient tensor by copying another one.
102 template <typename OtherNumericType>
105 this->value = static_cast<Dyad<NumericType>>(other.Value());
106 return *this;
107 }
108
109 /// \brief Move assignment operator. Assigns this velocity gradient tensor by moving another one.
111 VelocityGradient<NumericType>&& other) noexcept = default;
112
113 /// \brief Statically creates a velocity gradient tensor of zero.
114 [[nodiscard]] static constexpr VelocityGradient<NumericType> Zero() {
116 }
117
118 /// \brief Statically creates a velocity gradient tensor from the given xx, xy, xz, yx, yy, yz,
119 /// zx,zy, and zz Cartesian components expressed in a given frequency unit.
120 template <Unit::Frequency Unit>
121 [[nodiscard]] static constexpr VelocityGradient<NumericType> Create(
122 const NumericType xx, const NumericType xy, const NumericType xz, const NumericType yx,
123 const NumericType yy, const NumericType yz, const NumericType zx, const NumericType zy,
124 const NumericType zz) {
126 ConvertStatically<Unit::Frequency, Unit, Standard<Unit::Frequency>>(
127 Dyad<NumericType>{xx, xy, xz, yx, yy, yz, zx, zy, zz})};
128 }
129
130 /// \brief Statically creates a velocity gradient tensor from the given xx, xy, xz, yx, yy, yz,
131 /// zx,zy, and zz Cartesian components expressed in a given frequency unit.
132 template <Unit::Frequency Unit>
133 [[nodiscard]] static constexpr VelocityGradient<NumericType> Create(
134 const std::array<NumericType, 9>& xx_xy_xz_yx_yy_yz_zx_zy_zz) {
136 ConvertStatically<Unit::Frequency, Unit, Standard<Unit::Frequency>>(
137 Dyad<NumericType>{xx_xy_xz_yx_yy_yz_zx_zy_zz})};
138 }
139
140 /// \brief Statically creates a velocity gradient tensor with a given value expressed in a given
141 /// frequency unit.
142 template <Unit::Frequency Unit>
143 [[nodiscard]] static constexpr VelocityGradient<NumericType> Create(
144 const Dyad<NumericType>& value) {
146 ConvertStatically<Unit::Frequency, Unit, Standard<Unit::Frequency>>(value)};
147 }
148
149 /// \brief Returns the xx Cartesian component of this velocity gradient tensor.
150 [[nodiscard]] constexpr ScalarVelocityGradient<NumericType> xx() const noexcept {
152 }
153
154 /// \brief Returns the xy Cartesian component of this velocity gradient tensor.
155 [[nodiscard]] constexpr ScalarVelocityGradient<NumericType> xy() const noexcept {
157 }
158
159 /// \brief Returns the xz Cartesian component of this velocity gradient tensor.
160 [[nodiscard]] constexpr ScalarVelocityGradient<NumericType> xz() const noexcept {
162 }
163
164 /// \brief Returns the yx Cartesian component of this velocity gradient tensor.
165 [[nodiscard]] constexpr ScalarVelocityGradient<NumericType> yx() const noexcept {
167 }
168
169 /// \brief Returns the yy Cartesian component of this velocity gradient tensor.
170 [[nodiscard]] constexpr ScalarVelocityGradient<NumericType> yy() const noexcept {
172 }
173
174 /// \brief Returns the yz Cartesian component of this velocity gradient tensor.
175 [[nodiscard]] constexpr ScalarVelocityGradient<NumericType> yz() const noexcept {
177 }
178
179 /// \brief Returns the zx Cartesian component of this velocity gradient tensor.
180 [[nodiscard]] constexpr ScalarVelocityGradient<NumericType> zx() const noexcept {
182 }
183
184 /// \brief Returns the zy Cartesian component of this velocity gradient tensor.
185 [[nodiscard]] constexpr ScalarVelocityGradient<NumericType> zy() const noexcept {
187 }
188
189 /// \brief Returns the zz Cartesian component of this velocity gradient tensor.
190 [[nodiscard]] constexpr ScalarVelocityGradient<NumericType> zz() const noexcept {
192 }
193
194 /// \brief Creates a strain rate tensor from this velocity gradient tensor using the definition of
195 /// the strain rate tensor.
196 [[nodiscard]] constexpr PhQ::StrainRate<NumericType> StrainRate() const {
197 return PhQ::StrainRate<NumericType>{*this};
198 }
199
201 const VelocityGradient<NumericType>& velocity_gradient) const {
202 return VelocityGradient<NumericType>{this->value + velocity_gradient.value};
203 }
204
206 const VelocityGradient<NumericType>& velocity_gradient) const {
207 return VelocityGradient<NumericType>{this->value - velocity_gradient.value};
208 }
209
210 constexpr VelocityGradient<NumericType> operator*(const NumericType number) const {
211 return VelocityGradient<NumericType>{this->value * number};
212 }
213
215 return DisplacementGradient<NumericType>{*this, time};
216 }
217
218 constexpr VelocityGradient<NumericType> operator/(const NumericType number) const {
219 return VelocityGradient<NumericType>{this->value / number};
220 }
221
223 const Frequency<NumericType>& frequency) const {
224 return DisplacementGradient<NumericType>{*this, frequency};
225 }
226
227 constexpr void operator+=(const VelocityGradient<NumericType>& velocity_gradient) noexcept {
228 this->value += velocity_gradient.value;
229 }
230
231 constexpr void operator-=(const VelocityGradient<NumericType>& velocity_gradient) noexcept {
232 this->value -= velocity_gradient.value;
233 }
234
235 constexpr void operator*=(const NumericType number) noexcept {
236 this->value *= number;
237 }
238
239 constexpr void operator/=(const NumericType number) noexcept {
240 this->value /= number;
241 }
242
243private:
244 /// \brief Constructor. Constructs a velocity gradient tensor with a given value expressed in the
245 /// standard frequency unit.
246 explicit constexpr VelocityGradient(const Dyad<NumericType>& value)
247 : DimensionalDyad<Unit::Frequency, NumericType>(value) {}
248};
249
250template <typename NumericType>
251inline constexpr bool operator==(const VelocityGradient<NumericType>& left,
252 const VelocityGradient<NumericType>& right) noexcept {
253 return left.Value() == right.Value();
254}
255
256template <typename NumericType>
257inline constexpr bool operator!=(const VelocityGradient<NumericType>& left,
258 const VelocityGradient<NumericType>& right) noexcept {
259 return left.Value() != right.Value();
260}
261
262template <typename NumericType>
263inline constexpr bool operator<(const VelocityGradient<NumericType>& left,
264 const VelocityGradient<NumericType>& right) noexcept {
265 return left.Value() < right.Value();
266}
267
268template <typename NumericType>
269inline constexpr bool operator>(const VelocityGradient<NumericType>& left,
270 const VelocityGradient<NumericType>& right) noexcept {
271 return left.Value() > right.Value();
272}
273
274template <typename NumericType>
275inline constexpr bool operator<=(const VelocityGradient<NumericType>& left,
276 const VelocityGradient<NumericType>& right) noexcept {
277 return left.Value() <= right.Value();
278}
279
280template <typename NumericType>
281inline constexpr bool operator>=(const VelocityGradient<NumericType>& left,
282 const VelocityGradient<NumericType>& right) noexcept {
283 return left.Value() >= right.Value();
284}
285
286template <typename NumericType>
287inline std::ostream& operator<<(
288 std::ostream& stream, const VelocityGradient<NumericType>& velocity_gradient) {
289 stream << velocity_gradient.Print();
290 return stream;
291}
292
293template <typename NumericType>
295 const NumericType number, const VelocityGradient<NumericType>& velocity_gradient) {
296 return velocity_gradient * number;
297}
298
299template <typename NumericType>
301 const VelocityGradient<NumericType>& velocity_gradient)
302 : StrainRate<NumericType>(
303 {velocity_gradient.Value().xx(),
304 0.5 * (velocity_gradient.Value().xy() + velocity_gradient.Value().yx()),
305 0.5 * (velocity_gradient.Value().xz() + velocity_gradient.Value().zx()),
306 velocity_gradient.Value().yy(),
307 0.5 * (velocity_gradient.Value().yz() + velocity_gradient.Value().zy()),
308 velocity_gradient.Value().zz()}) {}
309
310template <typename NumericType>
312 const VelocityGradient<NumericType>& scalar_velocity_gradient, const Time<NumericType>& time)
313 : DisplacementGradient<NumericType>(scalar_velocity_gradient.Value() * time.Value()) {}
314
315template <typename NumericType>
317 const VelocityGradient<NumericType>& scalar_velocity_gradient,
318 const Frequency<NumericType>& frequency)
319 : DisplacementGradient<NumericType>(scalar_velocity_gradient.Value() / frequency.Value()) {}
320
321template <typename NumericType>
323 const Frequency<NumericType>& frequency) const {
324 return VelocityGradient<NumericType>{*this, frequency};
325}
326
327template <typename NumericType>
332
333template <typename NumericType>
335 const VelocityGradient<NumericType>& velocity_gradient) const {
336 return DisplacementGradient<NumericType>{velocity_gradient, *this};
337}
338
339template <typename NumericType>
341 const DisplacementGradient<NumericType>& displacement_gradient) const {
342 return VelocityGradient<NumericType>{displacement_gradient, *this};
343}
344
345} // namespace PhQ
346
347namespace std {
348
349template <typename NumericType>
350struct hash<PhQ::VelocityGradient<NumericType>> {
351 inline size_t operator()(const PhQ::VelocityGradient<NumericType>& velocity_gradient) const {
352 return hash<PhQ::Dyad<NumericType>>()(velocity_gradient.Value());
353 }
354};
355
356} // namespace std
357
358#endif // PHQ_VELOCITY_GRADIENT_HPP
Abstract base class that represents any dimensional dyadic tensor physical quantity....
static constexpr UnitType Unit()
Standard unit of measure for this physical quantity. This physical quantity's value is stored interna...
PhQ::Dyad< NumericType > value
Value of this physical quantity expressed in its standard unit of measure.
std::string Print() const
Prints this physical quantity as a string. This physical quantity's value is expressed in its standar...
constexpr const PhQ::Dyad< NumericType > & Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
constexpr NumericType Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
Three-dimensional Euclidean displacement gradient dyadic tensor. Gradient of the displacement vector....
constexpr DisplacementGradient< NumericType > operator/(const NumericType number) const
DisplacementGradient()=default
Default constructor. Constructs a displacement gradient tensor with an uninitialized value.
constexpr DisplacementGradient< NumericType > operator*(const NumericType number) const
Three-dimensional Euclidean dyadic tensor. Contains nine components in Cartesian coordinates: xx,...
Definition Dyad.hpp:51
static constexpr Dyad< NumericType > Zero()
Statically creates a three-dimensional dyadic tensor with its xx, xy, xz, yx, yy, yz,...
Definition Dyad.hpp:149
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 velocity gradient dyadic tensor....
Three-dimensional Euclidean strain rate symmetric dyadic tensor. Time rate of change of strain....
StrainRate()=default
Default constructor. Constructs a strain rate tensor with an uninitialized value.
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....
constexpr VelocityGradient(const Dyad< NumericType > &value)
Constructor. Constructs a velocity gradient tensor with a given value expressed in the standard frequ...
constexpr DisplacementGradient< NumericType > operator*(const Time< NumericType > &time) const
constexpr VelocityGradient(const DisplacementGradient< NumericType > &displacement_gradient, const Frequency< NumericType > &frequency)
Constructor. Constructs a velocity gradient tensor from a given displacement gradient tensor and freq...
constexpr ScalarVelocityGradient< NumericType > yx() const noexcept
Returns the yx Cartesian component of this velocity gradient tensor.
static constexpr VelocityGradient< NumericType > Create(const std::array< NumericType, 9 > &xx_xy_xz_yx_yy_yz_zx_zy_zz)
Statically creates a velocity gradient tensor from the given xx, xy, xz, yx, yy, yz,...
constexpr void operator-=(const VelocityGradient< NumericType > &velocity_gradient) noexcept
constexpr VelocityGradient< NumericType > operator-(const VelocityGradient< NumericType > &velocity_gradient) const
constexpr VelocityGradient< NumericType > & operator=(const VelocityGradient< NumericType > &other)=default
Copy assignment operator. Assigns this velocity gradient tensor by copying another one.
constexpr PhQ::StrainRate< NumericType > StrainRate() const
Creates a strain rate tensor from this velocity gradient tensor using the definition of the strain ra...
constexpr VelocityGradient< NumericType > operator/(const NumericType number) const
constexpr ScalarVelocityGradient< NumericType > xz() const noexcept
Returns the xz Cartesian component of this velocity gradient tensor.
constexpr ScalarVelocityGradient< NumericType > zz() const noexcept
Returns the zz Cartesian component of this velocity gradient tensor.
VelocityGradient()=default
Default constructor. Constructs a velocity gradient tensor with an uninitialized value.
constexpr ScalarVelocityGradient< NumericType > yy() const noexcept
Returns the yy Cartesian component of this velocity gradient tensor.
constexpr VelocityGradient< NumericType > & operator=(VelocityGradient< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this velocity gradient tensor by moving another one.
static constexpr VelocityGradient< NumericType > Create(const Dyad< NumericType > &value)
Statically creates a velocity gradient tensor with a given value expressed in a given frequency unit.
constexpr void operator/=(const NumericType number) noexcept
~VelocityGradient() noexcept=default
Destructor. Destroys this velocity gradient tensor.
constexpr DisplacementGradient< NumericType > operator/(const Frequency< NumericType > &frequency) const
constexpr void operator+=(const VelocityGradient< NumericType > &velocity_gradient) noexcept
static constexpr VelocityGradient< NumericType > Create(const NumericType xx, const NumericType xy, const NumericType xz, const NumericType yx, const NumericType yy, const NumericType yz, const NumericType zx, const NumericType zy, const NumericType zz)
Statically creates a velocity gradient tensor from the given xx, xy, xz, yx, yy, yz,...
constexpr ScalarVelocityGradient< NumericType > zx() const noexcept
Returns the zx Cartesian component of this velocity gradient tensor.
constexpr VelocityGradient(VelocityGradient< NumericType > &&other) noexcept=default
Move constructor. Constructs a velocity gradient tensor by moving another one.
constexpr VelocityGradient< NumericType > & operator=(const VelocityGradient< OtherNumericType > &other)
Copy assignment operator. Assigns this velocity gradient tensor by copying another one.
VelocityGradient(const Dyad< NumericType > &value, const Unit::Frequency &unit)
Constructor. Constructs a velocity gradient tensor with a given value expressed in a given frequency ...
constexpr ScalarVelocityGradient< NumericType > xy() const noexcept
Returns the xy Cartesian component of this velocity gradient tensor.
constexpr void operator*=(const NumericType number) noexcept
constexpr VelocityGradient< NumericType > operator+(const VelocityGradient< NumericType > &velocity_gradient) const
constexpr ScalarVelocityGradient< NumericType > yz() const noexcept
Returns the yz Cartesian component of this velocity gradient tensor.
constexpr VelocityGradient(const DisplacementGradient< NumericType > &displacement_gradient, const Time< NumericType > &time)
Constructor. Constructs a velocity gradient tensor from a given displacement gradient tensor and time...
constexpr ScalarVelocityGradient< NumericType > zy() const noexcept
Returns the zy Cartesian component of this velocity gradient tensor.
static constexpr VelocityGradient< NumericType > Zero()
Statically creates a velocity gradient tensor of zero.
VelocityGradient(const ScalarVelocityGradient< NumericType > &xx, const ScalarVelocityGradient< NumericType > &xy, const ScalarVelocityGradient< NumericType > &xz, const ScalarVelocityGradient< NumericType > &yx, const ScalarVelocityGradient< NumericType > &yy, const ScalarVelocityGradient< NumericType > &yz, const ScalarVelocityGradient< NumericType > &zx, const ScalarVelocityGradient< NumericType > &zy, const ScalarVelocityGradient< NumericType > &zz)
Constructor. Constructs a velocity gradient tensor from a given set of scalar velocity gradient compo...
constexpr ScalarVelocityGradient< NumericType > xx() const noexcept
Returns the xx Cartesian component of this velocity gradient tensor.
constexpr VelocityGradient< NumericType > operator*(const NumericType number) const
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