Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
Traction.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_TRACTION_HPP
26 #define PHQ_TRACTION_HPP
27 
28 #include <array>
29 #include <cstddef>
30 #include <functional>
31 #include <ostream>
32 
33 #include "Area.hpp"
34 #include "DimensionalVector.hpp"
35 #include "Direction.hpp"
36 #include "Force.hpp"
37 #include "PlanarTraction.hpp"
38 #include "ScalarTraction.hpp"
39 #include "Unit/Pressure.hpp"
40 #include "Vector.hpp"
41 
42 namespace PhQ {
43 
44 // Forward declaration for class PhQ::Traction.
45 template <typename NumericType>
46 class Stress;
47 
48 /// \brief Three-dimensional Euclidean traction vector. Contains three components in Cartesian
49 /// coordinates: x, y, and z. Traction is similar to pressure; however, traction can act in any
50 /// direction, whereas pressure always acts compressively perpendicular to a surface. For a
51 /// two-dimensional Euclidean traction vector in the XY plane, see PhQ::PlanarTraction. For scalar
52 /// traction components or for the magnitude of a traction vector, see PhQ::ScalarTraction.
53 template <typename NumericType = double>
54 class Traction : public DimensionalVector<Unit::Pressure, NumericType> {
55 public:
56  /// \brief Default constructor. Constructs a traction vector with an uninitialized value.
57  Traction() = default;
58 
59  /// \brief Constructor. Constructs a traction vector with a given value expressed in a given
60  /// pressure unit.
62  : DimensionalVector<Unit::Pressure, NumericType>(value, unit) {}
63 
64  /// \brief Constructor. Constructs a traction vector from a given set of scalar traction
65  /// components.
68  : Traction<NumericType>({x.Value(), y.Value(), z.Value()}) {}
69 
70  /// \brief Constructor. Constructs a traction vector from a given scalar traction and direction.
71  constexpr Traction(
72  const ScalarTraction<NumericType>& scalar_traction, const Direction<NumericType>& direction)
73  : Traction<NumericType>(scalar_traction.Value() * direction.Value()) {}
74 
75  /// \brief Constructor. Constructs a traction vector from a given planar traction vector in the XY
76  /// plane. This traction vector's z-component is initialized to zero.
77  explicit constexpr Traction(const PlanarTraction<NumericType>& planar_traction)
78  : Traction<NumericType>(Vector<NumericType>{planar_traction.Value()}) {}
79 
80  /// \brief Constructor. Constructs a traction vector from a given force and area using the
81  /// definition of traction.
82  constexpr Traction(const Force<NumericType>& force, const Area<NumericType>& area)
83  : Traction<NumericType>(force.Value() / area.Value()) {}
84 
85  /// \brief Constructor. Constructs a traction vector from a given stress and direction using the
86  /// definition of traction.
87  constexpr Traction(const Stress<NumericType>& stress, const Direction<NumericType>& direction);
88 
89  /// \brief Destructor. Destroys this traction vector.
90  ~Traction() noexcept = default;
91 
92  /// \brief Copy constructor. Constructs a traction vector by copying another one.
93  constexpr Traction(const Traction<NumericType>& other) = default;
94 
95  /// \brief Copy constructor. Constructs a traction vector by copying another one.
96  template <typename OtherNumericType>
97  explicit constexpr Traction(const Traction<OtherNumericType>& other)
98  : Traction(static_cast<Vector<NumericType>>(other.Value())) {}
99 
100  /// \brief Move constructor. Constructs a traction vector by moving another one.
101  constexpr Traction(Traction<NumericType>&& other) noexcept = default;
102 
103  /// \brief Copy assignment operator. Assigns this traction vector by copying another one.
104  constexpr Traction<NumericType>& operator=(const Traction<NumericType>& other) = default;
105 
106  /// \brief Copy assignment operator. Assigns this traction vector by copying another one.
107  template <typename OtherNumericType>
109  this->value = static_cast<Vector<NumericType>>(other.Value());
110  return *this;
111  }
112 
113  /// \brief Move assignment operator. Assigns this traction vector by moving another one.
114  constexpr Traction<NumericType>& operator=(Traction<NumericType>&& other) noexcept = default;
115 
116  /// \brief Statically creates a traction vector of zero.
117  [[nodiscard]] static constexpr Traction<NumericType> Zero() {
119  }
120 
121  /// \brief Statically creates a traction vector from the given x, y, and z Cartesian components
122  /// expressed in a given pressure unit.
123  template <Unit::Pressure Unit>
124  [[nodiscard]] static constexpr Traction<NumericType> Create(
125  const NumericType x, const NumericType y, const NumericType z) {
126  return Traction<NumericType>{ConvertStatically<Unit::Pressure, Unit, Standard<Unit::Pressure>>(
127  Vector<NumericType>{x, y, z})};
128  }
129 
130  /// \brief Statically creates a traction vector from the given x, y, and z Cartesian components
131  /// expressed in a given pressure unit.
132  template <Unit::Pressure Unit>
133  [[nodiscard]] static constexpr Traction<NumericType> Create(
134  const std::array<NumericType, 3>& x_y_z) {
135  return Traction<NumericType>{ConvertStatically<Unit::Pressure, Unit, Standard<Unit::Pressure>>(
136  Vector<NumericType>{x_y_z})};
137  }
138 
139  /// \brief Statically creates a traction vector with a given value expressed in a given pressure
140  /// unit.
141  template <Unit::Pressure Unit>
142  [[nodiscard]] static constexpr Traction<NumericType> Create(const Vector<NumericType>& value) {
143  return Traction<NumericType>{
144  ConvertStatically<Unit::Pressure, Unit, Standard<Unit::Pressure>>(value)};
145  }
146 
147  /// \brief Returns the x Cartesian component of this traction vector.
148  [[nodiscard]] constexpr ScalarTraction<NumericType> x() const noexcept {
149  return ScalarTraction<NumericType>{this->value.x()};
150  }
151 
152  /// \brief Returns the y Cartesian component of this traction vector.
153  [[nodiscard]] constexpr ScalarTraction<NumericType> y() const noexcept {
154  return ScalarTraction<NumericType>{this->value.y()};
155  }
156 
157  /// \brief Returns the z Cartesian component of this traction vector.
158  [[nodiscard]] constexpr ScalarTraction<NumericType> z() const noexcept {
159  return ScalarTraction<NumericType>{this->value.z()};
160  }
161 
162  /// \brief Returns the magnitude of this traction vector.
163  [[nodiscard]] ScalarTraction<NumericType> Magnitude() const {
165  }
166 
167  /// \brief Returns the direction of this traction vector.
168  [[nodiscard]] PhQ::Direction<NumericType> Direction() const {
169  return this->value.Direction();
170  }
171 
172  /// \brief Returns the angle between this traction vector and another one.
173  [[nodiscard]] PhQ::Angle<NumericType> Angle(const Traction<NumericType>& traction) const {
174  return PhQ::Angle<NumericType>{*this, traction};
175  }
176 
177  constexpr Traction<NumericType> operator+(const Traction<NumericType>& traction) const {
178  return Traction<NumericType>{this->value + traction.value};
179  }
180 
181  constexpr Traction<NumericType> operator-(const Traction<NumericType>& traction) const {
182  return Traction<NumericType>{this->value - traction.value};
183  }
184 
185  constexpr Traction<NumericType> operator*(const NumericType number) const {
186  return Traction<NumericType>{this->value * number};
187  }
188 
189  constexpr Force<NumericType> operator*(const Area<NumericType>& area) const {
190  return Force<NumericType>{*this, area};
191  }
192 
193  constexpr Traction<NumericType> operator/(const NumericType number) const {
194  return Traction<NumericType>{this->value / number};
195  }
196 
197  constexpr void operator+=(const Traction<NumericType>& traction) noexcept {
198  this->value += traction.value;
199  }
200 
201  constexpr void operator-=(const Traction<NumericType>& traction) noexcept {
202  this->value -= traction.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 private:
214  /// \brief Constructor. Constructs a traction vector with a given value expressed in the standard
215  /// pressure unit.
216  explicit constexpr Traction(const Vector<NumericType>& value)
217  : DimensionalVector<Unit::Pressure, NumericType>(value) {}
218 };
219 
220 template <typename NumericType>
221 inline constexpr bool operator==(
222  const Traction<NumericType>& left, const Traction<NumericType>& right) noexcept {
223  return left.Value() == right.Value();
224 }
225 
226 template <typename NumericType>
227 inline constexpr bool operator!=(
228  const Traction<NumericType>& left, const Traction<NumericType>& right) noexcept {
229  return left.Value() != right.Value();
230 }
231 
232 template <typename NumericType>
233 inline constexpr bool operator<(
234  const Traction<NumericType>& left, const Traction<NumericType>& right) noexcept {
235  return left.Value() < right.Value();
236 }
237 
238 template <typename NumericType>
239 inline constexpr bool operator>(
240  const Traction<NumericType>& left, const Traction<NumericType>& right) noexcept {
241  return left.Value() > right.Value();
242 }
243 
244 template <typename NumericType>
245 inline constexpr bool operator<=(
246  const Traction<NumericType>& left, const Traction<NumericType>& right) noexcept {
247  return left.Value() <= right.Value();
248 }
249 
250 template <typename NumericType>
251 inline constexpr bool operator>=(
252  const Traction<NumericType>& left, const Traction<NumericType>& right) noexcept {
253  return left.Value() >= right.Value();
254 }
255 
256 template <typename NumericType>
257 inline std::ostream& operator<<(std::ostream& stream, const Traction<NumericType>& traction) {
258  stream << traction.Print();
259  return stream;
260 }
261 
262 template <typename NumericType>
264  const NumericType number, const Traction<NumericType>& traction) {
265  return traction * number;
266 }
267 
268 template <typename NumericType>
270  : Direction<NumericType>(traction.Value()) {}
271 
272 template <typename NumericType>
274  const Traction<NumericType>& traction1, const Traction<NumericType>& traction2)
275  : Angle<NumericType>(traction1.Value(), traction2.Value()) {}
276 
277 template <typename NumericType>
278 inline constexpr Force<NumericType>::Force(
279  const Traction<NumericType>& traction, const Area<NumericType>& area)
280  : Force<NumericType>(traction.Value() * area.Value()) {}
281 
282 template <typename NumericType>
284  const ScalarTraction<NumericType>& scalar_traction) const {
285  return Traction<NumericType>{scalar_traction, *this};
286 }
287 
288 template <typename NumericType>
290  const Direction<NumericType>& direction) const {
291  return Traction<NumericType>{*this, direction};
292 }
293 
294 template <typename NumericType>
296  const Area<NumericType>& area) const {
297  return Traction<NumericType>{*this, area};
298 }
299 
300 template <typename NumericType>
302  : PlanarTraction(PlanarVector<NumericType>{traction.Value()}) {}
303 
304 } // namespace PhQ
305 
306 namespace std {
307 
308 template <typename NumericType>
309 struct hash<PhQ::Traction<NumericType>> {
310  inline size_t operator()(const PhQ::Traction<NumericType>& traction) const {
311  return hash<PhQ::Vector<NumericType>>()(traction.Value());
312  }
313 };
314 
315 } // namespace std
316 
317 #endif // PHQ_TRACTION_HPP
Plane angle between two lines or dihedral angle between two planes.
Definition: Angle.hpp:130
Angle()=default
Default constructor. Constructs an angle with an uninitialized value.
Surface area or cross-sectional area. Can also represent a scalar component of a vector area or the m...
Definition: Area.hpp:71
constexpr const PhQ::PlanarVector< NumericType > & Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
Abstract base class that represents any dimensional vector physical quantity. Such a physical quantit...
std::string Print() const
Prints this physical quantity as a string. This physical quantity's value is expressed in its standar...
static constexpr Unit::Pressure Unit()
Standard unit of measure for this physical quantity. This physical quantity's value is stored interna...
PhQ::Vector< double > value
Value of this physical quantity expressed in its standard unit of measure.
constexpr const PhQ::Vector< double > & 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,...
Definition: Direction.hpp:115
constexpr Direction()
Default constructor. Initializes a direction to the zero vector.
Definition: Direction.hpp:118
constexpr Acceleration< NumericType > operator*(const ScalarAcceleration< NumericType > &scalar_acceleration) const
Three-dimensional Euclidean force vector. Contains three components in Cartesian coordinates: x,...
Definition: Force.hpp:52
constexpr Force< NumericType > operator/(const NumericType number) const
Definition: Force.hpp:180
Force()=default
Default constructor. Constructs a force vector with an uninitialized value.
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 traction component or magnitude of a traction vector. Traction is similar to pressure; however...
constexpr ScalarTraction< NumericType > operator*(const NumericType number) const
Three-dimensional Euclidean Cauchy stress symmetric dyadic tensor. Contains six components in Cartesi...
Definition: Stress.hpp:50
Three-dimensional Euclidean traction vector. Contains three components in Cartesian coordinates: x,...
Definition: Traction.hpp:54
~Traction() noexcept=default
Destructor. Destroys this traction vector.
constexpr Traction< NumericType > & operator=(const Traction< NumericType > &other)=default
Copy assignment operator. Assigns this traction vector by copying another one.
ScalarTraction< NumericType > Magnitude() const
Returns the magnitude of this traction vector.
Definition: Traction.hpp:163
constexpr Traction(const PlanarTraction< NumericType > &planar_traction)
Constructor. Constructs a traction vector from a given planar traction vector in the XY plane....
Definition: Traction.hpp:77
constexpr ScalarTraction< NumericType > y() const noexcept
Returns the y Cartesian component of this traction vector.
Definition: Traction.hpp:153
constexpr Force< NumericType > operator*(const Area< NumericType > &area) const
Definition: Traction.hpp:189
constexpr void operator/=(const NumericType number) noexcept
Definition: Traction.hpp:209
constexpr void operator-=(const Traction< NumericType > &traction) noexcept
Definition: Traction.hpp:201
constexpr ScalarTraction< NumericType > x() const noexcept
Returns the x Cartesian component of this traction vector.
Definition: Traction.hpp:148
constexpr Traction< NumericType > & operator=(Traction< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this traction vector by moving another one.
constexpr Traction< NumericType > & operator=(const Traction< OtherNumericType > &other)
Copy assignment operator. Assigns this traction vector by copying another one.
Definition: Traction.hpp:108
constexpr Traction< NumericType > operator/(const NumericType number) const
Definition: Traction.hpp:193
static constexpr Traction< NumericType > Create(const NumericType x, const NumericType y, const NumericType z)
Statically creates a traction vector from the given x, y, and z Cartesian components expressed in a g...
Definition: Traction.hpp:124
PhQ::Direction< NumericType > Direction() const
Returns the direction of this traction vector.
Definition: Traction.hpp:168
constexpr Traction< NumericType > operator*(const NumericType number) const
Definition: Traction.hpp:185
constexpr Traction(Traction< NumericType > &&other) noexcept=default
Move constructor. Constructs a traction vector by moving another one.
static constexpr Traction< NumericType > Create(const std::array< NumericType, 3 > &x_y_z)
Statically creates a traction vector from the given x, y, and z Cartesian components expressed in a g...
Definition: Traction.hpp:133
static constexpr Traction< NumericType > Create(const Vector< NumericType > &value)
Statically creates a traction vector with a given value expressed in a given pressure unit.
Definition: Traction.hpp:142
Traction(const ScalarTraction< NumericType > &x, const ScalarTraction< NumericType > &y, const ScalarTraction< NumericType > &z)
Constructor. Constructs a traction vector from a given set of scalar traction components.
Definition: Traction.hpp:66
constexpr Traction(const ScalarTraction< NumericType > &scalar_traction, const Direction< NumericType > &direction)
Constructor. Constructs a traction vector from a given scalar traction and direction.
Definition: Traction.hpp:71
constexpr Traction< NumericType > operator-(const Traction< NumericType > &traction) const
Definition: Traction.hpp:181
static constexpr Traction< NumericType > Zero()
Statically creates a traction vector of zero.
Definition: Traction.hpp:117
Traction(const Vector< NumericType > &value, const Unit::Pressure unit)
Constructor. Constructs a traction vector with a given value expressed in a given pressure unit.
Definition: Traction.hpp:61
constexpr ScalarTraction< NumericType > z() const noexcept
Returns the z Cartesian component of this traction vector.
Definition: Traction.hpp:158
Traction()=default
Default constructor. Constructs a traction vector with an uninitialized value.
PhQ::Angle< NumericType > Angle(const Traction< NumericType > &traction) const
Returns the angle between this traction vector and another one.
Definition: Traction.hpp:173
constexpr Traction< NumericType > operator+(const Traction< NumericType > &traction) const
Definition: Traction.hpp:177
constexpr void operator+=(const Traction< NumericType > &traction) noexcept
Definition: Traction.hpp:197
constexpr Traction(const Vector< NumericType > &value)
Constructor. Constructs a traction vector with a given value expressed in the standard pressure unit.
Definition: Traction.hpp:216
constexpr void operator*=(const NumericType number) noexcept
Definition: Traction.hpp:205
constexpr Traction(const Force< NumericType > &force, const Area< NumericType > &area)
Constructor. Constructs a traction vector from a given force and area using the definition of tractio...
Definition: Traction.hpp:82
Three-dimensional Euclidean vector. Contains three components in Cartesian coordinates: x,...
Definition: Vector.hpp:60
NumericType Magnitude() const noexcept
Returns the magnitude (also known as the L2 norm) of this three-dimensional vector.
Definition: Vector.hpp:209
static constexpr Vector< NumericType > Zero()
Statically creates a three-dimensional vector with its x, y, and z Cartesian components initialized t...
Definition: Vector.hpp:126
constexpr NumericType x() const noexcept
Returns this three-dimensional vector's x Cartesian component.
Definition: Vector.hpp:139
PhQ::Direction< NumericType > Direction() const
Returns the direction of this three-dimensional vector.
Definition: Direction.hpp:377
constexpr NumericType y() const noexcept
Returns this three-dimensional vector's y Cartesian component.
Definition: Vector.hpp:144
constexpr NumericType z() const noexcept
Returns this three-dimensional vector's z Cartesian component.
Definition: Vector.hpp:149
Force
Force units.
Definition: Force.hpp:53
Pressure
Pressure units.
Definition: Pressure.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)