Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
MassRate.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_MASS_RATE_HPP
26 #define PHQ_UNIT_MASS_RATE_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 rate units. Can represent the time rate of change of a mass or a mass flow rate.
53 enum class MassRate : int8_t {
54  /// \brief Kilogram per second (kg/s) mass rate unit.
56 
57  /// \brief Gram per second (g/s) mass rate unit.
59 
60  /// \brief Slug per second (slug/s) mass rate unit.
62 
63  /// \brief Slinch per second (slinch/s) mass rate unit.
65 
66  /// \brief Pound per second (lbm/s) mass rate unit.
68 
69  /// \brief Kilogram per minute (kg/min) mass rate unit.
71 
72  /// \brief Gram per minute (g/min) mass rate unit.
74 
75  /// \brief Slug per minute (slug/min) mass rate unit.
77 
78  /// \brief Slinch per minute (slinch/min) mass rate unit.
80 
81  /// \brief Pound per minute (lbm/min) mass rate unit.
83 
84  /// \brief Kilogram per hour (kg/hr) mass rate unit.
86 
87  /// \brief Gram per hour (g/hr) mass rate unit.
89 
90  /// \brief Slug per hour (slug/hr) mass rate unit.
92 
93  /// \brief Slinch per hour (slinch/hr) mass rate unit.
95 
96  /// \brief Pound per hour (lbm/hr) mass rate unit.
98 };
99 
100 } // namespace Unit
101 
102 /// \brief Standard time rate of mass unit: kilogram per second (kg/s).
103 template <>
104 inline constexpr const Unit::MassRate Standard<Unit::MassRate>{Unit::MassRate::KilogramPerSecond};
105 
106 /// \brief Physical dimension set of time rate of mass units.
107 template <>
108 inline constexpr const Dimensions RelatedDimensions<Unit::MassRate>{
109  Dimensions{Dimension::Time{-1}, Dimension::Length{0}, Dimension::Mass{1},
111  Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
112 };
113 
114 inline std::ostream& operator<<(std::ostream& stream, const Unit::MassRate unit) {
115  stream << Abbreviation(unit);
116  return stream;
117 }
118 
119 namespace Internal {
120 
121 template <>
122 inline const std::map<UnitSystem, Unit::MassRate> ConsistentUnits<Unit::MassRate>{
127 };
128 
129 template <>
130 inline const std::map<Unit::MassRate, UnitSystem> RelatedUnitSystems<Unit::MassRate>{
135 };
136 
137 template <>
138 inline const std::map<Unit::MassRate, std::string_view> Abbreviations<Unit::MassRate>{
141  {Unit::MassRate::SlugPerSecond, "slug/s" },
142  {Unit::MassRate::SlinchPerSecond, "slinch/s" },
143  {Unit::MassRate::PoundPerSecond, "lbm/s" },
145  {Unit::MassRate::GramPerMinute, "g/min" },
146  {Unit::MassRate::SlugPerMinute, "slug/min" },
147  {Unit::MassRate::SlinchPerMinute, "slinch/min"},
148  {Unit::MassRate::PoundPerMinute, "lbm/min" },
150  {Unit::MassRate::GramPerHour, "g/hr" },
151  {Unit::MassRate::SlugPerHour, "slug/hr" },
152  {Unit::MassRate::SlinchPerHour, "slinch/hr" },
153  {Unit::MassRate::PoundPerHour, "lbm/hr" },
154 };
155 
156 template <>
157 inline const std::unordered_map<std::string_view, Unit::MassRate> Spellings<Unit::MassRate>{
160  {"slug/s", Unit::MassRate::SlugPerSecond },
161  {"slinch/s", Unit::MassRate::SlinchPerSecond },
162  {"lbm/s", Unit::MassRate::PoundPerSecond },
165  {"g/min", Unit::MassRate::GramPerMinute },
166  {"slug/min", Unit::MassRate::SlugPerMinute },
167  {"slinch/min", Unit::MassRate::SlinchPerMinute },
168  {"lbm/min", Unit::MassRate::PoundPerMinute },
169  {"lb/min", Unit::MassRate::PoundPerMinute },
171  {"g/hr", Unit::MassRate::GramPerHour },
172  {"slug/hr", Unit::MassRate::SlugPerHour },
173  {"slinch/hr", Unit::MassRate::SlinchPerHour },
174  {"lbm/hr", Unit::MassRate::PoundPerHour },
175  {"lb/hr", Unit::MassRate::PoundPerHour },
176 };
177 
178 template <>
179 template <typename NumericType>
180 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::KilogramPerSecond>::FromStandard(
181  NumericType& /*value*/) noexcept {}
182 
183 template <>
184 template <typename NumericType>
185 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::KilogramPerSecond>::ToStandard(
186  NumericType& /*value*/) noexcept {}
187 
188 template <>
189 template <typename NumericType>
190 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::GramPerSecond>::FromStandard(
191  NumericType& value) noexcept {
192  value *= static_cast<NumericType>(1000.0L);
193 }
194 
195 template <>
196 template <typename NumericType>
197 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::GramPerSecond>::ToStandard(
198  NumericType& value) noexcept {
199  value *= static_cast<NumericType>(0.001L);
200 }
201 
202 template <>
203 template <typename NumericType>
204 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::SlugPerSecond>::FromStandard(
205  NumericType& value) noexcept {
206  value *= static_cast<NumericType>(0.3048L)
207  / (static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L));
208 }
209 
210 template <>
211 template <typename NumericType>
212 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::SlugPerSecond>::ToStandard(
213  NumericType& value) noexcept {
214  value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L)
215  / static_cast<NumericType>(0.3048L);
216 }
217 
218 template <>
219 template <typename NumericType>
220 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::SlinchPerSecond>::FromStandard(
221  NumericType& value) noexcept {
222  value *= static_cast<NumericType>(0.0254L)
223  / (static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L));
224 }
225 
226 template <>
227 template <typename NumericType>
228 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::SlinchPerSecond>::ToStandard(
229  NumericType& value) noexcept {
230  value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L)
231  / static_cast<NumericType>(0.0254L);
232 }
233 
234 template <>
235 template <typename NumericType>
236 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::PoundPerSecond>::FromStandard(
237  NumericType& value) noexcept {
238  value /= static_cast<NumericType>(0.45359237L);
239 }
240 
241 template <>
242 template <typename NumericType>
243 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::PoundPerSecond>::ToStandard(
244  NumericType& value) noexcept {
245  value *= static_cast<NumericType>(0.45359237L);
246 }
247 
248 template <>
249 template <typename NumericType>
250 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::KilogramPerMinute>::FromStandard(
251  NumericType& value) noexcept {
252  value *= static_cast<NumericType>(60.0L);
253 }
254 
255 template <>
256 template <typename NumericType>
257 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::KilogramPerMinute>::ToStandard(
258  NumericType& value) noexcept {
259  value /= static_cast<NumericType>(60.0L);
260 }
261 
262 template <>
263 template <typename NumericType>
264 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::GramPerMinute>::FromStandard(
265  NumericType& value) noexcept {
266  value *= static_cast<NumericType>(60000.0L);
267 }
268 
269 template <>
270 template <typename NumericType>
271 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::GramPerMinute>::ToStandard(
272  NumericType& value) noexcept {
273  value /= static_cast<NumericType>(60000.0L);
274 }
275 
276 template <>
277 template <typename NumericType>
278 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::SlugPerMinute>::FromStandard(
279  NumericType& value) noexcept {
280  value *= static_cast<NumericType>(60.0L) * static_cast<NumericType>(0.3048L)
281  / (static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L));
282 }
283 
284 template <>
285 template <typename NumericType>
286 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::SlugPerMinute>::ToStandard(
287  NumericType& value) noexcept {
288  value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L)
289  / (static_cast<NumericType>(0.3048L) * static_cast<NumericType>(60.0L));
290 }
291 
292 template <>
293 template <typename NumericType>
294 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::SlinchPerMinute>::FromStandard(
295  NumericType& value) noexcept {
296  value *= static_cast<NumericType>(60.0L) * static_cast<NumericType>(0.0254L)
297  / (static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L));
298 }
299 
300 template <>
301 template <typename NumericType>
302 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::SlinchPerMinute>::ToStandard(
303  NumericType& value) noexcept {
304  value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L)
305  / (static_cast<NumericType>(0.0254L) * static_cast<NumericType>(60.0L));
306 }
307 
308 template <>
309 template <typename NumericType>
310 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::PoundPerMinute>::FromStandard(
311  NumericType& value) noexcept {
312  value *= static_cast<NumericType>(60.0L) / static_cast<NumericType>(0.45359237L);
313 }
314 
315 template <>
316 template <typename NumericType>
317 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::PoundPerMinute>::ToStandard(
318  NumericType& value) noexcept {
319  value *= static_cast<NumericType>(0.45359237L) / static_cast<NumericType>(60.0L);
320 }
321 
322 template <>
323 template <typename NumericType>
324 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::KilogramPerHour>::FromStandard(
325  NumericType& value) noexcept {
326  value *= static_cast<NumericType>(3600.0L);
327 }
328 
329 template <>
330 template <typename NumericType>
331 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::KilogramPerHour>::ToStandard(
332  NumericType& value) noexcept {
333  value /= static_cast<NumericType>(3600.0L);
334 }
335 
336 template <>
337 template <typename NumericType>
338 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::GramPerHour>::FromStandard(
339  NumericType& value) noexcept {
340  value *= static_cast<NumericType>(3600000.0L);
341 }
342 
343 template <>
344 template <typename NumericType>
345 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::GramPerHour>::ToStandard(
346  NumericType& value) noexcept {
347  value /= static_cast<NumericType>(3600000.0L);
348 }
349 
350 template <>
351 template <typename NumericType>
352 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::SlugPerHour>::FromStandard(
353  NumericType& value) noexcept {
354  value *= static_cast<NumericType>(3600.0L) * static_cast<NumericType>(0.3048L)
355  / (static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L));
356 }
357 
358 template <>
359 template <typename NumericType>
360 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::SlugPerHour>::ToStandard(
361  NumericType& value) noexcept {
362  value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L)
363  / (static_cast<NumericType>(0.3048L) * static_cast<NumericType>(3600.0L));
364 }
365 
366 template <>
367 template <typename NumericType>
368 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::SlinchPerHour>::FromStandard(
369  NumericType& value) noexcept {
370  value *= static_cast<NumericType>(3600.0L) * static_cast<NumericType>(0.0254L)
371  / (static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L));
372 }
373 
374 template <>
375 template <typename NumericType>
376 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::SlinchPerHour>::ToStandard(
377  NumericType& value) noexcept {
378  value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L)
379  / (static_cast<NumericType>(0.0254L) * static_cast<NumericType>(3600.0L));
380 }
381 
382 template <>
383 template <typename NumericType>
384 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::PoundPerHour>::FromStandard(
385  NumericType& value) noexcept {
386  value *= static_cast<NumericType>(3600.0L) / static_cast<NumericType>(0.45359237L);
387 }
388 
389 template <>
390 template <typename NumericType>
391 inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::PoundPerHour>::ToStandard(
392  NumericType& value) noexcept {
393  value *= static_cast<NumericType>(0.45359237L) / static_cast<NumericType>(3600.0L);
394 }
395 
396 template <typename NumericType>
397 inline const std::map<Unit::MassRate,
398  std::function<void(NumericType* values, const std::size_t size)>>
399  MapOfConversionsFromStandard<Unit::MassRate, NumericType>{
401  Conversions<Unit::MassRate, Unit::MassRate::KilogramPerSecond>::FromStandard<NumericType>},
403  Conversions<Unit::MassRate, Unit::MassRate::GramPerSecond>::FromStandard<NumericType> },
405  Conversions<Unit::MassRate, Unit::MassRate::SlugPerSecond>::FromStandard<NumericType> },
407  Conversions<Unit::MassRate, Unit::MassRate::SlinchPerSecond>::FromStandard<NumericType> },
409  Conversions<Unit::MassRate, Unit::MassRate::PoundPerSecond>::FromStandard<NumericType> },
411  Conversions<Unit::MassRate, Unit::MassRate::KilogramPerMinute>::FromStandard<NumericType>},
413  Conversions<Unit::MassRate, Unit::MassRate::GramPerMinute>::FromStandard<NumericType> },
415  Conversions<Unit::MassRate, Unit::MassRate::SlugPerMinute>::FromStandard<NumericType> },
417  Conversions<Unit::MassRate, Unit::MassRate::SlinchPerMinute>::FromStandard<NumericType> },
419  Conversions<Unit::MassRate, Unit::MassRate::PoundPerMinute>::FromStandard<NumericType> },
421  Conversions<Unit::MassRate, Unit::MassRate::KilogramPerHour>::FromStandard<NumericType> },
423  Conversions<Unit::MassRate, Unit::MassRate::GramPerHour>::FromStandard<NumericType> },
425  Conversions<Unit::MassRate, Unit::MassRate::SlugPerHour>::FromStandard<NumericType> },
427  Conversions<Unit::MassRate, Unit::MassRate::SlinchPerHour>::FromStandard<NumericType> },
429  Conversions<Unit::MassRate, Unit::MassRate::PoundPerHour>::FromStandard<NumericType> },
430 };
431 
432 template <typename NumericType>
433 inline const std::map<Unit::MassRate,
434  std::function<void(NumericType* const values, const std::size_t size)>>
435  MapOfConversionsToStandard<Unit::MassRate, NumericType>{
437  Conversions<Unit::MassRate, Unit::MassRate::KilogramPerSecond>::ToStandard<NumericType>},
439  Conversions<Unit::MassRate, Unit::MassRate::GramPerSecond>::ToStandard<NumericType> },
441  Conversions<Unit::MassRate, Unit::MassRate::SlugPerSecond>::ToStandard<NumericType> },
443  Conversions<Unit::MassRate, Unit::MassRate::SlinchPerSecond>::ToStandard<NumericType> },
445  Conversions<Unit::MassRate, Unit::MassRate::PoundPerSecond>::ToStandard<NumericType> },
447  Conversions<Unit::MassRate, Unit::MassRate::KilogramPerMinute>::ToStandard<NumericType>},
449  Conversions<Unit::MassRate, Unit::MassRate::GramPerMinute>::ToStandard<NumericType> },
451  Conversions<Unit::MassRate, Unit::MassRate::SlugPerMinute>::ToStandard<NumericType> },
453  Conversions<Unit::MassRate, Unit::MassRate::SlinchPerMinute>::ToStandard<NumericType> },
455  Conversions<Unit::MassRate, Unit::MassRate::PoundPerMinute>::ToStandard<NumericType> },
457  Conversions<Unit::MassRate, Unit::MassRate::KilogramPerHour>::ToStandard<NumericType> },
459  Conversions<Unit::MassRate, Unit::MassRate::GramPerHour>::ToStandard<NumericType> },
461  Conversions<Unit::MassRate, Unit::MassRate::SlugPerHour>::ToStandard<NumericType> },
463  Conversions<Unit::MassRate, Unit::MassRate::SlinchPerHour>::ToStandard<NumericType> },
465  Conversions<Unit::MassRate, Unit::MassRate::PoundPerHour>::ToStandard<NumericType> },
466 };
467 
468 } // namespace Internal
469 
470 } // namespace PhQ
471 
472 #endif // PHQ_UNIT_MASS_RATE_HPP
ElectricCurrent
Electric current units.
Mass
Mass units.
Definition: Mass.hpp:53
Length
Length units.
Definition: Length.hpp:53
SubstanceAmount
Amount of substance units.
MassRate
Mass rate units. Can represent the time rate of change of a mass or a mass flow rate.
Definition: MassRate.hpp:53
@ GramPerMinute
Gram per minute (g/min) mass rate unit.
@ SlugPerSecond
Slug per second (slug/s) mass rate unit.
@ PoundPerSecond
Pound per second (lbm/s) mass rate unit.
@ KilogramPerHour
Kilogram per hour (kg/hr) mass rate unit.
@ KilogramPerSecond
Kilogram per second (kg/s) mass rate unit.
@ SlinchPerHour
Slinch per hour (slinch/hr) mass rate unit.
@ PoundPerMinute
Pound per minute (lbm/min) mass rate unit.
@ SlinchPerMinute
Slinch per minute (slinch/min) mass rate unit.
@ SlugPerMinute
Slug per minute (slug/min) mass rate unit.
@ GramPerSecond
Gram per second (g/s) mass rate unit.
@ SlugPerHour
Slug per hour (slug/hr) mass rate unit.
@ KilogramPerMinute
Kilogram per minute (kg/min) mass rate unit.
@ PoundPerHour
Pound per hour (lbm/hr) mass rate unit.
@ GramPerHour
Gram per hour (g/hr) mass rate unit.
@ SlinchPerSecond
Slinch per second (slinch/s) mass rate 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)