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
ScalarStrainRate.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_STRAIN_RATE_HPP
26#define PHQ_SCALAR_STRAIN_RATE_HPP
27
28#include <cstddef>
29#include <functional>
30#include <ostream>
31
32#include "DimensionalScalar.hpp"
33#include "Frequency.hpp"
34#include "ScalarStrain.hpp"
35#include "Time.hpp"
36#include "Unit/Frequency.hpp"
37
38namespace PhQ {
39
40/// \brief Scalar component or resultant of a three-dimensional Euclidean strain rate symmetric
41/// dyadic tensor. For the related tensor, see PhQ::StrainRate. See also PhQ::ScalarStrain,
42/// PhQ::Time, and PhQ::Frequency.
43template <typename NumericType = double>
44class ScalarStrainRate : public DimensionalScalar<Unit::Frequency, NumericType> {
45public:
46 /// \brief Default constructor. Constructs a scalar strain rate with an uninitialized value.
47 ScalarStrainRate() = default;
48
49 /// \brief Constructor. Constructs a scalar strain rate with a given value expressed in a given
50 /// frequency unit.
51 ScalarStrainRate(const NumericType value, const Unit::Frequency unit)
52 : DimensionalScalar<Unit::Frequency, NumericType>(value, unit) {}
53
54 /// \brief Constructor. Constructs a scalar strain rate from a given scalar strain and time using
55 /// the definition of strain rate.
57 const ScalarStrain<NumericType>& scalar_strain, const Time<NumericType>& time)
58 : ScalarStrainRate<NumericType>(scalar_strain.Value() / time.Value()) {}
59
60 /// \brief Constructor. Constructs a scalar strain rate from a given scalar strain and frequency
61 /// using the definition of strain rate.
63 const ScalarStrain<NumericType>& scalar_strain, const Frequency<NumericType>& frequency)
64 : ScalarStrainRate<NumericType>(scalar_strain.Value() * frequency.Value()) {}
65
66 /// \brief Destructor. Destroys this scalar strain rate.
67 ~ScalarStrainRate() noexcept = default;
68
69 /// \brief Copy constructor. Constructs a scalar strain rate by copying another one.
70 constexpr ScalarStrainRate(const ScalarStrainRate<NumericType>& other) = default;
71
72 /// \brief Copy constructor. Constructs a scalar strain rate by copying another one.
73 template <typename OtherNumericType>
74 explicit constexpr ScalarStrainRate(const ScalarStrainRate<OtherNumericType>& other)
75 : ScalarStrainRate(static_cast<NumericType>(other.Value())) {}
76
77 /// \brief Move constructor. Constructs a scalar strain rate by moving another one.
78 constexpr ScalarStrainRate(ScalarStrainRate<NumericType>&& other) noexcept = default;
79
80 /// \brief Copy assignment operator. Assigns this scalar strain rate by copying another one.
82 const ScalarStrainRate<NumericType>& other) = default;
83
84 /// \brief Copy assignment operator. Assigns this scalar strain rate by copying another one.
85 template <typename OtherNumericType>
88 this->value = static_cast<NumericType>(other.Value());
89 return *this;
90 }
91
92 /// \brief Move assignment operator. Assigns this scalar strain rate by moving another one.
94 ScalarStrainRate<NumericType>&& other) noexcept = default;
95
96 /// \brief Statically creates a scalar strain rate of zero.
97 [[nodiscard]] static constexpr ScalarStrainRate<NumericType> Zero() {
98 return ScalarStrainRate<NumericType>{static_cast<NumericType>(0)};
99 }
100
101 /// \brief Statically creates a scalar strain rate with a given value expressed in a given
102 /// frequency unit.
103 template <Unit::Frequency Unit>
104 [[nodiscard]] static constexpr ScalarStrainRate<NumericType> Create(const NumericType value) {
106 ConvertStatically<Unit::Frequency, Unit, Standard<Unit::Frequency>>(value)};
107 }
108
110 const ScalarStrainRate<NumericType>& other) const {
111 return ScalarStrainRate<NumericType>{this->value + other.value};
112 }
113
115 const ScalarStrainRate<NumericType>& other) const {
116 return ScalarStrainRate<NumericType>{this->value - other.value};
117 }
118
119 constexpr ScalarStrainRate<NumericType> operator*(const NumericType number) const {
120 return ScalarStrainRate<NumericType>{this->value * number};
121 }
122
123 constexpr ScalarStrainRate<NumericType> operator/(const NumericType number) const {
124 return ScalarStrainRate<NumericType>{this->value / number};
125 }
126
128 return ScalarStrain<NumericType>{*this, time};
129 }
130
131 constexpr NumericType operator/(const ScalarStrainRate<NumericType>& other) const noexcept {
132 return this->value / other.value;
133 }
134
136 return ScalarStrain<NumericType>{*this, frequency};
137 }
138
139 constexpr void operator+=(const ScalarStrainRate<NumericType>& other) noexcept {
140 this->value += other.value;
141 }
142
143 constexpr void operator-=(const ScalarStrainRate<NumericType>& other) noexcept {
144 this->value -= other.value;
145 }
146
147 constexpr void operator*=(const NumericType number) noexcept {
148 this->value *= number;
149 }
150
151 constexpr void operator/=(const NumericType number) noexcept {
152 this->value /= number;
153 }
154
155private:
156 /// \brief Constructor. Constructs a scalar strain rate with a given value expressed in the
157 /// standard frequency unit.
158 explicit constexpr ScalarStrainRate(const NumericType value)
159 : DimensionalScalar<Unit::Frequency, NumericType>(value) {}
160
161 template <typename OtherNumericType>
162 friend class StrainRate;
163};
164
165template <typename NumericType>
166inline constexpr bool operator==(const ScalarStrainRate<NumericType>& left,
167 const ScalarStrainRate<NumericType>& right) noexcept {
168 return left.Value() == right.Value();
169}
170
171template <typename NumericType>
172inline constexpr bool operator!=(const ScalarStrainRate<NumericType>& left,
173 const ScalarStrainRate<NumericType>& right) noexcept {
174 return left.Value() != right.Value();
175}
176
177template <typename NumericType>
178inline constexpr bool operator<(const ScalarStrainRate<NumericType>& left,
179 const ScalarStrainRate<NumericType>& right) noexcept {
180 return left.Value() < right.Value();
181}
182
183template <typename NumericType>
184inline constexpr bool operator>(const ScalarStrainRate<NumericType>& left,
185 const ScalarStrainRate<NumericType>& right) noexcept {
186 return left.Value() > right.Value();
187}
188
189template <typename NumericType>
190inline constexpr bool operator<=(const ScalarStrainRate<NumericType>& left,
191 const ScalarStrainRate<NumericType>& right) noexcept {
192 return left.Value() <= right.Value();
193}
194
195template <typename NumericType>
196inline constexpr bool operator>=(const ScalarStrainRate<NumericType>& left,
197 const ScalarStrainRate<NumericType>& right) noexcept {
198 return left.Value() >= right.Value();
199}
200
201template <typename NumericType>
202inline std::ostream& operator<<(
203 std::ostream& stream, const ScalarStrainRate<NumericType>& scalar_strain_rate) {
204 stream << scalar_strain_rate.Print();
205 return stream;
206}
207
208template <typename NumericType>
210 const NumericType number, const ScalarStrainRate<NumericType>& scalar_strain_rate) {
211 return scalar_strain_rate * number;
212}
213
214template <typename NumericType>
216 const ScalarStrainRate<NumericType>& scalar_strain_rate, const Time<NumericType>& time)
217 : ScalarStrain<NumericType>(scalar_strain_rate.Value() * time.Value()) {}
218
219template <typename NumericType>
221 const ScalarStrainRate<NumericType>& scalar_strain_rate,
222 const Frequency<NumericType>& frequency)
223 : ScalarStrain<NumericType>(scalar_strain_rate.Value() / frequency.Value()) {}
224
225template <typename NumericType>
227 const Frequency<NumericType>& frequency) const {
228 return ScalarStrainRate<NumericType>{*this, frequency};
229}
230
231template <typename NumericType>
233 const Time<NumericType>& time) const {
234 return ScalarStrainRate<NumericType>{*this, time};
235}
236
237template <typename NumericType>
239 const ScalarStrainRate<NumericType>& scalar_strain_rate) const {
240 return ScalarStrain<NumericType>{scalar_strain_rate, *this};
241}
242
243template <typename NumericType>
245 const ScalarStrain<NumericType>& scalar_strain) const {
246 return ScalarStrainRate<NumericType>{scalar_strain, *this};
247}
248
249} // namespace PhQ
250
251namespace std {
252
253template <typename NumericType>
254struct hash<PhQ::ScalarStrainRate<NumericType>> {
255 inline size_t operator()(const PhQ::ScalarStrainRate<NumericType>& scalar_strain_rate) const {
256 return hash<NumericType>()(scalar_strain_rate.Value());
257 }
258};
259
260} // namespace std
261
262#endif // PHQ_SCALAR_STRAIN_RATE_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.
Frequency. Inverse of a time duration. See also PhQ::Time.
Definition Frequency.hpp:40
constexpr Frequency< NumericType > operator*(const NumericType number) const
Scalar component or resultant of a three-dimensional Euclidean strain rate symmetric dyadic tensor....
constexpr ScalarStrainRate< NumericType > operator+(const ScalarStrainRate< NumericType > &other) const
constexpr NumericType operator/(const ScalarStrainRate< NumericType > &other) const noexcept
static constexpr ScalarStrainRate< NumericType > Create(const NumericType value)
Statically creates a scalar strain rate with a given value expressed in a given frequency unit.
constexpr ScalarStrainRate< NumericType > operator-(const ScalarStrainRate< NumericType > &other) const
ScalarStrainRate(const NumericType value, const Unit::Frequency unit)
Constructor. Constructs a scalar strain rate with a given value expressed in a given frequency unit.
static constexpr ScalarStrainRate< NumericType > Zero()
Statically creates a scalar strain rate of zero.
constexpr ScalarStrainRate(const ScalarStrain< NumericType > &scalar_strain, const Time< NumericType > &time)
Constructor. Constructs a scalar strain rate from a given scalar strain and time using the definition...
constexpr void operator-=(const ScalarStrainRate< NumericType > &other) noexcept
constexpr ScalarStrainRate< NumericType > operator/(const NumericType number) const
constexpr void operator/=(const NumericType number) noexcept
constexpr ScalarStrainRate(const NumericType value)
Constructor. Constructs a scalar strain rate with a given value expressed in the standard frequency u...
constexpr ScalarStrain< NumericType > operator*(const Time< NumericType > &time) const
constexpr ScalarStrainRate< NumericType > operator*(const NumericType number) const
~ScalarStrainRate() noexcept=default
Destructor. Destroys this scalar strain rate.
constexpr ScalarStrainRate< NumericType > & operator=(ScalarStrainRate< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this scalar strain rate by moving another one.
constexpr ScalarStrainRate(const ScalarStrain< NumericType > &scalar_strain, const Frequency< NumericType > &frequency)
Constructor. Constructs a scalar strain rate from a given scalar strain and frequency using the defin...
constexpr ScalarStrainRate< NumericType > & operator=(const ScalarStrainRate< OtherNumericType > &other)
Copy assignment operator. Assigns this scalar strain rate by copying another one.
constexpr void operator+=(const ScalarStrainRate< NumericType > &other) noexcept
constexpr ScalarStrain< NumericType > operator/(const Frequency< NumericType > &frequency) const
constexpr ScalarStrainRate(ScalarStrainRate< NumericType > &&other) noexcept=default
Move constructor. Constructs a scalar strain rate by moving another one.
constexpr ScalarStrainRate< NumericType > & operator=(const ScalarStrainRate< NumericType > &other)=default
Copy assignment operator. Assigns this scalar strain rate by copying another one.
ScalarStrainRate()=default
Default constructor. Constructs a scalar strain rate with an uninitialized value.
constexpr void operator*=(const NumericType number) noexcept
Scalar component or resultant of a three-dimensional Euclidean strain symmetric dyadic tensor....
constexpr ScalarStrain< NumericType > operator*(const NumericType number) const
ScalarStrain()=default
Default constructor. Constructs a scalar strain with an uninitialized value.
constexpr ScalarStrain< NumericType > operator/(const NumericType number) const
Three-dimensional Euclidean strain rate symmetric dyadic tensor. Time rate of change of strain....
Time. Can represent either a point in time, a time duration, or a period. For the inverse of time,...
Definition Time.hpp:172
constexpr Time< NumericType > operator*(const NumericType number) const
Definition Time.hpp:278
Frequency
Frequency units.
Definition Frequency.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