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
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
48namespace PhQ {
49
50namespace Unit {
51
52/// \brief Mass rate units. Can represent the time rate of change of a mass or a mass flow rate.
53enum 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).
103template <>
104inline constexpr const Unit::MassRate Standard<Unit::MassRate>{Unit::MassRate::KilogramPerSecond};
105
106/// \brief Physical dimension set of time rate of mass units.
107template <>
108inline constexpr const Dimensions RelatedDimensions<Unit::MassRate>{
109 Dimensions{Dimension::Time{-1}, Dimension::Length{0}, Dimension::Mass{1},
110 Dimension::ElectricCurrent{0}, Dimension::Temperature{0},
111 Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
112};
113
114inline std::ostream& operator<<(std::ostream& stream, const Unit::MassRate unit) {
115 stream << Abbreviation(unit);
116 return stream;
117}
118
119namespace Internal {
120
121template <>
122inline const std::map<UnitSystem, Unit::MassRate> ConsistentUnits<Unit::MassRate>{
127};
128
129template <>
130inline const std::map<Unit::MassRate, UnitSystem> RelatedUnitSystems<Unit::MassRate>{
135};
136
137template <>
138inline const std::map<Unit::MassRate, std::string_view> Abbreviations<Unit::MassRate>{
142 {Unit::MassRate::SlinchPerSecond, "slinch/s" },
146 {Unit::MassRate::SlugPerMinute, "slug/min" },
147 {Unit::MassRate::SlinchPerMinute, "slinch/min"},
148 {Unit::MassRate::PoundPerMinute, "lbm/min" },
151 {Unit::MassRate::SlugPerHour, "slug/hr" },
152 {Unit::MassRate::SlinchPerHour, "slinch/hr" },
153 {Unit::MassRate::PoundPerHour, "lbm/hr" },
154};
155
156template <>
157inline const std::unordered_map<std::string_view, Unit::MassRate> Spellings<Unit::MassRate>{
161 {"slinch/s", Unit::MassRate::SlinchPerSecond },
166 {"slug/min", Unit::MassRate::SlugPerMinute },
167 {"slinch/min", Unit::MassRate::SlinchPerMinute },
168 {"lbm/min", Unit::MassRate::PoundPerMinute },
172 {"slug/hr", Unit::MassRate::SlugPerHour },
173 {"slinch/hr", Unit::MassRate::SlinchPerHour },
174 {"lbm/hr", Unit::MassRate::PoundPerHour },
176};
177
178template <>
179template <typename NumericType>
180inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::KilogramPerSecond>::FromStandard(
181 NumericType& /*value*/) noexcept {}
182
183template <>
184template <typename NumericType>
185inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::KilogramPerSecond>::ToStandard(
186 NumericType& /*value*/) noexcept {}
187
188template <>
189template <typename NumericType>
190inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::GramPerSecond>::FromStandard(
191 NumericType& value) noexcept {
192 value *= static_cast<NumericType>(1000.0L);
193}
194
195template <>
196template <typename NumericType>
197inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::GramPerSecond>::ToStandard(
198 NumericType& value) noexcept {
199 value *= static_cast<NumericType>(0.001L);
200}
201
202template <>
203template <typename NumericType>
204inline 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
210template <>
211template <typename NumericType>
212inline 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
218template <>
219template <typename NumericType>
220inline 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
226template <>
227template <typename NumericType>
228inline 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
234template <>
235template <typename NumericType>
236inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::PoundPerSecond>::FromStandard(
237 NumericType& value) noexcept {
238 value /= static_cast<NumericType>(0.45359237L);
239}
240
241template <>
242template <typename NumericType>
243inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::PoundPerSecond>::ToStandard(
244 NumericType& value) noexcept {
245 value *= static_cast<NumericType>(0.45359237L);
246}
247
248template <>
249template <typename NumericType>
250inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::KilogramPerMinute>::FromStandard(
251 NumericType& value) noexcept {
252 value *= static_cast<NumericType>(60.0L);
253}
254
255template <>
256template <typename NumericType>
257inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::KilogramPerMinute>::ToStandard(
258 NumericType& value) noexcept {
259 value /= static_cast<NumericType>(60.0L);
260}
261
262template <>
263template <typename NumericType>
264inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::GramPerMinute>::FromStandard(
265 NumericType& value) noexcept {
266 value *= static_cast<NumericType>(60000.0L);
267}
268
269template <>
270template <typename NumericType>
271inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::GramPerMinute>::ToStandard(
272 NumericType& value) noexcept {
273 value /= static_cast<NumericType>(60000.0L);
274}
275
276template <>
277template <typename NumericType>
278inline 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
284template <>
285template <typename NumericType>
286inline 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
292template <>
293template <typename NumericType>
294inline 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
300template <>
301template <typename NumericType>
302inline 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
308template <>
309template <typename NumericType>
310inline 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
315template <>
316template <typename NumericType>
317inline 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
322template <>
323template <typename NumericType>
324inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::KilogramPerHour>::FromStandard(
325 NumericType& value) noexcept {
326 value *= static_cast<NumericType>(3600.0L);
327}
328
329template <>
330template <typename NumericType>
331inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::KilogramPerHour>::ToStandard(
332 NumericType& value) noexcept {
333 value /= static_cast<NumericType>(3600.0L);
334}
335
336template <>
337template <typename NumericType>
338inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::GramPerHour>::FromStandard(
339 NumericType& value) noexcept {
340 value *= static_cast<NumericType>(3600000.0L);
341}
342
343template <>
344template <typename NumericType>
345inline constexpr void Conversion<Unit::MassRate, Unit::MassRate::GramPerHour>::ToStandard(
346 NumericType& value) noexcept {
347 value /= static_cast<NumericType>(3600000.0L);
348}
349
350template <>
351template <typename NumericType>
352inline 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
358template <>
359template <typename NumericType>
360inline 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
366template <>
367template <typename NumericType>
368inline 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
374template <>
375template <typename NumericType>
376inline 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
382template <>
383template <typename NumericType>
384inline 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
389template <>
390template <typename NumericType>
391inline 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
396template <typename NumericType>
397inline 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
432template <typename NumericType>
433inline const std::
434 map<Unit::MassRate, 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
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.
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