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
ScalarStress.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_STRESS_HPP
26#define PHQ_SCALAR_STRESS_HPP
27
28#include <cstddef>
29#include <functional>
30#include <ostream>
31
32#include "DimensionalScalar.hpp"
33#include "Unit/Pressure.hpp"
34
35namespace PhQ {
36
37// Forward declaration for class PhQ::ScalarStress.
38template <typename NumericType>
39class Stress;
40
41/// \brief Scalar component or resultant of a three-dimensional Euclidean Cauchy stress symmetric
42/// dyadic tensor. For the related tensor, see PhQ::Stress.
43template <typename NumericType = double>
44class ScalarStress : public DimensionalScalar<Unit::Pressure, NumericType> {
45public:
46 /// \brief Default constructor. Constructs a scalar stress with an uninitialized value.
47 ScalarStress() = default;
48
49 /// \brief Constructor. Constructs a scalar stress with a given value expressed in a given
50 /// pressure unit.
51 ScalarStress(const NumericType value, const Unit::Pressure unit)
52 : DimensionalScalar<Unit::Pressure, NumericType>(value, unit) {}
53
54 /// \brief Destructor. Destroys this scalar stress.
55 ~ScalarStress() noexcept = default;
56
57 /// \brief Copy constructor. Constructs a scalar stress by copying another one.
58 constexpr ScalarStress(const ScalarStress<NumericType>& other) = default;
59
60 /// \brief Copy constructor. Constructs a scalar stress by copying another one.
61 template <typename OtherNumericType>
62 explicit constexpr ScalarStress(const ScalarStress<OtherNumericType>& other)
63 : ScalarStress(static_cast<NumericType>(other.Value())) {}
64
65 /// \brief Move constructor. Constructs a scalar stress by moving another one.
66 constexpr ScalarStress(ScalarStress<NumericType>&& other) noexcept = default;
67
68 /// \brief Copy assignment operator. Assigns this scalar stress by copying another one.
70
71 /// \brief Copy assignment operator. Assigns this scalar stress by copying another one.
72 template <typename OtherNumericType>
74 this->value = static_cast<NumericType>(other.Value());
75 return *this;
76 }
77
78 /// \brief Move assignment operator. Assigns this scalar stress by moving another one.
80 ScalarStress<NumericType>&& other) noexcept = default;
81
82 /// \brief Statically creates a scalar stress of zero.
83 [[nodiscard]] static constexpr ScalarStress<NumericType> Zero() {
84 return ScalarStress<NumericType>{static_cast<NumericType>(0)};
85 }
86
87 /// \brief Statically creates a scalar stress with a given value expressed in a given pressure
88 /// unit.
89 template <Unit::Pressure Unit>
90 [[nodiscard]] static constexpr ScalarStress<NumericType> Create(const NumericType value) {
92 ConvertStatically<Unit::Pressure, Unit, Standard<Unit::Pressure>>(value)};
93 }
94
96 const ScalarStress<NumericType>& scalar_stress) const {
97 return ScalarStress<NumericType>{this->value + scalar_stress.value};
98 }
99
101 const ScalarStress<NumericType>& scalar_stress) const {
102 return ScalarStress<NumericType>{this->value - scalar_stress.value};
103 }
104
105 constexpr ScalarStress<NumericType> operator*(const NumericType number) const {
106 return ScalarStress<NumericType>{this->value * number};
107 }
108
109 constexpr ScalarStress<NumericType> operator/(const NumericType number) const {
110 return ScalarStress<NumericType>{this->value / number};
111 }
112
113 constexpr NumericType operator/(const ScalarStress<NumericType>& scalar_stress) const noexcept {
114 return this->value / scalar_stress.value;
115 }
116
117 constexpr void operator+=(const ScalarStress<NumericType>& scalar_stress) noexcept {
118 this->value += scalar_stress.value;
119 }
120
121 constexpr void operator-=(const ScalarStress<NumericType>& scalar_stress) noexcept {
122 this->value -= scalar_stress.value;
123 }
124
125 constexpr void operator*=(const NumericType number) noexcept {
126 this->value *= number;
127 }
128
129 constexpr void operator/=(const NumericType number) noexcept {
130 this->value /= number;
131 }
132
133private:
134 /// \brief Constructor. Constructs a scalar stress with a given value expressed in the standard
135 /// pressure unit.
136 explicit constexpr ScalarStress(const NumericType value)
137 : DimensionalScalar<Unit::Pressure, NumericType>(value) {}
138
139 template <typename OtherNumericType>
140 friend class Stress;
141};
142
143template <typename NumericType>
144inline constexpr bool operator==(
145 const ScalarStress<NumericType>& left, const ScalarStress<NumericType>& right) noexcept {
146 return left.Value() == right.Value();
147}
148
149template <typename NumericType>
150inline constexpr bool operator!=(
151 const ScalarStress<NumericType>& left, const ScalarStress<NumericType>& right) noexcept {
152 return left.Value() != right.Value();
153}
154
155template <typename NumericType>
156inline constexpr bool operator<(
157 const ScalarStress<NumericType>& left, const ScalarStress<NumericType>& right) noexcept {
158 return left.Value() < right.Value();
159}
160
161template <typename NumericType>
162inline constexpr bool operator>(
163 const ScalarStress<NumericType>& left, const ScalarStress<NumericType>& right) noexcept {
164 return left.Value() > right.Value();
165}
166
167template <typename NumericType>
168inline constexpr bool operator<=(
169 const ScalarStress<NumericType>& left, const ScalarStress<NumericType>& right) noexcept {
170 return left.Value() <= right.Value();
171}
172
173template <typename NumericType>
174inline constexpr bool operator>=(
175 const ScalarStress<NumericType>& left, const ScalarStress<NumericType>& right) noexcept {
176 return left.Value() >= right.Value();
177}
178
179template <typename NumericType>
180inline std::ostream& operator<<(
181 std::ostream& stream, const ScalarStress<NumericType>& scalar_stress) {
182 stream << scalar_stress.Print();
183 return stream;
184}
185
186template <typename NumericType>
188 const NumericType number, const ScalarStress<NumericType>& scalar_stress) {
189 return scalar_stress * number;
190}
191
192} // namespace PhQ
193
194namespace std {
195
196template <typename NumericType>
197struct hash<PhQ::ScalarStress<NumericType>> {
198 inline size_t operator()(const PhQ::ScalarStress<NumericType>& scalar_stress) const {
199 return hash<NumericType>()(scalar_stress.Value());
200 }
201};
202
203} // namespace std
204
205#endif // PHQ_SCALAR_STRESS_HPP
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::SymmetricDyad< NumericType > & Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
Scalar component or resultant of a three-dimensional Euclidean Cauchy stress symmetric dyadic tensor....
ScalarStress()=default
Default constructor. Constructs a scalar stress with an uninitialized value.
constexpr ScalarStress< NumericType > operator*(const NumericType number) const
ScalarStress(const NumericType value, const Unit::Pressure unit)
Constructor. Constructs a scalar stress with a given value expressed in a given pressure unit.
~ScalarStress() noexcept=default
Destructor. Destroys this scalar stress.
constexpr ScalarStress< NumericType > operator+(const ScalarStress< NumericType > &scalar_stress) const
constexpr void operator/=(const NumericType number) noexcept
constexpr ScalarStress< NumericType > & operator=(const ScalarStress< OtherNumericType > &other)
Copy assignment operator. Assigns this scalar stress by copying another one.
constexpr void operator*=(const NumericType number) noexcept
constexpr ScalarStress(ScalarStress< NumericType > &&other) noexcept=default
Move constructor. Constructs a scalar stress by moving another one.
constexpr ScalarStress< NumericType > & operator=(const ScalarStress< NumericType > &other)=default
Copy assignment operator. Assigns this scalar stress by copying another one.
constexpr ScalarStress< NumericType > operator-(const ScalarStress< NumericType > &scalar_stress) const
static constexpr ScalarStress< NumericType > Zero()
Statically creates a scalar stress of zero.
static constexpr ScalarStress< NumericType > Create(const NumericType value)
Statically creates a scalar stress with a given value expressed in a given pressure unit.
constexpr ScalarStress< NumericType > & operator=(ScalarStress< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this scalar stress by moving another one.
constexpr ScalarStress< NumericType > operator/(const NumericType number) const
constexpr void operator+=(const ScalarStress< NumericType > &scalar_stress) noexcept
constexpr ScalarStress(const NumericType value)
Constructor. Constructs a scalar stress with a given value expressed in the standard pressure unit.
constexpr void operator-=(const ScalarStress< NumericType > &scalar_stress) noexcept
constexpr NumericType operator/(const ScalarStress< NumericType > &scalar_stress) const noexcept
Three-dimensional Euclidean Cauchy stress symmetric dyadic tensor. Contains six components in Cartesi...
Definition Stress.hpp:50
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