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
SubstanceAmount.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_SUBSTANCE_AMOUNT_HPP
26#define PHQ_UNIT_SUBSTANCE_AMOUNT_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 Amount of substance units.
53enum class SubstanceAmount : int8_t {
54 /// \brief Mole (mol) substance amount unit.
55 Mole,
56
57 /// \brief Kilomole (kmol) substance amount unit.
59
60 /// \brief Megamole (Mmol) substance amount unit.
62
63 /// \brief Gigamole (Gmol) substance amount unit.
65
66 /// \brief Particles (particles) substance amount unit.
68};
69
70} // namespace Unit
71
72/// \brief Standard amount of substance unit: mole (mol).
73template <>
74inline constexpr const Unit::
75 SubstanceAmount Standard<Unit::SubstanceAmount>{Unit::SubstanceAmount::Mole};
76
77/// \brief Physical dimension set of amount of substance units.
78template <>
79inline constexpr const Dimensions RelatedDimensions<Unit::SubstanceAmount>{
80 Dimensions{Dimension::Time{0}, Dimension::Length{0}, Dimension::Mass{0},
81 Dimension::ElectricCurrent{0}, Dimension::Temperature{0},
82 Dimension::SubstanceAmount{1}, Dimension::LuminousIntensity{0}}
83};
84
85inline std::ostream& operator<<(std::ostream& stream, const Unit::SubstanceAmount unit) {
86 stream << Abbreviation(unit);
87 return stream;
88}
89
90namespace Internal {
91
92template <>
93inline const std::map<UnitSystem, Unit::SubstanceAmount> ConsistentUnits<Unit::SubstanceAmount>{
98};
99
100template <>
101inline const std::map<Unit::SubstanceAmount, UnitSystem>
102 RelatedUnitSystems<Unit::SubstanceAmount>{};
103
104template <>
105inline const std::map<Unit::SubstanceAmount, std::string_view> Abbreviations<Unit::SubstanceAmount>{
111};
112
113template <>
114inline const std::unordered_map<std::string_view, Unit::SubstanceAmount>
115 Spellings<Unit::SubstanceAmount>{
121};
122
123template <>
124template <typename NumericType>
125inline constexpr void Conversion<Unit::SubstanceAmount, Unit::SubstanceAmount::Mole>::FromStandard(
126 NumericType& /*value*/) noexcept {}
127
128template <>
129template <typename NumericType>
130inline constexpr void Conversion<Unit::SubstanceAmount, Unit::SubstanceAmount::Mole>::ToStandard(
131 NumericType& /*value*/) noexcept {}
132
133template <>
134template <typename NumericType>
135inline constexpr void Conversion<Unit::SubstanceAmount, Unit::SubstanceAmount::Kilomole>::
136 FromStandard(NumericType& value) noexcept {
137 value *= static_cast<NumericType>(0.001L);
138}
139
140template <>
141template <typename NumericType>
142inline constexpr void Conversion<Unit::SubstanceAmount, Unit::SubstanceAmount::Kilomole>::
143 ToStandard(NumericType& value) noexcept {
144 value *= static_cast<NumericType>(1000.0L);
145}
146
147template <>
148template <typename NumericType>
149inline constexpr void Conversion<Unit::SubstanceAmount, Unit::SubstanceAmount::Megamole>::
150 FromStandard(NumericType& value) noexcept {
151 value *= static_cast<NumericType>(1.0E-6L);
152}
153
154template <>
155template <typename NumericType>
156inline constexpr void Conversion<Unit::SubstanceAmount, Unit::SubstanceAmount::Megamole>::
157 ToStandard(NumericType& value) noexcept {
158 value *= static_cast<NumericType>(1.0E6L);
159}
160
161template <>
162template <typename NumericType>
163inline constexpr void Conversion<Unit::SubstanceAmount, Unit::SubstanceAmount::Gigamole>::
164 FromStandard(NumericType& value) noexcept {
165 value *= static_cast<NumericType>(1.0E-9L);
166}
167
168template <>
169template <typename NumericType>
170inline constexpr void Conversion<Unit::SubstanceAmount, Unit::SubstanceAmount::Gigamole>::
171 ToStandard(NumericType& value) noexcept {
172 value *= static_cast<NumericType>(1.0E9L);
173}
174
175template <>
176template <typename NumericType>
177inline constexpr void Conversion<Unit::SubstanceAmount, Unit::SubstanceAmount::Particles>::
178 FromStandard(NumericType& value) noexcept {
179 value *= static_cast<NumericType>(6.02214076E23L);
180}
181
182template <>
183template <typename NumericType>
184inline constexpr void Conversion<Unit::SubstanceAmount, Unit::SubstanceAmount::Particles>::
185 ToStandard(NumericType& value) noexcept {
186 value /= static_cast<NumericType>(6.02214076E23L);
187}
188
189template <typename NumericType>
190inline const std::
191 map<Unit::SubstanceAmount, std::function<void(NumericType* values, const std::size_t size)>>
192 MapOfConversionsFromStandard<Unit::SubstanceAmount, NumericType>{
194 Conversions<Unit::SubstanceAmount, Unit::SubstanceAmount::Mole>::
195 FromStandard<NumericType>},
197 Conversions<Unit::SubstanceAmount, Unit::SubstanceAmount::Kilomole>::
198 FromStandard<NumericType>},
200 Conversions<Unit::SubstanceAmount, Unit::SubstanceAmount::Megamole>::
201 FromStandard<NumericType>},
203 Conversions<Unit::SubstanceAmount, Unit::SubstanceAmount::Gigamole>::
204 FromStandard<NumericType>},
206 Conversions<Unit::SubstanceAmount, Unit::SubstanceAmount::Particles>::
207 FromStandard<NumericType>},
208};
209
210template <typename NumericType>
211inline const std::map<Unit::SubstanceAmount,
212 std::function<void(NumericType* const values, const std::size_t size)>>
213 MapOfConversionsToStandard<Unit::SubstanceAmount, NumericType>{
215 Conversions<Unit::SubstanceAmount, Unit::SubstanceAmount::Mole>::ToStandard<NumericType>},
217 Conversions<Unit::SubstanceAmount, Unit::SubstanceAmount::Kilomole>::
218 ToStandard<NumericType> },
220 Conversions<Unit::SubstanceAmount, Unit::SubstanceAmount::Megamole>::
221 ToStandard<NumericType> },
223 Conversions<Unit::SubstanceAmount, Unit::SubstanceAmount::Gigamole>::
224 ToStandard<NumericType> },
226 Conversions<Unit::SubstanceAmount, Unit::SubstanceAmount::Particles>::
227 ToStandard<NumericType> },
228};
229
230} // namespace Internal
231
232} // namespace PhQ
233
234#endif // PHQ_UNIT_SUBSTANCE_AMOUNT_HPP
SubstanceAmount
Amount of substance units.
@ Kilomole
Kilomole (kmol) substance amount unit.
@ Megamole
Megamole (Mmol) substance amount unit.
@ Gigamole
Gigamole (Gmol) substance amount unit.
@ Particles
Particles (particles) substance amount unit.
@ Mole
Mole (mol) substance amount 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