Phyth v0.1.0
A dimensional safe C++ header-only mechanics and electromagnetics simulation library.
Loading...
Searching...
No Matches
Units.hpp
Go to the documentation of this file.
1#ifndef PHYTH_UNITS_HPP
2#define PHYTH_UNITS_HPP
3
6#include "Unit.hpp"
8
9namespace Phyth {
10#define PHYTH_CONCAT_IMPL(a, b) a##b
11#define PHYTH_CONCAT(a, b) PHYTH_CONCAT_IMPL(a, b)
12
32#define PHYTH_DEFINE_UNIT(dim_type, unit_type, suffix, scale_num, scale_den) \
33 using unit_type = Unit<dim_type, std::ratio<scale_num, scale_den>>; \
34 \
35 constexpr auto operator""_##suffix(long double x) { \
36 return Quantity<unit_type>(x); \
37 } \
38 \
39 constexpr auto operator""_##suffix(unsigned long long x) { \
40 return Quantity<unit_type>(x); \
41 } \
42 \
43 static const Phyth::UnitRegistrar<unit_type> PHYTH_CONCAT(registrar_, unit_type)(#unit_type, #suffix);
44
59#define PHYTH_DEFINE_UNIT_WITH_NAME(dim_type, unit_type, suffix, scale_num, scale_den, symbol) \
60 using unit_type = Unit<dim_type, std::ratio<scale_num, scale_den>>; \
61 \
62 constexpr auto operator""_##suffix(long double x) { \
63 return Quantity<unit_type>(x); \
64 } \
65 \
66 constexpr auto operator""_##suffix(unsigned long long x) { \
67 return Quantity<unit_type>(x); \
68 } \
69 \
70 static const Phyth::UnitRegistrar<unit_type> PHYTH_CONCAT(registrar_, unit_type)(#unit_type, symbol);
71
88#define PHYTH_DEFINE_UNIT_WITH_TAG(dim_type, unit_type, suffix, scale_num, scale_den, symbol, tag) \
89 using unit_type = Unit<dim_type, std::ratio<scale_num, scale_den>, tag>; \
90 \
91 constexpr auto operator""_##suffix(long double x) { \
92 return Quantity<unit_type>(x); \
93 } \
94 \
95 constexpr auto operator""_##suffix(unsigned long long x) { \
96 return Quantity<unit_type>(x); \
97 } \
98 \
99 static const Phyth::UnitRegistrar<unit_type> PHYTH_CONCAT(registrar_, unit_type)(#unit_type, symbol);
100
102
105
107
110
111 PHYTH_DEFINE_UNIT_WITH_TAG(Dimensionless, Degree, deg, 3141592653589793, 18000000000000000, "deg", DegreeTag)
112
117 PHYTH_DEFINE_UNIT(Length, Foot, ft, 3048, 10000)
118 PHYTH_DEFINE_UNIT(Length, Inch, in, 254, 10000)
119 PHYTH_DEFINE_UNIT(Length, Mile, mi, 1609344, 1000)
120
122 PHYTH_DEFINE_UNIT(Mass, Gram, g, 1, 1000)
123
126 PHYTH_DEFINE_UNIT(Time, Minute, min, 60, 1)
127 PHYTH_DEFINE_UNIT(Time, Hour, h, 3600, 1)
128
133
136
138
141
143
145 PHYTH_DEFINE_UNIT(Energy, ElectronVolt, eV, 160217663, 1000000000000000000LL)
146
149
152 PHYTH_DEFINE_UNIT(Pressure, Bar, bar, 100000, 1)
153
156
158
161
164
167
170
173
176
178
184
186
189
191
195
200
202
205
206 PHYTH_DEFINE_UNIT_WITH_TAG(AngularVelocity, DegreePerSecond, degps, 3141592653589793, 18000000000000000, "deg/m",
208
210
211#undef PHYTH_DEFINE_UNIT
212#undef PHYTH_DEFINE_UNIT_WITH_NAME
213}
214
215#endif //PHYTH_UNITS_HPP
#define PHYTH_DEFINE_UNIT(dim_type, unit_type, suffix, scale_num, scale_den)
Define a unit, literal operator, and registry entry.
Definition Units.hpp:32
#define PHYTH_DEFINE_UNIT_WITH_TAG(dim_type, unit_type, suffix, scale_num, scale_den, symbol, tag)
Define a unit with a tag type for type-safe differentiation.
Definition Units.hpp:88
#define PHYTH_DEFINE_UNIT_WITH_NAME(dim_type, unit_type, suffix, scale_num, scale_den, symbol)
Same as DEFINE_UNIT with custom display symbol.
Definition Units.hpp:59
DimDivT< Mass, Time > DampingCoefficient
DimDivT< Force, Volume > ForceDensity
DimDivT< Energy, Time > Power
DimMulT< Mass, Area > MomentOfInertia
DimDivT< Force, Charge > ElectricFieldIntensity
DimDivT< Dimensionless, Time > Frequency
DimDivT< Force, DimMulT< Length, Length > > Pressure
DimDivT< Voltage, DimDivT< ElectricCurrent, Time > > Inductance
DimDivT< Mass, Volume > MassDensity
DimDivT< Velocity, Time > Acceleration
DimMulT< Voltage, Time > MagneticFlux
DimMulT< Length, Area > Volume
DimMulT< Time, ElectricCurrent > Charge
DimDivT< MagneticFlux, DimMulT< Length, Length > > MagneticFluxDensity
Dimension< std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 >, std::ratio< 0 > > Dimensionless
DimDivT< Force, Length > TranslationalStiffness
DimMulT< ElectricCurrent, Area > MagneticDipoleMoment
DimMulT< Mass, Acceleration > Force
DimDivT< Charge, Voltage > Capacitance
DimDivT< Charge, Length > LinearChargeDensity
DimDivT< Dimensionless, Time > AngularVelocity
DimDivT< Charge, Area > SurfaceChargeDensity
DimDivT< Charge, Volume > BulkChargeDensity
DimDivT< Length, Time > Velocity
constexpr bool is_unit_v
Definition Unit.hpp:79
DimDivT< Voltage, ElectricCurrent > Resistance
DimDivT< Capacitance, Length > ElectricPotential
DimMulT< Length, Length > Area
DimMulT< Charge, Length > ElectricDipoleMoment
DimMulT< Force, Length > Energy
DimDivT< Power, ElectricCurrent > Voltage
Compile-time physical dimension as 7 SI base exponents.
Definition Dimension.hpp:25