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
ScalarTraction.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_SCALAR_TRACTION_HPP
26#define PHQ_SCALAR_TRACTION_HPP
27
28#include <cstddef>
29#include <functional>
30#include <ostream>
31
32#include "Area.hpp"
33#include "DimensionalScalar.hpp"
34#include "ScalarForce.hpp"
35#include "Unit/Pressure.hpp"
36
37namespace PhQ {
38
39// Forward declaration for class PhQ::ScalarTraction.
40template <typename NumericType>
41class Direction;
42
43// Forward declaration for class PhQ::ScalarTraction.
44template <typename NumericType>
45class PlanarDirection;
46
47// Forward declaration for class PhQ::ScalarTraction.
48template <typename NumericType>
49class PlanarTraction;
50
51// Forward declaration for class PhQ::ScalarTraction.
52template <typename NumericType>
53class Traction;
54
55/// \brief Scalar traction component or magnitude of a traction vector. Traction is similar to
56/// pressure; however, traction can act in any direction, whereas pressure always acts compressively
57/// perpendicular to a surface. For a three-dimensional Euclidean traction vector, see
58/// PhQ::Traction. For a two-dimensional Euclidean traction vector in the XY plane, see
59/// PhQ::PlanarTraction.
60template <typename NumericType = double>
61class ScalarTraction : public DimensionalScalar<Unit::Pressure, NumericType> {
62public:
63 /// \brief Default constructor. Constructs a scalar traction with an uninitialized value.
64 ScalarTraction() = default;
65
66 /// \brief Constructor. Constructs a scalar traction with a given value expressed in a given
67 /// pressure unit.
68 ScalarTraction(const NumericType value, const Unit::Pressure unit)
69 : DimensionalScalar<Unit::Pressure, NumericType>(value, unit) {}
70
71 /// \brief Constructor. Constructs a scalar traction from a given scalar force magnitude and area
72 /// using the definition of traction.
73 constexpr ScalarTraction(
74 const ScalarForce<NumericType>& scalar_force, const Area<NumericType>& area)
75 : ScalarTraction<NumericType>(scalar_force.Value() / area.Value()) {}
76
77 /// \brief Destructor. Destroys this scalar traction.
78 ~ScalarTraction() noexcept = default;
79
80 /// \brief Copy constructor. Constructs a scalar traction by copying another one.
81 constexpr ScalarTraction(const ScalarTraction<NumericType>& other) = default;
82
83 /// \brief Copy constructor. Constructs a scalar traction by copying another one.
84 template <typename OtherNumericType>
85 explicit constexpr ScalarTraction(const ScalarTraction<OtherNumericType>& other)
86 : ScalarTraction(static_cast<NumericType>(other.Value())) {}
87
88 /// \brief Move constructor. Constructs a scalar traction by moving another one.
89 constexpr ScalarTraction(ScalarTraction<NumericType>&& other) noexcept = default;
90
91 /// \brief Copy assignment operator. Assigns this scalar traction by copying another one.
93 const ScalarTraction<NumericType>& other) = default;
94
95 /// \brief Copy assignment operator. Assigns this scalar traction by copying another one.
96 template <typename OtherNumericType>
98 this->value = static_cast<NumericType>(other.Value());
99 return *this;
100 }
101
102 /// \brief Move assignment operator. Assigns this scalar traction by moving another one.
104 ScalarTraction<NumericType>&& other) noexcept = default;
105
106 /// \brief Statically creates a scalar traction of zero.
107 [[nodiscard]] static constexpr ScalarTraction<NumericType> Zero() {
108 return ScalarTraction<NumericType>{static_cast<NumericType>(0)};
109 }
110
111 /// \brief Statically creates a scalar traction with a given value expressed in a given pressure
112 /// unit.
113 template <Unit::Pressure Unit>
114 [[nodiscard]] static constexpr ScalarTraction<NumericType> Create(const NumericType value) {
116 ConvertStatically<Unit::Pressure, Unit, Standard<Unit::Pressure>>(value)};
117 }
118
120 return ScalarTraction<NumericType>{this->value + other.value};
121 }
122
124 return ScalarTraction<NumericType>{this->value - other.value};
125 }
126
127 constexpr ScalarTraction<NumericType> operator*(const NumericType number) const {
128 return ScalarTraction<NumericType>{this->value * number};
129 }
130
132 return ScalarForce<NumericType>{*this, area};
133 }
134
136 const PlanarDirection<NumericType>& planar_direction) const;
137
138 constexpr Traction<NumericType> operator*(const Direction<NumericType>& direction) const;
139
140 constexpr ScalarTraction<NumericType> operator/(const NumericType number) const {
141 return ScalarTraction<NumericType>{this->value / number};
142 }
143
144 constexpr NumericType operator/(const ScalarTraction<NumericType>& other) const noexcept {
145 return this->value / other.value;
146 }
147
148 constexpr void operator+=(const ScalarTraction<NumericType>& other) noexcept {
149 this->value += other.value;
150 }
151
152 constexpr void operator-=(const ScalarTraction<NumericType>& other) noexcept {
153 this->value -= other.value;
154 }
155
156 constexpr void operator*=(const NumericType number) noexcept {
157 this->value *= number;
158 }
159
160 constexpr void operator/=(const NumericType number) noexcept {
161 this->value /= number;
162 }
163
164private:
165 /// \brief Constructor. Constructs a scalar traction with a given value expressed in the standard
166 /// pressure unit.
167 explicit constexpr ScalarTraction(const NumericType value)
168 : DimensionalScalar<Unit::Pressure, NumericType>(value) {}
169
170 template <typename OtherNumericType>
171 friend class PlanarTraction;
172
173 template <typename OtherNumericType>
174 friend class Traction;
175};
176
177template <typename NumericType>
178inline constexpr bool operator==(
179 const ScalarTraction<NumericType>& left, const ScalarTraction<NumericType>& right) noexcept {
180 return left.Value() == right.Value();
181}
182
183template <typename NumericType>
184inline constexpr bool operator!=(
185 const ScalarTraction<NumericType>& left, const ScalarTraction<NumericType>& right) noexcept {
186 return left.Value() != right.Value();
187}
188
189template <typename NumericType>
190inline constexpr bool operator<(
191 const ScalarTraction<NumericType>& left, const ScalarTraction<NumericType>& right) noexcept {
192 return left.Value() < right.Value();
193}
194
195template <typename NumericType>
196inline constexpr bool operator>(
197 const ScalarTraction<NumericType>& left, const ScalarTraction<NumericType>& right) noexcept {
198 return left.Value() > right.Value();
199}
200
201template <typename NumericType>
202inline constexpr bool operator<=(
203 const ScalarTraction<NumericType>& left, const ScalarTraction<NumericType>& right) noexcept {
204 return left.Value() <= right.Value();
205}
206
207template <typename NumericType>
208inline constexpr bool operator>=(
209 const ScalarTraction<NumericType>& left, const ScalarTraction<NumericType>& right) noexcept {
210 return left.Value() >= right.Value();
211}
212
213template <typename NumericType>
214inline std::ostream& operator<<(
215 std::ostream& stream, const ScalarTraction<NumericType>& static_pressure) {
216 stream << static_pressure.Print();
217 return stream;
218}
219
220template <typename NumericType>
222 const NumericType number, const ScalarTraction<NumericType>& static_pressure) {
223 return static_pressure * number;
224}
225
226template <typename NumericType>
227inline constexpr Area<NumericType>::Area(const ScalarForce<NumericType>& scalar_force,
228 const ScalarTraction<NumericType>& scalar_traction)
229 : Area<NumericType>(scalar_force.Value() / scalar_traction.Value()) {}
230
231template <typename NumericType>
233 const ScalarTraction<NumericType>& scalar_traction, const Area<NumericType>& area)
234 : ScalarForce<NumericType>(scalar_traction.Value() * area.Value()) {}
235
236template <typename NumericType>
238 const ScalarTraction<NumericType>& scalar_traction) const {
239 return ScalarForce<NumericType>{scalar_traction, *this};
240}
241
242} // namespace PhQ
243
244namespace std {
245
246template <typename NumericType>
247struct hash<PhQ::ScalarTraction<NumericType>> {
248 inline size_t operator()(const PhQ::ScalarTraction<NumericType>& static_pressure) const {
249 return hash<NumericType>()(static_pressure.Value());
250 }
251};
252
253} // namespace std
254
255#endif // PHQ_SCALAR_TRACTION_HPP
Surface area or cross-sectional area. Can also represent a scalar component of a vector area or the m...
Definition Area.hpp:71
constexpr Area< NumericType > operator*(const NumericType number) const
Definition Area.hpp:143
Area()=default
Default constructor. Constructs an area with an uninitialized value.
Abstract base class that represents any dimensional scalar physical quantity. Such a physical quantit...
NumericType value
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.
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...
constexpr const PhQ::Vector< 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...
Scalar force component or magnitude of a force vector. For a three-dimensional Euclidean force vector...
ScalarForce()=default
Default constructor. Constructs a scalar force with an uninitialized value.
Scalar traction component or magnitude of a traction vector. Traction is similar to pressure; however...
static constexpr ScalarTraction< NumericType > Zero()
Statically creates a scalar traction of zero.
constexpr ScalarTraction< NumericType > operator-(const ScalarTraction< NumericType > &other) const
constexpr NumericType operator/(const ScalarTraction< NumericType > &other) const noexcept
constexpr ScalarTraction< NumericType > & operator=(const ScalarTraction< OtherNumericType > &other)
Copy assignment operator. Assigns this scalar traction by copying another one.
constexpr ScalarTraction< NumericType > & operator=(ScalarTraction< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this scalar traction by moving another one.
constexpr ScalarForce< NumericType > operator*(const Area< NumericType > &area) const
static constexpr ScalarTraction< NumericType > Create(const NumericType value)
Statically creates a scalar traction with a given value expressed in a given pressure unit.
constexpr ScalarTraction(ScalarTraction< NumericType > &&other) noexcept=default
Move constructor. Constructs a scalar traction by moving another one.
~ScalarTraction() noexcept=default
Destructor. Destroys this scalar traction.
ScalarTraction(const NumericType value, const Unit::Pressure unit)
Constructor. Constructs a scalar traction with a given value expressed in a given pressure unit.
constexpr ScalarTraction< NumericType > operator/(const NumericType number) const
constexpr void operator+=(const ScalarTraction< NumericType > &other) noexcept
constexpr void operator*=(const NumericType number) noexcept
constexpr ScalarTraction(const NumericType value)
Constructor. Constructs a scalar traction with a given value expressed in the standard pressure unit.
constexpr ScalarTraction< NumericType > & operator=(const ScalarTraction< NumericType > &other)=default
Copy assignment operator. Assigns this scalar traction by copying another one.
ScalarTraction()=default
Default constructor. Constructs a scalar traction with an uninitialized value.
constexpr ScalarTraction< NumericType > operator+(const ScalarTraction< NumericType > &other) const
constexpr ScalarTraction< NumericType > operator*(const NumericType number) const
constexpr void operator-=(const ScalarTraction< NumericType > &other) noexcept
constexpr void operator/=(const NumericType number) noexcept
constexpr ScalarTraction(const ScalarForce< NumericType > &scalar_force, const Area< NumericType > &area)
Constructor. Constructs a scalar traction from a given scalar force magnitude and area using the defi...
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