Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
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 
48 namespace PhQ {
49 
50 namespace Unit {
51 
52 /// \brief Energy consumption in transport units.
53 enum 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).
115 template <>
116 inline constexpr const Unit::TransportEnergyConsumption Standard<Unit::TransportEnergyConsumption>{
118 
119 /// \brief Physical dimension set of transport energy consumption units.
120 template <>
121 inline constexpr const Dimensions RelatedDimensions<Unit::TransportEnergyConsumption>{
122  Dimensions{Dimension::Time{-2}, Dimension::Length{1}, Dimension::Mass{1},
124  Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
125 };
126 
127 inline std::ostream& operator<<(std::ostream& stream, const Unit::TransportEnergyConsumption unit) {
128  stream << Abbreviation(unit);
129  return stream;
130 }
131 
132 namespace Internal {
133 
134 template <>
135 inline const std::map<UnitSystem, Unit::TransportEnergyConsumption>
136  ConsistentUnits<Unit::TransportEnergyConsumption>{
142 };
143 
144 template <>
145 inline const std::map<Unit::TransportEnergyConsumption, UnitSystem>
146  RelatedUnitSystems<Unit::TransportEnergyConsumption>{
152 };
153 
154 // clang-format off
155 
156 template <>
157 inline const std::map<Unit::TransportEnergyConsumption, std::string_view>
158  Abbreviations<Unit::TransportEnergyConsumption>{
178 };
179 
180 template <>
181 inline const std::unordered_map<std::string_view, Unit::TransportEnergyConsumption>
182  Spellings<Unit::TransportEnergyConsumption>{
216 };
217 
218 // clang-format on
219 
220 template <>
221 template <typename NumericType>
222 inline constexpr void
223 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::JoulePerMetre>::
224  FromStandard(NumericType& /*value*/) noexcept {}
225 
226 template <>
227 template <typename NumericType>
228 inline constexpr void
229 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::JoulePerMetre>::
230  ToStandard(NumericType& /*value*/) noexcept {}
231 
232 template <>
233 template <typename NumericType>
234 inline constexpr void
235 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::JoulePerMile>::
236  FromStandard(NumericType& value) noexcept {
237  value *= static_cast<NumericType>(1609.344L);
238 }
239 
240 template <>
241 template <typename NumericType>
242 inline constexpr void
243 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::JoulePerMile>::
244  ToStandard(NumericType& value) noexcept {
245  value /= static_cast<NumericType>(1609.344L);
246 }
247 
248 template <>
249 template <typename NumericType>
250 inline constexpr void
251 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::JoulePerKilometre>::
252  FromStandard(NumericType& value) noexcept {
253  value *= static_cast<NumericType>(1000.0L);
254 }
255 
256 template <>
257 template <typename NumericType>
258 inline constexpr void
259 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::JoulePerKilometre>::
260  ToStandard(NumericType& value) noexcept {
261  value *= static_cast<NumericType>(0.001L);
262 }
263 
264 template <>
265 template <typename NumericType>
266 inline constexpr void Conversion<Unit::TransportEnergyConsumption,
268  FromStandard(NumericType& value) noexcept {
269  value *= static_cast<NumericType>(1000000.0L);
270 }
271 
272 template <>
273 template <typename NumericType>
274 inline constexpr void Conversion<Unit::TransportEnergyConsumption,
276  ToStandard(NumericType& value) noexcept {
277  value *= static_cast<NumericType>(0.000001L);
278 }
279 
280 template <>
281 template <typename NumericType>
282 inline constexpr void
283 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::KilojoulePerMile>::
284  FromStandard(NumericType& value) noexcept {
285  value *= static_cast<NumericType>(1.609344L);
286 }
287 
288 template <>
289 template <typename NumericType>
290 inline constexpr void
291 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::KilojoulePerMile>::
292  ToStandard(NumericType& value) noexcept {
293  value /= static_cast<NumericType>(1.609344L);
294 }
295 
296 template <>
297 template <typename NumericType>
298 inline constexpr void
299 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::WattMinutePerMile>::
300  FromStandard(NumericType& value) noexcept {
301  value *= static_cast<NumericType>(1609.344L) / static_cast<NumericType>(60.0L);
302 }
303 
304 template <>
305 template <typename NumericType>
306 inline constexpr void
307 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::WattMinutePerMile>::
308  ToStandard(NumericType& value) noexcept {
309  value *= static_cast<NumericType>(60.0L) / static_cast<NumericType>(1609.344L);
310 }
311 
312 template <>
313 template <typename NumericType>
314 inline constexpr void
315 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::WattHourPerMile>::
316  FromStandard(NumericType& value) noexcept {
317  value *= static_cast<NumericType>(1609.344L) / static_cast<NumericType>(3600.0L);
318 }
319 
320 template <>
321 template <typename NumericType>
322 inline constexpr void
323 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::WattHourPerMile>::
324  ToStandard(NumericType& value) noexcept {
325  value *= static_cast<NumericType>(3600.0L) / static_cast<NumericType>(1609.344L);
326 }
327 
328 template <>
329 template <typename NumericType>
330 inline constexpr void Conversion<Unit::TransportEnergyConsumption,
332  FromStandard(NumericType& value) noexcept {
333  value /= static_cast<NumericType>(0.06L);
334 }
335 
336 template <>
337 template <typename NumericType>
338 inline constexpr void Conversion<Unit::TransportEnergyConsumption,
340  ToStandard(NumericType& value) noexcept {
341  value *= static_cast<NumericType>(0.06L);
342 }
343 
344 template <>
345 template <typename NumericType>
346 inline constexpr void Conversion<Unit::TransportEnergyConsumption,
348  FromStandard(NumericType& value) noexcept {
349  value /= static_cast<NumericType>(3.6L);
350 }
351 
352 template <>
353 template <typename NumericType>
354 inline constexpr void
357  value) noexcept {
358  value *= static_cast<NumericType>(3.6L);
359 }
360 
361 template <>
362 template <typename NumericType>
363 inline constexpr void
364 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::WattMinutePerMetre>::
365  FromStandard(NumericType& value) noexcept {
366  value /= static_cast<NumericType>(60.0L);
367 }
368 
369 template <>
370 template <typename NumericType>
371 inline constexpr void
372 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::WattMinutePerMetre>::
373  ToStandard(NumericType& value) noexcept {
374  value *= static_cast<NumericType>(60.0L);
375 }
376 
377 template <>
378 template <typename NumericType>
379 inline constexpr void
380 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::WattHourPerMetre>::
381  FromStandard(NumericType& value) noexcept {
382  value /= static_cast<NumericType>(3600.0L);
383 }
384 
385 template <>
386 template <typename NumericType>
387 inline constexpr void
388 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::WattHourPerMetre>::
389  ToStandard(NumericType& value) noexcept {
390  value *= static_cast<NumericType>(3600.0L);
391 }
392 
393 template <>
394 template <typename NumericType>
395 inline constexpr void Conversion<Unit::TransportEnergyConsumption,
397  FromStandard(NumericType& value) noexcept {
398  value *= static_cast<NumericType>(1609.344L) / static_cast<NumericType>(60000.0L);
399 }
400 
401 template <>
402 template <typename NumericType>
403 inline constexpr void Conversion<Unit::TransportEnergyConsumption,
405  ToStandard(NumericType& value) noexcept {
406  value *= static_cast<NumericType>(60000.0L) / static_cast<NumericType>(1609.344L);
407 }
408 
409 template <>
410 template <typename NumericType>
411 inline constexpr void Conversion<Unit::TransportEnergyConsumption,
413  FromStandard(NumericType& value) noexcept {
414  value *= static_cast<NumericType>(1609.344L) / static_cast<NumericType>(3600000.0L);
415 }
416 
417 template <>
418 template <typename NumericType>
419 inline constexpr void
422  value) noexcept {
423  value *= static_cast<NumericType>(3600000.0L) / static_cast<NumericType>(1609.344L);
424 }
425 
426 template <>
427 template <typename NumericType>
428 inline constexpr void Conversion<Unit::TransportEnergyConsumption,
430  FromStandard(NumericType& value) noexcept {
431  value /= static_cast<NumericType>(60.0L);
432 }
433 
434 template <>
435 template <typename NumericType>
436 inline constexpr void Conversion<Unit::TransportEnergyConsumption,
438  ToStandard(NumericType& value) noexcept {
439  value *= static_cast<NumericType>(60.0L);
440 }
441 
442 template <>
443 template <typename NumericType>
444 inline constexpr void Conversion<Unit::TransportEnergyConsumption,
446  FromStandard(NumericType& value) noexcept {
447  value /= static_cast<NumericType>(3600.0L);
448 }
449 
450 template <>
451 template <typename NumericType>
452 inline constexpr void Conversion<Unit::TransportEnergyConsumption,
454  ToStandard(NumericType& value) noexcept {
455  value *= static_cast<NumericType>(3600.0L);
456 }
457 
458 template <>
459 template <typename NumericType>
460 inline constexpr void Conversion<Unit::TransportEnergyConsumption,
462  FromStandard(NumericType& value) noexcept {
463  value /= static_cast<NumericType>(60000.0L);
464 }
465 
466 template <>
467 template <typename NumericType>
468 inline constexpr void Conversion<Unit::TransportEnergyConsumption,
470  ToStandard(NumericType& value) noexcept {
471  value *= static_cast<NumericType>(60000.0L);
472 }
473 
474 template <>
475 template <typename NumericType>
476 inline constexpr void Conversion<Unit::TransportEnergyConsumption,
478  FromStandard(NumericType& value) noexcept {
479  value /= static_cast<NumericType>(3600000.0L);
480 }
481 
482 template <>
483 template <typename NumericType>
484 inline constexpr void
487  value) noexcept {
488  value *= static_cast<NumericType>(3600000.0L);
489 }
490 
491 template <>
492 template <typename NumericType>
493 inline constexpr void
494 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::FootPoundPerFoot>::
495  FromStandard(NumericType& value) noexcept {
496  value /= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L);
497 }
498 
499 template <>
500 template <typename NumericType>
501 inline constexpr void
502 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::FootPoundPerFoot>::
503  ToStandard(NumericType& value) noexcept {
504  value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L);
505 }
506 
507 template <>
508 template <typename NumericType>
509 inline constexpr void
510 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::InchPoundPerInch>::
511  FromStandard(NumericType& value) noexcept {
512  value /= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L);
513 }
514 
515 template <>
516 template <typename NumericType>
517 inline constexpr void
518 Conversion<Unit::TransportEnergyConsumption, Unit::TransportEnergyConsumption::InchPoundPerInch>::
519  ToStandard(NumericType& value) noexcept {
520  value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L);
521 }
522 
523 template <typename NumericType>
524 inline const std::map<Unit::TransportEnergyConsumption,
525  std::function<void(NumericType* values, const std::size_t size)>>
526  MapOfConversionsFromStandard<Unit::TransportEnergyConsumption, NumericType>{
529  Unit::TransportEnergyConsumption::JoulePerMetre>::FromStandard<NumericType> },
532  Unit::TransportEnergyConsumption::JoulePerMile>::FromStandard<NumericType> },
534  Conversions<
536  Unit::TransportEnergyConsumption::JoulePerKilometre>::FromStandard<NumericType> },
538  Conversions<
542  Conversions<
544  Unit::TransportEnergyConsumption::KilojoulePerMile>::FromStandard<NumericType> },
546  Conversions<
548  Unit::TransportEnergyConsumption::WattMinutePerMile>::FromStandard<NumericType> },
551  Unit::TransportEnergyConsumption::WattHourPerMile>::FromStandard<NumericType> },
553  Conversions<
557  Conversions<
559  Unit::TransportEnergyConsumption::WattHourPerKilometre>::FromStandard<NumericType> },
561  Conversions<
563  Unit::TransportEnergyConsumption::WattMinutePerMetre>::FromStandard<NumericType> },
565  Conversions<
567  Unit::TransportEnergyConsumption::WattHourPerMetre>::FromStandard<NumericType> },
569  Conversions<
571  Unit::TransportEnergyConsumption::KilowattMinutePerMile>::FromStandard<NumericType> },
573  Conversions<
575  Unit::TransportEnergyConsumption::KilowattHourPerMile>::FromStandard<NumericType> },
579  FromStandard<NumericType> },
583  FromStandard<NumericType> },
585  Conversions<
589  Conversions<
591  Unit::TransportEnergyConsumption::KilowattHourPerMetre>::FromStandard<NumericType> },
593  Conversions<
595  Unit::TransportEnergyConsumption::FootPoundPerFoot>::FromStandard<NumericType> },
597  Conversions<
599  Unit::TransportEnergyConsumption::InchPoundPerInch>::FromStandard<NumericType> },
600 };
601 
602 template <typename NumericType>
603 inline const std::map<Unit::TransportEnergyConsumption,
604  std::function<void(NumericType* const values, const std::size_t size)>>
605  MapOfConversionsToStandard<Unit::TransportEnergyConsumption, NumericType>{
608  Unit::TransportEnergyConsumption::JoulePerMetre>::ToStandard<NumericType> },
611  Unit::TransportEnergyConsumption::JoulePerMile>::ToStandard<NumericType> },
614  Unit::TransportEnergyConsumption::JoulePerKilometre>::ToStandard<NumericType> },
616  Conversions<
621  Unit::TransportEnergyConsumption::KilojoulePerMile>::ToStandard<NumericType> },
624  Unit::TransportEnergyConsumption::WattMinutePerMile>::ToStandard<NumericType> },
627  Unit::TransportEnergyConsumption::WattHourPerMile>::ToStandard<NumericType> },
629  Conversions<
633  Conversions<
635  Unit::TransportEnergyConsumption::WattHourPerKilometre>::ToStandard<NumericType> },
637  Conversions<
639  Unit::TransportEnergyConsumption::WattMinutePerMetre>::ToStandard<NumericType> },
642  Unit::TransportEnergyConsumption::WattHourPerMetre>::ToStandard<NumericType> },
644  Conversions<
648  Conversions<
650  Unit::TransportEnergyConsumption::KilowattHourPerMile>::ToStandard<NumericType> },
654  ToStandard<NumericType> },
656  Conversions<
660  Conversions<
664  Conversions<
666  Unit::TransportEnergyConsumption::KilowattHourPerMetre>::ToStandard<NumericType> },
669  Unit::TransportEnergyConsumption::FootPoundPerFoot>::ToStandard<NumericType> },
672  Unit::TransportEnergyConsumption::InchPoundPerInch>::ToStandard<NumericType> },
673 };
674 
675 } // namespace Internal
676 
677 } // namespace PhQ
678 
679 #endif // PHQ_UNIT_TRANSPORT_ENERGY_CONSUMPTION_HPP
ElectricCurrent
Electric current units.
Mass
Mass units.
Definition: Mass.hpp:53
Length
Length units.
Definition: Length.hpp:53
SubstanceAmount
Amount of substance units.
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.
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)