Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
AngularSpeed.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_UNIT_ANGULAR_SPEED_HPP
26 #define PHQ_UNIT_ANGULAR_SPEED_HPP
27 
28 #include <cstddef>
29 #include <cstdint>
30 #include <functional>
31 #include <map>
32 #include <ostream>
33 #include <string_view>
34 #include <unordered_map>
35 
36 #include "../Base.hpp"
37 #include "../Dimension/ElectricCurrent.hpp"
38 #include "../Dimension/Length.hpp"
39 #include "../Dimension/LuminousIntensity.hpp"
40 #include "../Dimension/Mass.hpp"
41 #include "../Dimension/SubstanceAmount.hpp"
42 #include "../Dimension/Temperature.hpp"
43 #include "../Dimension/Time.hpp"
44 #include "../Dimensions.hpp"
45 #include "../Unit.hpp"
46 #include "../UnitSystem.hpp"
47 
48 namespace PhQ {
49 
50 namespace Unit {
51 
52 /// \brief Angular speed units.
53 enum class AngularSpeed : int8_t {
54  /// \brief Radian per second (rad/s) angular speed unit.
56 
57  /// \brief Radian per minute (rad/min) angular speed unit.
59 
60  /// \brief Radian per hour (rad/hr) angular speed unit.
62 
63  /// \brief Degree per second (deg/s) angular speed unit.
65 
66  /// \brief Degree per minute (deg/min) angular speed unit.
68 
69  /// \brief Degree per hour (deg/hr) angular speed unit.
71 
72  /// \brief Arcminute per second (arcmin/s) angular speed unit.
74 
75  /// \brief Arcminute per minute (arcmin/min) angular speed unit.
77 
78  /// \brief Arcminute per hour (arcmin/hr) angular speed unit.
80 
81  /// \brief Arcsecond per second (arcsec/s) angular speed unit.
83 
84  /// \brief Arcsecond per minute (arcsec/min) angular speed unit.
86 
87  /// \brief Arcsecond per hour (arcsec/hr) angular speed unit.
89 
90  /// \brief Revolution per second (rev/s) angular speed unit.
92 
93  /// \brief Revolution per minute (rev/min) angular speed unit.
95 
96  /// \brief Revolution per hour (rev/hr) angular speed unit.
98 };
99 
100 } // namespace Unit
101 
102 /// \brief Standard angular speed unit: radian per second (rad/s).
103 template <>
104 inline constexpr const Unit::AngularSpeed Standard<Unit::AngularSpeed>{
106 
107 /// \brief Physical dimension set of angular speed units.
108 template <>
109 inline constexpr const Dimensions RelatedDimensions<Unit::AngularSpeed>{
110  Dimensions{Dimension::Time{-1}, Dimension::Length{0}, Dimension::Mass{0},
112  Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
113 };
114 
115 inline std::ostream& operator<<(std::ostream& stream, const Unit::AngularSpeed unit) {
116  stream << Abbreviation(unit);
117  return stream;
118 }
119 
120 namespace Internal {
121 
122 template <>
123 inline const std::map<UnitSystem, Unit::AngularSpeed> ConsistentUnits<Unit::AngularSpeed>{
128 };
129 
130 template <>
131 inline const std::map<Unit::AngularSpeed, UnitSystem> RelatedUnitSystems<Unit::AngularSpeed>{};
132 
133 template <>
134 inline const std::map<Unit::AngularSpeed, std::string_view> Abbreviations<Unit::AngularSpeed>{
143  {Unit::AngularSpeed::ArcminutePerHour, "arcmin/hr" },
146  {Unit::AngularSpeed::ArcsecondPerHour, "arcsec/hr" },
150 };
151 
152 // clang-format off
153 
154 template <>
155 inline const std::unordered_map<std::string_view, Unit::AngularSpeed> Spellings<Unit::AngularSpeed>{
167  {"arcmin/hr", Unit::AngularSpeed::ArcminutePerHour },
170  {"arcsec/hr", Unit::AngularSpeed::ArcsecondPerHour },
174 };
175 
176 // clang-format on
177 
178 template <>
179 template <typename NumericType>
180 inline constexpr void
181 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::RadianPerSecond>::FromStandard(
182  NumericType& /*value*/) noexcept {}
183 
184 template <>
185 template <typename NumericType>
186 inline constexpr void
187 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::RadianPerSecond>::ToStandard(
188  NumericType& /*value*/) noexcept {}
189 
190 template <>
191 template <typename NumericType>
192 inline constexpr void
193 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::RadianPerMinute>::FromStandard(
194  NumericType& value) noexcept {
195  value *= static_cast<NumericType>(60.0L);
196 }
197 
198 template <>
199 template <typename NumericType>
200 inline constexpr void
201 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::RadianPerMinute>::ToStandard(
202  NumericType& value) noexcept {
203  value /= static_cast<NumericType>(60.0L);
204 }
205 
206 template <>
207 template <typename NumericType>
208 inline constexpr void
209 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::RadianPerHour>::FromStandard(
210  NumericType& value) noexcept {
211  value *= static_cast<NumericType>(3600.0L);
212 }
213 
214 template <>
215 template <typename NumericType>
216 inline constexpr void Conversion<Unit::AngularSpeed, Unit::AngularSpeed::RadianPerHour>::ToStandard(
217  NumericType& value) noexcept {
218  value /= static_cast<NumericType>(3600.0L);
219 }
220 
221 template <>
222 template <typename NumericType>
223 inline constexpr void
224 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::DegreePerSecond>::FromStandard(
225  NumericType& value) noexcept {
226  value *= static_cast<NumericType>(180.0L) / Pi<NumericType>;
227 }
228 
229 template <>
230 template <typename NumericType>
231 inline constexpr void
232 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::DegreePerSecond>::ToStandard(
233  NumericType& value) noexcept {
234  value *= Pi<NumericType> / static_cast<NumericType>(180.0L);
235 }
236 
237 template <>
238 template <typename NumericType>
239 inline constexpr void
240 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::DegreePerMinute>::FromStandard(
241  NumericType& value) noexcept {
242  value *= static_cast<NumericType>(10800.0L) / Pi<NumericType>;
243 }
244 
245 template <>
246 template <typename NumericType>
247 inline constexpr void
248 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::DegreePerMinute>::ToStandard(
249  NumericType& value) noexcept {
250  value *= Pi<NumericType> / static_cast<NumericType>(10800.0L);
251 }
252 
253 template <>
254 template <typename NumericType>
255 inline constexpr void
256 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::DegreePerHour>::FromStandard(
257  NumericType& value) noexcept {
258  value *= static_cast<NumericType>(648000.0L) / Pi<NumericType>;
259 }
260 
261 template <>
262 template <typename NumericType>
263 inline constexpr void Conversion<Unit::AngularSpeed, Unit::AngularSpeed::DegreePerHour>::ToStandard(
264  NumericType& value) noexcept {
265  value *= Pi<NumericType> / static_cast<NumericType>(648000.0L);
266 }
267 
268 template <>
269 template <typename NumericType>
270 inline constexpr void
271 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::ArcminutePerSecond>::FromStandard(
272  NumericType& value) noexcept {
273  value *= static_cast<NumericType>(10800.0L) / Pi<NumericType>;
274 }
275 
276 template <>
277 template <typename NumericType>
278 inline constexpr void
279 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::ArcminutePerSecond>::ToStandard(
280  NumericType& value) noexcept {
281  value *= Pi<NumericType> / static_cast<NumericType>(10800.0L);
282 }
283 
284 template <>
285 template <typename NumericType>
286 inline constexpr void
287 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::ArcminutePerMinute>::FromStandard(
288  NumericType& value) noexcept {
289  value *= static_cast<NumericType>(648000.0L) / Pi<NumericType>;
290 }
291 
292 template <>
293 template <typename NumericType>
294 inline constexpr void
295 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::ArcminutePerMinute>::ToStandard(
296  NumericType& value) noexcept {
297  value *= Pi<NumericType> / static_cast<NumericType>(648000.0L);
298 }
299 
300 template <>
301 template <typename NumericType>
302 inline constexpr void
303 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::ArcminutePerHour>::FromStandard(
304  NumericType& value) noexcept {
305  value *= static_cast<NumericType>(38880000.0L) / Pi<NumericType>;
306 }
307 
308 template <>
309 template <typename NumericType>
310 inline constexpr void
311 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::ArcminutePerHour>::ToStandard(
312  NumericType& value) noexcept {
313  value *= Pi<NumericType> / static_cast<NumericType>(38880000.0L);
314 }
315 
316 template <>
317 template <typename NumericType>
318 inline constexpr void
319 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::ArcsecondPerSecond>::FromStandard(
320  NumericType& value) noexcept {
321  value *= static_cast<NumericType>(648000.0L) / Pi<NumericType>;
322 }
323 
324 template <>
325 template <typename NumericType>
326 inline constexpr void
327 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::ArcsecondPerSecond>::ToStandard(
328  NumericType& value) noexcept {
329  value *= Pi<NumericType> / static_cast<NumericType>(648000.0L);
330 }
331 
332 template <>
333 template <typename NumericType>
334 inline constexpr void
335 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::ArcsecondPerMinute>::FromStandard(
336  NumericType& value) noexcept {
337  value *= static_cast<NumericType>(38880000.0L) / Pi<NumericType>;
338 }
339 
340 template <>
341 template <typename NumericType>
342 inline constexpr void
343 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::ArcsecondPerMinute>::ToStandard(
344  NumericType& value) noexcept {
345  value *= Pi<NumericType> / static_cast<NumericType>(38880000.0L);
346 }
347 
348 template <>
349 template <typename NumericType>
350 inline constexpr void
351 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::ArcsecondPerHour>::FromStandard(
352  NumericType& value) noexcept {
353  value *= static_cast<NumericType>(2332800000.0L) / Pi<NumericType>;
354 }
355 
356 template <>
357 template <typename NumericType>
358 inline constexpr void
359 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::ArcsecondPerHour>::ToStandard(
360  NumericType& value) noexcept {
361  value *= Pi<NumericType> / static_cast<NumericType>(2332800000.0L);
362 }
363 
364 template <>
365 template <typename NumericType>
366 inline constexpr void
367 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::RevolutionPerSecond>::FromStandard(
368  NumericType& value) noexcept {
369  value *= static_cast<NumericType>(0.5L) / Pi<NumericType>;
370 }
371 
372 template <>
373 template <typename NumericType>
374 inline constexpr void
375 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::RevolutionPerSecond>::ToStandard(
376  NumericType& value) noexcept {
377  value *= static_cast<NumericType>(2.0L) * Pi<NumericType>;
378 }
379 
380 template <>
381 template <typename NumericType>
382 inline constexpr void
383 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::RevolutionPerMinute>::FromStandard(
384  NumericType& value) noexcept {
385  value *= static_cast<NumericType>(30.0L) / Pi<NumericType>;
386 }
387 
388 template <>
389 template <typename NumericType>
390 inline constexpr void
391 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::RevolutionPerMinute>::ToStandard(
392  NumericType& value) noexcept {
393  value *= Pi<NumericType> / static_cast<NumericType>(30.0L);
394 }
395 
396 template <>
397 template <typename NumericType>
398 inline constexpr void
399 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::RevolutionPerHour>::FromStandard(
400  NumericType& value) noexcept {
401  value *= static_cast<NumericType>(1800.0L) / Pi<NumericType>;
402 }
403 
404 template <>
405 template <typename NumericType>
406 inline constexpr void
407 Conversion<Unit::AngularSpeed, Unit::AngularSpeed::RevolutionPerHour>::ToStandard(
408  NumericType& value) noexcept {
409  value *= Pi<NumericType> / static_cast<NumericType>(1800.0L);
410 }
411 
412 template <typename NumericType>
413 inline const std::map<Unit::AngularSpeed,
414  std::function<void(NumericType* values, const std::size_t size)>>
415  MapOfConversionsFromStandard<Unit::AngularSpeed, NumericType>{
417  Conversions<Unit::AngularSpeed,
418  Unit::AngularSpeed::RadianPerSecond>::FromStandard<NumericType> },
420  Conversions<Unit::AngularSpeed,
421  Unit::AngularSpeed::RadianPerMinute>::FromStandard<NumericType> },
423  Conversions<Unit::AngularSpeed,
424  Unit::AngularSpeed::RadianPerHour>::FromStandard<NumericType> },
426  Conversions<Unit::AngularSpeed,
427  Unit::AngularSpeed::DegreePerSecond>::FromStandard<NumericType> },
429  Conversions<Unit::AngularSpeed,
430  Unit::AngularSpeed::DegreePerMinute>::FromStandard<NumericType> },
432  Conversions<Unit::AngularSpeed,
433  Unit::AngularSpeed::DegreePerHour>::FromStandard<NumericType> },
435  Conversions<Unit::AngularSpeed,
436  Unit::AngularSpeed::ArcminutePerSecond>::FromStandard<NumericType> },
438  Conversions<Unit::AngularSpeed,
439  Unit::AngularSpeed::ArcminutePerMinute>::FromStandard<NumericType> },
441  Conversions<Unit::AngularSpeed,
442  Unit::AngularSpeed::ArcminutePerHour>::FromStandard<NumericType> },
444  Conversions<Unit::AngularSpeed,
445  Unit::AngularSpeed::ArcsecondPerSecond>::FromStandard<NumericType> },
447  Conversions<Unit::AngularSpeed,
448  Unit::AngularSpeed::ArcsecondPerMinute>::FromStandard<NumericType> },
450  Conversions<Unit::AngularSpeed,
451  Unit::AngularSpeed::ArcsecondPerHour>::FromStandard<NumericType> },
453  Conversions<Unit::AngularSpeed,
454  Unit::AngularSpeed::RevolutionPerSecond>::FromStandard<NumericType>},
456  Conversions<Unit::AngularSpeed,
457  Unit::AngularSpeed::RevolutionPerMinute>::FromStandard<NumericType>},
459  Conversions<Unit::AngularSpeed,
460  Unit::AngularSpeed::RevolutionPerHour>::FromStandard<NumericType> },
461 };
462 
463 template <typename NumericType>
464 inline const std::map<Unit::AngularSpeed,
465  std::function<void(NumericType* const values, const std::size_t size)>>
466  MapOfConversionsToStandard<Unit::AngularSpeed, NumericType>{
468  Conversions<Unit::AngularSpeed,
469  Unit::AngularSpeed::RadianPerSecond>::ToStandard<NumericType> },
471  Conversions<Unit::AngularSpeed,
472  Unit::AngularSpeed::RadianPerMinute>::ToStandard<NumericType> },
474  Conversions<Unit::AngularSpeed,
475  Unit::AngularSpeed::RadianPerHour>::ToStandard<NumericType> },
477  Conversions<Unit::AngularSpeed,
478  Unit::AngularSpeed::DegreePerSecond>::ToStandard<NumericType> },
480  Conversions<Unit::AngularSpeed,
481  Unit::AngularSpeed::DegreePerMinute>::ToStandard<NumericType> },
483  Conversions<Unit::AngularSpeed,
484  Unit::AngularSpeed::DegreePerHour>::ToStandard<NumericType> },
486  Conversions<Unit::AngularSpeed,
487  Unit::AngularSpeed::ArcminutePerSecond>::ToStandard<NumericType> },
489  Conversions<Unit::AngularSpeed,
490  Unit::AngularSpeed::ArcminutePerMinute>::ToStandard<NumericType> },
492  Conversions<Unit::AngularSpeed,
493  Unit::AngularSpeed::ArcminutePerHour>::ToStandard<NumericType> },
495  Conversions<Unit::AngularSpeed,
496  Unit::AngularSpeed::ArcsecondPerSecond>::ToStandard<NumericType> },
498  Conversions<Unit::AngularSpeed,
499  Unit::AngularSpeed::ArcsecondPerMinute>::ToStandard<NumericType> },
501  Conversions<Unit::AngularSpeed,
502  Unit::AngularSpeed::ArcsecondPerHour>::ToStandard<NumericType> },
504  Conversions<Unit::AngularSpeed,
505  Unit::AngularSpeed::RevolutionPerSecond>::ToStandard<NumericType>},
507  Conversions<Unit::AngularSpeed,
508  Unit::AngularSpeed::RevolutionPerMinute>::ToStandard<NumericType>},
510  Conversions<Unit::AngularSpeed,
511  Unit::AngularSpeed::RevolutionPerHour>::ToStandard<NumericType> },
512 };
513 
514 } // namespace Internal
515 
516 } // namespace PhQ
517 
518 #endif // PHQ_UNIT_ANGULAR_SPEED_HPP
ElectricCurrent
Electric current units.
Mass
Mass units.
Definition: Mass.hpp:53
Length
Length units.
Definition: Length.hpp:53
SubstanceAmount
Amount of substance units.
Temperature
Temperature units. Not to be confused with temperature difference units. For example,...
Definition: Temperature.hpp:55
Time
Time units.
Definition: Time.hpp:53
AngularSpeed
Angular speed units.
@ ArcminutePerHour
Arcminute per hour (arcmin/hr) angular speed unit.
@ ArcminutePerSecond
Arcminute per second (arcmin/s) angular speed unit.
@ DegreePerHour
Degree per hour (deg/hr) angular speed unit.
@ RevolutionPerMinute
Revolution per minute (rev/min) angular speed unit.
@ RevolutionPerSecond
Revolution per second (rev/s) angular speed unit.
@ ArcsecondPerSecond
Arcsecond per second (arcsec/s) angular speed unit.
@ RevolutionPerHour
Revolution per hour (rev/hr) angular speed unit.
@ RadianPerSecond
Radian per second (rad/s) angular speed unit.
@ ArcminutePerMinute
Arcminute per minute (arcmin/min) angular speed unit.
@ RadianPerHour
Radian per hour (rad/hr) angular speed unit.
@ ArcsecondPerMinute
Arcsecond per minute (arcsec/min) angular speed unit.
@ DegreePerSecond
Degree per second (deg/s) angular speed unit.
@ DegreePerMinute
Degree per minute (deg/min) angular speed unit.
@ ArcsecondPerHour
Arcsecond per hour (arcsec/hr) angular speed unit.
@ RadianPerMinute
Radian per minute (rad/min) angular speed unit.
Namespace that encompasses all of the Physical Quantities library's content.
@ FootPoundSecondRankine
Foot-pound-second-rankine (ft·lbf·s·°R) system.
@ MillimetreGramSecondKelvin
Millimetre-gram-second-kelvin (mm·g·s·K) system.
@ MetreKilogramSecondKelvin
Metre-kilogram-second-kelvin (m·kg·s·K) system.
@ InchPoundSecondRankine
Inch-pound-second-rankine (in·lbf·s·°R) system.
std::string_view Abbreviation(const Enumeration enumeration)
Returns the abbreviation of a given enumeration value. For example, PhQ::Abbreviation(PhQ::Unit::Time...
Definition: Base.hpp:89
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)