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
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
48namespace PhQ {
49
50namespace Unit {
51
52/// \brief Electric current units.
53enum class ElectricCurrent : int8_t {
54 /// \brief Ampere (A) electric current unit.
55 Ampere,
56
57 /// \brief Kiloampere (kA) electric current unit.
59
60 /// \brief Megaampere (MA) electric current unit.
62
63 /// \brief Gigaampere (GA) electric current unit.
65
66 /// \brief Teraampere (TA) electric current unit.
68
69 /// \brief Milliampere (mA) electric current unit.
71
72 /// \brief Microampere (μA) electric current unit.
74
75 /// \brief Nanoampere (nA) electric current unit.
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).
91template <>
92inline constexpr const Unit::
93 ElectricCurrent Standard<Unit::ElectricCurrent>{Unit::ElectricCurrent::Ampere};
94
95/// \brief Physical dimension set of electric current units.
96template <>
97inline constexpr const Dimensions RelatedDimensions<Unit::ElectricCurrent>{
98 Dimensions{Dimension::Time{0}, Dimension::Length{0}, Dimension::Mass{0},
99 Dimension::ElectricCurrent{1}, Dimension::Temperature{0},
100 Dimension::SubstanceAmount{0}, Dimension::LuminousIntensity{0}}
101};
102
103inline std::ostream& operator<<(std::ostream& stream, const Unit::ElectricCurrent unit) {
104 stream << Abbreviation(unit);
105 return stream;
106}
107
108namespace Internal {
109
110template <>
111inline const std::map<UnitSystem, Unit::ElectricCurrent> ConsistentUnits<Unit::ElectricCurrent>{
116};
117
118template <>
119inline const std::map<Unit::ElectricCurrent, UnitSystem>
120 RelatedUnitSystems<Unit::ElectricCurrent>{};
121
122// clang-format off
123
124template <>
125inline const std::map<Unit::ElectricCurrent, std::string_view> Abbreviations<Unit::ElectricCurrent>{
137};
138
139template <>
140inline const std::unordered_map<std::string_view, Unit::ElectricCurrent>
141 Spellings<Unit::ElectricCurrent>{
154};
155
156// clang-format on
157
158template <>
159template <typename NumericType>
160inline constexpr void Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Ampere>::
161 FromStandard(NumericType& /*value*/) noexcept {}
162
163template <>
164template <typename NumericType>
165inline constexpr void Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Ampere>::ToStandard(
166 NumericType& /*value*/) noexcept {}
167
168template <>
169template <typename NumericType>
170inline constexpr void Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Kiloampere>::
171 FromStandard(NumericType& value) noexcept {
172 value *= static_cast<NumericType>(0.001L);
173}
174
175template <>
176template <typename NumericType>
177inline constexpr void Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Kiloampere>::
178 ToStandard(NumericType& value) noexcept {
179 value *= static_cast<NumericType>(1000.0L);
180}
181
182template <>
183template <typename NumericType>
184inline constexpr void Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Megaampere>::
185 FromStandard(NumericType& value) noexcept {
186 value *= static_cast<NumericType>(1.0E-6L);
187}
188
189template <>
190template <typename NumericType>
191inline constexpr void Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Megaampere>::
192 ToStandard(NumericType& value) noexcept {
193 value *= static_cast<NumericType>(1.0E6L);
194}
195
196template <>
197template <typename NumericType>
198inline constexpr void Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Gigaampere>::
199 FromStandard(NumericType& value) noexcept {
200 value *= static_cast<NumericType>(1.0E-9L);
201}
202
203template <>
204template <typename NumericType>
205inline constexpr void Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Gigaampere>::
206 ToStandard(NumericType& value) noexcept {
207 value *= static_cast<NumericType>(1.0E9L);
208}
209
210template <>
211template <typename NumericType>
212inline constexpr void Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Teraampere>::
213 FromStandard(NumericType& value) noexcept {
214 value *= static_cast<NumericType>(1.0E-12L);
215}
216
217template <>
218template <typename NumericType>
219inline constexpr void Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Teraampere>::
220 ToStandard(NumericType& value) noexcept {
221 value *= static_cast<NumericType>(1.0E12L);
222}
223
224template <>
225template <typename NumericType>
226inline constexpr void Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Milliampere>::
227 FromStandard(NumericType& value) noexcept {
228 value *= static_cast<NumericType>(1000.0L);
229}
230
231template <>
232template <typename NumericType>
233inline constexpr void Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Milliampere>::
234 ToStandard(NumericType& value) noexcept {
235 value *= static_cast<NumericType>(0.001L);
236}
237
238template <>
239template <typename NumericType>
240inline constexpr void Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Microampere>::
241 FromStandard(NumericType& value) noexcept {
242 value *= static_cast<NumericType>(1.0E6L);
243}
244
245template <>
246template <typename NumericType>
247inline constexpr void Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Microampere>::
248 ToStandard(NumericType& value) noexcept {
249 value *= static_cast<NumericType>(1.0E-6L);
250}
251
252template <>
253template <typename NumericType>
254inline constexpr void Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Nanoampere>::
255 FromStandard(NumericType& value) noexcept {
256 value *= static_cast<NumericType>(1.0E9L);
257}
258
259template <>
260template <typename NumericType>
261inline constexpr void Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::Nanoampere>::
262 ToStandard(NumericType& value) noexcept {
263 value *= static_cast<NumericType>(1.0E-9L);
264}
265
266template <>
267template <typename NumericType>
268inline constexpr void
269Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::ElementaryChargePerSecond>::FromStandard(
270 NumericType& value) noexcept {
271 value /= static_cast<NumericType>(1.602176634E-19L);
272}
273
274template <>
275template <typename NumericType>
276inline constexpr void
277Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::ElementaryChargePerSecond>::ToStandard(
278 NumericType& value) noexcept {
279 value *= static_cast<NumericType>(1.602176634E-19L);
280}
281
282template <>
283template <typename NumericType>
284inline constexpr void
285Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::ElementaryChargePerMinute>::FromStandard(
286 NumericType& value) noexcept {
287 value *= static_cast<NumericType>(60.0L) / static_cast<NumericType>(1.602176634E-19L);
288}
289
290template <>
291template <typename NumericType>
292inline constexpr void
293Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::ElementaryChargePerMinute>::ToStandard(
294 NumericType& value) noexcept {
295 value *= static_cast<NumericType>(1.602176634E-19L) / static_cast<NumericType>(60.0L);
296}
297
298template <>
299template <typename NumericType>
300inline constexpr void
301Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::ElementaryChargePerHour>::FromStandard(
302 NumericType& value) noexcept {
303 value *= static_cast<NumericType>(3600.0L) / static_cast<NumericType>(1.602176634E-19L);
304}
305
306template <>
307template <typename NumericType>
308inline constexpr void
309Conversion<Unit::ElectricCurrent, Unit::ElectricCurrent::ElementaryChargePerHour>::ToStandard(
310 NumericType& value) noexcept {
311 value *= static_cast<NumericType>(1.602176634E-19L) / static_cast<NumericType>(3600.0L);
312}
313
314template <typename NumericType>
315inline const std::
316 map<Unit::ElectricCurrent, std::function<void(NumericType* values, const std::size_t size)>>
317 MapOfConversionsFromStandard<Unit::ElectricCurrent, NumericType>{
319 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::Ampere>::
320 FromStandard<NumericType>},
322 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::Kiloampere>::
323 FromStandard<NumericType>},
325 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::Megaampere>::
326 FromStandard<NumericType>},
328 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::Gigaampere>::
329 FromStandard<NumericType>},
331 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::Teraampere>::
332 FromStandard<NumericType>},
334 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::Milliampere>::
335 FromStandard<NumericType>},
337 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::Microampere>::
338 FromStandard<NumericType>},
340 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::Nanoampere>::
341 FromStandard<NumericType>},
343 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::ElementaryChargePerSecond>::
344 FromStandard<NumericType>},
346 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::ElementaryChargePerMinute>::
347 FromStandard<NumericType>},
349 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::ElementaryChargePerHour>::
350 FromStandard<NumericType>},
351};
352
353template <typename NumericType>
354inline const std::map<Unit::ElectricCurrent,
355 std::function<void(NumericType* const values, const std::size_t size)>>
356 MapOfConversionsToStandard<Unit::ElectricCurrent, NumericType>{
358 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::Ampere>::ToStandard<NumericType>},
360 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::Kiloampere>::
361 ToStandard<NumericType> },
363 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::Megaampere>::
364 ToStandard<NumericType> },
366 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::Gigaampere>::
367 ToStandard<NumericType> },
369 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::Teraampere>::
370 ToStandard<NumericType> },
372 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::Milliampere>::
373 ToStandard<NumericType> },
375 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::Microampere>::
376 ToStandard<NumericType> },
378 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::Nanoampere>::
379 ToStandard<NumericType> },
381 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::ElementaryChargePerSecond>::
382 ToStandard<NumericType> },
384 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::ElementaryChargePerMinute>::
385 ToStandard<NumericType> },
387 Conversions<Unit::ElectricCurrent, Unit::ElectricCurrent::ElementaryChargePerHour>::
388 ToStandard<NumericType> },
389};
390
391} // namespace Internal
392
393} // namespace PhQ
394
395#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.
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