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
MassDensity.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_DENSITY_HPP
26#define PHQ_UNIT_MASS_DENSITY_HPP
27
28#include <cmath>
29#include <cstddef>
30#include <cstdint>
31#include <functional>
32#include <map>
33#include <ostream>
34#include <string_view>
35#include <unordered_map>
36
37#include "../Base.hpp"
38#include "../Dimension/ElectricCurrent.hpp"
39#include "../Dimension/Length.hpp"
40#include "../Dimension/LuminousIntensity.hpp"
41#include "../Dimension/Mass.hpp"
42#include "../Dimension/SubstanceAmount.hpp"
43#include "../Dimension/Temperature.hpp"
44#include "../Dimension/Time.hpp"
45#include "../Dimensions.hpp"
46#include "../Unit.hpp"
47#include "../UnitSystem.hpp"
48
49namespace PhQ {
50
51namespace Unit {
52
53/// \brief Mass density units.
54enum class MassDensity : int8_t {
55 /// \brief Kilogram per cubic metre (kg/m^3) mass density unit.
57
58 /// \brief Gram per cubic millimetre (g/mm^3) mass density unit.
60
61 /// \brief Slug per cubic foot (slug/ft^3) mass density unit.
63
64 /// \brief Slinch per cubic inch (slinch/in^3) mass density unit.
66
67 /// \brief Pound per cubic foot (lbm/ft^3) mass density unit.
69
70 /// \brief Pound per cubic inch (lbm/in^3) mass density unit.
72};
73
74} // namespace Unit
75
76/// \brief Standard mass density unit: kilogram per cubic metre (kg/m^3).
77template <>
78inline constexpr const Unit::
79 MassDensity Standard<Unit::MassDensity>{Unit::MassDensity::KilogramPerCubicMetre};
80
81/// \brief Physical dimension set of mass density units.
82template <>
83inline constexpr const Dimensions RelatedDimensions<Unit::MassDensity>{
84 Dimensions{Dimension::Time{0}, Dimension::Length{-3}, Dimension::Mass{1},
85 Dimension::ElectricCurrent{0}, Dimension::Temperature{0},
86 Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
87};
88
89inline std::ostream& operator<<(std::ostream& stream, const Unit::MassDensity unit) {
90 stream << Abbreviation(unit);
91 return stream;
92}
93
94namespace Internal {
95
96template <>
97inline const std::map<UnitSystem, Unit::MassDensity> ConsistentUnits<Unit::MassDensity>{
102};
103
104template <>
105inline const std::map<Unit::MassDensity, UnitSystem> RelatedUnitSystems<Unit::MassDensity>{
110};
111
112template <>
113inline const std::map<Unit::MassDensity, std::string_view> Abbreviations<Unit::MassDensity>{
120};
121
122template <>
123inline const std::unordered_map<std::string_view, Unit::MassDensity> Spellings<Unit::MassDensity>{
132 {"slug/ft/ft/ft", Unit::MassDensity::SlugPerCubicFoot },
135 {"slinch/in/in/in", Unit::MassDensity::SlinchPerCubicInch },
138 {"lbm/ft/ft/ft", Unit::MassDensity::PoundPerCubicFoot },
141 {"lb/ft/ft/ft", Unit::MassDensity::PoundPerCubicFoot },
144 {"lbm/in/in/in", Unit::MassDensity::PoundPerCubicInch },
147 {"lb/in/in/in", Unit::MassDensity::PoundPerCubicInch },
148};
149
150template <>
151template <typename NumericType>
152inline constexpr void Conversion<Unit::MassDensity, Unit::MassDensity::KilogramPerCubicMetre>::
153 FromStandard(NumericType& /*value*/) noexcept {}
154
155template <>
156template <typename NumericType>
157inline constexpr void Conversion<Unit::MassDensity, Unit::MassDensity::KilogramPerCubicMetre>::
158 ToStandard(NumericType& /*value*/) noexcept {}
159
160template <>
161template <typename NumericType>
162inline constexpr void Conversion<Unit::MassDensity, Unit::MassDensity::GramPerCubicMillimetre>::
163 FromStandard(NumericType& value) noexcept {
164 value *= static_cast<NumericType>(0.000001L);
165}
166
167template <>
168template <typename NumericType>
169inline constexpr void Conversion<Unit::MassDensity, Unit::MassDensity::GramPerCubicMillimetre>::
170 ToStandard(NumericType& value) noexcept {
171 value *= static_cast<NumericType>(1000000.0L);
172}
173
174template <>
175template <typename NumericType>
176inline constexpr void Conversion<Unit::MassDensity, Unit::MassDensity::SlugPerCubicFoot>::
177 FromStandard(NumericType& value) noexcept {
178 value *= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L)
179 * static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L)
180 / (static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L));
181}
182
183template <>
184template <typename NumericType>
185inline constexpr void Conversion<Unit::MassDensity, Unit::MassDensity::SlugPerCubicFoot>::
186 ToStandard(NumericType& value) noexcept {
187 value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L)
188 / std::pow(static_cast<NumericType>(0.3048L), 4);
189}
190
191template <>
192template <typename NumericType>
193inline constexpr void Conversion<Unit::MassDensity, Unit::MassDensity::SlinchPerCubicInch>::
194 FromStandard(NumericType& value) noexcept {
195 value *= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L)
196 * static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L)
197 / (static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L));
198}
199
200template <>
201template <typename NumericType>
202inline constexpr void Conversion<Unit::MassDensity, Unit::MassDensity::SlinchPerCubicInch>::
203 ToStandard(NumericType& value) noexcept {
204 value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L)
205 / std::pow(static_cast<NumericType>(0.0254L), 4);
206}
207
208template <>
209template <typename NumericType>
210inline constexpr void Conversion<Unit::MassDensity, Unit::MassDensity::PoundPerCubicFoot>::
211 FromStandard(NumericType& value) noexcept {
212 value *= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L)
213 * static_cast<NumericType>(0.3048L) / static_cast<NumericType>(0.45359237L);
214}
215
216template <>
217template <typename NumericType>
218inline constexpr void Conversion<Unit::MassDensity, Unit::MassDensity::PoundPerCubicFoot>::
219 ToStandard(NumericType& value) noexcept {
220 value *= static_cast<NumericType>(0.45359237L) / std::pow(static_cast<NumericType>(0.3048L), 3);
221}
222
223template <>
224template <typename NumericType>
225inline constexpr void Conversion<Unit::MassDensity, Unit::MassDensity::PoundPerCubicInch>::
226 FromStandard(NumericType& value) noexcept {
227 value *= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L)
228 * static_cast<NumericType>(0.0254L) / static_cast<NumericType>(0.45359237L);
229}
230
231template <>
232template <typename NumericType>
233inline constexpr void Conversion<Unit::MassDensity, Unit::MassDensity::PoundPerCubicInch>::
234 ToStandard(NumericType& value) noexcept {
235 value *= static_cast<NumericType>(0.45359237L) / std::pow(static_cast<NumericType>(0.0254L), 3);
236}
237
238template <typename NumericType>
239inline const std::
240 map<Unit::MassDensity, std::function<void(NumericType* values, const std::size_t size)>>
241 MapOfConversionsFromStandard<Unit::MassDensity, NumericType>{
243 Conversions<Unit::MassDensity, Unit::MassDensity::KilogramPerCubicMetre>::
244 FromStandard<NumericType>},
246 Conversions<Unit::MassDensity, Unit::MassDensity::GramPerCubicMillimetre>::
247 FromStandard<NumericType>},
249 Conversions<Unit::MassDensity, Unit::MassDensity::SlugPerCubicFoot>::
250 FromStandard<NumericType>},
252 Conversions<Unit::MassDensity, Unit::MassDensity::SlinchPerCubicInch>::
253 FromStandard<NumericType>},
255 Conversions<Unit::MassDensity, Unit::MassDensity::PoundPerCubicFoot>::
256 FromStandard<NumericType>},
258 Conversions<Unit::MassDensity, Unit::MassDensity::PoundPerCubicInch>::
259 FromStandard<NumericType>},
260};
261
262template <typename NumericType>
263inline const std::
264 map<Unit::MassDensity, std::function<void(NumericType* const values, const std::size_t size)>>
265 MapOfConversionsToStandard<Unit::MassDensity, NumericType>{
267 Conversions<Unit::MassDensity, Unit::MassDensity::KilogramPerCubicMetre>::
268 ToStandard<NumericType>},
270 Conversions<Unit::MassDensity, Unit::MassDensity::GramPerCubicMillimetre>::
271 ToStandard<NumericType>},
273 Conversions<Unit::MassDensity, Unit::MassDensity::SlugPerCubicFoot>::
274 ToStandard<NumericType>},
276 Conversions<Unit::MassDensity, Unit::MassDensity::SlinchPerCubicInch>::
277 ToStandard<NumericType>},
279 Conversions<Unit::MassDensity, Unit::MassDensity::PoundPerCubicFoot>::
280 ToStandard<NumericType>},
282 Conversions<Unit::MassDensity, Unit::MassDensity::PoundPerCubicInch>::
283 ToStandard<NumericType>},
284};
285
286} // namespace Internal
287
288} // namespace PhQ
289
290#endif // PHQ_UNIT_MASS_DENSITY_HPP
MassDensity
Mass density units.
@ SlugPerCubicFoot
Slug per cubic foot (slug/ft^3) mass density unit.
@ PoundPerCubicInch
Pound per cubic inch (lbm/in^3) mass density unit.
@ SlinchPerCubicInch
Slinch per cubic inch (slinch/in^3) mass density unit.
@ GramPerCubicMillimetre
Gram per cubic millimetre (g/mm^3) mass density unit.
@ PoundPerCubicFoot
Pound per cubic foot (lbm/ft^3) mass density unit.
@ KilogramPerCubicMetre
Kilogram per cubic metre (kg/m^3) mass density 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