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
TransportEnergyConsumption.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_TRANSPORT_ENERGY_CONSUMPTION_HPP
26#define PHQ_UNIT_TRANSPORT_ENERGY_CONSUMPTION_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 Energy consumption in transport units.
53enum class TransportEnergyConsumption : int8_t {
54 /// \brief Joule per metre (J/m) transport energy consumption unit.
56
57 /// \brief Joule per mile (J/mi) transport energy consumption unit.
59
60 /// \brief Joule per kilometre (J/km) transport energy consumption unit.
62
63 /// \brief Nanojoule per millimetre (nJ/mm) transport energy consumption unit.
65
66 /// \brief Kilojoule per mile (kJ/mi) transport energy consumption unit.
68
69 /// \brief Watt-minute per mile (W·min/mi) transport energy consumption unit.
71
72 /// \brief Watt-hour per mile (W·hr/mi) transport energy consumption unit.
74
75 /// \brief Watt-minute per kilometre (W·min/km) transport energy consumption unit.
77
78 /// \brief Watt-hour per kilometre (W·hr/km) transport energy consumption unit.
80
81 /// \brief Watt-minute per metre (W·min/m) transport energy consumption unit.
83
84 /// \brief Watt-hour per metre (W·hr/m) transport energy consumption unit.
86
87 /// \brief Kilowatt-minute per mile (kW·min/mi) transport energy consumption unit.
89
90 /// \brief Kilowatt-hour per mile (kW·hr/mi) transport energy consumption unit.
92
93 /// \brief Kilowatt-minute per kilometre (kW·min/km) transport energy consumption unit.
95
96 /// \brief Kilowatt-hour per kilometre (kW·hr/km) transport energy consumption unit.
98
99 /// \brief Kilowatt-minute per metre (kW·min/m) transport energy consumption unit.
101
102 /// \brief Kilowatt-hour per metre (kW·hr/m) transport energy consumption unit.
104
105 /// \brief Foot-pound per foot (ft·lbf/ft) transport energy consumption unit.
107
108 /// \brief Inch-pound per inch (in·lbf/in) transport energy consumption unit.
110};
111
112} // namespace Unit
113
114/// \brief Standard transport energy consumption unit: joule per metre (J/m).
115template <>
116inline constexpr const Unit::TransportEnergyConsumption Standard<Unit::TransportEnergyConsumption>{
118
119/// \brief Physical dimension set of transport energy consumption units.
120template <>
121inline constexpr const Dimensions RelatedDimensions<Unit::TransportEnergyConsumption>{
122 Dimensions{Dimension::Time{-2}, Dimension::Length{1}, Dimension::Mass{1},
123 Dimension::ElectricCurrent{0}, Dimension::Temperature{0},
124 Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
125};
126
127inline std::ostream& operator<<(std::ostream& stream, const Unit::TransportEnergyConsumption unit) {
128 stream << Abbreviation(unit);
129 return stream;
130}
131
132namespace Internal {
133
134template <>
135inline const std::map<UnitSystem, Unit::TransportEnergyConsumption>
136 ConsistentUnits<Unit::TransportEnergyConsumption>{
142};
143
144template <>
145inline const std::map<Unit::TransportEnergyConsumption, UnitSystem>
146 RelatedUnitSystems<Unit::TransportEnergyConsumption>{
152};
153
154// clang-format off
155
156template <>
157inline const std::map<Unit::TransportEnergyConsumption, std::string_view>
158 Abbreviations<Unit::TransportEnergyConsumption>{
178};
179
180template <>
181inline const std::unordered_map<std::string_view, Unit::TransportEnergyConsumption>
182 Spellings<Unit::TransportEnergyConsumption>{
216};
217
218// clang-format on
219
220template <>
221template <typename NumericType>
222inline constexpr void
223Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::JoulePerMetre>::
224 FromStandard(NumericType& /*value*/) noexcept {}
225
226template <>
227template <typename NumericType>
228inline constexpr void
229Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::JoulePerMetre>::
230 ToStandard(NumericType& /*value*/) noexcept {}
231
232template <>
233template <typename NumericType>
234inline constexpr void
235Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::JoulePerMile>::
236 FromStandard(NumericType& value) noexcept {
237 value *= static_cast<NumericType>(1609.344L);
238}
239
240template <>
241template <typename NumericType>
242inline constexpr void
243Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::JoulePerMile>::
244 ToStandard(NumericType& value) noexcept {
245 value /= static_cast<NumericType>(1609.344L);
246}
247
248template <>
249template <typename NumericType>
250inline constexpr void
251Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::JoulePerKilometre>::
252 FromStandard(NumericType& value) noexcept {
253 value *= static_cast<NumericType>(1000.0L);
254}
255
256template <>
257template <typename NumericType>
258inline constexpr void
259Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::JoulePerKilometre>::
260 ToStandard(NumericType& value) noexcept {
261 value *= static_cast<NumericType>(0.001L);
262}
263
264template <>
265template <typename NumericType>
266inline constexpr void Conversion<Unit::TransportEnergyConsumption,
268 FromStandard(NumericType& value) noexcept {
269 value *= static_cast<NumericType>(1000000.0L);
270}
271
272template <>
273template <typename NumericType>
274inline constexpr void Conversion<Unit::TransportEnergyConsumption,
276 ToStandard(NumericType& value) noexcept {
277 value *= static_cast<NumericType>(0.000001L);
278}
279
280template <>
281template <typename NumericType>
282inline constexpr void
283Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::KilojoulePerMile>::
284 FromStandard(NumericType& value) noexcept {
285 value *= static_cast<NumericType>(1.609344L);
286}
287
288template <>
289template <typename NumericType>
290inline constexpr void
291Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::KilojoulePerMile>::
292 ToStandard(NumericType& value) noexcept {
293 value /= static_cast<NumericType>(1.609344L);
294}
295
296template <>
297template <typename NumericType>
298inline constexpr void
299Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::WattMinutePerMile>::
300 FromStandard(NumericType& value) noexcept {
301 value *= static_cast<NumericType>(1609.344L) / static_cast<NumericType>(60.0L);
302}
303
304template <>
305template <typename NumericType>
306inline constexpr void
307Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::WattMinutePerMile>::
308 ToStandard(NumericType& value) noexcept {
309 value *= static_cast<NumericType>(60.0L) / static_cast<NumericType>(1609.344L);
310}
311
312template <>
313template <typename NumericType>
314inline constexpr void
315Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::WattHourPerMile>::
316 FromStandard(NumericType& value) noexcept {
317 value *= static_cast<NumericType>(1609.344L) / static_cast<NumericType>(3600.0L);
318}
319
320template <>
321template <typename NumericType>
322inline constexpr void
323Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::WattHourPerMile>::
324 ToStandard(NumericType& value) noexcept {
325 value *= static_cast<NumericType>(3600.0L) / static_cast<NumericType>(1609.344L);
326}
327
328template <>
329template <typename NumericType>
330inline constexpr void Conversion<Unit::TransportEnergyConsumption,
332 FromStandard(NumericType& value) noexcept {
333 value /= static_cast<NumericType>(0.06L);
334}
335
336template <>
337template <typename NumericType>
338inline constexpr void Conversion<Unit::TransportEnergyConsumption,
340 ToStandard(NumericType& value) noexcept {
341 value *= static_cast<NumericType>(0.06L);
342}
343
344template <>
345template <typename NumericType>
346inline constexpr void Conversion<Unit::TransportEnergyConsumption,
348 FromStandard(NumericType& value) noexcept {
349 value /= static_cast<NumericType>(3.6L);
350}
351
352template <>
353template <typename NumericType>
354inline constexpr void Conversion<Unit::TransportEnergyConsumption,
356 ToStandard(NumericType& value) noexcept {
357 value *= static_cast<NumericType>(3.6L);
358}
359
360template <>
361template <typename NumericType>
362inline constexpr void
363Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::WattMinutePerMetre>::
364 FromStandard(NumericType& value) noexcept {
365 value /= static_cast<NumericType>(60.0L);
366}
367
368template <>
369template <typename NumericType>
370inline constexpr void
371Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::WattMinutePerMetre>::
372 ToStandard(NumericType& value) noexcept {
373 value *= static_cast<NumericType>(60.0L);
374}
375
376template <>
377template <typename NumericType>
378inline constexpr void
379Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::WattHourPerMetre>::
380 FromStandard(NumericType& value) noexcept {
381 value /= static_cast<NumericType>(3600.0L);
382}
383
384template <>
385template <typename NumericType>
386inline constexpr void
387Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::WattHourPerMetre>::
388 ToStandard(NumericType& value) noexcept {
389 value *= static_cast<NumericType>(3600.0L);
390}
391
392template <>
393template <typename NumericType>
394inline constexpr void Conversion<Unit::TransportEnergyConsumption,
396 FromStandard(NumericType& value) noexcept {
397 value *= static_cast<NumericType>(1609.344L) / static_cast<NumericType>(60000.0L);
398}
399
400template <>
401template <typename NumericType>
402inline constexpr void Conversion<Unit::TransportEnergyConsumption,
404 ToStandard(NumericType& value) noexcept {
405 value *= static_cast<NumericType>(60000.0L) / static_cast<NumericType>(1609.344L);
406}
407
408template <>
409template <typename NumericType>
410inline constexpr void Conversion<Unit::TransportEnergyConsumption,
412 FromStandard(NumericType& value) noexcept {
413 value *= static_cast<NumericType>(1609.344L) / static_cast<NumericType>(3600000.0L);
414}
415
416template <>
417template <typename NumericType>
418inline constexpr void Conversion<Unit::TransportEnergyConsumption,
420 ToStandard(NumericType& value) noexcept {
421 value *= static_cast<NumericType>(3600000.0L) / static_cast<NumericType>(1609.344L);
422}
423
424template <>
425template <typename NumericType>
426inline constexpr void Conversion<Unit::TransportEnergyConsumption,
428 FromStandard(NumericType& value) noexcept {
429 value /= static_cast<NumericType>(60.0L);
430}
431
432template <>
433template <typename NumericType>
434inline constexpr void Conversion<Unit::TransportEnergyConsumption,
436 ToStandard(NumericType& value) noexcept {
437 value *= static_cast<NumericType>(60.0L);
438}
439
440template <>
441template <typename NumericType>
442inline constexpr void Conversion<Unit::TransportEnergyConsumption,
444 FromStandard(NumericType& value) noexcept {
445 value /= static_cast<NumericType>(3600.0L);
446}
447
448template <>
449template <typename NumericType>
450inline constexpr void Conversion<Unit::TransportEnergyConsumption,
452 ToStandard(NumericType& value) noexcept {
453 value *= static_cast<NumericType>(3600.0L);
454}
455
456template <>
457template <typename NumericType>
458inline constexpr void Conversion<Unit::TransportEnergyConsumption,
460 FromStandard(NumericType& value) noexcept {
461 value /= static_cast<NumericType>(60000.0L);
462}
463
464template <>
465template <typename NumericType>
466inline constexpr void Conversion<Unit::TransportEnergyConsumption,
468 ToStandard(NumericType& value) noexcept {
469 value *= static_cast<NumericType>(60000.0L);
470}
471
472template <>
473template <typename NumericType>
474inline constexpr void Conversion<Unit::TransportEnergyConsumption,
476 FromStandard(NumericType& value) noexcept {
477 value /= static_cast<NumericType>(3600000.0L);
478}
479
480template <>
481template <typename NumericType>
482inline constexpr void Conversion<Unit::TransportEnergyConsumption,
484 ToStandard(NumericType& value) noexcept {
485 value *= static_cast<NumericType>(3600000.0L);
486}
487
488template <>
489template <typename NumericType>
490inline constexpr void
491Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::FootPoundPerFoot>::
492 FromStandard(NumericType& value) noexcept {
493 value /= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L);
494}
495
496template <>
497template <typename NumericType>
498inline constexpr void
499Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::FootPoundPerFoot>::
500 ToStandard(NumericType& value) noexcept {
501 value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L);
502}
503
504template <>
505template <typename NumericType>
506inline constexpr void
507Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::InchPoundPerInch>::
508 FromStandard(NumericType& value) noexcept {
509 value /= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L);
510}
511
512template <>
513template <typename NumericType>
514inline constexpr void
515Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::InchPoundPerInch>::
516 ToStandard(NumericType& value) noexcept {
517 value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L);
518}
519
520template <typename NumericType>
521inline const std::map<Unit::TransportEnergyConsumption,
522 std::function<void(NumericType* values, const std::size_t size)>>
523 MapOfConversionsFromStandard<Unit::TransportEnergyConsumption, NumericType>{
526 Unit::TransportEnergyConsumption::JoulePerMetre>::FromStandard<NumericType> },
529 Unit::TransportEnergyConsumption::JoulePerMile>::FromStandard<NumericType> },
532 Unit::TransportEnergyConsumption::JoulePerKilometre>::FromStandard<NumericType>},
536 FromStandard<NumericType> },
539 Unit::TransportEnergyConsumption::KilojoulePerMile>::FromStandard<NumericType> },
542 Unit::TransportEnergyConsumption::WattMinutePerMile>::FromStandard<NumericType>},
545 Unit::TransportEnergyConsumption::WattHourPerMile>::FromStandard<NumericType> },
549 FromStandard<NumericType> },
553 FromStandard<NumericType> },
557 FromStandard<NumericType> },
560 Unit::TransportEnergyConsumption::WattHourPerMetre>::FromStandard<NumericType> },
564 FromStandard<NumericType> },
568 FromStandard<NumericType> },
572 FromStandard<NumericType> },
576 FromStandard<NumericType> },
580 FromStandard<NumericType> },
584 FromStandard<NumericType> },
587 Unit::TransportEnergyConsumption::FootPoundPerFoot>::FromStandard<NumericType> },
590 Unit::TransportEnergyConsumption::InchPoundPerInch>::FromStandard<NumericType> },
591};
592
593template <typename NumericType>
594inline const std::map<Unit::TransportEnergyConsumption,
595 std::function<void(NumericType* const values, const std::size_t size)>>
596 MapOfConversionsToStandard<Unit::TransportEnergyConsumption, NumericType>{
599 Unit::TransportEnergyConsumption::JoulePerMetre>::ToStandard<NumericType> },
602 Unit::TransportEnergyConsumption::JoulePerMile>::ToStandard<NumericType> },
605 Unit::TransportEnergyConsumption::JoulePerKilometre>::ToStandard<NumericType> },
609 ToStandard<NumericType> },
612 Unit::TransportEnergyConsumption::KilojoulePerMile>::ToStandard<NumericType> },
615 Unit::TransportEnergyConsumption::WattMinutePerMile>::ToStandard<NumericType> },
618 Unit::TransportEnergyConsumption::WattHourPerMile>::ToStandard<NumericType> },
622 ToStandard<NumericType> },
626 ToStandard<NumericType> },
632 Unit::TransportEnergyConsumption::WattHourPerMetre>::ToStandard<NumericType> },
636 ToStandard<NumericType> },
643 ToStandard<NumericType> },
647 ToStandard<NumericType> },
651 ToStandard<NumericType> },
655 ToStandard<NumericType> },
658 Unit::TransportEnergyConsumption::FootPoundPerFoot>::ToStandard<NumericType> },
661 Unit::TransportEnergyConsumption::InchPoundPerInch>::ToStandard<NumericType> },
662};
663
664} // namespace Internal
665
666} // namespace PhQ
667
668#endif // PHQ_UNIT_TRANSPORT_ENERGY_CONSUMPTION_HPP
TransportEnergyConsumption
Energy consumption in transport units.
@ WattMinutePerMetre
Watt-minute per metre (W·min/m) transport energy consumption unit.
@ KilowattHourPerKilometre
Kilowatt-hour per kilometre (kW·hr/km) transport energy consumption unit.
@ KilowattHourPerMile
Kilowatt-hour per mile (kW·hr/mi) transport energy consumption unit.
@ JoulePerKilometre
Joule per kilometre (J/km) transport energy consumption unit.
@ WattHourPerMetre
Watt-hour per metre (W·hr/m) transport energy consumption unit.
@ KilojoulePerMile
Kilojoule per mile (kJ/mi) transport energy consumption unit.
@ KilowattMinutePerMetre
Kilowatt-minute per metre (kW·min/m) transport energy consumption unit.
@ NanojoulePerMillimetre
Nanojoule per millimetre (nJ/mm) transport energy consumption unit.
@ InchPoundPerInch
Inch-pound per inch (in·lbf/in) transport energy consumption unit.
@ FootPoundPerFoot
Foot-pound per foot (ft·lbf/ft) transport energy consumption unit.
@ WattMinutePerKilometre
Watt-minute per kilometre (W·min/km) transport energy consumption unit.
@ WattHourPerKilometre
Watt-hour per kilometre (W·hr/km) transport energy consumption unit.
@ JoulePerMetre
Joule per metre (J/m) transport energy consumption unit.
@ WattMinutePerMile
Watt-minute per mile (W·min/mi) transport energy consumption unit.
@ JoulePerMile
Joule per mile (J/mi) transport energy consumption unit.
@ WattHourPerMile
Watt-hour per mile (W·hr/mi) transport energy consumption unit.
@ KilowattMinutePerKilometre
Kilowatt-minute per kilometre (kW·min/km) transport energy consumption unit.
@ KilowattHourPerMetre
Kilowatt-hour per metre (kW·hr/m) transport energy consumption unit.
@ KilowattMinutePerMile
Kilowatt-minute per mile (kW·min/mi) transport energy consumption 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