Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
SpecificPower.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_SPECIFIC_POWER_HPP
26 #define PHQ_UNIT_SPECIFIC_POWER_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 Mass-specific power units.
53 enum class SpecificPower : int8_t {
54  /// \brief Watt per kilogram (W/kg) specific power unit.
56 
57  /// \brief Nanowatt per gram (nW/g) specific power unit.
59 
60  /// \brief Foot-pound per slug per second (ft·lbf/slug/s) specific power unit.
62 
63  /// \brief Inch-pound per slinch per second (in·lbf/slinch/s) specific power unit.
65 };
66 
67 } // namespace Unit
68 
69 /// \brief Standard mass-specific power unit: watt per kilogram (W/kg).
70 template <>
71 inline constexpr const Unit::SpecificPower Standard<Unit::SpecificPower>{
73 
74 /// \brief Physical dimension set of mass-specific power units.
75 template <>
76 inline constexpr const Dimensions RelatedDimensions<Unit::SpecificPower>{
77  Dimensions{Dimension::Time{-3}, Dimension::Length{2}, Dimension::Mass{0},
79  Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
80 };
81 
82 inline std::ostream& operator<<(std::ostream& stream, const Unit::SpecificPower unit) {
83  stream << Abbreviation(unit);
84  return stream;
85 }
86 
87 namespace Internal {
88 
89 template <>
90 inline const std::map<UnitSystem, Unit::SpecificPower> ConsistentUnits<Unit::SpecificPower>{
95 };
96 
97 template <>
98 inline const std::map<Unit::SpecificPower, UnitSystem> RelatedUnitSystems<Unit::SpecificPower>{
103 };
104 
105 // clang-format off
106 
107 template <>
108 inline const std::map<Unit::SpecificPower, std::string_view> Abbreviations<Unit::SpecificPower>{
113 };
114 
115 template <>
116 inline const std::unordered_map<std::string_view, Unit::SpecificPower> Spellings<
119  {"N·m/kg/s", Unit::SpecificPower::WattPerKilogram },
121  {"N·m/(kg·s)", Unit::SpecificPower::WattPerKilogram },
122  {"N*m/(kg*s)", Unit::SpecificPower::WattPerKilogram },
123  {"N·m/s/kg", Unit::SpecificPower::WattPerKilogram },
125  {"N·m/(s·kg)", Unit::SpecificPower::WattPerKilogram },
126  {"N*m/(s*kg)", Unit::SpecificPower::WattPerKilogram },
127  {"m·N/kg/s", Unit::SpecificPower::WattPerKilogram },
129  {"m·N/(kg·s)", Unit::SpecificPower::WattPerKilogram },
130  {"m*N/(kg*s)", Unit::SpecificPower::WattPerKilogram },
131  {"m·N/s/kg", Unit::SpecificPower::WattPerKilogram },
133  {"m·N/(s·kg)", Unit::SpecificPower::WattPerKilogram },
134  {"m*N/(s*kg)", Unit::SpecificPower::WattPerKilogram },
138  {"μN·mm/g/s", Unit::SpecificPower::NanowattPerGram },
139  {"μN*mm/g/s", Unit::SpecificPower::NanowattPerGram },
140  {"μN·mm/(g·s)", Unit::SpecificPower::NanowattPerGram },
141  {"μN*mm/(g*s)", Unit::SpecificPower::NanowattPerGram },
142  {"uN·mm/g/s", Unit::SpecificPower::NanowattPerGram },
143  {"uN*mm/g/s", Unit::SpecificPower::NanowattPerGram },
144  {"uN·mm/(g·s)", Unit::SpecificPower::NanowattPerGram },
145  {"uN*mm/(g*s)", Unit::SpecificPower::NanowattPerGram },
146  {"μN·mm/s/g", Unit::SpecificPower::NanowattPerGram },
147  {"μN*mm/s/g", Unit::SpecificPower::NanowattPerGram },
148  {"μN·mm/(s·g)", Unit::SpecificPower::NanowattPerGram },
149  {"μN*mm/(s*g)", Unit::SpecificPower::NanowattPerGram },
150  {"uN·mm/s/g", Unit::SpecificPower::NanowattPerGram },
151  {"uN*mm/s/g", Unit::SpecificPower::NanowattPerGram },
152  {"uN·mm/(s·g)", Unit::SpecificPower::NanowattPerGram },
153  {"uN*mm/(s*g)", Unit::SpecificPower::NanowattPerGram },
154  {"mm·μN/g/s", Unit::SpecificPower::NanowattPerGram },
155  {"mm*μN/g/s", Unit::SpecificPower::NanowattPerGram },
156  {"mm·μN/(g·s)", Unit::SpecificPower::NanowattPerGram },
157  {"mm*μN/(g*s)", Unit::SpecificPower::NanowattPerGram },
158  {"mm·uN/g/s", Unit::SpecificPower::NanowattPerGram },
159  {"mm*uN/g/s", Unit::SpecificPower::NanowattPerGram },
160  {"mm·uN/(g·s)", Unit::SpecificPower::NanowattPerGram },
161  {"mm*uN/(g*s)", Unit::SpecificPower::NanowattPerGram },
162  {"mm·μN/s/g", Unit::SpecificPower::NanowattPerGram },
163  {"mm*μN/s/g", Unit::SpecificPower::NanowattPerGram },
164  {"mm·μN/(s·g)", Unit::SpecificPower::NanowattPerGram },
165  {"mm*μN/(s*g)", Unit::SpecificPower::NanowattPerGram },
166  {"mm·uN/s/g", Unit::SpecificPower::NanowattPerGram },
167  {"mm*uN/s/g", Unit::SpecificPower::NanowattPerGram },
168  {"mm·uN/(s·g)", Unit::SpecificPower::NanowattPerGram },
169  {"mm*uN/(s*g)", Unit::SpecificPower::NanowattPerGram },
174  {"ft·lbf/(slug·s)", Unit::SpecificPower::FootPoundPerSlugPerSecond },
178  {"ft·lbf/(s·slug)", Unit::SpecificPower::FootPoundPerSlugPerSecond },
182  {"lbf·ft/(slug·s)", Unit::SpecificPower::FootPoundPerSlugPerSecond },
186  {"lbf·ft/(s·slug)", Unit::SpecificPower::FootPoundPerSlugPerSecond },
190  {"ft·lb/(slug·s)", Unit::SpecificPower::FootPoundPerSlugPerSecond },
194  {"ft·lb/(s·slug)", Unit::SpecificPower::FootPoundPerSlugPerSecond },
198  {"lb·ft/(slug·s)", Unit::SpecificPower::FootPoundPerSlugPerSecond },
202  {"lb·ft/(s·slug)", Unit::SpecificPower::FootPoundPerSlugPerSecond },
208  {"in·lbf/(slinch·s)", Unit::SpecificPower::InchPoundPerSlinchPerSecond},
212  {"in·lbf/(s·slinch)", Unit::SpecificPower::InchPoundPerSlinchPerSecond},
216  {"lbf·in/(slinch·s)", Unit::SpecificPower::InchPoundPerSlinchPerSecond},
220  {"lbf·in/(s·slinch)", Unit::SpecificPower::InchPoundPerSlinchPerSecond},
224  {"in·lb/(slinch·s)", Unit::SpecificPower::InchPoundPerSlinchPerSecond},
228  {"in·lb/(s·slinch)", Unit::SpecificPower::InchPoundPerSlinchPerSecond},
232  {"lb·in/(slinch·s)", Unit::SpecificPower::InchPoundPerSlinchPerSecond},
236  {"lb·in/(s·slinch)", Unit::SpecificPower::InchPoundPerSlinchPerSecond},
240 };
241 
242 // clang-format on
243 
244 template <>
245 template <typename NumericType>
246 inline constexpr void
247 Conversion<Unit::SpecificPower, Unit::SpecificPower::WattPerKilogram>::FromStandard(
248  NumericType& /*value*/) noexcept {}
249 
250 template <>
251 template <typename NumericType>
252 inline constexpr void
253 Conversion<Unit::SpecificPower, Unit::SpecificPower::WattPerKilogram>::ToStandard(
254  NumericType& /*value*/) noexcept {}
255 
256 template <>
257 template <typename NumericType>
258 inline constexpr void
259 Conversion<Unit::SpecificPower, Unit::SpecificPower::NanowattPerGram>::FromStandard(
260  NumericType& value) noexcept {
261  value *= static_cast<NumericType>(1000000.0L);
262 }
263 
264 template <>
265 template <typename NumericType>
266 inline constexpr void
267 Conversion<Unit::SpecificPower, Unit::SpecificPower::NanowattPerGram>::ToStandard(
268  NumericType& value) noexcept {
269  value *= static_cast<NumericType>(0.000001L);
270 }
271 
272 template <>
273 template <typename NumericType>
274 inline constexpr void
275 Conversion<Unit::SpecificPower, Unit::SpecificPower::FootPoundPerSlugPerSecond>::FromStandard(
276  NumericType& value) noexcept {
277  value /= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L);
278 }
279 
280 template <>
281 template <typename NumericType>
282 inline constexpr void
283 Conversion<Unit::SpecificPower, Unit::SpecificPower::FootPoundPerSlugPerSecond>::ToStandard(
284  NumericType& value) noexcept {
285  value *= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L);
286 }
287 
288 template <>
289 template <typename NumericType>
290 inline constexpr void
291 Conversion<Unit::SpecificPower, Unit::SpecificPower::InchPoundPerSlinchPerSecond>::FromStandard(
292  NumericType& value) noexcept {
293  value /= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L);
294 }
295 
296 template <>
297 template <typename NumericType>
298 inline constexpr void
299 Conversion<Unit::SpecificPower, Unit::SpecificPower::InchPoundPerSlinchPerSecond>::ToStandard(
300  NumericType& value) noexcept {
301  value *= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L);
302 }
303 
304 template <typename NumericType>
305 inline const std::map<Unit::SpecificPower,
306  std::function<void(NumericType* values, const std::size_t size)>>
307  MapOfConversionsFromStandard<Unit::SpecificPower, NumericType>{
309  Conversions<Unit::SpecificPower,
310  Unit::SpecificPower::WattPerKilogram>::FromStandard<NumericType> },
312  Conversions<Unit::SpecificPower,
313  Unit::SpecificPower::NanowattPerGram>::FromStandard<NumericType> },
315  Conversions<Unit::SpecificPower,
316  Unit::SpecificPower::FootPoundPerSlugPerSecond>::FromStandard<NumericType> },
318  Conversions<Unit::SpecificPower,
319  Unit::SpecificPower::InchPoundPerSlinchPerSecond>::FromStandard<NumericType>},
320 };
321 
322 template <typename NumericType>
323 inline const std::map<Unit::SpecificPower,
324  std::function<void(NumericType* const values, const std::size_t size)>>
325  MapOfConversionsToStandard<Unit::SpecificPower, NumericType>{
327  Conversions<Unit::SpecificPower,
328  Unit::SpecificPower::WattPerKilogram>::ToStandard<NumericType> },
330  Conversions<Unit::SpecificPower,
331  Unit::SpecificPower::NanowattPerGram>::ToStandard<NumericType> },
333  Conversions<Unit::SpecificPower,
334  Unit::SpecificPower::FootPoundPerSlugPerSecond>::ToStandard<NumericType> },
336  Conversions<Unit::SpecificPower,
337  Unit::SpecificPower::InchPoundPerSlinchPerSecond>::ToStandard<NumericType>},
338 };
339 
340 } // namespace Internal
341 
342 } // namespace PhQ
343 
344 #endif // PHQ_UNIT_SPECIFIC_POWER_HPP
ElectricCurrent
Electric current units.
Mass
Mass units.
Definition: Mass.hpp:53
Length
Length units.
Definition: Length.hpp:53
SubstanceAmount
Amount of substance units.
SpecificPower
Mass-specific power units.
@ NanowattPerGram
Nanowatt per gram (nW/g) specific power unit.
@ WattPerKilogram
Watt per kilogram (W/kg) specific power unit.
@ InchPoundPerSlinchPerSecond
Inch-pound per slinch per second (in·lbf/slinch/s) specific power unit.
@ FootPoundPerSlugPerSecond
Foot-pound per slug per second (ft·lbf/slug/s) specific power 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)