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
PlanarTraction.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_PLANAR_TRACTION_HPP
26#define PHQ_PLANAR_TRACTION_HPP
27
28#include <array>
29#include <cstddef>
30#include <functional>
31#include <ostream>
32
33#include "Area.hpp"
35#include "PlanarDirection.hpp"
36#include "PlanarForce.hpp"
37#include "PlanarVector.hpp"
38#include "ScalarTraction.hpp"
39#include "Unit/Pressure.hpp"
40
41namespace PhQ {
42
43// Forward declaration for class PhQ::PlanarTraction.
44template <typename NumericType>
45class Stress;
46
47/// \brief Two-dimensional Euclidean traction vector in the XY plane. Contains two components in
48/// Cartesian coordinates: x and y. Traction is similar to pressure; however, traction can act in
49/// any direction, whereas pressure always acts compressively perpendicular to a surface. For a
50/// three-dimensional Euclidean traction vector, see PhQ::Traction. For scalar traction components
51/// or for the magnitude of a traction vector, see PhQ::ScalarTraction.
52template <typename NumericType = double>
53class PlanarTraction : public DimensionalPlanarVector<Unit::Pressure, NumericType> {
54public:
55 /// \brief Default constructor. Constructs a planar traction vector with an uninitialized value.
56 PlanarTraction() = default;
57
58 /// \brief Constructor. Constructs a planar traction vector with a given value expressed in a
59 /// given pressure unit.
61 : DimensionalPlanarVector<Unit::Pressure, NumericType>(value, unit) {}
62
63 /// \brief Constructor. Constructs a planar traction vector from a given set of scalar traction
64 /// components.
66 : PlanarTraction<NumericType>({x.Value(), y.Value()}) {}
67
68 /// \brief Constructor. Constructs a planar traction vector from a given scalar traction and
69 /// planar direction.
70 constexpr PlanarTraction(const ScalarTraction<NumericType>& scalar_traction,
71 const PlanarDirection<NumericType>& planar_direction)
72 : PlanarTraction<NumericType>(scalar_traction.Value() * planar_direction.Value()) {}
73
74 /// \brief Constructor. Constructs a planar traction vector from a given traction vector by
75 /// projecting the traction vector onto the XY plane.
76 explicit constexpr PlanarTraction(const Traction<NumericType>& traction);
77
78 /// \brief Constructor. Constructs a planar traction vector from a given planar force and area
79 /// using the definition of traction.
80 constexpr PlanarTraction(
81 const PlanarForce<NumericType>& planar_force, const Area<NumericType>& area)
82 : PlanarTraction<NumericType>(planar_force.Value() / area.Value()) {}
83
84 /// \brief Constructor. Constructs a planar traction vector from a given stress and direction
85 /// using the definition of traction.
86 constexpr PlanarTraction(
87 const Stress<NumericType>& stress, const PlanarDirection<NumericType>& planar_direction);
88
89 /// \brief Destructor. Destroys this planar traction vector.
90 ~PlanarTraction() noexcept = default;
91
92 /// \brief Copy constructor. Constructs a planar traction vector by copying another one.
93 constexpr PlanarTraction(const PlanarTraction<NumericType>& other) = default;
94
95 /// \brief Copy constructor. Constructs a planar traction vector by copying another one.
96 template <typename OtherNumericType>
97 explicit constexpr PlanarTraction(const PlanarTraction<OtherNumericType>& other)
98 : PlanarTraction(static_cast<PlanarVector<NumericType>>(other.Value())) {}
99
100 /// \brief Move constructor. Constructs a planar traction vector by moving another one.
101 constexpr PlanarTraction(PlanarTraction<NumericType>&& other) noexcept = default;
102
103 /// \brief Copy assignment operator. Assigns this planar traction vector by copying another one.
105 const PlanarTraction<NumericType>& other) = default;
106
107 /// \brief Copy assignment operator. Assigns this planar traction vector by copying another one.
108 template <typename OtherNumericType>
110 this->value = static_cast<PlanarVector<NumericType>>(other.Value());
111 return *this;
112 }
113
114 /// \brief Move assignment operator. Assigns this planar traction vector by moving another one.
116 PlanarTraction<NumericType>&& other) noexcept = default;
117
118 /// \brief Statically creates a planar traction vector of zero.
122
123 /// \brief Statically creates a planar traction vector from the given x and y Cartesian components
124 /// expressed in a given pressure unit.
125 template <Unit::Pressure Unit>
126 [[nodiscard]] static constexpr PlanarTraction<NumericType> Create(
127 const NumericType x, const NumericType y) {
129 ConvertStatically<Unit::Pressure, Unit, Standard<Unit::Pressure>>(
131 }
132
133 /// \brief Statically creates a planar traction vector from the given x and y Cartesian components
134 /// expressed in a given pressure unit.
135 template <Unit::Pressure Unit>
136 [[nodiscard]] static constexpr PlanarTraction<NumericType> Create(
137 const std::array<NumericType, 2>& x_y) {
139 ConvertStatically<Unit::Pressure, Unit, Standard<Unit::Pressure>>(
141 }
142
143 /// \brief Statically creates a planar traction vector with a given value expressed in a given
144 /// pressure unit.
145 template <Unit::Pressure Unit>
146 [[nodiscard]] static constexpr PlanarTraction<NumericType> Create(
149 ConvertStatically<Unit::Pressure, Unit, Standard<Unit::Pressure>>(value)};
150 }
151
152 /// \brief Returns the x Cartesian component of this planar traction vector.
153 [[nodiscard]] constexpr ScalarTraction<NumericType> x() const noexcept {
154 return ScalarTraction<NumericType>{this->value.x()};
155 }
156
157 /// \brief Returns the y Cartesian component of this planar traction vector.
158 [[nodiscard]] constexpr ScalarTraction<NumericType> y() const noexcept {
159 return ScalarTraction<NumericType>{this->value.y()};
160 }
161
162 /// \brief Returns the magnitude of this planar traction vector.
164 return ScalarTraction<NumericType>{this->value.Magnitude()};
165 }
166
167 /// \brief Returns the direction of this planar traction vector.
169 return this->value.PlanarDirection();
170 }
171
172 /// \brief Returns the angle between this planar traction vector and another one.
174 const PlanarTraction<NumericType>& planar_traction) const {
175 return PhQ::Angle<NumericType>{*this, planar_traction};
176 }
177
179 const PlanarTraction<NumericType>& planar_traction) const {
180 return PlanarTraction<NumericType>{this->value + planar_traction.value};
181 }
182
184 const PlanarTraction<NumericType>& planar_traction) const {
185 return PlanarTraction<NumericType>{this->value - planar_traction.value};
186 }
187
188 constexpr PlanarTraction<NumericType> operator*(const NumericType number) const {
189 return PlanarTraction<NumericType>{this->value * number};
190 }
191
193 return PlanarForce<NumericType>{*this, area};
194 }
195
196 constexpr PlanarTraction<NumericType> operator/(const NumericType number) const {
197 return PlanarTraction<NumericType>{this->value / number};
198 }
199
200 constexpr void operator+=(const PlanarTraction<NumericType>& planar_traction) noexcept {
201 this->value += planar_traction.value;
202 }
203
204 constexpr void operator-=(const PlanarTraction<NumericType>& planar_traction) noexcept {
205 this->value -= planar_traction.value;
206 }
207
208 constexpr void operator*=(const NumericType number) noexcept {
209 this->value *= number;
210 }
211
212 constexpr void operator/=(const NumericType number) noexcept {
213 this->value /= number;
214 }
215
216private:
217 /// \brief Constructor. Constructs a planar traction vector with a given value expressed in the
218 /// standard pressure unit.
220 : DimensionalPlanarVector<Unit::Pressure, NumericType>(value) {}
221};
222
223template <typename NumericType>
224inline constexpr bool operator==(
225 const PlanarTraction<NumericType>& left, const PlanarTraction<NumericType>& right) noexcept {
226 return left.Value() == right.Value();
227}
228
229template <typename NumericType>
230inline constexpr bool operator!=(
231 const PlanarTraction<NumericType>& left, const PlanarTraction<NumericType>& right) noexcept {
232 return left.Value() != right.Value();
233}
234
235template <typename NumericType>
236inline constexpr bool operator<(
237 const PlanarTraction<NumericType>& left, const PlanarTraction<NumericType>& right) noexcept {
238 return left.Value() < right.Value();
239}
240
241template <typename NumericType>
242inline constexpr bool operator>(
243 const PlanarTraction<NumericType>& left, const PlanarTraction<NumericType>& right) noexcept {
244 return left.Value() > right.Value();
245}
246
247template <typename NumericType>
248inline constexpr bool operator<=(
249 const PlanarTraction<NumericType>& left, const PlanarTraction<NumericType>& right) noexcept {
250 return left.Value() <= right.Value();
251}
252
253template <typename NumericType>
254inline constexpr bool operator>=(
255 const PlanarTraction<NumericType>& left, const PlanarTraction<NumericType>& right) noexcept {
256 return left.Value() >= right.Value();
257}
258
259template <typename NumericType>
260inline std::ostream& operator<<(
261 std::ostream& stream, const PlanarTraction<NumericType>& planar_traction) {
262 stream << planar_traction.Print();
263 return stream;
264}
265
266template <typename NumericType>
268 const NumericType number, const PlanarTraction<NumericType>& planar_traction) {
269 return planar_traction * number;
270}
271
272template <typename NumericType>
274 const PlanarTraction<NumericType>& planar_traction)
275 : PlanarDirection<NumericType>(planar_traction.Value()) {}
276
277template <typename NumericType>
279 const PlanarTraction<NumericType>& planar_traction_2)
280 : Angle<NumericType>(planar_traction_1.Value(), planar_traction_2.Value()) {}
281
282template <typename NumericType>
284 const PlanarTraction<NumericType>& planar_traction, const Area<NumericType>& area)
285 : PlanarForce<NumericType>(planar_traction.Value() * area.Value()) {}
286
287template <typename NumericType>
289 const ScalarTraction<NumericType>& scalar_traction) const {
290 return PlanarTraction<NumericType>{scalar_traction, *this};
291}
292
293template <typename NumericType>
295 const PlanarDirection<NumericType>& planar_direction) const {
296 return PlanarTraction<NumericType>{*this, planar_direction};
297}
298
299template <typename NumericType>
301 const Area<NumericType>& area) const {
302 return PlanarTraction<NumericType>{*this, area};
303}
304
305} // namespace PhQ
306
307namespace std {
308
309template <typename NumericType>
310struct hash<PhQ::PlanarTraction<NumericType>> {
311 inline size_t operator()(const PhQ::PlanarTraction<NumericType>& planar_traction) const {
312 return hash<PhQ::PlanarVector<NumericType>>()(planar_traction.Value());
313 }
314};
315
316} // namespace std
317
318#endif // PHQ_PLANAR_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
Abstract base class that represents any dimensional planar vector physical quantity....
PhQ::PlanarVector< NumericType > value
Value of this physical quantity expressed in its standard unit of measure.
static constexpr UnitType Unit()
Standard unit of measure for this physical quantity. This physical quantity's value is stored interna...
constexpr const PhQ::PlanarVector< NumericType > & Value() const noexcept
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...
two-dimensional Euclidean direction vector in the XY plane. Contains two components in Cartesian coor...
constexpr PlanarAcceleration< NumericType > operator*(const ScalarAcceleration< NumericType > &scalar_acceleration) const
constexpr PlanarDirection()
Default constructor. Initializes a planar direction to the zero planar vector.
Two-dimensional Euclidean force vector in the XY plane. Contains two components in Cartesian coordina...
constexpr PlanarForce< NumericType > operator/(const NumericType number) const
PlanarForce()=default
Default constructor. Constructs a planar force vector with an uninitialized value.
Two-dimensional Euclidean traction vector in the XY plane. Contains two components in Cartesian coord...
PhQ::PlanarDirection< NumericType > PlanarDirection() const
Returns the direction of this planar traction vector.
constexpr void operator-=(const PlanarTraction< NumericType > &planar_traction) noexcept
PlanarTraction(const PlanarVector< NumericType > &value, const Unit::Pressure unit)
Constructor. Constructs a planar traction vector with a given value expressed in a given pressure uni...
constexpr ScalarTraction< NumericType > x() const noexcept
Returns the x Cartesian component of this planar traction vector.
static constexpr PlanarTraction< NumericType > Create(const PlanarVector< NumericType > &value)
Statically creates a planar traction vector with a given value expressed in a given pressure unit.
ScalarTraction< NumericType > Magnitude() const
Returns the magnitude of this planar traction vector.
constexpr void operator/=(const NumericType number) noexcept
constexpr PlanarTraction(const PlanarVector< NumericType > &value)
Constructor. Constructs a planar traction vector with a given value expressed in the standard pressur...
constexpr PlanarTraction< NumericType > & operator=(const PlanarTraction< OtherNumericType > &other)
Copy assignment operator. Assigns this planar traction vector by copying another one.
constexpr PlanarTraction< NumericType > operator*(const NumericType number) const
constexpr PlanarForce< NumericType > operator*(const Area< NumericType > &area) const
constexpr PlanarTraction< NumericType > operator+(const PlanarTraction< NumericType > &planar_traction) const
constexpr void operator+=(const PlanarTraction< NumericType > &planar_traction) noexcept
constexpr PlanarTraction< NumericType > operator/(const NumericType number) const
constexpr PlanarTraction(const PlanarForce< NumericType > &planar_force, const Area< NumericType > &area)
Constructor. Constructs a planar traction vector from a given planar force and area using the definit...
~PlanarTraction() noexcept=default
Destructor. Destroys this planar traction vector.
constexpr PlanarTraction(const ScalarTraction< NumericType > &scalar_traction, const PlanarDirection< NumericType > &planar_direction)
Constructor. Constructs a planar traction vector from a given scalar traction and planar direction.
PlanarTraction(const ScalarTraction< NumericType > &x, const ScalarTraction< NumericType > &y)
Constructor. Constructs a planar traction vector from a given set of scalar traction components.
constexpr void operator*=(const NumericType number) noexcept
constexpr PlanarTraction(PlanarTraction< NumericType > &&other) noexcept=default
Move constructor. Constructs a planar traction vector by moving another one.
constexpr PlanarTraction< NumericType > & operator=(PlanarTraction< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this planar traction vector by moving another one.
PlanarTraction()=default
Default constructor. Constructs a planar traction vector with an uninitialized value.
static constexpr PlanarTraction< NumericType > Create(const NumericType x, const NumericType y)
Statically creates a planar traction vector from the given x and y Cartesian components expressed in ...
PhQ::Angle< NumericType > Angle(const PlanarTraction< NumericType > &planar_traction) const
Returns the angle between this planar traction vector and another one.
constexpr ScalarTraction< NumericType > y() const noexcept
Returns the y Cartesian component of this planar traction vector.
static constexpr PlanarTraction< NumericType > Zero()
Statically creates a planar traction vector of zero.
constexpr PlanarTraction< NumericType > & operator=(const PlanarTraction< NumericType > &other)=default
Copy assignment operator. Assigns this planar traction vector by copying another one.
constexpr PlanarTraction< NumericType > operator-(const PlanarTraction< NumericType > &planar_traction) const
static constexpr PlanarTraction< NumericType > Create(const std::array< NumericType, 2 > &x_y)
Statically creates a planar traction vector from the given x and y Cartesian components expressed in ...
Two-dimensional Euclidean vector in the XY plane. Contains two components in Cartesian coordinates: x...
static constexpr PlanarVector< NumericType > Zero()
Statically creates a two-dimensional planar vector with its x and y Cartesian components initialized ...
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
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