-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathphysics.quantities.cppm
176 lines (140 loc) · 6.49 KB
/
physics.quantities.cppm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
* Primary module interface for the `quantities library`
*/
export module physics.quantities;
export import :quantity;
export import :dimensions;
export import :units;
export import :units.symbols;
export import :ratios;
export namespace zero::physics {
/* ----------------------------------- Dimensions ----------------------------------- */
/* ---------- Base Dimensions ---------- */
template <short DimensionExponent = 1>
struct mass : public base_dimension<mass<DimensionExponent>, DimensionExponent> {};
template <short DimensionExponent = 1>
struct length : public base_dimension<length<DimensionExponent>, DimensionExponent> {};
template <short DimensionExponent = 1>
struct time : public base_dimension<time<DimensionExponent>, DimensionExponent> {};
template <short DimensionExponent = 1>
struct temperature : public base_dimension<temperature<DimensionExponent>, DimensionExponent> {};
template <short DimensionExponent = 1>
struct electric_current : public base_dimension<electric_current<DimensionExponent>, DimensionExponent> {};
template <short DimensionExponent = 1>
struct amount_of_substance : public base_dimension<amount_of_substance<DimensionExponent>, DimensionExponent> {};
template <short DimensionExponent = 1>
struct luminous_intensity : public base_dimension<luminous_intensity<DimensionExponent>, DimensionExponent> {};
template <short DimensionExponent = 1>
struct dimensionless : public base_dimension<dimensionless<DimensionExponent>, DimensionExponent> {};
/* ---------- Derived Dimensions ---------- */
struct speed : public derived_dimension<length<>, time< -1 >> {};
struct frequency : public derived_dimension<dimensionless<>, time< -1 >> {};
struct force : public derived_dimension<mass<>, length<>, time< -2 >> {};
struct energy : public derived_dimension<mass<>, length<2>, time< -2 >> {};
struct power : public derived_dimension<mass<>, length<2>, time< -3 >> {};
struct electric_charge : public derived_dimension<electric_current<>, time<>> {};
struct voltage : public derived_dimension<mass<>, length<2>, time< -3 >, electric_current< -1 >> {};
/* ----------------------------------- Units ----------------------------------- */
/* ---------- Base Units ---------- */
/* Base Units for Mass dimension */
struct Kilogram: public mass<>, public base_unit<kilo, kg> {};
struct Hectogram: public mass<>, public base_unit<hecto, hg> {};
/* Base Units for Length dimension */
struct Meter: public length<>, public base_unit<root, m> {};
/* Base Units for Time dimension */
struct Second: public time<>, public base_unit<second, s> {};
struct Minute: public time<>, public base_unit<minute, min> {};
struct Hour: public time<>, public base_unit<hour, h> {};
struct Day: public time<>, public base_unit<day, d> {};
/* Base Units for the Electric Current dimension */
struct Ampere: public electric_current<>, public base_unit<root, A> {};
/* ---------- Derived Units ---------- */
/* Derived Units for the Speed dimension */
struct MetersPerSecond :
public derived_unit<
speed,
base_unit<root, m>,
base_unit<second, s>
> {};
struct KilometersPerHour :
public derived_unit<
speed,
base_unit<kilo, km>,
base_unit<hour, h>
> {};
/* Derived Units for the Frequency dimension */
struct Hertz :
public derived_unit<
frequency,
base_unit<unit_r, unit_type>,
base_unit<second, s>
> {};
/* Derived Units for the Force dimension */
struct Newton :
public derived_unit<
force,
base_unit<kilo, kg>,
base_unit<root, m>,
base_unit<second, s>
> {};
/* Derived Units for the Energy dimension */
struct Joule :
public derived_unit<
energy,
base_unit<kilo, kg>,
base_unit<root, m>,
base_unit<second, s>
> {};
/* Derived Units for the Power dimension */
struct Watt :
public derived_unit<
power,
base_unit<kilo, kg>,
base_unit<root, m>,
base_unit<second, s>
> {};
/* Derived Units for the Electric Charge dimension */
struct Coulomb :
public derived_unit<
electric_charge,
base_unit<root, A>,
base_unit<second, s>
> {};
/* Derived Units for the Voltage dimension */
struct Volt :
public derived_unit<
voltage,
base_unit<kilo, kg>,
base_unit<root, m>,
base_unit<second, s>,
base_unit<root, A>
> {};
}
/* Testing our base dimensions */
static_assert(zero::physics::BaseDimension<zero::physics::mass<>>);
static_assert(zero::physics::BaseDimension<zero::physics::length<>>);
static_assert(zero::physics::BaseDimension<zero::physics::time<>>);
static_assert(zero::physics::BaseDimension<zero::physics::temperature<>>);
static_assert(zero::physics::BaseDimension<zero::physics::electric_current<>>);
static_assert(zero::physics::BaseDimension<zero::physics::amount_of_substance<>>);
static_assert(zero::physics::BaseDimension<zero::physics::luminous_intensity<>>);
static_assert(zero::physics::BaseDimension<zero::physics::dimensionless<>>);
/* Testing our derived dimensions */
static_assert(zero::physics::DerivedDimension<zero::physics::speed>);
static_assert(zero::physics::DerivedDimension<zero::physics::frequency>);
static_assert(zero::physics::DerivedDimension<zero::physics::force>);
static_assert(zero::physics::DerivedDimension<zero::physics::energy>);
static_assert(zero::physics::DerivedDimension<zero::physics::power>);
static_assert(zero::physics::DerivedDimension<zero::physics::electric_charge>);
static_assert(zero::physics::DerivedDimension<zero::physics::voltage>);
/* Testing our symbols */
static_assert(zero::physics::Symbol<zero::physics::kg>);
/* Testing our base units */
static_assert(zero::physics::BaseUnit<zero::physics::Kilogram>);
static_assert(zero::physics::BaseUnit<zero::physics::Hectogram>);
static_assert(zero::physics::BaseUnit<zero::physics::Meter>);
static_assert(zero::physics::BaseUnit<zero::physics::Second>);
static_assert(zero::physics::BaseUnit<zero::physics::Hour>);
/* Testing our derived units */
static_assert(zero::physics::DerivedUnit<zero::physics::MetersPerSecond>);
static_assert(zero::physics::DerivedUnit<zero::physics::KilometersPerHour>);