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
SpecificEnergy.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_ENERGY_HPP
26#define PHQ_UNIT_SPECIFIC_ENERGY_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 energy units.
53enum class SpecificEnergy : int8_t {
54 /// \brief Joule per kilogram (J/kg) specific energy unit.
56
57 /// \brief Nanojoule per gram (nJ/g) specific energy unit.
59
60 /// \brief Foot-pound per slug (ft·lbf/slug) specific energy unit.
62
63 /// \brief Inch-pound per slinch (in·lbf/slinch) specific energy unit.
65};
66
67} // namespace Unit
68
69/// \brief Standard mass-specific energy unit: joule per kilogram (J/kg).
70template <>
71inline constexpr const Unit::
72 SpecificEnergy Standard<Unit::SpecificEnergy>{Unit::SpecificEnergy::JoulePerKilogram};
73
74/// \brief Physical dimension set of mass-specific energy units.
75template <>
76inline constexpr const Dimensions RelatedDimensions<Unit::SpecificEnergy>{
77 Dimensions{Dimension::Time{-2}, 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::SpecificEnergy unit) {
83 stream << Abbreviation(unit);
84 return stream;
85}
86
87namespace Internal {
88
89template <>
90inline const std::map<UnitSystem, Unit::SpecificEnergy> ConsistentUnits<Unit::SpecificEnergy>{
95};
96
97template <>
98inline const std::map<Unit::SpecificEnergy, UnitSystem> RelatedUnitSystems<Unit::SpecificEnergy>{
103};
104
105// clang-format off
106
107template <>
108inline const std::map<Unit::SpecificEnergy, std::string_view> Abbreviations<Unit::SpecificEnergy>{
113};
114
115template <>
116inline const std::unordered_map<std::string_view, Unit::SpecificEnergy> Spellings<
156};
157
158// clang-format on
159
160template <>
161template <typename NumericType>
162inline constexpr void Conversion<Unit::SpecificEnergy, Unit::SpecificEnergy::JoulePerKilogram>::
163 FromStandard(NumericType& /*value*/) noexcept {}
164
165template <>
166template <typename NumericType>
167inline constexpr void Conversion<Unit::SpecificEnergy, Unit::SpecificEnergy::JoulePerKilogram>::
168 ToStandard(NumericType& /*value*/) noexcept {}
169
170template <>
171template <typename NumericType>
172inline constexpr void Conversion<Unit::SpecificEnergy, Unit::SpecificEnergy::NanojoulePerGram>::
173 FromStandard(NumericType& value) noexcept {
174 value *= static_cast<NumericType>(1000000.0L);
175}
176
177template <>
178template <typename NumericType>
179inline constexpr void Conversion<Unit::SpecificEnergy, Unit::SpecificEnergy::NanojoulePerGram>::
180 ToStandard(NumericType& value) noexcept {
181 value *= static_cast<NumericType>(0.000001L);
182}
183
184template <>
185template <typename NumericType>
186inline constexpr void Conversion<Unit::SpecificEnergy, Unit::SpecificEnergy::FootPoundPerSlug>::
187 FromStandard(NumericType& value) noexcept {
188 value /= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L);
189}
190
191template <>
192template <typename NumericType>
193inline constexpr void Conversion<Unit::SpecificEnergy, Unit::SpecificEnergy::FootPoundPerSlug>::
194 ToStandard(NumericType& value) noexcept {
195 value *= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L);
196}
197
198template <>
199template <typename NumericType>
200inline constexpr void Conversion<Unit::SpecificEnergy, Unit::SpecificEnergy::InchPoundPerSlinch>::
201 FromStandard(NumericType& value) noexcept {
202 value /= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L);
203}
204
205template <>
206template <typename NumericType>
207inline constexpr void Conversion<Unit::SpecificEnergy, Unit::SpecificEnergy::InchPoundPerSlinch>::
208 ToStandard(NumericType& value) noexcept {
209 value *= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L);
210}
211
212template <typename NumericType>
213inline const std::
214 map<Unit::SpecificEnergy, std::function<void(NumericType* values, const std::size_t size)>>
215 MapOfConversionsFromStandard<Unit::SpecificEnergy, NumericType>{
217 Conversions<Unit::SpecificEnergy, Unit::SpecificEnergy::JoulePerKilogram>::
218 FromStandard<NumericType>},
220 Conversions<Unit::SpecificEnergy, Unit::SpecificEnergy::NanojoulePerGram>::
221 FromStandard<NumericType>},
223 Conversions<Unit::SpecificEnergy, Unit::SpecificEnergy::FootPoundPerSlug>::
224 FromStandard<NumericType>},
226 Conversions<Unit::SpecificEnergy, Unit::SpecificEnergy::InchPoundPerSlinch>::
227 FromStandard<NumericType>},
228};
229
230template <typename NumericType>
231inline const std::map<Unit::SpecificEnergy,
232 std::function<void(NumericType* const values, const std::size_t size)>>
233 MapOfConversionsToStandard<Unit::SpecificEnergy, NumericType>{
235 Conversions<Unit::SpecificEnergy, Unit::SpecificEnergy::JoulePerKilogram>::
236 ToStandard<NumericType>},
238 Conversions<Unit::SpecificEnergy, Unit::SpecificEnergy::NanojoulePerGram>::
239 ToStandard<NumericType>},
241 Conversions<Unit::SpecificEnergy, Unit::SpecificEnergy::FootPoundPerSlug>::
242 ToStandard<NumericType>},
244 Conversions<Unit::SpecificEnergy, Unit::SpecificEnergy::InchPoundPerSlinch>::
245 ToStandard<NumericType>},
246};
247
248} // namespace Internal
249
250} // namespace PhQ
251
252#endif // PHQ_UNIT_SPECIFIC_ENERGY_HPP
SpecificEnergy
Mass-specific energy units.
@ NanojoulePerGram
Nanojoule per gram (nJ/g) specific energy unit.
@ JoulePerKilogram
Joule per kilogram (J/kg) specific energy unit.
@ FootPoundPerSlug
Foot-pound per slug (ft·lbf/slug) specific energy unit.
@ InchPoundPerSlinch
Inch-pound per slinch (in·lbf/slinch) specific energy 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