Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
DynamicViscosity.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_DYNAMIC_VISCOSITY_HPP
26 #define PHQ_UNIT_DYNAMIC_VISCOSITY_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 Dynamic viscosity units.
53 enum class DynamicViscosity : int8_t {
54  /// \brief Pascal-second (Pa·s) dynamic viscosity unit.
56 
57  /// \brief Kilopascal-second (kPa·s) dynamic viscosity unit.
59 
60  /// \brief Megapascal-second (MPa·s) dynamic viscosity unit.
62 
63  /// \brief Gigapascal-second (GPa·s) dynamic viscosity unit.
65 
66  /// \brief Poise (P) dynamic viscosity unit.
67  Poise,
68 
69  /// \brief Pound-second per square foot (lbf·s/ft^2) dynamic viscosity unit.
71 
72  /// \brief Pound-second per square inch (lbf·s/in^2) dynamic viscosity unit.
74 };
75 
76 } // namespace Unit
77 
78 /// \brief Standard dynamic viscosity unit: pascal-second (Pa·s).
79 template <>
80 inline constexpr const Unit::DynamicViscosity Standard<Unit::DynamicViscosity>{
82 
83 /// \brief Physical dimension set of dynamic viscosity units.
84 template <>
85 inline constexpr const Dimensions RelatedDimensions<Unit::DynamicViscosity>{
86  Dimensions{Dimension::Time{-1}, Dimension::Length{-1}, Dimension::Mass{1},
88  Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
89 };
90 
91 inline std::ostream& operator<<(std::ostream& stream, const Unit::DynamicViscosity unit) {
92  stream << Abbreviation(unit);
93  return stream;
94 }
95 
96 namespace Internal {
97 
98 template <>
99 inline const std::map<UnitSystem, Unit::DynamicViscosity> ConsistentUnits<Unit::DynamicViscosity>{
104 };
105 
106 template <>
107 inline const std::map<Unit::DynamicViscosity, UnitSystem>
108  RelatedUnitSystems<Unit::DynamicViscosity>{
111 };
112 
113 // clang-format off
114 
115 template <>
116 inline const std::map<Unit::DynamicViscosity, std::string_view>
117  Abbreviations<Unit::DynamicViscosity>{
125 };
126 
127 template <>
128 inline const std::unordered_map<std::string_view, Unit::DynamicViscosity> Spellings<
136  {"kg/(m·s)", Unit::DynamicViscosity::PascalSecond },
186 };
187 
188 // clang-format on
189 
190 template <>
191 template <typename NumericType>
192 inline constexpr void
193 Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::PascalSecond>::FromStandard(
194  NumericType& /*value*/) noexcept {}
195 
196 template <>
197 template <typename NumericType>
198 inline constexpr void
199 Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::PascalSecond>::ToStandard(
200  NumericType& /*value*/) noexcept {}
201 
202 template <>
203 template <typename NumericType>
204 inline constexpr void
205 Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::KilopascalSecond>::FromStandard(
206  NumericType& value) noexcept {
207  value *= static_cast<NumericType>(0.001L);
208 }
209 
210 template <>
211 template <typename NumericType>
212 inline constexpr void
213 Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::KilopascalSecond>::ToStandard(
214  NumericType& value) noexcept {
215  value *= static_cast<NumericType>(1000.0L);
216 }
217 
218 template <>
219 template <typename NumericType>
220 inline constexpr void
221 Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::MegapascalSecond>::FromStandard(
222  NumericType& value) noexcept {
223  value *= static_cast<NumericType>(0.000001L);
224 }
225 
226 template <>
227 template <typename NumericType>
228 inline constexpr void
229 Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::MegapascalSecond>::ToStandard(
230  NumericType& value) noexcept {
231  value *= static_cast<NumericType>(1000000.0L);
232 }
233 
234 template <>
235 template <typename NumericType>
236 inline constexpr void
237 Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::GigapascalSecond>::FromStandard(
238  NumericType& value) noexcept {
239  value *= static_cast<NumericType>(0.000000001L);
240 }
241 
242 template <>
243 template <typename NumericType>
244 inline constexpr void
245 Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::GigapascalSecond>::ToStandard(
246  NumericType& value) noexcept {
247  value *= static_cast<NumericType>(1000000000.0L);
248 }
249 
250 template <>
251 template <typename NumericType>
252 inline constexpr void
253 Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::Poise>::FromStandard(
254  NumericType& value) noexcept {
255  value *= static_cast<NumericType>(10.0L);
256 }
257 
258 template <>
259 template <typename NumericType>
260 inline constexpr void Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::Poise>::ToStandard(
261  NumericType& value) noexcept {
262  value *= static_cast<NumericType>(0.1L);
263 }
264 
265 template <>
266 template <typename NumericType>
267 inline constexpr void
268 Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::PoundSecondPerSquareFoot>::FromStandard(
269  NumericType& value) noexcept {
270  value *= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L)
271  / (static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L));
272 }
273 
274 template <>
275 template <typename NumericType>
276 inline constexpr void
277 Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::PoundSecondPerSquareFoot>::ToStandard(
278  NumericType& value) noexcept {
279  value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L)
280  / (static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L));
281 }
282 
283 template <>
284 template <typename NumericType>
285 inline constexpr void
286 Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::PoundSecondPerSquareInch>::FromStandard(
287  NumericType& value) noexcept {
288  value *= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L)
289  / (static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L));
290 }
291 
292 template <>
293 template <typename NumericType>
294 inline constexpr void
295 Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::PoundSecondPerSquareInch>::ToStandard(
296  NumericType& value) noexcept {
297  value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L)
298  / (static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L));
299 }
300 
301 template <typename NumericType>
302 inline const std::map<Unit::DynamicViscosity,
303  std::function<void(NumericType* values, const std::size_t size)>>
304  MapOfConversionsFromStandard<Unit::DynamicViscosity, NumericType>{
306  Conversions<Unit::DynamicViscosity,
307  Unit::DynamicViscosity::PascalSecond>::FromStandard<NumericType> },
309  Conversions<Unit::DynamicViscosity,
310  Unit::DynamicViscosity::KilopascalSecond>::FromStandard<NumericType> },
312  Conversions<Unit::DynamicViscosity,
313  Unit::DynamicViscosity::MegapascalSecond>::FromStandard<NumericType> },
315  Conversions<Unit::DynamicViscosity,
316  Unit::DynamicViscosity::GigapascalSecond>::FromStandard<NumericType> },
318  Conversions<Unit::DynamicViscosity,
319  Unit::DynamicViscosity::Poise>::FromStandard<NumericType> },
321  Conversions<Unit::DynamicViscosity,
322  Unit::DynamicViscosity::PoundSecondPerSquareFoot>::FromStandard<NumericType>},
324  Conversions<Unit::DynamicViscosity,
325  Unit::DynamicViscosity::PoundSecondPerSquareInch>::FromStandard<NumericType>},
326 };
327 
328 template <typename NumericType>
329 inline const std::map<Unit::DynamicViscosity,
330  std::function<void(NumericType* const values, const std::size_t size)>>
331  MapOfConversionsToStandard<Unit::DynamicViscosity, NumericType>{
333  Conversions<Unit::DynamicViscosity,
334  Unit::DynamicViscosity::PascalSecond>::ToStandard<NumericType> },
336  Conversions<Unit::DynamicViscosity,
337  Unit::DynamicViscosity::KilopascalSecond>::ToStandard<NumericType> },
339  Conversions<Unit::DynamicViscosity,
340  Unit::DynamicViscosity::MegapascalSecond>::ToStandard<NumericType> },
342  Conversions<Unit::DynamicViscosity,
343  Unit::DynamicViscosity::GigapascalSecond>::ToStandard<NumericType> },
345  Conversions<Unit::DynamicViscosity,
346  Unit::DynamicViscosity::Poise>::ToStandard<NumericType> },
348  Conversions<Unit::DynamicViscosity,
349  Unit::DynamicViscosity::PoundSecondPerSquareFoot>::ToStandard<NumericType>},
351  Conversions<Unit::DynamicViscosity,
352  Unit::DynamicViscosity::PoundSecondPerSquareInch>::ToStandard<NumericType>},
353 };
354 
355 } // namespace Internal
356 
357 } // namespace PhQ
358 
359 #endif // PHQ_UNIT_DYNAMIC_VISCOSITY_HPP
ElectricCurrent
Electric current units.
DynamicViscosity
Dynamic viscosity units.
@ PoundSecondPerSquareFoot
Pound-second per square foot (lbf·s/ft^2) dynamic viscosity unit.
@ PoundSecondPerSquareInch
Pound-second per square inch (lbf·s/in^2) dynamic viscosity unit.
@ Poise
Poise (P) dynamic viscosity unit.
@ KilopascalSecond
Kilopascal-second (kPa·s) dynamic viscosity unit.
@ GigapascalSecond
Gigapascal-second (GPa·s) dynamic viscosity unit.
@ MegapascalSecond
Megapascal-second (MPa·s) dynamic viscosity unit.
@ PascalSecond
Pascal-second (Pa·s) dynamic viscosity unit.
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
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)