Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
ScalarStrain.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_HPP
26 #define PHQ_SCALAR_STRAIN_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 
32 #include "DimensionlessScalar.hpp"
33 
34 namespace PhQ {
35 
36 // Forward declaration for class PhQ::ScalarStrain.
37 template <typename NumericType>
38 class Frequency;
39 
40 // Forward declaration for class PhQ::ScalarStrain.
41 template <typename NumericType>
42 class LinearThermalExpansionCoefficient;
43 
44 // Forward declaration for class PhQ::ScalarStrain.
45 template <typename NumericType>
46 class ScalarStrainRate;
47 
48 // Forward declaration for class PhQ::ScalarStrain.
49 template <typename NumericType>
51 
52 // Forward declaration for class PhQ::ScalarStrain.
53 template <typename NumericType>
54 class Time;
55 
56 /// \brief Scalar component or resultant of a three-dimensional Euclidean strain symmetric dyadic
57 /// tensor. For the related tensor, see PhQ::Strain. For the time rate of change of scalar strain,
58 /// see PhQ::ScalarStrainRate, PhQ::Time, and PhQ::Frequency.
59 template <typename NumericType = double>
60 class ScalarStrain : public DimensionlessScalar<NumericType> {
61 public:
62  /// \brief Default constructor. Constructs a scalar strain with an uninitialized value.
63  ScalarStrain() = default;
64 
65  /// \brief Constructor. Constructs a scalar strain with a given value.
66  explicit constexpr ScalarStrain(const NumericType value)
67  : DimensionlessScalar<NumericType>(value) {}
68 
69  /// \brief Constructor. Constructs a scalar strain from a given scalar strain rate and time using
70  /// the definition of strain rate.
71  constexpr ScalarStrain(
72  const ScalarStrainRate<NumericType>& scalar_strain_rate, const Time<NumericType>& time);
73 
74  /// \brief Constructor. Constructs a scalar strain from a given scalar strain rate and frequency
75  /// using the definition of strain rate.
76  constexpr ScalarStrain(const ScalarStrainRate<NumericType>& scalar_strain_rate,
77  const Frequency<NumericType>& frequency);
78 
79  /// \brief Constructor. Constructs a scalar strain from a given linear thermal expansion
80  /// coefficient and temperature difference using the definition of the linear thermal expansion
81  /// coefficient.
82  constexpr ScalarStrain(
83  const LinearThermalExpansionCoefficient<NumericType>& linear_thermal_expansion_coefficient,
84  const TemperatureDifference<NumericType>& temperature_difference);
85 
86  /// \brief Destructor. Destroys this scalar strain.
87  ~ScalarStrain() noexcept = default;
88 
89  /// \brief Copy constructor. Constructs a scalar strain by copying another one.
90  constexpr ScalarStrain(const ScalarStrain<NumericType>& other) = default;
91 
92  /// \brief Copy constructor. Constructs a scalar strain by copying another one.
93  template <typename OtherNumericType>
94  explicit constexpr ScalarStrain(const ScalarStrain<OtherNumericType>& other)
95  : ScalarStrain(static_cast<NumericType>(other.Value())) {}
96 
97  /// \brief Move constructor. Constructs a scalar strain by moving another one.
98  constexpr ScalarStrain(ScalarStrain<NumericType>&& other) noexcept = default;
99 
100  /// \brief Copy assignment operator. Assigns this scalar strain by copying another one.
102 
103  /// \brief Copy assignment operator. Assigns this scalar strain by copying another one.
104  template <typename OtherNumericType>
106  this->value = static_cast<NumericType>(other.Value());
107  return *this;
108  }
109 
110  /// \brief Move assignment operator. Assigns this scalar strain by moving another one.
112  ScalarStrain<NumericType>&& other) noexcept = default;
113 
114  /// \brief Statically creates a scalar strain of zero.
115  [[nodiscard]] static constexpr ScalarStrain<NumericType> Zero() {
116  return ScalarStrain<NumericType>{static_cast<NumericType>(0)};
117  }
118 
120  const ScalarStrain<NumericType>& scalar_strain) const {
121  return ScalarStrain<NumericType>{this->value + scalar_strain.value};
122  }
123 
125  const ScalarStrain<NumericType>& scalar_strain) const {
126  return ScalarStrain<NumericType>{this->value - scalar_strain.value};
127  }
128 
129  constexpr ScalarStrain<NumericType> operator*(const NumericType number) const {
130  return ScalarStrain<NumericType>{this->value * number};
131  }
132 
133  constexpr ScalarStrainRate<NumericType> operator*(const Frequency<NumericType>& frequency) const;
134 
135  constexpr ScalarStrain<NumericType> operator/(const NumericType number) const {
136  return ScalarStrain<NumericType>{this->value / number};
137  }
138 
139  constexpr ScalarStrainRate<NumericType> operator/(const Time<NumericType>& time) const;
140 
141  constexpr NumericType operator/(const ScalarStrain<NumericType>& scalar_strain) const noexcept {
142  return this->value / scalar_strain.value;
143  }
144 
145  constexpr void operator+=(const ScalarStrain<NumericType>& scalar_strain) noexcept {
146  this->value += scalar_strain.value;
147  }
148 
149  constexpr void operator-=(const ScalarStrain<NumericType>& scalar_strain) noexcept {
150  this->value -= scalar_strain.value;
151  }
152 
153  constexpr void operator*=(const NumericType number) noexcept {
154  this->value *= number;
155  }
156 
157  constexpr void operator/=(const NumericType number) noexcept {
158  this->value /= number;
159  }
160 };
161 
162 template <typename NumericType>
163 inline constexpr bool operator==(
164  const ScalarStrain<NumericType>& left, const ScalarStrain<NumericType>& right) noexcept {
165  return left.Value() == right.Value();
166 }
167 
168 template <typename NumericType>
169 inline constexpr bool operator!=(
170  const ScalarStrain<NumericType>& left, const ScalarStrain<NumericType>& right) noexcept {
171  return left.Value() != right.Value();
172 }
173 
174 template <typename NumericType>
175 inline constexpr bool operator<(
176  const ScalarStrain<NumericType>& left, const ScalarStrain<NumericType>& right) noexcept {
177  return left.Value() < right.Value();
178 }
179 
180 template <typename NumericType>
181 inline constexpr bool operator>(
182  const ScalarStrain<NumericType>& left, const ScalarStrain<NumericType>& right) noexcept {
183  return left.Value() > right.Value();
184 }
185 
186 template <typename NumericType>
187 inline constexpr bool operator<=(
188  const ScalarStrain<NumericType>& left, const ScalarStrain<NumericType>& right) noexcept {
189  return left.Value() <= right.Value();
190 }
191 
192 template <typename NumericType>
193 inline constexpr bool operator>=(
194  const ScalarStrain<NumericType>& left, const ScalarStrain<NumericType>& right) noexcept {
195  return left.Value() >= right.Value();
196 }
197 
198 template <typename NumericType>
199 inline std::ostream& operator<<(
200  std::ostream& stream, const ScalarStrain<NumericType>& scalar_strain) {
201  stream << scalar_strain.Print();
202  return stream;
203 }
204 
205 template <typename NumericType>
207  const NumericType number, const ScalarStrain<NumericType>& scalar_strain) {
208  return ScalarStrain<NumericType>{number * scalar_strain.Value()};
209 }
210 
211 } // namespace PhQ
212 
213 namespace std {
214 
215 template <typename NumericType>
216 struct hash<PhQ::ScalarStrain<NumericType>> {
217  inline size_t operator()(const PhQ::ScalarStrain<NumericType>& scalar_strain) const {
218  return hash<NumericType>()(scalar_strain.Value());
219  }
220 };
221 
222 } // namespace std
223 
224 #endif // PHQ_SCALAR_STRAIN_HPP
Abstract base class that represents any dimensionless scalar physical quantity. Such a physical quant...
constexpr double Value() const noexcept
Value of this physical quantity.
double value
Value of this physical quantity.
std::string Print() const
Prints this physical quantity as a string.
Frequency. Inverse of a time duration. See also PhQ::Time.
Definition: Frequency.hpp:40
Linear thermal expansion coefficient. Not to be confused with the volumetric thermal expansion coeffi...
Scalar component or resultant of a three-dimensional Euclidean strain rate symmetric dyadic tensor....
Scalar component or resultant of a three-dimensional Euclidean strain symmetric dyadic tensor....
constexpr ScalarStrain< NumericType > & operator=(const ScalarStrain< OtherNumericType > &other)
Copy assignment operator. Assigns this scalar strain by copying another one.
constexpr ScalarStrain< NumericType > operator-(const ScalarStrain< NumericType > &scalar_strain) const
constexpr ScalarStrain< NumericType > operator+(const ScalarStrain< NumericType > &scalar_strain) const
constexpr NumericType operator/(const ScalarStrain< NumericType > &scalar_strain) const noexcept
constexpr ScalarStrain(const NumericType value)
Constructor. Constructs a scalar strain with a given value.
constexpr ScalarStrain< NumericType > & operator=(ScalarStrain< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this scalar strain by moving another one.
constexpr void operator/=(const NumericType number) noexcept
constexpr void operator*=(const NumericType number) noexcept
constexpr ScalarStrain< NumericType > & operator=(const ScalarStrain< NumericType > &other)=default
Copy assignment operator. Assigns this scalar strain by copying another one.
constexpr void operator+=(const ScalarStrain< NumericType > &scalar_strain) noexcept
constexpr void operator-=(const ScalarStrain< NumericType > &scalar_strain) noexcept
ScalarStrain()=default
Default constructor. Constructs a scalar strain with an uninitialized value.
static constexpr ScalarStrain< NumericType > Zero()
Statically creates a scalar strain of zero.
constexpr ScalarStrain< NumericType > operator*(const NumericType number) const
constexpr ScalarStrain< NumericType > operator/(const NumericType number) const
~ScalarStrain() noexcept=default
Destructor. Destroys this scalar strain.
constexpr ScalarStrain(ScalarStrain< NumericType > &&other) noexcept=default
Move constructor. Constructs a scalar strain by moving another one.
Temperature difference. Not to be confused with temperature; see PhQ::Temperature....
Time. Can represent either a point in time, a time duration, or a period. For the inverse of time,...
Definition: Time.hpp:172
Frequency
Frequency units.
Definition: Frequency.hpp:53
Time
Time units.
Definition: Time.hpp:53
TemperatureDifference
Temperature difference units. Not to be confused with temperature units. For example,...
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)