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