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
Stress.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_STRESS_HPP
26#define PHQ_STRESS_HPP
27
28#include <array>
29#include <cmath>
30#include <cstddef>
31#include <functional>
32#include <ostream>
33
35#include "Direction.hpp"
36#include "PlanarDirection.hpp"
37#include "PlanarTraction.hpp"
38#include "ScalarStress.hpp"
39#include "StaticPressure.hpp"
40#include "SymmetricDyad.hpp"
41#include "Traction.hpp"
42#include "Unit/Pressure.hpp"
43
44namespace PhQ {
45
46/// \brief Three-dimensional Euclidean Cauchy stress symmetric dyadic tensor. Contains six
47/// components in Cartesian coordinates: xx, xy = yx, xz = zx, yy, yz = zy, and zz. For the scalar
48/// components or resultants of a Cauchy stress tensor, see PhQ::ScalarStress.
49template <typename NumericType = double>
50class Stress : public DimensionalSymmetricDyad<Unit::Pressure, NumericType> {
51public:
52 /// \brief Default constructor. Constructs a stress tensor with an uninitialized value.
53 Stress() = default;
54
55 /// \brief Constructor. Constructs a stress tensor with a given value expressed in a given
56 /// pressure unit.
58 : DimensionalSymmetricDyad<Unit::Pressure, NumericType>(value, unit) {}
59
60 /// \brief Constructor. Constructs a stress tensor from a given set of scalar stress components.
64 : Stress<NumericType>(
65 {xx.Value(), xy.Value(), xz.Value(), yy.Value(), yz.Value(), zz.Value()}) {}
66
67 /// \brief Constructor. Constructs a stress tensor from a given static pressure using the
68 /// definition of stress due to pressure. Since pressure is compressive, the negative of the
69 /// static pressure contributes to the stress.
70 constexpr explicit Stress(const StaticPressure<NumericType>& static_pressure)
71 : Stress<NumericType>(
72 {static_cast<NumericType>(-1.0) * static_pressure.Value(), static_cast<NumericType>(0.0),
73 static_cast<NumericType>(0.0), static_cast<NumericType>(-1.0) * static_pressure.Value(),
74 static_cast<NumericType>(0.0),
75 static_cast<NumericType>(-1.0) * static_pressure.Value()}) {}
76
77 /// \brief Destructor. Destroys this stress tensor.
78 ~Stress() noexcept = default;
79
80 /// \brief Copy constructor. Constructs a stress tensor by copying another one.
81 constexpr Stress(const Stress<NumericType>& other) = default;
82
83 /// \brief Copy constructor. Constructs a stress tensor by copying another one.
84 template <typename OtherNumericType>
85 explicit constexpr Stress(const Stress<OtherNumericType>& other)
86 : Stress(static_cast<SymmetricDyad<NumericType>>(other.Value())) {}
87
88 /// \brief Move constructor. Constructs a stress tensor by moving another one.
89 constexpr Stress(Stress<NumericType>&& other) noexcept = default;
90
91 /// \brief Copy assignment operator. Assigns this stress tensor by copying another one.
92 constexpr Stress<NumericType>& operator=(const Stress<NumericType>& other) = default;
93
94 /// \brief Copy assignment operator. Assigns this stress tensor by copying another one.
95 template <typename OtherNumericType>
97 this->value = static_cast<SymmetricDyad<NumericType>>(other.Value());
98 return *this;
99 }
100
101 /// \brief Move assignment operator. Assigns this stress tensor by moving another one.
102 constexpr Stress<NumericType>& operator=(Stress<NumericType>&& other) noexcept = default;
103
104 /// \brief Statically creates a stress tensor of zero.
105 [[nodiscard]] static constexpr Stress<NumericType> Zero() {
107 }
108
109 /// \brief Statically creates a stress tensor from the given xx, xy, xz, yy, yz, and zz Cartesian
110 /// components expressed in a given pressure unit.
111 template <Unit::Pressure Unit>
112 [[nodiscard]] static constexpr Stress<NumericType> Create(
113 const NumericType xx, const NumericType xy, const NumericType xz, const NumericType yy,
114 const NumericType yz, const NumericType zz) {
115 return Stress<NumericType>{ConvertStatically<Unit::Pressure, Unit, Standard<Unit::Pressure>>(
117 }
118
119 /// \brief Statically creates a stress tensor from the given xx, xy, xz, yy, yz, and zz Cartesian
120 /// components expressed in a given pressure unit.
121 template <Unit::Pressure Unit>
122 [[nodiscard]] static constexpr Stress<NumericType> Create(
123 const std::array<NumericType, 6>& xx_xy_xz_yy_yz_zz) {
124 return Stress<NumericType>{ConvertStatically<Unit::Pressure, Unit, Standard<Unit::Pressure>>(
125 SymmetricDyad<NumericType>{xx_xy_xz_yy_yz_zz})};
126 }
127
128 /// \brief Statically creates a stress tensor with a given value expressed in a given pressure
129 /// unit.
130 template <Unit::Pressure Unit>
131 [[nodiscard]] static constexpr Stress<NumericType> Create(
133 return Stress<NumericType>{
134 ConvertStatically<Unit::Pressure, Unit, Standard<Unit::Pressure>>(value)};
135 }
136
137 /// \brief Returns the xx Cartesian component of this stress tensor.
138 [[nodiscard]] constexpr ScalarStress<NumericType> xx() const noexcept {
139 return ScalarStress<NumericType>{this->value.xx()};
140 }
141
142 /// \brief Returns the xy = yx Cartesian component of this stress tensor.
143 [[nodiscard]] constexpr ScalarStress<NumericType> xy() const noexcept {
144 return ScalarStress<NumericType>{this->value.xy()};
145 }
146
147 /// \brief Returns the xz = zx Cartesian component of this stress tensor.
148 [[nodiscard]] constexpr ScalarStress<NumericType> xz() const noexcept {
149 return ScalarStress<NumericType>{this->value.xz()};
150 }
151
152 /// \brief Returns the yx = xy Cartesian component of this stress tensor.
153 [[nodiscard]] constexpr ScalarStress<NumericType> yx() const noexcept {
154 return ScalarStress<NumericType>{this->value.yx()};
155 }
156
157 /// \brief Returns the yy Cartesian component of this stress tensor.
158 [[nodiscard]] constexpr ScalarStress<NumericType> yy() const noexcept {
159 return ScalarStress<NumericType>{this->value.yy()};
160 }
161
162 /// \brief Returns the yz = zy Cartesian component of this stress tensor.
163 [[nodiscard]] constexpr ScalarStress<NumericType> yz() const noexcept {
164 return ScalarStress<NumericType>{this->value.yz()};
165 }
166
167 /// \brief Returns the zx = xz Cartesian component of this stress tensor.
168 [[nodiscard]] constexpr ScalarStress<NumericType> zx() const noexcept {
169 return ScalarStress<NumericType>{this->value.zx()};
170 }
171
172 /// \brief Returns the zy = yz Cartesian component of this stress tensor.
173 [[nodiscard]] constexpr ScalarStress<NumericType> zy() const noexcept {
174 return ScalarStress<NumericType>{this->value.zy()};
175 }
176
177 /// \brief Returns the zz Cartesian component of this stress tensor.
178 [[nodiscard]] constexpr ScalarStress<NumericType> zz() const noexcept {
179 return ScalarStress<NumericType>{this->value.zz()};
180 }
181
182 /// \brief Creates a planar traction vector from this stress tensor and a given planar direction
183 /// using the definition of traction.
185 const PlanarDirection<NumericType>& direction) const {
186 return PhQ::PlanarTraction<NumericType>{*this, direction};
187 }
188
189 /// \brief Creates a traction vector from this stress tensor and a given direction using the
190 /// definition of traction.
191 [[nodiscard]] constexpr PhQ::Traction<NumericType> Traction(
192 const Direction<NumericType>& direction) const {
193 return PhQ::Traction<NumericType>{*this, direction};
194 }
195
196 /// \brief Computes the von Mises stress of this stress tensor using the von Mises yield
197 /// criterion.
198 [[nodiscard]] constexpr ScalarStress<NumericType> VonMises() const {
199 return ScalarStress<NumericType>{std::sqrt(
200 0.5
201 * (std::pow(this->value.xx() - this->value.yy(), 2)
202 + std::pow(this->value.yy() - this->value.zz(), 2)
203 + std::pow(this->value.zz() - this->value.xx(), 2)
204 + 6.0
205 * (std::pow(this->value.xy(), 2) + std::pow(this->value.xz(), 2)
206 + std::pow(this->value.yz(), 2))))};
207 }
208
209 constexpr Stress<NumericType> operator+(const Stress<NumericType>& stress) const {
210 return Stress<NumericType>{this->value + stress.value};
211 }
212
213 constexpr Stress<NumericType> operator-(const Stress<NumericType>& stress) const {
214 return Stress<NumericType>{this->value - stress.value};
215 }
216
217 constexpr Stress<NumericType> operator*(const NumericType number) const {
218 return Stress<NumericType>{this->value * number};
219 }
220
221 constexpr Stress<NumericType> operator/(const NumericType number) const {
222 return Stress<NumericType>{this->value / number};
223 }
224
225 constexpr void operator+=(const Stress<NumericType>& stress) noexcept {
226 this->value += stress.value;
227 }
228
229 constexpr void operator-=(const Stress<NumericType>& stress) noexcept {
230 this->value -= stress.value;
231 }
232
233 constexpr void operator*=(const NumericType number) noexcept {
234 this->value *= number;
235 }
236
237 constexpr void operator/=(const NumericType number) noexcept {
238 this->value /= number;
239 }
240
241private:
242 /// \brief Constructor. Constructs a stress tensor with a given value expressed in the standard
243 /// pressure unit.
244 explicit constexpr Stress(const SymmetricDyad<NumericType>& value)
245 : DimensionalSymmetricDyad<Unit::Pressure, NumericType>(value) {}
246};
247
248template <typename NumericType>
249inline constexpr bool operator==(
250 const Stress<NumericType>& left, const Stress<NumericType>& right) noexcept {
251 return left.Value() == right.Value();
252}
253
254template <typename NumericType>
255inline constexpr bool operator!=(
256 const Stress<NumericType>& left, const Stress<NumericType>& right) noexcept {
257 return left.Value() != right.Value();
258}
259
260template <typename NumericType>
261inline constexpr bool operator<(
262 const Stress<NumericType>& left, const Stress<NumericType>& right) noexcept {
263 return left.Value() < right.Value();
264}
265
266template <typename NumericType>
267inline constexpr bool operator>(
268 const Stress<NumericType>& left, const Stress<NumericType>& right) noexcept {
269 return left.Value() > right.Value();
270}
271
272template <typename NumericType>
273inline constexpr bool operator<=(
274 const Stress<NumericType>& left, const Stress<NumericType>& right) noexcept {
275 return left.Value() <= right.Value();
276}
277
278template <typename NumericType>
279inline constexpr bool operator>=(
280 const Stress<NumericType>& left, const Stress<NumericType>& right) noexcept {
281 return left.Value() >= right.Value();
282}
283
284template <typename NumericType>
285inline std::ostream& operator<<(std::ostream& stream, const Stress<NumericType>& stress) {
286 stream << stress.Print();
287 return stream;
288}
289
290template <typename NumericType>
292 const NumericType number, const Stress<NumericType>& stress) {
293 return stress * number;
294}
295
296template <typename NumericType>
298 const Stress<NumericType>& stress, const PhQ::PlanarDirection<NumericType>& planar_direction)
299 : PlanarTraction<NumericType>(PlanarVector<NumericType>{stress.Value() * planar_direction}) {}
300
301template <typename NumericType>
303 const Stress<NumericType>& stress, const PhQ::Direction<NumericType>& direction)
304 : Traction<NumericType>(Vector<NumericType>{stress.Value() * direction}) {}
305
306template <typename NumericType>
310
311} // namespace PhQ
312
313namespace std {
314
315template <typename NumericType>
316struct hash<PhQ::Stress<NumericType>> {
317 inline size_t operator()(const PhQ::Stress<NumericType>& stress) const {
318 return hash<PhQ::SymmetricDyad<NumericType>>()(stress.Value());
319 }
320};
321
322} // namespace std
323
324#endif // PHQ_STRESS_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.
Three-dimensional Euclidean direction vector. Contains three components in Cartesian coordinates: x,...
two-dimensional Euclidean direction vector in the XY plane. Contains two components in Cartesian coor...
Two-dimensional Euclidean traction vector in the XY plane. Contains two components in Cartesian coord...
PlanarTraction()=default
Default constructor. Constructs a planar traction vector with an uninitialized value.
Two-dimensional Euclidean vector in the XY plane. Contains two components in Cartesian coordinates: x...
Scalar component or resultant of a three-dimensional Euclidean Cauchy stress symmetric dyadic tensor....
Static pressure. Pressure of a fluid at rest. Not to be confused with dynamic pressure,...
constexpr PhQ::Stress< NumericType > Stress() const
Definition Stress.hpp:307
Three-dimensional Euclidean Cauchy stress symmetric dyadic tensor. Contains six components in Cartesi...
Definition Stress.hpp:50
static constexpr Stress< NumericType > Zero()
Statically creates a stress tensor of zero.
Definition Stress.hpp:105
constexpr void operator+=(const Stress< NumericType > &stress) noexcept
Definition Stress.hpp:225
Stress(const SymmetricDyad< NumericType > &value, const Unit::Pressure unit)
Constructor. Constructs a stress tensor with a given value expressed in a given pressure unit.
Definition Stress.hpp:57
static constexpr Stress< NumericType > Create(const std::array< NumericType, 6 > &xx_xy_xz_yy_yz_zz)
Statically creates a stress tensor from the given xx, xy, xz, yy, yz, and zz Cartesian components exp...
Definition Stress.hpp:122
constexpr void operator*=(const NumericType number) noexcept
Definition Stress.hpp:233
constexpr ScalarStress< NumericType > xz() const noexcept
Returns the xz = zx Cartesian component of this stress tensor.
Definition Stress.hpp:148
constexpr void operator/=(const NumericType number) noexcept
Definition Stress.hpp:237
constexpr Stress< NumericType > & operator=(const Stress< OtherNumericType > &other)
Copy assignment operator. Assigns this stress tensor by copying another one.
Definition Stress.hpp:96
Stress(const ScalarStress< NumericType > &xx, const ScalarStress< NumericType > &xy, const ScalarStress< NumericType > &xz, const ScalarStress< NumericType > &yy, const ScalarStress< NumericType > &yz, const ScalarStress< NumericType > &zz)
Constructor. Constructs a stress tensor from a given set of scalar stress components.
Definition Stress.hpp:61
constexpr ScalarStress< NumericType > VonMises() const
Computes the von Mises stress of this stress tensor using the von Mises yield criterion.
Definition Stress.hpp:198
Stress()=default
Default constructor. Constructs a stress tensor with an uninitialized value.
constexpr PhQ::Traction< NumericType > Traction(const Direction< NumericType > &direction) const
Creates a traction vector from this stress tensor and a given direction using the definition of tract...
Definition Stress.hpp:191
constexpr ScalarStress< NumericType > zy() const noexcept
Returns the zy = yz Cartesian component of this stress tensor.
Definition Stress.hpp:173
constexpr Stress< NumericType > operator-(const Stress< NumericType > &stress) const
Definition Stress.hpp:213
constexpr void operator-=(const Stress< NumericType > &stress) noexcept
Definition Stress.hpp:229
constexpr Stress(Stress< NumericType > &&other) noexcept=default
Move constructor. Constructs a stress tensor by moving another one.
constexpr ScalarStress< NumericType > yz() const noexcept
Returns the yz = zy Cartesian component of this stress tensor.
Definition Stress.hpp:163
constexpr ScalarStress< NumericType > yx() const noexcept
Returns the yx = xy Cartesian component of this stress tensor.
Definition Stress.hpp:153
constexpr ScalarStress< NumericType > xy() const noexcept
Returns the xy = yx Cartesian component of this stress tensor.
Definition Stress.hpp:143
constexpr ScalarStress< NumericType > zz() const noexcept
Returns the zz Cartesian component of this stress tensor.
Definition Stress.hpp:178
constexpr Stress(const SymmetricDyad< NumericType > &value)
Constructor. Constructs a stress tensor with a given value expressed in the standard pressure unit.
Definition Stress.hpp:244
constexpr Stress(const StaticPressure< NumericType > &static_pressure)
Constructor. Constructs a stress tensor from a given static pressure using the definition of stress d...
Definition Stress.hpp:70
~Stress() noexcept=default
Destructor. Destroys this stress tensor.
constexpr ScalarStress< NumericType > xx() const noexcept
Returns the xx Cartesian component of this stress tensor.
Definition Stress.hpp:138
static constexpr Stress< NumericType > Create(const NumericType xx, const NumericType xy, const NumericType xz, const NumericType yy, const NumericType yz, const NumericType zz)
Statically creates a stress tensor from the given xx, xy, xz, yy, yz, and zz Cartesian components exp...
Definition Stress.hpp:112
constexpr Stress< NumericType > & operator=(Stress< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this stress tensor by moving another one.
constexpr Stress< NumericType > & operator=(const Stress< NumericType > &other)=default
Copy assignment operator. Assigns this stress tensor by copying another one.
constexpr PhQ::PlanarTraction< NumericType > PlanarTraction(const PlanarDirection< NumericType > &direction) const
Creates a planar traction vector from this stress tensor and a given planar direction using the defin...
Definition Stress.hpp:184
static constexpr Stress< NumericType > Create(const SymmetricDyad< NumericType > &value)
Statically creates a stress tensor with a given value expressed in a given pressure unit.
Definition Stress.hpp:131
constexpr ScalarStress< NumericType > zx() const noexcept
Returns the zx = xz Cartesian component of this stress tensor.
Definition Stress.hpp:168
constexpr ScalarStress< NumericType > yy() const noexcept
Returns the yy Cartesian component of this stress tensor.
Definition Stress.hpp:158
constexpr Stress< NumericType > operator+(const Stress< NumericType > &stress) const
Definition Stress.hpp:209
constexpr Stress< NumericType > operator*(const NumericType number) const
Definition Stress.hpp:217
constexpr Stress< NumericType > operator/(const NumericType number) const
Definition Stress.hpp:221
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,...
Three-dimensional Euclidean traction vector. Contains three components in Cartesian coordinates: x,...
Definition Traction.hpp:54
Traction()=default
Default constructor. Constructs a traction vector with an uninitialized value.
Three-dimensional Euclidean vector. Contains three components in Cartesian coordinates: x,...
Definition Vector.hpp:60
Pressure
Pressure units.
Definition Pressure.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