Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
ScalarDisplacementGradient.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_DISPLACEMENT_GRADIENT_HPP
26 #define PHQ_SCALAR_DISPLACEMENT_GRADIENT_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::ScalarDisplacementGradient.
37 template <typename NumericType>
38 class Frequency;
39 
40 // Forward declaration for class PhQ::ScalarDisplacementGradient.
41 template <typename NumericType>
42 class ScalarVelocityGradient;
43 
44 // Forward declaration for class PhQ::ScalarDisplacementGradient.
45 template <typename NumericType>
46 class Time;
47 
48 /// \brief Scalar component or resultant of a three-dimensional Euclidean displacement gradient
49 /// dyadic tensor. For the related tensor, see PhQ::DisplacementGradient. The time rate of change of
50 /// a scalar displacement gradient is a scalar velocity gradient; see PhQ::ScalarVelocityGradient,
51 /// PhQ::Time, and PhQ::Frequency.
52 template <typename NumericType = double>
53 class ScalarDisplacementGradient : public DimensionlessScalar<NumericType> {
54 public:
55  /// \brief Default constructor. Constructs a scalar displacement gradient with an uninitialized
56  /// value.
58 
59  /// \brief Constructor. Constructs a scalar displacement gradient with a given value.
60  explicit constexpr ScalarDisplacementGradient(const NumericType value)
61  : DimensionlessScalar<NumericType>(value) {}
62 
63  /// \brief Constructor. Constructs a scalar displacement gradient from a given scalar velocity
64  /// gradient and time using the definition of speed.
66  const ScalarVelocityGradient<NumericType>& scalar_velocity_gradient,
67  const Time<NumericType>& time);
68 
69  /// \brief Constructor. Constructs a scalar displacement gradient from a given scalar velocity
70  /// gradient and frequency using the definition of speed.
72  const ScalarVelocityGradient<NumericType>& scalar_velocity_gradient,
73  const Frequency<NumericType>& frequency);
74 
75  /// \brief Destructor. Destroys this scalar displacement gradient.
76  ~ScalarDisplacementGradient() noexcept = default;
77 
78  /// \brief Copy constructor. Constructs a scalar displacement gradient by copying another one.
80  const ScalarDisplacementGradient<NumericType>& other) = default;
81 
82  /// \brief Copy constructor. Constructs a scalar displacement gradient by copying another one.
83  template <typename OtherNumericType>
84  explicit constexpr ScalarDisplacementGradient(
85  const ScalarDisplacementGradient<OtherNumericType>& other)
86  : ScalarDisplacementGradient(static_cast<NumericType>(other.Value())) {}
87 
88  /// \brief Move constructor. Constructs a scalar displacement gradient by moving another one.
90  ScalarDisplacementGradient<NumericType>&& other) noexcept = default;
91 
92  /// \brief Copy assignment operator. Assigns this scalar displacement gradient by copying another
93  /// one.
95  const ScalarDisplacementGradient<NumericType>& other) = default;
96 
97  /// \brief Copy assignment operator. Assigns this scalar displacement gradient by copying another
98  /// one.
99  template <typename OtherNumericType>
102  this->value = static_cast<NumericType>(other.Value());
103  return *this;
104  }
105 
106  /// \brief Move assignment operator. Assigns this scalar displacement gradient by moving another
107  /// one.
109  ScalarDisplacementGradient<NumericType>&& other) noexcept = default;
110 
111  /// \brief Statically creates a scalar displacement gradient of zero.
112  [[nodiscard]] static constexpr ScalarDisplacementGradient<NumericType> Zero() {
113  return ScalarDisplacementGradient<NumericType>{static_cast<NumericType>(0)};
114  }
115 
117  const ScalarDisplacementGradient<NumericType>& scalar_displacement_gradient) const {
119  this->value + scalar_displacement_gradient.value};
120  }
121 
123  const ScalarDisplacementGradient<NumericType>& scalar_displacement_gradient) const {
125  this->value - scalar_displacement_gradient.value};
126  }
127 
128  constexpr ScalarDisplacementGradient<NumericType> operator*(const NumericType number) const {
129  return ScalarDisplacementGradient<NumericType>{this->value * number};
130  }
131 
133  const Frequency<NumericType>& frequency) const;
134 
135  constexpr ScalarDisplacementGradient<NumericType> operator/(const NumericType number) const {
136  return ScalarDisplacementGradient<NumericType>{this->value / number};
137  }
138 
140 
141  constexpr NumericType operator/(
142  const ScalarDisplacementGradient<NumericType>& scalar_displacement_gradient) const noexcept {
143  return this->value / scalar_displacement_gradient.value;
144  }
145 
146  constexpr void operator+=(
147  const ScalarDisplacementGradient<NumericType>& scalar_displacement_gradient) noexcept {
148  this->value += scalar_displacement_gradient.value;
149  }
150 
151  constexpr void operator-=(
152  const ScalarDisplacementGradient<NumericType>& scalar_displacement_gradient) noexcept {
153  this->value -= scalar_displacement_gradient.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 };
164 
165 template <typename NumericType>
166 inline constexpr bool operator==(const ScalarDisplacementGradient<NumericType>& left,
167  const ScalarDisplacementGradient<NumericType>& right) noexcept {
168  return left.Value() == right.Value();
169 }
170 
171 template <typename NumericType>
172 inline constexpr bool operator!=(const ScalarDisplacementGradient<NumericType>& left,
173  const ScalarDisplacementGradient<NumericType>& right) noexcept {
174  return left.Value() != right.Value();
175 }
176 
177 template <typename NumericType>
178 inline constexpr bool operator<(const ScalarDisplacementGradient<NumericType>& left,
179  const ScalarDisplacementGradient<NumericType>& right) noexcept {
180  return left.Value() < right.Value();
181 }
182 
183 template <typename NumericType>
184 inline constexpr bool operator>(const ScalarDisplacementGradient<NumericType>& left,
185  const ScalarDisplacementGradient<NumericType>& right) noexcept {
186  return left.Value() > right.Value();
187 }
188 
189 template <typename NumericType>
190 inline constexpr bool operator<=(const ScalarDisplacementGradient<NumericType>& left,
191  const ScalarDisplacementGradient<NumericType>& right) noexcept {
192  return left.Value() <= right.Value();
193 }
194 
195 template <typename NumericType>
196 inline constexpr bool operator>=(const ScalarDisplacementGradient<NumericType>& left,
197  const ScalarDisplacementGradient<NumericType>& right) noexcept {
198  return left.Value() >= right.Value();
199 }
200 
201 template <typename NumericType>
202 inline std::ostream& operator<<(
203  std::ostream& stream,
204  const ScalarDisplacementGradient<NumericType>& scalar_displacement_gradient) {
205  stream << scalar_displacement_gradient.Print();
206  return stream;
207 }
208 
209 template <typename NumericType>
211  const NumericType number,
212  const ScalarDisplacementGradient<NumericType>& scalar_displacement_gradient) {
213  return ScalarDisplacementGradient<NumericType>{number * scalar_displacement_gradient.Value()};
214 }
215 
216 } // namespace PhQ
217 
218 namespace std {
219 
220 template <typename NumericType>
221 struct hash<PhQ::ScalarDisplacementGradient<NumericType>> {
222  inline size_t operator()(
223  const PhQ::ScalarDisplacementGradient<NumericType>& scalar_displacement_gradient) const {
224  return hash<NumericType>()(scalar_displacement_gradient.Value());
225  }
226 };
227 
228 } // namespace std
229 
230 #endif // PHQ_SCALAR_DISPLACEMENT_GRADIENT_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
Scalar component or resultant of a three-dimensional Euclidean displacement gradient dyadic tensor....
constexpr NumericType operator/(const ScalarDisplacementGradient< NumericType > &scalar_displacement_gradient) const noexcept
constexpr void operator*=(const NumericType number) noexcept
constexpr ScalarDisplacementGradient< NumericType > & operator=(ScalarDisplacementGradient< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this scalar displacement gradient by moving another one.
constexpr ScalarDisplacementGradient< NumericType > operator/(const NumericType number) const
constexpr ScalarDisplacementGradient< NumericType > & operator=(const ScalarDisplacementGradient< NumericType > &other)=default
Copy assignment operator. Assigns this scalar displacement gradient by copying another one.
static constexpr ScalarDisplacementGradient< NumericType > Zero()
Statically creates a scalar displacement gradient of zero.
constexpr ScalarDisplacementGradient(ScalarDisplacementGradient< NumericType > &&other) noexcept=default
Move constructor. Constructs a scalar displacement gradient by moving another one.
constexpr ScalarDisplacementGradient< NumericType > operator*(const NumericType number) const
~ScalarDisplacementGradient() noexcept=default
Destructor. Destroys this scalar displacement gradient.
constexpr ScalarDisplacementGradient< NumericType > & operator=(const ScalarDisplacementGradient< OtherNumericType > &other)
Copy assignment operator. Assigns this scalar displacement gradient by copying another one.
constexpr void operator+=(const ScalarDisplacementGradient< NumericType > &scalar_displacement_gradient) noexcept
constexpr void operator/=(const NumericType number) noexcept
constexpr ScalarDisplacementGradient< NumericType > operator+(const ScalarDisplacementGradient< NumericType > &scalar_displacement_gradient) const
ScalarDisplacementGradient()=default
Default constructor. Constructs a scalar displacement gradient with an uninitialized value.
constexpr ScalarDisplacementGradient< NumericType > operator-(const ScalarDisplacementGradient< NumericType > &scalar_displacement_gradient) const
constexpr void operator-=(const ScalarDisplacementGradient< NumericType > &scalar_displacement_gradient) noexcept
constexpr ScalarDisplacementGradient(const NumericType value)
Constructor. Constructs a scalar displacement gradient with a given value.
Scalar component or resultant of a three-dimensional Euclidean velocity gradient dyadic tensor....
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
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)