Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
ElectricCurrent.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_ELECTRIC_CURRENT_HPP
26 #define PHQ_UNIT_ELECTRIC_CURRENT_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 Electric current units.
53 enum class ElectricCurrent : int8_t {
54  /// \brief Ampere (A) electric current unit.
55  Ampere,
56 
57  /// \brief Kiloampere (kA) electric current unit.
58  Kiloampere,
59 
60  /// \brief Megaampere (MA) electric current unit.
61  Megaampere,
62 
63  /// \brief Gigaampere (GA) electric current unit.
64  Gigaampere,
65 
66  /// \brief Teraampere (TA) electric current unit.
67  Teraampere,
68 
69  /// \brief Milliampere (mA) electric current unit.
71 
72  /// \brief Microampere (μA) electric current unit.
74 
75  /// \brief Nanoampere (nA) electric current unit.
76  Nanoampere,
77 
78  /// \brief Elementary charge per second (e/s) electric current unit.
80 
81  /// \brief Elementary charge per minute (e/min) electric current unit.
83 
84  /// \brief Elementary charge per hour (e/hr) electric current unit.
86 };
87 
88 } // namespace Unit
89 
90 /// \brief Standard electric current unit: ampere (A).
91 template <>
92 inline constexpr const Unit::ElectricCurrent Standard<Unit::ElectricCurrent>{
94 
95 /// \brief Physical dimension set of electric current units.
96 template <>
97 inline constexpr const Dimensions RelatedDimensions<Unit::ElectricCurrent>{
100  Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
101 };
102 
103 inline std::ostream& operator<<(std::ostream& stream, const Unit::ElectricCurrent unit) {
104  stream << Abbreviation(unit);
105  return stream;
106 }
107 
108 namespace Internal {
109 
110 template <>
111 inline const std::map<UnitSystem, Unit::ElectricCurrent> ConsistentUnits<Unit::ElectricCurrent>{
116 };
117 
118 template <>
119 inline const std::map<Unit::ElectricCurrent, UnitSystem>
120  RelatedUnitSystems<Unit::ElectricCurrent>{};
121 
122 // clang-format off
123 
124 template <>
125 inline const std::map<Unit::ElectricCurrent, std::string_view> Abbreviations<Unit::ElectricCurrent>{
137 };
138 
139 template <>
140 inline const std::unordered_map<std::string_view, Unit::ElectricCurrent>
141  Spellings<Unit::ElectricCurrent>{
154 };
155 
156 // clang-format on
157 
158 template <>
159 template <typename NumericType>
160 inline constexpr void
161 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Ampere>::FromStandard(
162  NumericType& /*value*/) noexcept {}
163 
164 template <>
165 template <typename NumericType>
166 inline constexpr void Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Ampere>::ToStandard(
167  NumericType& /*value*/) noexcept {}
168 
169 template <>
170 template <typename NumericType>
171 inline constexpr void
172 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Kiloampere>::FromStandard(
173  NumericType& value) noexcept {
174  value *= static_cast<NumericType>(0.001L);
175 }
176 
177 template <>
178 template <typename NumericType>
179 inline constexpr void
180 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Kiloampere>::ToStandard(
181  NumericType& value) noexcept {
182  value *= static_cast<NumericType>(1000.0L);
183 }
184 
185 template <>
186 template <typename NumericType>
187 inline constexpr void
188 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Megaampere>::FromStandard(
189  NumericType& value) noexcept {
190  value *= static_cast<NumericType>(1.0E-6L);
191 }
192 
193 template <>
194 template <typename NumericType>
195 inline constexpr void
196 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Megaampere>::ToStandard(
197  NumericType& value) noexcept {
198  value *= static_cast<NumericType>(1.0E6L);
199 }
200 
201 template <>
202 template <typename NumericType>
203 inline constexpr void
204 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Gigaampere>::FromStandard(
205  NumericType& value) noexcept {
206  value *= static_cast<NumericType>(1.0E-9L);
207 }
208 
209 template <>
210 template <typename NumericType>
211 inline constexpr void
212 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Gigaampere>::ToStandard(
213  NumericType& value) noexcept {
214  value *= static_cast<NumericType>(1.0E9L);
215 }
216 
217 template <>
218 template <typename NumericType>
219 inline constexpr void
220 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Teraampere>::FromStandard(
221  NumericType& value) noexcept {
222  value *= static_cast<NumericType>(1.0E-12L);
223 }
224 
225 template <>
226 template <typename NumericType>
227 inline constexpr void
228 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Teraampere>::ToStandard(
229  NumericType& value) noexcept {
230  value *= static_cast<NumericType>(1.0E12L);
231 }
232 
233 template <>
234 template <typename NumericType>
235 inline constexpr void
236 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Milliampere>::FromStandard(
237  NumericType& value) noexcept {
238  value *= static_cast<NumericType>(1000.0L);
239 }
240 
241 template <>
242 template <typename NumericType>
243 inline constexpr void
244 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Milliampere>::ToStandard(
245  NumericType& value) noexcept {
246  value *= static_cast<NumericType>(0.001L);
247 }
248 
249 template <>
250 template <typename NumericType>
251 inline constexpr void
252 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Microampere>::FromStandard(
253  NumericType& value) noexcept {
254  value *= static_cast<NumericType>(1.0E6L);
255 }
256 
257 template <>
258 template <typename NumericType>
259 inline constexpr void
260 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Microampere>::ToStandard(
261  NumericType& value) noexcept {
262  value *= static_cast<NumericType>(1.0E-6L);
263 }
264 
265 template <>
266 template <typename NumericType>
267 inline constexpr void
268 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Nanoampere>::FromStandard(
269  NumericType& value) noexcept {
270  value *= static_cast<NumericType>(1.0E9L);
271 }
272 
273 template <>
274 template <typename NumericType>
275 inline constexpr void
276 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Nanoampere>::ToStandard(
277  NumericType& value) noexcept {
278  value *= static_cast<NumericType>(1.0E-9L);
279 }
280 
281 template <>
282 template <typename NumericType>
283 inline constexpr void
284 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::ElementaryChargePerSecond>::FromStandard(
285  NumericType& value) noexcept {
286  value /= static_cast<NumericType>(1.602176634E-19L);
287 }
288 
289 template <>
290 template <typename NumericType>
291 inline constexpr void
292 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::ElementaryChargePerSecond>::ToStandard(
293  NumericType& value) noexcept {
294  value *= static_cast<NumericType>(1.602176634E-19L);
295 }
296 
297 template <>
298 template <typename NumericType>
299 inline constexpr void
300 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::ElementaryChargePerMinute>::FromStandard(
301  NumericType& value) noexcept {
302  value *= static_cast<NumericType>(60.0L) / static_cast<NumericType>(1.602176634E-19L);
303 }
304 
305 template <>
306 template <typename NumericType>
307 inline constexpr void
308 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::ElementaryChargePerMinute>::ToStandard(
309  NumericType& value) noexcept {
310  value *= static_cast<NumericType>(1.602176634E-19L) / static_cast<NumericType>(60.0L);
311 }
312 
313 template <>
314 template <typename NumericType>
315 inline constexpr void
316 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::ElementaryChargePerHour>::FromStandard(
317  NumericType& value) noexcept {
318  value *= static_cast<NumericType>(3600.0L) / static_cast<NumericType>(1.602176634E-19L);
319 }
320 
321 template <>
322 template <typename NumericType>
323 inline constexpr void
324 Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::ElementaryChargePerHour>::ToStandard(
325  NumericType& value) noexcept {
326  value *= static_cast<NumericType>(1.602176634E-19L) / static_cast<NumericType>(3600.0L);
327 }
328 
329 template <typename NumericType>
330 inline const std::map<Unit::ElectricCurrent,
331  std::function<void(NumericType* values, const std::size_t size)>>
332  MapOfConversionsFromStandard<Unit::ElectricCurrent, NumericType>{
334  Conversions<Unit::ElectricCurrent,
335  Unit::ElectricCurrent::Ampere>::FromStandard<NumericType> },
337  Conversions<Unit::ElectricCurrent,
338  Unit::ElectricCurrent::Kiloampere>::FromStandard<NumericType> },
340  Conversions<Unit::ElectricCurrent,
341  Unit::ElectricCurrent::Megaampere>::FromStandard<NumericType> },
343  Conversions<Unit::ElectricCurrent,
344  Unit::ElectricCurrent::Gigaampere>::FromStandard<NumericType> },
346  Conversions<Unit::ElectricCurrent,
347  Unit::ElectricCurrent::Teraampere>::FromStandard<NumericType> },
349  Conversions<Unit::ElectricCurrent,
350  Unit::ElectricCurrent::Milliampere>::FromStandard<NumericType> },
352  Conversions<Unit::ElectricCurrent,
353  Unit::ElectricCurrent::Microampere>::FromStandard<NumericType> },
355  Conversions<Unit::ElectricCurrent,
356  Unit::ElectricCurrent::Nanoampere>::FromStandard<NumericType> },
358  Conversions<Unit::ElectricCurrent,
359  Unit::ElectricCurrent::ElementaryChargePerSecond>::FromStandard<NumericType>},
361  Conversions<Unit::ElectricCurrent,
362  Unit::ElectricCurrent::ElementaryChargePerMinute>::FromStandard<NumericType>},
364  Conversions<Unit::ElectricCurrent,
365  Unit::ElectricCurrent::ElementaryChargePerHour>::FromStandard<NumericType> },
366 };
367 
368 template <typename NumericType>
369 inline const std::map<Unit::ElectricCurrent,
370  std::function<void(NumericType* const values, const std::size_t size)>>
371  MapOfConversionsToStandard<Unit::ElectricCurrent, NumericType>{
373  Conversions<Unit::ElectricCurrent,
374  Unit::ElectricCurrent::Ampere>::ToStandard<NumericType> },
376  Conversions<Unit::ElectricCurrent,
377  Unit::ElectricCurrent::Kiloampere>::ToStandard<NumericType> },
379  Conversions<Unit::ElectricCurrent,
380  Unit::ElectricCurrent::Megaampere>::ToStandard<NumericType> },
382  Conversions<Unit::ElectricCurrent,
383  Unit::ElectricCurrent::Gigaampere>::ToStandard<NumericType> },
385  Conversions<Unit::ElectricCurrent,
386  Unit::ElectricCurrent::Teraampere>::ToStandard<NumericType> },
388  Conversions<Unit::ElectricCurrent,
389  Unit::ElectricCurrent::Milliampere>::ToStandard<NumericType> },
391  Conversions<Unit::ElectricCurrent,
392  Unit::ElectricCurrent::Microampere>::ToStandard<NumericType> },
394  Conversions<Unit::ElectricCurrent,
395  Unit::ElectricCurrent::Nanoampere>::ToStandard<NumericType> },
397  Conversions<Unit::ElectricCurrent,
398  Unit::ElectricCurrent::ElementaryChargePerSecond>::ToStandard<NumericType>},
400  Conversions<Unit::ElectricCurrent,
401  Unit::ElectricCurrent::ElementaryChargePerMinute>::ToStandard<NumericType>},
403  Conversions<Unit::ElectricCurrent,
404  Unit::ElectricCurrent::ElementaryChargePerHour>::ToStandard<NumericType> },
405 };
406 
407 } // namespace Internal
408 
409 } // namespace PhQ
410 
411 #endif // PHQ_UNIT_ELECTRIC_CURRENT_HPP
ElectricCurrent
Electric current units.
@ Microampere
Microampere (μA) electric current unit.
@ ElementaryChargePerMinute
Elementary charge per minute (e/min) electric current unit.
@ Nanoampere
Nanoampere (nA) electric current unit.
@ ElementaryChargePerSecond
Elementary charge per second (e/s) electric current unit.
@ Ampere
Ampere (A) electric current unit.
@ Megaampere
Megaampere (MA) electric current unit.
@ Kiloampere
Kiloampere (kA) electric current unit.
@ Milliampere
Milliampere (mA) electric current unit.
@ Teraampere
Teraampere (TA) electric current unit.
@ Gigaampere
Gigaampere (GA) electric current unit.
@ ElementaryChargePerHour
Elementary charge per hour (e/hr) electric current unit.
Mass
Mass units.
Definition: Mass.hpp:53
Length
Length units.
Definition: Length.hpp:53
SubstanceAmount
Amount of substance units.
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)