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
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
38namespace 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.
44template <typename NumericType = double>
45class ScalarVelocityGradient : public DimensionalScalar<Unit::Frequency, NumericType> {
46public:
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
118
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
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
161private:
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
171template <typename NumericType>
172inline constexpr bool operator==(const ScalarVelocityGradient<NumericType>& left,
173 const ScalarVelocityGradient<NumericType>& right) noexcept {
174 return left.Value() == right.Value();
175}
176
177template <typename NumericType>
178inline constexpr bool operator!=(const ScalarVelocityGradient<NumericType>& left,
179 const ScalarVelocityGradient<NumericType>& right) noexcept {
180 return left.Value() != right.Value();
181}
182
183template <typename NumericType>
184inline constexpr bool operator<(const ScalarVelocityGradient<NumericType>& left,
185 const ScalarVelocityGradient<NumericType>& right) noexcept {
186 return left.Value() < right.Value();
187}
188
189template <typename NumericType>
190inline constexpr bool operator>(const ScalarVelocityGradient<NumericType>& left,
191 const ScalarVelocityGradient<NumericType>& right) noexcept {
192 return left.Value() > right.Value();
193}
194
195template <typename NumericType>
196inline constexpr bool operator<=(const ScalarVelocityGradient<NumericType>& left,
197 const ScalarVelocityGradient<NumericType>& right) noexcept {
198 return left.Value() <= right.Value();
199}
200
201template <typename NumericType>
202inline constexpr bool operator>=(const ScalarVelocityGradient<NumericType>& left,
203 const ScalarVelocityGradient<NumericType>& right) noexcept {
204 return left.Value() >= right.Value();
205}
206
207template <typename NumericType>
208inline std::ostream& operator<<(
209 std::ostream& stream, const ScalarVelocityGradient<NumericType>& scalar_velocity_gradient) {
210 stream << scalar_velocity_gradient.Print();
211 return stream;
212}
213
214template <typename NumericType>
216 const NumericType number, const ScalarVelocityGradient<NumericType>& scalar_velocity_gradient) {
217 return scalar_velocity_gradient * number;
218}
219
220template <typename NumericType>
222 const ScalarVelocityGradient<NumericType>& scalar_velocity_gradient,
223 const Time<NumericType>& time)
224 : ScalarDisplacementGradient<NumericType>(scalar_velocity_gradient.Value() * time.Value()) {}
225
226template <typename NumericType>
228 const ScalarVelocityGradient<NumericType>& scalar_velocity_gradient,
229 const Frequency<NumericType>& frequency)
230 : ScalarDisplacementGradient<NumericType>(scalar_velocity_gradient.Value() / frequency.Value()) {}
231
232template <typename NumericType>
237
238template <typename NumericType>
243
244template <typename NumericType>
246 const ScalarVelocityGradient<NumericType>& scalar_velocity_gradient) const {
247 return ScalarDisplacementGradient<NumericType>{scalar_velocity_gradient, *this};
248}
249
250template <typename NumericType>
252 const ScalarDisplacementGradient<NumericType>& scalar_displacement_gradient) const {
253 return ScalarVelocityGradient<NumericType>{scalar_displacement_gradient, *this};
254}
255
256} // namespace PhQ
257
258namespace std {
259
260template <typename NumericType>
261struct 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
constexpr const PhQ::Dyad< NumericType > & Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
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...
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 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< NumericType > &other) const
constexpr ScalarVelocityGradient< NumericType > operator+(const ScalarVelocityGradient< NumericType > &other) const
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 ScalarDisplacementGradient< NumericType > operator/(const Frequency< NumericType > &frequency) const
~ScalarVelocityGradient() noexcept=default
Destructor. Destroys this scalar velocity gradient.
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
constexpr ScalarDisplacementGradient< NumericType > operator*(const Time< NumericType > &time) const
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)=default
Copy assignment operator. Assigns this scalar velocity gradient by copying another one.
constexpr ScalarVelocityGradient< NumericType > & operator=(const ScalarVelocityGradient< OtherNumericType > &other)
Copy assignment operator. Assigns this scalar velocity gradient by copying another one.
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...
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 > Create(const NumericType value)
Statically creates a scalar velocity gradient with a given value expressed in a given frequency unit.
constexpr ScalarVelocityGradient< NumericType > operator*(const NumericType number) const
static constexpr ScalarVelocityGradient< NumericType > Zero()
Statically creates a scalar velocity gradient of zero.
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.
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