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
Pressure.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_PRESSURE_HPP
26#define PHQ_UNIT_PRESSURE_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 Pressure units.
53enum class Pressure : int8_t {
54 /// \brief Pascal (Pa) pressure unit.
55 Pascal,
56
57 /// \brief Kilopascal (kPa) pressure unit.
59
60 /// \brief Megapascal (MPa) pressure unit.
62
63 /// \brief Gigapascal (GPa) pressure unit.
65
66 /// \brief Bar (bar) pressure unit.
67 Bar,
68
69 /// \brief Atmosphere (atm) pressure unit.
71
72 /// \brief Pound per square foot (lbf/ft^2) pressure unit.
74
75 /// \brief Pound per square inch (lbf/in^2) pressure unit.
77};
78
79} // namespace Unit
80
81/// \brief Standard pressure unit: pascal (Pa).
82template <>
83inline constexpr const Unit::Pressure Standard<Unit::Pressure>{Unit::Pressure::Pascal};
84
85/// \brief Physical dimension set of pressure units.
86template <>
87inline constexpr const Dimensions RelatedDimensions<Unit::Pressure>{
88 Dimensions{Dimension::Time{-2}, Dimension::Length{-1}, Dimension::Mass{1},
89 Dimension::ElectricCurrent{0}, Dimension::Temperature{0},
90 Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
91};
92
93inline std::ostream& operator<<(std::ostream& stream, const Unit::Pressure unit) {
94 stream << Abbreviation(unit);
95 return stream;
96}
97
98namespace Internal {
99
100template <>
101inline const std::map<UnitSystem, Unit::Pressure> ConsistentUnits<Unit::Pressure>{
106};
107
108template <>
109inline const std::map<Unit::Pressure, UnitSystem> RelatedUnitSystems<Unit::Pressure>{
112};
113
114template <>
115inline const std::map<Unit::Pressure, std::string_view> Abbreviations<Unit::Pressure>{
116 {Unit::Pressure::Pascal, "Pa" },
120 {Unit::Pressure::Bar, "bar" },
124};
125
126// clang-format off
127
128template <>
129inline const std::unordered_map<std::string_view, Unit::Pressure> Spellings<Unit::Pressure>{
130 {"Pa", Unit::Pressure::Pascal },
131 {"N/m^2", Unit::Pressure::Pascal },
132 {"N/m2", Unit::Pressure::Pascal },
133 {"kg/(m·s^2)", Unit::Pressure::Pascal },
134 {"kg/(m·s2)", Unit::Pressure::Pascal },
135 {"kg/(m*s^2)", Unit::Pressure::Pascal },
136 {"kg/(m*s2)", Unit::Pressure::Pascal },
137 {"kg/m/s^2", Unit::Pressure::Pascal },
138 {"kg/m/s2", Unit::Pressure::Pascal },
140 {"kN/m^2", Unit::Pressure::Kilopascal },
141 {"kN/m2", Unit::Pressure::Kilopascal },
143 {"N/mm^2", Unit::Pressure::Megapascal },
144 {"N/mm2", Unit::Pressure::Megapascal },
145 {"MN/m^2", Unit::Pressure::Megapascal },
146 {"MN/m2", Unit::Pressure::Megapascal },
148 {"GN/m^2", Unit::Pressure::Gigapascal },
149 {"GN/m2", Unit::Pressure::Gigapascal },
150 {"kN/mm^2", Unit::Pressure::Gigapascal },
151 {"kN/mm2", Unit::Pressure::Gigapascal },
152 {"bar", Unit::Pressure::Bar },
154 {"atmosphere", Unit::Pressure::Atmosphere },
165};
166
167// clang-format on
168
169template <>
170template <typename NumericType>
171inline constexpr void Conversion<Unit::Pressure, Unit::Pressure::Pascal>::FromStandard(
172 NumericType& /*value*/) noexcept {}
173
174template <>
175template <typename NumericType>
176inline constexpr void Conversion<Unit::Pressure, Unit::Pressure::Pascal>::ToStandard(
177 NumericType& /*value*/) noexcept {}
178
179template <>
180template <typename NumericType>
181inline constexpr void Conversion<Unit::Pressure, Unit::Pressure::Kilopascal>::FromStandard(
182 NumericType& value) noexcept {
183 value *= static_cast<NumericType>(0.001L);
184}
185
186template <>
187template <typename NumericType>
188inline constexpr void Conversion<Unit::Pressure, Unit::Pressure::Kilopascal>::ToStandard(
189 NumericType& value) noexcept {
190 value *= static_cast<NumericType>(1000.0L);
191}
192
193template <>
194template <typename NumericType>
195inline constexpr void Conversion<Unit::Pressure, Unit::Pressure::Megapascal>::FromStandard(
196 NumericType& value) noexcept {
197 value *= static_cast<NumericType>(0.000001L);
198}
199
200template <>
201template <typename NumericType>
202inline constexpr void Conversion<Unit::Pressure, Unit::Pressure::Megapascal>::ToStandard(
203 NumericType& value) noexcept {
204 value *= static_cast<NumericType>(1000000.0L);
205}
206
207template <>
208template <typename NumericType>
209inline constexpr void Conversion<Unit::Pressure, Unit::Pressure::Gigapascal>::FromStandard(
210 NumericType& value) noexcept {
211 value *= static_cast<NumericType>(0.000000001L);
212}
213
214template <>
215template <typename NumericType>
216inline constexpr void Conversion<Unit::Pressure, Unit::Pressure::Gigapascal>::ToStandard(
217 NumericType& value) noexcept {
218 value *= static_cast<NumericType>(1000000000.0L);
219}
220
221template <>
222template <typename NumericType>
223inline constexpr void Conversion<Unit::Pressure, Unit::Pressure::Bar>::FromStandard(
224 NumericType& value) noexcept {
225 value *= static_cast<NumericType>(0.00001L);
226}
227
228template <>
229template <typename NumericType>
230inline constexpr void Conversion<Unit::Pressure, Unit::Pressure::Bar>::ToStandard(
231 NumericType& value) noexcept {
232 value *= static_cast<NumericType>(100000.0L);
233}
234
235template <>
236template <typename NumericType>
237inline constexpr void Conversion<Unit::Pressure, Unit::Pressure::Atmosphere>::FromStandard(
238 NumericType& value) noexcept {
239 value /= static_cast<NumericType>(101325.0L);
240}
241
242template <>
243template <typename NumericType>
244inline constexpr void Conversion<Unit::Pressure, Unit::Pressure::Atmosphere>::ToStandard(
245 NumericType& value) noexcept {
246 value *= static_cast<NumericType>(101325.0L);
247}
248
249template <>
250template <typename NumericType>
251inline constexpr void Conversion<Unit::Pressure, Unit::Pressure::PoundPerSquareFoot>::FromStandard(
252 NumericType& value) noexcept {
253 value *= static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L)
254 / (static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L));
255}
256
257template <>
258template <typename NumericType>
259inline constexpr void Conversion<Unit::Pressure, Unit::Pressure::PoundPerSquareFoot>::ToStandard(
260 NumericType& value) noexcept {
261 value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L)
262 / (static_cast<NumericType>(0.3048L) * static_cast<NumericType>(0.3048L));
263}
264
265template <>
266template <typename NumericType>
267inline constexpr void Conversion<Unit::Pressure, Unit::Pressure::PoundPerSquareInch>::FromStandard(
268 NumericType& value) noexcept {
269 value *= static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L)
270 / (static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L));
271}
272
273template <>
274template <typename NumericType>
275inline constexpr void Conversion<Unit::Pressure, Unit::Pressure::PoundPerSquareInch>::ToStandard(
276 NumericType& value) noexcept {
277 value *= static_cast<NumericType>(0.45359237L) * static_cast<NumericType>(9.80665L)
278 / (static_cast<NumericType>(0.0254L) * static_cast<NumericType>(0.0254L));
279}
280
281template <typename NumericType>
282inline const std::map<Unit::Pressure,
283 std::function<void(NumericType* values, const std::size_t size)>>
284 MapOfConversionsFromStandard<Unit::Pressure, NumericType>{
286 Conversions<Unit::Pressure, Unit::Pressure::Pascal>::FromStandard<NumericType> },
288 Conversions<Unit::Pressure, Unit::Pressure::Kilopascal>::FromStandard<NumericType> },
290 Conversions<Unit::Pressure, Unit::Pressure::Megapascal>::FromStandard<NumericType> },
292 Conversions<Unit::Pressure, Unit::Pressure::Gigapascal>::FromStandard<NumericType> },
294 Conversions<Unit::Pressure, Unit::Pressure::Bar>::FromStandard<NumericType> },
296 Conversions<Unit::Pressure, Unit::Pressure::Atmosphere>::FromStandard<NumericType> },
298 Conversions<Unit::Pressure, Unit::Pressure::PoundPerSquareFoot>::FromStandard<NumericType>},
300 Conversions<Unit::Pressure, Unit::Pressure::PoundPerSquareInch>::FromStandard<NumericType>},
301};
302
303template <typename NumericType>
304inline const std::map<Unit::Pressure,
305 std::function<void(NumericType* const values, const std::size_t size)>>
306 MapOfConversionsToStandard<Unit::Pressure, NumericType>{
308 Conversions<Unit::Pressure, Unit::Pressure::Pascal>::ToStandard<NumericType> },
310 Conversions<Unit::Pressure, Unit::Pressure::Kilopascal>::ToStandard<NumericType> },
312 Conversions<Unit::Pressure, Unit::Pressure::Megapascal>::ToStandard<NumericType> },
314 Conversions<Unit::Pressure, Unit::Pressure::Gigapascal>::ToStandard<NumericType> },
316 Conversions<Unit::Pressure, Unit::Pressure::Bar>::ToStandard<NumericType> },
318 Conversions<Unit::Pressure, Unit::Pressure::Atmosphere>::ToStandard<NumericType> },
320 Conversions<Unit::Pressure, Unit::Pressure::PoundPerSquareFoot>::ToStandard<NumericType>},
322 Conversions<Unit::Pressure, Unit::Pressure::PoundPerSquareInch>::ToStandard<NumericType>},
323};
324
325} // namespace Internal
326
327} // namespace PhQ
328
329#endif // PHQ_UNIT_PRESSURE_HPP
Pressure
Pressure units.
Definition Pressure.hpp:53
@ PoundPerSquareInch
Pound per square inch (lbf/in^2) pressure unit.
@ Megapascal
Megapascal (MPa) pressure unit.
@ Kilopascal
Kilopascal (kPa) pressure unit.
@ Atmosphere
Atmosphere (atm) pressure unit.
@ Gigapascal
Gigapascal (GPa) pressure unit.
@ Pascal
Pascal (Pa) pressure unit.
@ PoundPerSquareFoot
Pound per square foot (lbf/ft^2) pressure unit.
@ Bar
Bar (bar) pressure 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