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
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
48namespace PhQ {
49
50namespace Unit {
51
52/// \brief Mass-specific power units.
53enum 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).
70template <>
71inline constexpr const Unit::
72 SpecificPower Standard<Unit::SpecificPower>{Unit::SpecificPower::WattPerKilogram};
73
74/// \brief Physical dimension set of mass-specific power units.
75template <>
76inline constexpr const Dimensions RelatedDimensions<Unit::SpecificPower>{
77 Dimensions{Dimension::Time{-3}, Dimension::Length{2}, Dimension::Mass{0},
78 Dimension::ElectricCurrent{0}, Dimension::Temperature{0},
79 Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
80};
81
82inline std::ostream& operator<<(std::ostream& stream, const Unit::SpecificPower unit) {
83 stream << Abbreviation(unit);
84 return stream;
85}
86
87namespace Internal {
88
89template <>
90inline const std::map<UnitSystem, Unit::SpecificPower> ConsistentUnits<Unit::SpecificPower>{
95};
96
97template <>
98inline const std::map<Unit::SpecificPower, UnitSystem> RelatedUnitSystems<Unit::SpecificPower>{
103};
104
105// clang-format off
106
107template <>
108inline const std::map<Unit::SpecificPower, std::string_view> Abbreviations<Unit::SpecificPower>{
113};
114
115template <>
116inline const std::unordered_map<std::string_view, Unit::SpecificPower> Spellings<
121 {"N·m/(kg·s)", Unit::SpecificPower::WattPerKilogram },
125 {"N·m/(s·kg)", Unit::SpecificPower::WattPerKilogram },
129 {"m·N/(kg·s)", Unit::SpecificPower::WattPerKilogram },
133 {"m·N/(s·kg)", Unit::SpecificPower::WattPerKilogram },
138 {"μN·mm/g/s", Unit::SpecificPower::NanowattPerGram },
140 {"μN·mm/(g·s)", Unit::SpecificPower::NanowattPerGram },
141 {"μN*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 },
148 {"μN·mm/(s·g)", Unit::SpecificPower::NanowattPerGram },
149 {"μN*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 },
156 {"mm·μN/(g·s)", Unit::SpecificPower::NanowattPerGram },
157 {"mm*μN/(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 },
164 {"mm·μN/(s·g)", Unit::SpecificPower::NanowattPerGram },
165 {"mm*μN/(s*g)", Unit::SpecificPower::NanowattPerGram },
168 {"mm·uN/(s·g)", Unit::SpecificPower::NanowattPerGram },
169 {"mm*uN/(s*g)", Unit::SpecificPower::NanowattPerGram },
240};
241
242// clang-format on
243
244template <>
245template <typename NumericType>
246inline constexpr void Conversion<Unit::SpecificPower, Unit::SpecificPower::WattPerKilogram>::
247 FromStandard(NumericType& /*value*/) noexcept {}
248
249template <>
250template <typename NumericType>
251inline constexpr void Conversion<Unit::SpecificPower, Unit::SpecificPower::WattPerKilogram>::
252 ToStandard(NumericType& /*value*/) noexcept {}
253
254template <>
255template <typename NumericType>
256inline constexpr void Conversion<Unit::SpecificPower, Unit::SpecificPower::NanowattPerGram>::
257 FromStandard(NumericType& value) noexcept {
258 value *= static_cast<NumericType>(1000000.0L);
259}
260
261template <>
262template <typename NumericType>
263inline constexpr void Conversion<Unit::SpecificPower, Unit::SpecificPower::NanowattPerGram>::
264 ToStandard(NumericType& value) noexcept {
265 value *= static_cast<NumericType>(0.000001L);
266}
267
268template <>
269template <typename NumericType>
270inline constexpr void
271Conversion<Unit::SpecificPower, Unit::SpecificPower::FootPoundPerSlugPerSecond>::FromStandard(
272 NumericType& value) noexcept {
273 value /= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L);
274}
275
276template <>
277template <typename NumericType>
278inline constexpr void
279Conversion<Unit::SpecificPower, Unit::SpecificPower::FootPoundPerSlugPerSecond>::ToStandard(
280 NumericType& value) noexcept {
281 value *= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L);
282}
283
284template <>
285template <typename NumericType>
286inline constexpr void
287Conversion<Unit::SpecificPower, Unit::SpecificPower::InchPoundPerSlinchPerSecond>::FromStandard(
288 NumericType& value) noexcept {
289 value /= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L);
290}
291
292template <>
293template <typename NumericType>
294inline constexpr void
295Conversion<Unit::SpecificPower, Unit::SpecificPower::InchPoundPerSlinchPerSecond>::ToStandard(
296 NumericType& value) noexcept {
297 value *= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L);
298}
299
300template <typename NumericType>
301inline const std::
302 map<Unit::SpecificPower, std::function<void(NumericType* values, const std::size_t size)>>
303 MapOfConversionsFromStandard<Unit::SpecificPower, NumericType>{
305 Conversions<Unit::SpecificPower, Unit::SpecificPower::WattPerKilogram>::
306 FromStandard<NumericType>},
308 Conversions<Unit::SpecificPower, Unit::SpecificPower::NanowattPerGram>::
309 FromStandard<NumericType>},
311 Conversions<Unit::SpecificPower, Unit::SpecificPower::FootPoundPerSlugPerSecond>::
312 FromStandard<NumericType>},
314 Conversions<Unit::SpecificPower, Unit::SpecificPower::InchPoundPerSlinchPerSecond>::
315 FromStandard<NumericType>},
316};
317
318template <typename NumericType>
319inline const std::
320 map<Unit::SpecificPower, std::function<void(NumericType* const values, const std::size_t size)>>
321 MapOfConversionsToStandard<Unit::SpecificPower, NumericType>{
323 Conversions<Unit::SpecificPower, Unit::SpecificPower::WattPerKilogram>::
324 ToStandard<NumericType>},
326 Conversions<Unit::SpecificPower, Unit::SpecificPower::NanowattPerGram>::
327 ToStandard<NumericType>},
329 Conversions<Unit::SpecificPower, Unit::SpecificPower::FootPoundPerSlugPerSecond>::
330 ToStandard<NumericType>},
332 Conversions<Unit::SpecificPower, Unit::SpecificPower::InchPoundPerSlinchPerSecond>::
333 ToStandard<NumericType>},
334};
335
336} // namespace Internal
337
338} // namespace PhQ
339
340#endif // PHQ_UNIT_SPECIFIC_POWER_HPP
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.
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