Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
ScalarVelocityGradient.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_VELOCITY_GRADIENT_HPP
26 #define PHQ_SCALAR_VELOCITY_GRADIENT_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 
32 #include "DimensionalScalar.hpp"
33 #include "Frequency.hpp"
35 #include "Time.hpp"
36 #include "Unit/Frequency.hpp"
37 
38 namespace PhQ {
39 
40 /// \brief Scalar component or resultant of a three-dimensional Euclidean velocity gradient dyadic
41 /// tensor. For the related tensor, see PhQ::VelocityGradient. Can also represent the time rate of
42 /// change of a scalar displacement gradient; see PhQ::ScalarDisplacementGradient, PhQ::Time, and
43 /// PhQ::Frequency.
44 template <typename NumericType = double>
45 class ScalarVelocityGradient : public DimensionalScalar<Unit::Frequency, NumericType> {
46 public:
47  /// \brief Default constructor. Constructs a scalar velocity gradient with an uninitialized value.
49 
50  /// \brief Constructor. Constructs a scalar velocity gradient with a given value expressed in a
51  /// given frequency unit.
52  ScalarVelocityGradient(const NumericType value, const Unit::Frequency unit)
53  : DimensionalScalar<Unit::Frequency, NumericType>(value, unit) {}
54 
55  /// \brief Constructor. Constructs a scalar velocity gradient from a given scalar displacement
56  /// gradient and time using the definition of speed.
58  const ScalarDisplacementGradient<NumericType>& scalar_displacement_gradient,
59  const Time<NumericType>& time)
60  : ScalarVelocityGradient<NumericType>(scalar_displacement_gradient.Value() / time.Value()) {}
61 
62  /// \brief Constructor. Constructs a scalar velocity gradient from a given scalar displacement
63  /// gradient and frequency using the definition of speed.
65  const ScalarDisplacementGradient<NumericType>& scalar_displacement_gradient,
66  const Frequency<NumericType>& frequency)
67  : ScalarVelocityGradient<NumericType>(
68  scalar_displacement_gradient.Value() * frequency.Value()) {}
69 
70  /// \brief Destructor. Destroys this scalar velocity gradient.
71  ~ScalarVelocityGradient() noexcept = default;
72 
73  /// \brief Copy constructor. Constructs a scalar velocity gradient by copying another one.
74  constexpr ScalarVelocityGradient(const ScalarVelocityGradient<NumericType>& other) = default;
75 
76  /// \brief Copy constructor. Constructs a scalar velocity gradient by copying another one.
77  template <typename OtherNumericType>
78  explicit constexpr ScalarVelocityGradient(const ScalarVelocityGradient<OtherNumericType>& other)
79  : ScalarVelocityGradient(static_cast<NumericType>(other.Value())) {}
80 
81  /// \brief Move constructor. Constructs a scalar velocity gradient by moving another one.
82  constexpr ScalarVelocityGradient(ScalarVelocityGradient<NumericType>&& other) noexcept = default;
83 
84  /// \brief Copy assignment operator. Assigns this scalar velocity gradient by copying another one.
86  const ScalarVelocityGradient<NumericType>& other) = default;
87 
88  /// \brief Copy assignment operator. Assigns this scalar velocity gradient by copying another one.
89  template <typename OtherNumericType>
92  this->value = static_cast<NumericType>(other.Value());
93  return *this;
94  }
95 
96  /// \brief Move assignment operator. Assigns this scalar velocity gradient by moving another one.
98  ScalarVelocityGradient<NumericType>&& other) noexcept = default;
99 
100  /// \brief Statically creates a scalar velocity gradient of zero.
101  [[nodiscard]] static constexpr ScalarVelocityGradient<NumericType> Zero() {
102  return ScalarVelocityGradient<NumericType>{static_cast<NumericType>(0)};
103  }
104 
105  /// \brief Statically creates a scalar velocity gradient with a given value expressed in a given
106  /// frequency unit.
107  template <Unit::Frequency Unit>
108  [[nodiscard]] static constexpr ScalarVelocityGradient<NumericType> Create(
109  const NumericType value) {
111  ConvertStatically<Unit::Frequency, Unit, Standard<Unit::Frequency>>(value)};
112  }
113 
115  const ScalarVelocityGradient<NumericType>& other) const {
116  return ScalarVelocityGradient<NumericType>{this->value + other.value};
117  }
118 
120  const ScalarVelocityGradient<NumericType>& other) const {
121  return ScalarVelocityGradient<NumericType>{this->value - other.value};
122  }
123 
124  constexpr ScalarVelocityGradient<NumericType> operator*(const NumericType number) const {
125  return ScalarVelocityGradient<NumericType>{this->value * number};
126  }
127 
128  constexpr ScalarVelocityGradient<NumericType> operator/(const NumericType number) const {
129  return ScalarVelocityGradient<NumericType>{this->value / number};
130  }
131 
133  return ScalarDisplacementGradient<NumericType>{*this, time};
134  }
135 
136  constexpr NumericType operator/(const ScalarVelocityGradient<NumericType>& other) const noexcept {
137  return this->value / other.value;
138  }
139 
141  const Frequency<NumericType>& frequency) const {
142  return ScalarDisplacementGradient<NumericType>{*this, frequency};
143  }
144 
145  constexpr void operator+=(const ScalarVelocityGradient<NumericType>& other) noexcept {
146  this->value += other.value;
147  }
148 
149  constexpr void operator-=(const ScalarVelocityGradient<NumericType>& other) noexcept {
150  this->value -= other.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 private:
162  /// \brief Constructor. Constructs a scalar velocity gradient with a given value expressed in the
163  /// standard frequency unit.
164  explicit constexpr ScalarVelocityGradient(const NumericType value)
165  : DimensionalScalar<Unit::Frequency, NumericType>(value) {}
166 
167  template <typename OtherNumericType>
168  friend class VelocityGradient;
169 };
170 
171 template <typename NumericType>
172 inline constexpr bool operator==(const ScalarVelocityGradient<NumericType>& left,
173  const ScalarVelocityGradient<NumericType>& right) noexcept {
174  return left.Value() == right.Value();
175 }
176 
177 template <typename NumericType>
178 inline constexpr bool operator!=(const ScalarVelocityGradient<NumericType>& left,
179  const ScalarVelocityGradient<NumericType>& right) noexcept {
180  return left.Value() != right.Value();
181 }
182 
183 template <typename NumericType>
184 inline constexpr bool operator<(const ScalarVelocityGradient<NumericType>& left,
185  const ScalarVelocityGradient<NumericType>& right) noexcept {
186  return left.Value() < right.Value();
187 }
188 
189 template <typename NumericType>
190 inline constexpr bool operator>(const ScalarVelocityGradient<NumericType>& left,
191  const ScalarVelocityGradient<NumericType>& right) noexcept {
192  return left.Value() > right.Value();
193 }
194 
195 template <typename NumericType>
196 inline constexpr bool operator<=(const ScalarVelocityGradient<NumericType>& left,
197  const ScalarVelocityGradient<NumericType>& right) noexcept {
198  return left.Value() <= right.Value();
199 }
200 
201 template <typename NumericType>
202 inline constexpr bool operator>=(const ScalarVelocityGradient<NumericType>& left,
203  const ScalarVelocityGradient<NumericType>& right) noexcept {
204  return left.Value() >= right.Value();
205 }
206 
207 template <typename NumericType>
208 inline std::ostream& operator<<(
209  std::ostream& stream, const ScalarVelocityGradient<NumericType>& scalar_velocity_gradient) {
210  stream << scalar_velocity_gradient.Print();
211  return stream;
212 }
213 
214 template <typename NumericType>
216  const NumericType number, const ScalarVelocityGradient<NumericType>& scalar_velocity_gradient) {
217  return scalar_velocity_gradient * number;
218 }
219 
220 template <typename NumericType>
222  const ScalarVelocityGradient<NumericType>& scalar_velocity_gradient,
223  const Time<NumericType>& time)
224  : ScalarDisplacementGradient<NumericType>(scalar_velocity_gradient.Value() * time.Value()) {}
225 
226 template <typename NumericType>
228  const ScalarVelocityGradient<NumericType>& scalar_velocity_gradient,
229  const Frequency<NumericType>& frequency)
230  : ScalarDisplacementGradient<NumericType>(scalar_velocity_gradient.Value() / frequency.Value()) {}
231 
232 template <typename NumericType>
235  return ScalarVelocityGradient<NumericType>{*this, frequency};
236 }
237 
238 template <typename NumericType>
241  return ScalarVelocityGradient<NumericType>{*this, time};
242 }
243 
244 template <typename NumericType>
246  const ScalarVelocityGradient<NumericType>& scalar_velocity_gradient) const {
247  return ScalarDisplacementGradient<NumericType>{scalar_velocity_gradient, *this};
248 }
249 
250 template <typename NumericType>
251 inline constexpr ScalarVelocityGradient<NumericType> Frequency<NumericType>::operator*(
252  const ScalarDisplacementGradient<NumericType>& scalar_displacement_gradient) const {
253  return ScalarVelocityGradient<NumericType>{scalar_displacement_gradient, *this};
254 }
255 
256 } // namespace PhQ
257 
258 namespace std {
259 
260 template <typename NumericType>
261 struct hash<PhQ::ScalarVelocityGradient<NumericType>> {
262  inline size_t operator()(
263  const PhQ::ScalarVelocityGradient<NumericType>& scalar_velocity_gradient) const {
264  return hash<NumericType>()(scalar_velocity_gradient.Value());
265  }
266 };
267 
268 } // namespace std
269 
270 #endif // PHQ_SCALAR_VELOCITY_GRADIENT_HPP
Abstract base class that represents any dimensional scalar physical quantity. Such a physical quantit...
double value
Value of this physical quantity expressed in its standard unit of measure.
constexpr double Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
static constexpr Unit::Frequency 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...
Frequency. Inverse of a time duration. See also PhQ::Time.
Definition: Frequency.hpp:40
constexpr Frequency< NumericType > operator*(const NumericType number) const
Definition: Frequency.hpp:154
Scalar component or resultant of a three-dimensional Euclidean displacement gradient dyadic tensor....
constexpr ScalarDisplacementGradient< NumericType > operator/(const NumericType number) const
constexpr ScalarDisplacementGradient< NumericType > operator*(const NumericType number) const
ScalarDisplacementGradient()=default
Default constructor. Constructs a scalar displacement gradient with an uninitialized value.
Scalar component or resultant of a three-dimensional Euclidean velocity gradient dyadic tensor....
constexpr ScalarVelocityGradient< NumericType > & operator=(const ScalarVelocityGradient< OtherNumericType > &other)
Copy assignment operator. Assigns this scalar velocity gradient by copying another one.
constexpr void operator+=(const ScalarVelocityGradient< NumericType > &other) noexcept
constexpr void operator-=(const ScalarVelocityGradient< NumericType > &other) noexcept
constexpr ScalarVelocityGradient(const ScalarDisplacementGradient< NumericType > &scalar_displacement_gradient, const Time< NumericType > &time)
Constructor. Constructs a scalar velocity gradient from a given scalar displacement gradient and time...
constexpr ScalarVelocityGradient< NumericType > operator*(const NumericType number) const
constexpr ScalarDisplacementGradient< NumericType > operator*(const Time< NumericType > &time) const
~ScalarVelocityGradient() noexcept=default
Destructor. Destroys this scalar velocity gradient.
static constexpr ScalarVelocityGradient< NumericType > Create(const NumericType value)
Statically creates a scalar velocity gradient with a given value expressed in a given frequency unit.
constexpr void operator*=(const NumericType number) noexcept
constexpr NumericType operator/(const ScalarVelocityGradient< NumericType > &other) const noexcept
constexpr ScalarVelocityGradient(const ScalarDisplacementGradient< NumericType > &scalar_displacement_gradient, const Frequency< NumericType > &frequency)
Constructor. Constructs a scalar velocity gradient from a given scalar displacement gradient and freq...
constexpr ScalarVelocityGradient< NumericType > & operator=(ScalarVelocityGradient< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this scalar velocity gradient by moving another one.
constexpr void operator/=(const NumericType number) noexcept
ScalarVelocityGradient(const NumericType value, const Unit::Frequency unit)
Constructor. Constructs a scalar velocity gradient with a given value expressed in a given frequency ...
constexpr ScalarVelocityGradient< NumericType > operator-(const ScalarVelocityGradient< NumericType > &other) const
constexpr ScalarVelocityGradient< NumericType > operator/(const NumericType number) const
constexpr ScalarVelocityGradient(const NumericType value)
Constructor. Constructs a scalar velocity gradient with a given value expressed in the standard frequ...
constexpr ScalarDisplacementGradient< NumericType > operator/(const Frequency< NumericType > &frequency) const
ScalarVelocityGradient()=default
Default constructor. Constructs a scalar velocity gradient with an uninitialized value.
constexpr ScalarVelocityGradient(ScalarVelocityGradient< NumericType > &&other) noexcept=default
Move constructor. Constructs a scalar velocity gradient by moving another one.
static constexpr ScalarVelocityGradient< NumericType > Zero()
Statically creates a scalar velocity gradient of zero.
constexpr ScalarVelocityGradient< NumericType > & operator=(const ScalarVelocityGradient< NumericType > &other)=default
Copy assignment operator. Assigns this scalar velocity gradient by copying another one.
constexpr ScalarVelocityGradient< NumericType > operator+(const ScalarVelocityGradient< NumericType > &other) const
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
Three-dimensional Euclidean velocity gradient dyadic tensor. Gradient of the velocity vector....
Frequency
Frequency units.
Definition: Frequency.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)