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
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
48namespace PhQ {
49
50namespace Unit {
51
52/// \brief Dynamic viscosity units.
53enum 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).
79template <>
80inline constexpr const Unit::
81 DynamicViscosity Standard<Unit::DynamicViscosity>{Unit::DynamicViscosity::PascalSecond};
82
83/// \brief Physical dimension set of dynamic viscosity units.
84template <>
85inline constexpr const Dimensions RelatedDimensions<Unit::DynamicViscosity>{
86 Dimensions{Dimension::Time{-1}, Dimension::Length{-1}, Dimension::Mass{1},
87 Dimension::ElectricCurrent{0}, Dimension::Temperature{0},
88 Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
89};
90
91inline std::ostream& operator<<(std::ostream& stream, const Unit::DynamicViscosity unit) {
92 stream << Abbreviation(unit);
93 return stream;
94}
95
96namespace Internal {
97
98template <>
99inline const std::map<UnitSystem, Unit::DynamicViscosity> ConsistentUnits<Unit::DynamicViscosity>{
104};
105
106template <>
107inline const std::map<Unit::DynamicViscosity, UnitSystem>
108 RelatedUnitSystems<Unit::DynamicViscosity>{
111};
112
113// clang-format off
114
115template <>
116inline const std::map<Unit::DynamicViscosity, std::string_view>
117 Abbreviations<Unit::DynamicViscosity>{
125};
126
127template <>
128inline const std::unordered_map<std::string_view, Unit::DynamicViscosity> Spellings<
186};
187
188// clang-format on
189
190template <>
191template <typename NumericType>
192inline constexpr void Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::PascalSecond>::
193 FromStandard(NumericType& /*value*/) noexcept {}
194
195template <>
196template <typename NumericType>
197inline constexpr void Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::PascalSecond>::
198 ToStandard(NumericType& /*value*/) noexcept {}
199
200template <>
201template <typename NumericType>
202inline constexpr void Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::KilopascalSecond>::
203 FromStandard(NumericType& value) noexcept {
204 value *= static_cast<NumericType>(0.001L);
205}
206
207template <>
208template <typename NumericType>
209inline constexpr void Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::KilopascalSecond>::
210 ToStandard(NumericType& value) noexcept {
211 value *= static_cast<NumericType>(1000.0L);
212}
213
214template <>
215template <typename NumericType>
216inline constexpr void Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::MegapascalSecond>::
217 FromStandard(NumericType& value) noexcept {
218 value *= static_cast<NumericType>(0.000001L);
219}
220
221template <>
222template <typename NumericType>
223inline constexpr void Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::MegapascalSecond>::
224 ToStandard(NumericType& value) noexcept {
225 value *= static_cast<NumericType>(1000000.0L);
226}
227
228template <>
229template <typename NumericType>
230inline constexpr void Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::GigapascalSecond>::
231 FromStandard(NumericType& value) noexcept {
232 value *= static_cast<NumericType>(0.000000001L);
233}
234
235template <>
236template <typename NumericType>
237inline constexpr void Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::GigapascalSecond>::
238 ToStandard(NumericType& value) noexcept {
239 value *= static_cast<NumericType>(1000000000.0L);
240}
241
242template <>
243template <typename NumericType>
244inline constexpr void Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::Poise>::
245 FromStandard(NumericType& value) noexcept {
246 value *= static_cast<NumericType>(10.0L);
247}
248
249template <>
250template <typename NumericType>
251inline constexpr void Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::Poise>::ToStandard(
252 NumericType& value) noexcept {
253 value *= static_cast<NumericType>(0.1L);
254}
255
256template <>
257template <typename NumericType>
258inline constexpr void
259Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::PoundSecondPerSquareFoot>::FromStandard(
260 NumericType& value) noexcept {
261 value *= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L)
262 / (static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L));
263}
264
265template <>
266template <typename NumericType>
267inline constexpr void
268Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::PoundSecondPerSquareFoot>::ToStandard(
269 NumericType& value) noexcept {
270 value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L)
271 / (static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L));
272}
273
274template <>
275template <typename NumericType>
276inline constexpr void
277Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::PoundSecondPerSquareInch>::FromStandard(
278 NumericType& value) noexcept {
279 value *= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L)
280 / (static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L));
281}
282
283template <>
284template <typename NumericType>
285inline constexpr void
286Conversion<Unit::DynamicViscosity, Unit::DynamicViscosity::PoundSecondPerSquareInch>::ToStandard(
287 NumericType& value) noexcept {
288 value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L)
289 / (static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L));
290}
291
292template <typename NumericType>
293inline const std::
294 map<Unit::DynamicViscosity, std::function<void(NumericType* values, const std::size_t size)>>
295 MapOfConversionsFromStandard<Unit::DynamicViscosity, NumericType>{
297 Conversions<Unit::DynamicViscosity, Unit::DynamicViscosity::PascalSecond>::
298 FromStandard<NumericType>},
300 Conversions<Unit::DynamicViscosity, Unit::DynamicViscosity::KilopascalSecond>::
301 FromStandard<NumericType>},
303 Conversions<Unit::DynamicViscosity, Unit::DynamicViscosity::MegapascalSecond>::
304 FromStandard<NumericType>},
306 Conversions<Unit::DynamicViscosity, Unit::DynamicViscosity::GigapascalSecond>::
307 FromStandard<NumericType>},
309 Conversions<Unit::DynamicViscosity, Unit::DynamicViscosity::Poise>::
310 FromStandard<NumericType>},
312 Conversions<Unit::DynamicViscosity, Unit::DynamicViscosity::PoundSecondPerSquareFoot>::
313 FromStandard<NumericType>},
315 Conversions<Unit::DynamicViscosity, Unit::DynamicViscosity::PoundSecondPerSquareInch>::
316 FromStandard<NumericType>},
317};
318
319template <typename NumericType>
320inline const std::map<Unit::DynamicViscosity,
321 std::function<void(NumericType* const values, const std::size_t size)>>
322 MapOfConversionsToStandard<Unit::DynamicViscosity, NumericType>{
324 Conversions<Unit::DynamicViscosity, Unit::DynamicViscosity::PascalSecond>::
325 ToStandard<NumericType> },
327 Conversions<Unit::DynamicViscosity, Unit::DynamicViscosity::KilopascalSecond>::
328 ToStandard<NumericType> },
330 Conversions<Unit::DynamicViscosity, Unit::DynamicViscosity::MegapascalSecond>::
331 ToStandard<NumericType> },
333 Conversions<Unit::DynamicViscosity, Unit::DynamicViscosity::GigapascalSecond>::
334 ToStandard<NumericType> },
336 Conversions<Unit::DynamicViscosity, Unit::DynamicViscosity::Poise>::ToStandard<NumericType>},
338 Conversions<Unit::DynamicViscosity, Unit::DynamicViscosity::PoundSecondPerSquareFoot>::
339 ToStandard<NumericType> },
341 Conversions<Unit::DynamicViscosity, Unit::DynamicViscosity::PoundSecondPerSquareInch>::
342 ToStandard<NumericType> },
343};
344
345} // namespace Internal
346
347} // namespace PhQ
348
349#endif // PHQ_UNIT_DYNAMIC_VISCOSITY_HPP
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.
Namespace that encompasses all of the Physical Quantities library's content.
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)
@ 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