-
Notifications
You must be signed in to change notification settings - Fork 2
/
si.rs
318 lines (256 loc) · 8.75 KB
/
si.rs
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
use crate::unit_system;
unit_system!(
quantity_type Quantity;
dimension_type Dimension;
dimension Length;
dimension Time;
dimension Mass;
dimension Temperature;
dimension Current;
dimension AmountOfSubstance;
dimension LuminousIntensity;
dimension Dimensionless = 1;
dimension Angle = 1; // SI: plane angle
dimension SolidAngle = Angle^2;
dimension Area = Length^2;
dimension Volume = Length^3;
dimension Wavenumber = 1 / Length;
dimension Frequency = 1 / Time;
dimension Velocity = Length / Time;
dimension Acceleration = Length / Time^2;
dimension Jerk = Length / Time^3;
dimension FlowRate = Volume / Time;
dimension Momentum = Mass * Velocity;
dimension Force = Mass * Acceleration;
dimension Energy = Momentum^2 / Mass;
dimension Power = Energy / Time;
dimension Pressure = Force / Area;
dimension Action = Energy * Time;
dimension MassDensity = Mass / Length^3;
dimension MomentOfInertia = Mass * Length^2 / Angle^2;
dimension AngularMomentum = MomentOfInertia * Angle / Time;
dimension Torque = Length * Force / Angle;
dimension EnergyDensity = Energy / Volume;
dimension MassFlow = Mass / Time;
dimension ElectricCharge = Current * Time;
dimension Voltage = Energy / ElectricCharge; // ISQ: electric tension, SI: electric potential difference
dimension Capacitance = ElectricCharge / Voltage;
dimension ElectricResistance = Voltage / Current;
dimension Resistivity = ElectricResistance * Length;
dimension ElectricConductance = 1 / ElectricResistance;
dimension Conductivity = ElectricConductance / Length;
dimension MagneticFluxDensity = Force / (ElectricCharge * Velocity);
dimension MagneticFlux = MagneticFluxDensity * Area;
dimension MagneticFieldStrength = Current / Length;
dimension Inductance = MagneticFlux / Current;
dimension ElectricChargeDensity = ElectricCharge / Volume;
dimension CurrentDensity = Current / Area;
dimension ElectricDipoleMoment = ElectricCharge * Length;
dimension ElectricQuadrupoleMoment = ElectricCharge * Length^2;
dimension MagneticDipoleMoment = Current * Area;
dimension ElectricFieldStrength = Voltage / Length;
dimension ElectricDisplacementFieldStrength = ElectricCharge / Area;
dimension ElectricPermittivity = Time^4 * Current^2 / Mass / Length^3 * Angle;
dimension MagneticPermeability = Length * Mass / Time^2 / Current^2 / Angle;
dimension Polarizability = ElectricDipoleMoment / ElectricFieldStrength;
dimension ElectricMobility = Velocity / ElectricFieldStrength;
dimension Entropy = Energy / Temperature;
dimension HeatCapacity = Energy / Temperature;
dimension SpecificHeatCapacity = HeatCapacity / Mass;
dimension ThermalConductivity = Power / (Length * Temperature);
dimension ThermalTransmittance = Power / (Length^2 * Temperature);
dimension MolarMass = Mass / AmountOfSubstance;
dimension MolarVolume = Volume / AmountOfSubstance;
dimension CatalyticActivity = AmountOfSubstance / Time;
dimension Molarity = AmountOfSubstance / Volume;
dimension Molality = AmountOfSubstance / Mass;
dimension ChemicalPotential = Energy / AmountOfSubstance;
dimension MolarHeatCapacity = HeatCapacity / AmountOfSubstance;
dimension LuminousFlux = LuminousIntensity * Angle^2;
dimension Illuminance = LuminousFlux / Area;
dimension Irradiance = Power / Area;
dimension Activity = 1 / Time;
dimension AbsorbedDose = Energy / Mass;
dimension EquivalentDose = Energy / Mass; // also: dose equivalent
dimension SpecificActivity = Activity / Mass;
dimension DynamicViscosity = Pressure * Time;
dimension KinematicViscosity = Length^2 / Time;
dimension MomentumDensity = Momentum / Volume;
dimension SpecificEnergy = Energy / Mass;
dimension MassFlux = Mass / (Area * Time);
dimension EnergyFlux = Power / Area;
#[metric_prefixes]
#[symbol(m)]
#[alias(metre, metres, meters)]
#[base(Length)]
unit meter: Length;
#[metric_prefixes]
#[symbol(s)]
#[alias(seconds)]
#[base(Time)]
unit second: Time;
#[alias(kilograms)]
#[base(Mass)]
#[symbol(kg)]
unit kilogram: Mass;
#[metric_prefixes(skip: kilo)]
#[symbol(g)]
#[alias(grams)]
unit gram: Mass = 1.0e-3 * kilogram;
#[metric_prefixes]
#[symbol(A)]
#[alias(amperes)]
#[base(Current)]
unit ampere: Current;
#[metric_prefixes]
#[symbol(K)]
#[alias(kelvins)]
#[base(Temperature)]
unit kelvin: Temperature;
#[metric_prefixes]
#[symbol(mol)]
#[alias(moles)]
#[base(AmountOfSubstance)]
unit mole: AmountOfSubstance;
#[metric_prefixes]
#[symbol(cd)]
#[alias(candelas)]
#[base(LuminousIntensity)]
unit candela: LuminousIntensity;
// derived units
#[metric_prefixes]
#[symbol(rad)]
#[alias(radians)]
unit radian: Angle = meter / meter;
#[metric_prefixes]
#[symbol(sr)]
#[alias(steradians)]
unit steradian: SolidAngle = radian^2;
#[metric_prefixes]
#[symbol(Hz)]
unit hertz: Frequency = 1 / second;
#[metric_prefixes]
#[symbol(N)]
#[alias(newtons)]
unit newton: Force = kilogram meter / second^2;
#[metric_prefixes]
#[symbol(Pa)]
#[alias(pascals)]
unit pascal: Pressure = newton / meter^2;
#[metric_prefixes]
#[symbol(J)]
#[alias(joules)]
unit joule: Energy = newton meter;
#[metric_prefixes]
#[symbol(W)]
#[alias(watts)]
unit watt: Power = joule / second;
#[metric_prefixes]
#[symbol(C)]
#[alias(coulombs)]
unit coulomb: ElectricCharge = ampere second;
#[metric_prefixes]
#[symbol(V)]
#[alias(volts)]
unit volt: Voltage = kilogram meter^2 / (second^3 ampere);
#[metric_prefixes]
#[symbol(F)]
#[alias(farads)]
unit farad: Capacitance = coulomb / volt;
#[metric_prefixes]
#[symbol(Ω)]
#[alias(ohms)]
unit ohm: ElectricResistance = volt / ampere;
#[metric_prefixes]
#[symbol(S)]
unit siemens: ElectricConductance = 1 / ohm;
#[metric_prefixes]
#[symbol(Wb)]
#[alias(webers)]
unit weber: MagneticFlux = volt second;
#[metric_prefixes]
#[symbol(T)]
#[alias(teslas)]
unit tesla: MagneticFluxDensity = weber / meter^2;
#[metric_prefixes]
#[symbol(H)]
#[alias(henrys)]
unit henry: Inductance = weber / ampere;
#[metric_prefixes]
#[symbol(lm)]
#[alias(lumens)]
unit lumen: LuminousFlux = candela steradian;
#[metric_prefixes]
#[symbol(lx)]
unit lux: Illuminance = lumen / meter^2;
#[metric_prefixes]
#[symbol(Bq)]
#[alias(becquerels)]
unit becquerel: Activity = 1 / second;
#[metric_prefixes]
#[symbol(Gy)]
#[alias(grays)]
unit gray: AbsorbedDose = joule / kilogram;
#[metric_prefixes]
#[symbol(Sv)]
#[alias(sieverts)]
unit sievert: EquivalentDose = joule / kilogram;
#[metric_prefixes]
#[symbol(kat)]
#[alias(katals)]
unit katal: CatalyticActivity = mole / second;
// SI accepted units
#[symbol(min)]
#[alias(minutes)]
unit minute: Time = 60 second;
#[symbol(h)]
#[alias(hours)]
unit hour: Time = 60 minute;
#[symbol(day)]
#[alias(days)]
unit day: Time = 24 hour;
#[symbol(au)]
#[alias(astronomicalunits)]
unit astronomicalunit: Length = 149_597_870_700 meter;
constant PI = 3.141592653589793;
//TODO(minor): Support using ° here.
#[symbol(deg)]
#[alias(degrees)]
unit degree: Angle = PI / 180 * radian;
#[alias(arcminutes)]
unit arcminute: Angle = 1 / 60 * degree;
#[alias(arcseconds)]
unit arcsecond: Angle = 1 / 60 * arcminute;
#[alias(ares)]
unit are: Area = 100 meter^2;
#[symbol(ha)]
#[alias(hectares)]
unit hectare: Area = 100 are;
#[metric_prefixes]
#[symbol(l)]
#[alias(litres)]
unit litre: Volume = decimeter^3;
#[metric_prefixes]
#[alias(tonnes)]
unit tonne: Mass = 10^3 kilogram;
#[symbol(Da)]
#[alias(daltons)]
unit dalton: Mass = 1.660_539_066_60e-27 kilogram;
#[metric_prefixes]
#[symbol(eV)]
#[alias(electronvolts)]
unit electronvolt: Energy = 1.602_176_634e-19 joule;
#[metric_prefixes]
#[alias(joules_per_kilogram)]
unit joule_per_kilogram: SpecificEnergy = joule / kilogram;
#[metric_prefixes]
#[alias(joules_per_kilogram_kelvin)]
unit joule_per_kilogram_kelvin: SpecificHeatCapacity = joule_per_kilogram / kelvin;
#[metric_prefixes]
#[alias(meters_per_second)]
unit meter_per_second: Velocity = meter / second;
#[alias(square_metre, square_meters, square_metres)]
unit square_meter: Area = meter^2;
#[alias(cubic_metre, cubic_meters, cubic_metres)]
unit cubic_meter: Volume = meter^3;
);