Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
Diffusivity.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_DIFFUSIVITY_HPP
26 #define PHQ_UNIT_DIFFUSIVITY_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 Diffusivity units.
53 enum class Diffusivity : int8_t {
54  /// \brief Square metre per second (m^2/s) diffusivity unit.
56 
57  /// \brief Square nautical mile per second (nmi^2/s) diffusivity unit.
59 
60  /// \brief Square mile per second (mi^2/s) diffusivity unit.
62 
63  /// \brief Square kilometre per second (km^2/s) diffusivity unit.
65 
66  /// \brief Hectare per second (ha/s) diffusivity unit.
68 
69  /// \brief Acre per second (ac/s) diffusivity unit.
71 
72  /// \brief Square yard per second (yd^2/s) diffusivity unit.
74 
75  /// \brief Square foot per second (ft^2/s) diffusivity unit.
77 
78  /// \brief Square decimetre per second (dm^2/s) diffusivity unit.
80 
81  /// \brief Square inch per second (in^2/s) diffusivity unit.
83 
84  /// \brief Square centimetre per second (cm^2/s) diffusivity unit.
86 
87  /// \brief Square millimetre per second (mm^2/s) diffusivity unit.
89 
90  /// \brief Square milliinch per second (mil^2/s) diffusivity unit.
92 
93  /// \brief Square micrometre per second (μm^2/s) diffusivity unit.
95 
96  /// \brief Square microinch per second (μin^2/s) diffusivity unit.
98 };
99 
100 } // namespace Unit
101 
102 /// \brief Standard diffusivity unit: square metre per second (m^2/s).
103 template <>
104 inline constexpr const Unit::Diffusivity Standard<Unit::Diffusivity>{
106 
107 /// \brief Physical dimension set of diffusivity units.
108 template <>
109 inline constexpr const Dimensions RelatedDimensions<Unit::Diffusivity>{
110  Dimensions{Dimension::Time{-1}, Dimension::Length{2}, Dimension::Mass{0},
112  Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
113 };
114 
115 inline std::ostream& operator<<(std::ostream& stream, const Unit::Diffusivity unit) {
116  stream << Abbreviation(unit);
117  return stream;
118 }
119 
120 namespace Internal {
121 
122 template <>
123 inline const std::map<UnitSystem, Unit::Diffusivity> ConsistentUnits<Unit::Diffusivity>{
128 };
129 
130 template <>
131 inline const std::map<Unit::Diffusivity, UnitSystem> RelatedUnitSystems<Unit::Diffusivity>{
136 };
137 
138 // clang-format off
139 
140 template <>
141 inline const std::map<Unit::Diffusivity, std::string_view> Abbreviations<Unit::Diffusivity>{
157 };
158 
159 template <>
160 inline const std::unordered_map<std::string_view, Unit::Diffusivity> Spellings<Unit::Diffusivity>{
199 };
200 
201 // clang-format on
202 
203 template <>
204 template <typename NumericType>
205 inline constexpr void
206 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareMetrePerSecond>::FromStandard(
207  NumericType& /*value*/) noexcept {}
208 
209 template <>
210 template <typename NumericType>
211 inline constexpr void
212 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareMetrePerSecond>::ToStandard(
213  NumericType& /*value*/) noexcept {}
214 
215 template <>
216 template <typename NumericType>
217 inline constexpr void
218 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareNauticalMilePerSecond>::FromStandard(
219  NumericType& value) noexcept {
220  value /= static_cast<NumericType>(1852.0L) * static_cast<NumericType>(1852.0L);
221 }
222 
223 template <>
224 template <typename NumericType>
225 inline constexpr void
226 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareNauticalMilePerSecond>::ToStandard(
227  NumericType& value) noexcept {
228  value *= static_cast<NumericType>(1852.0L) * static_cast<NumericType>(1852.0L);
229 }
230 
231 template <>
232 template <typename NumericType>
233 inline constexpr void
234 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareMilePerSecond>::FromStandard(
235  NumericType& value) noexcept {
236  value /= static_cast<NumericType>(1609.344L) * static_cast<NumericType>(1609.344L);
237 }
238 
239 template <>
240 template <typename NumericType>
241 inline constexpr void
242 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareMilePerSecond>::ToStandard(
243  NumericType& value) noexcept {
244  value *= static_cast<NumericType>(1609.344L) * static_cast<NumericType>(1609.344L);
245 }
246 
247 template <>
248 template <typename NumericType>
249 inline constexpr void
250 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareKilometrePerSecond>::FromStandard(
251  NumericType& value) noexcept {
252  value *= static_cast<NumericType>(0.000001L);
253 }
254 
255 template <>
256 template <typename NumericType>
257 inline constexpr void
258 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareKilometrePerSecond>::ToStandard(
259  NumericType& value) noexcept {
260  value *= static_cast<NumericType>(1000000.0L);
261 }
262 
263 template <>
264 template <typename NumericType>
265 inline constexpr void
266 Conversion<Unit::Diffusivity, Unit::Diffusivity::HectarePerSecond>::FromStandard(
267  NumericType& value) noexcept {
268  value *= static_cast<NumericType>(0.0001L);
269 }
270 
271 template <>
272 template <typename NumericType>
273 inline constexpr void
274 Conversion<Unit::Diffusivity, Unit::Diffusivity::HectarePerSecond>::ToStandard(
275  NumericType& value) noexcept {
276  value *= static_cast<NumericType>(10000.0L);
277 }
278 
279 template <>
280 template <typename NumericType>
281 inline constexpr void Conversion<Unit::Diffusivity, Unit::Diffusivity::AcrePerSecond>::FromStandard(
282  NumericType& value) noexcept {
283  value *= static_cast<NumericType>(640.0L)
284  / (static_cast<NumericType>(1609.344L) * static_cast<NumericType>(1609.344L));
285 }
286 
287 template <>
288 template <typename NumericType>
289 inline constexpr void Conversion<Unit::Diffusivity, Unit::Diffusivity::AcrePerSecond>::ToStandard(
290  NumericType& value) noexcept {
291  value *= static_cast<NumericType>(1609.344L) * static_cast<NumericType>(1609.344L)
292  / static_cast<NumericType>(640.0L);
293 }
294 
295 template <>
296 template <typename NumericType>
297 inline constexpr void
298 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareYardPerSecond>::FromStandard(
299  NumericType& value) noexcept {
300  value /= static_cast<NumericType>(0.9144L) * static_cast<NumericType>(0.9144L);
301 }
302 
303 template <>
304 template <typename NumericType>
305 inline constexpr void
306 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareYardPerSecond>::ToStandard(
307  NumericType& value) noexcept {
308  value *= static_cast<NumericType>(0.9144L) * static_cast<NumericType>(0.9144L);
309 }
310 
311 template <>
312 template <typename NumericType>
313 inline constexpr void
314 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareFootPerSecond>::FromStandard(
315  NumericType& value) noexcept {
316  value /= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L);
317 }
318 
319 template <>
320 template <typename NumericType>
321 inline constexpr void
322 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareFootPerSecond>::ToStandard(
323  NumericType& value) noexcept {
324  value *= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L);
325 }
326 
327 template <>
328 template <typename NumericType>
329 inline constexpr void
330 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareDecimetrePerSecond>::FromStandard(
331  NumericType& value) noexcept {
332  value *= static_cast<NumericType>(100.0L);
333 }
334 
335 template <>
336 template <typename NumericType>
337 inline constexpr void
338 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareDecimetrePerSecond>::ToStandard(
339  NumericType& value) noexcept {
340  value *= static_cast<NumericType>(0.01L);
341 }
342 
343 template <>
344 template <typename NumericType>
345 inline constexpr void
346 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareInchPerSecond>::FromStandard(
347  NumericType& value) noexcept {
348  value /= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L);
349 }
350 
351 template <>
352 template <typename NumericType>
353 inline constexpr void
354 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareInchPerSecond>::ToStandard(
355  NumericType& value) noexcept {
356  value *= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L);
357 }
358 
359 template <>
360 template <typename NumericType>
361 inline constexpr void
362 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareCentimetrePerSecond>::FromStandard(
363  NumericType& value) noexcept {
364  value *= static_cast<NumericType>(10000.0L);
365 }
366 
367 template <>
368 template <typename NumericType>
369 inline constexpr void
370 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareCentimetrePerSecond>::ToStandard(
371  NumericType& value) noexcept {
372  value *= static_cast<NumericType>(0.0001L);
373 }
374 
375 template <>
376 template <typename NumericType>
377 inline constexpr void
378 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareMillimetrePerSecond>::FromStandard(
379  NumericType& value) noexcept {
380  value *= static_cast<NumericType>(1000000.0L);
381 }
382 
383 template <>
384 template <typename NumericType>
385 inline constexpr void
386 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareMillimetrePerSecond>::ToStandard(
387  NumericType& value) noexcept {
388  value *= static_cast<NumericType>(0.000001L);
389 }
390 
391 template <>
392 template <typename NumericType>
393 inline constexpr void
394 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareMilliinchPerSecond>::FromStandard(
395  NumericType& value) noexcept {
396  value /= static_cast<NumericType>(0.0000254L) * static_cast<NumericType>(0.0000254L);
397 }
398 
399 template <>
400 template <typename NumericType>
401 inline constexpr void
402 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareMilliinchPerSecond>::ToStandard(
403  NumericType& value) noexcept {
404  value *= static_cast<NumericType>(0.0000254L) * static_cast<NumericType>(0.0000254L);
405 }
406 
407 template <>
408 template <typename NumericType>
409 inline constexpr void
410 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareMicrometrePerSecond>::FromStandard(
411  NumericType& value) noexcept {
412  value *= static_cast<NumericType>(1000000000000.0L);
413 }
414 
415 template <>
416 template <typename NumericType>
417 inline constexpr void
418 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareMicrometrePerSecond>::ToStandard(
419  NumericType& value) noexcept {
420  value *= static_cast<NumericType>(0.000000000001L);
421 }
422 
423 template <>
424 template <typename NumericType>
425 inline constexpr void
426 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareMicroinchPerSecond>::FromStandard(
427  NumericType& value) noexcept {
428  value /= static_cast<NumericType>(0.0000000254L) * static_cast<NumericType>(0.0000000254L);
429 }
430 
431 template <>
432 template <typename NumericType>
433 inline constexpr void
434 Conversion<Unit::Diffusivity, Unit::Diffusivity::SquareMicroinchPerSecond>::ToStandard(
435  NumericType& value) noexcept {
436  value *= static_cast<NumericType>(0.0000000254L) * static_cast<NumericType>(0.0000000254L);
437 }
438 
439 template <typename NumericType>
440 inline const std::map<Unit::Diffusivity,
441  std::function<void(NumericType* const, const std::size_t size)>>
442  MapOfConversionsFromStandard<Unit::Diffusivity, NumericType>{
444  Conversions<Unit::Diffusivity,
445  Unit::Diffusivity::SquareMetrePerSecond>::FromStandard<NumericType> },
447  Conversions<Unit::Diffusivity,
448  Unit::Diffusivity::SquareNauticalMilePerSecond>::FromStandard<NumericType>},
450  Conversions<Unit::Diffusivity,
451  Unit::Diffusivity::SquareMilePerSecond>::FromStandard<NumericType> },
453  Conversions<Unit::Diffusivity,
454  Unit::Diffusivity::SquareKilometrePerSecond>::FromStandard<NumericType> },
456  Conversions<Unit::Diffusivity,
457  Unit::Diffusivity::HectarePerSecond>::FromStandard<NumericType> },
459  Conversions<Unit::Diffusivity,
460  Unit::Diffusivity::AcrePerSecond>::FromStandard<NumericType> },
462  Conversions<Unit::Diffusivity,
463  Unit::Diffusivity::SquareYardPerSecond>::FromStandard<NumericType> },
465  Conversions<Unit::Diffusivity,
466  Unit::Diffusivity::SquareFootPerSecond>::FromStandard<NumericType> },
468  Conversions<Unit::Diffusivity,
469  Unit::Diffusivity::SquareDecimetrePerSecond>::FromStandard<NumericType> },
471  Conversions<Unit::Diffusivity,
472  Unit::Diffusivity::SquareInchPerSecond>::FromStandard<NumericType> },
474  Conversions<Unit::Diffusivity,
475  Unit::Diffusivity::SquareCentimetrePerSecond>::FromStandard<NumericType> },
477  Conversions<Unit::Diffusivity,
478  Unit::Diffusivity::SquareMillimetrePerSecond>::FromStandard<NumericType> },
480  Conversions<Unit::Diffusivity,
481  Unit::Diffusivity::SquareMilliinchPerSecond>::FromStandard<NumericType> },
483  Conversions<Unit::Diffusivity,
484  Unit::Diffusivity::SquareMicrometrePerSecond>::FromStandard<NumericType> },
486  Conversions<Unit::Diffusivity,
487  Unit::Diffusivity::SquareMicroinchPerSecond>::FromStandard<NumericType> },
488 };
489 
490 template <typename NumericType>
491 inline const std::map<Unit::Diffusivity,
492  std::function<void(NumericType* values, const std::size_t size)>>
493  MapOfConversionsToStandard<Unit::Diffusivity, NumericType>{
495  Conversions<Unit::Diffusivity,
496  Unit::Diffusivity::SquareMetrePerSecond>::ToStandard<NumericType> },
498  Conversions<Unit::Diffusivity,
499  Unit::Diffusivity::SquareNauticalMilePerSecond>::ToStandard<NumericType> },
501  Conversions<Unit::Diffusivity,
502  Unit::Diffusivity::SquareMilePerSecond>::ToStandard<NumericType> },
504  Conversions<Unit::Diffusivity,
505  Unit::Diffusivity::SquareKilometrePerSecond>::ToStandard<NumericType> },
507  Conversions<Unit::Diffusivity,
508  Unit::Diffusivity::HectarePerSecond>::ToStandard<NumericType> },
510  Conversions<Unit::Diffusivity, Unit::Diffusivity::AcrePerSecond>::ToStandard<NumericType>},
512  Conversions<Unit::Diffusivity,
513  Unit::Diffusivity::SquareYardPerSecond>::ToStandard<NumericType> },
515  Conversions<Unit::Diffusivity,
516  Unit::Diffusivity::SquareFootPerSecond>::ToStandard<NumericType> },
518  Conversions<Unit::Diffusivity,
519  Unit::Diffusivity::SquareDecimetrePerSecond>::ToStandard<NumericType> },
521  Conversions<Unit::Diffusivity,
522  Unit::Diffusivity::SquareInchPerSecond>::ToStandard<NumericType> },
524  Conversions<Unit::Diffusivity,
525  Unit::Diffusivity::SquareCentimetrePerSecond>::ToStandard<NumericType> },
527  Conversions<Unit::Diffusivity,
528  Unit::Diffusivity::SquareMillimetrePerSecond>::ToStandard<NumericType> },
530  Conversions<Unit::Diffusivity,
531  Unit::Diffusivity::SquareMilliinchPerSecond>::ToStandard<NumericType> },
533  Conversions<Unit::Diffusivity,
534  Unit::Diffusivity::SquareMicrometrePerSecond>::ToStandard<NumericType> },
536  Conversions<Unit::Diffusivity,
537  Unit::Diffusivity::SquareMicroinchPerSecond>::ToStandard<NumericType> },
538 };
539 
540 } // namespace Internal
541 
542 } // namespace PhQ
543 
544 #endif // PHQ_UNIT_DIFFUSIVITY_HPP
ElectricCurrent
Electric current units.
Mass
Mass units.
Definition: Mass.hpp:53
Length
Length units.
Definition: Length.hpp:53
SubstanceAmount
Amount of substance units.
Diffusivity
Diffusivity units.
Definition: Diffusivity.hpp:53
@ SquareFootPerSecond
Square foot per second (ft^2/s) diffusivity unit.
@ SquareCentimetrePerSecond
Square centimetre per second (cm^2/s) diffusivity unit.
@ SquareDecimetrePerSecond
Square decimetre per second (dm^2/s) diffusivity unit.
@ SquareKilometrePerSecond
Square kilometre per second (km^2/s) diffusivity unit.
@ SquareMicrometrePerSecond
Square micrometre per second (μm^2/s) diffusivity unit.
@ HectarePerSecond
Hectare per second (ha/s) diffusivity unit.
@ SquareNauticalMilePerSecond
Square nautical mile per second (nmi^2/s) diffusivity unit.
@ SquareYardPerSecond
Square yard per second (yd^2/s) diffusivity unit.
@ SquareMilePerSecond
Square mile per second (mi^2/s) diffusivity unit.
@ SquareMillimetrePerSecond
Square millimetre per second (mm^2/s) diffusivity unit.
@ AcrePerSecond
Acre per second (ac/s) diffusivity unit.
@ SquareMilliinchPerSecond
Square milliinch per second (mil^2/s) diffusivity unit.
@ SquareMicroinchPerSecond
Square microinch per second (μin^2/s) diffusivity unit.
@ SquareInchPerSecond
Square inch per second (in^2/s) diffusivity unit.
@ SquareMetrePerSecond
Square metre per second (m^2/s) diffusivity unit.
Temperature
Temperature units. Not to be confused with temperature difference units. For example,...
Definition: Temperature.hpp:55
Time
Time units.
Definition: Time.hpp:53
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)