The unit manager reads the file unitfile.txt. The file loaded is the first found according the following search sequence:
gridlabd.exe GLPATH environment variable.Units are based on 6 physical/economic constants:
#c=2.997925e8 ; speed of light (m/s) #e=1.602189246e-19 ; electron charge (C) #h=6.62617636e-24 ; Plank's constant (kg.m.m/s) #k=1.38066244e-13 ; Boltzman's constant (kg.m.m/s.s.K) #m=9.10953447e-31 ; electron rest mass (kg) #s=1.233270e4 ; average price of gold in 1990 ($/kg - 383.59$/oz)
From these are derived all the fundamental SI units:
m=-1,0,1,0,-1,0,4.121487e01,0,7 kg=0,0,0,0,1,0,1.09775094e30,0,10 s=-2,0,1,0,-1,0,1.235591e10,0,7 A=2,1,-1,0,1,0,5.051397e08,0,7 K=2,0,0,-1,1,0,1.686358e00,0,7 cd=4,0,-1,0,2,0,1.447328E+00,0,7
An addition currency unit is defined because it's really useful:
1990$=0,0,0,0,1,1,1.097751e30,0,7
Based on these units, all the other units are derived using simple formulae, e.g.:
; Length cm=0.01 m mm=0.001 m km=1000 m in=2.54 cm ft=12 in yd=3 ft mile=5280 ft
where
where c, e, h, k, m, and s are the constants defined above, and the k terms are the unit terms defined for that unit.
Thus, two values can only be added (or subtracted) only if their units are the same (i.e., unit is a common factor), and when two values are multiplied (or divided), the exponential terms of the units are added (or subtracted).
For example, 1 second is defined as
Classes | |
| struct | s_unit |
Typedefs | |
| typedef s_unit | UNIT |
| the UNIT structure | |
Functions | |
| int | unit_constant (char name, double value) |
| int | unit_convert (char *from, char *to, double *pValue) |
| Convert a value from one unit to another. | |
| int | unit_convert_ex (UNIT *pFrom, UNIT *pTo, double *pValue) |
| Convert a value from one unit to another. | |
| int | unit_derived (char *name, char *derivation) |
| UNIT * | unit_find (char *unit) |
| Find a unit. | |
| UNIT * | unit_find_underived (char *unit) |
| void | unit_init (void) |
| Initialize the unit manager. | |
| int | unit_precision (char *term) |
| int | unit_primary (char *name, double c, double e, double h, double k, double m, double s, double a, double b, int prec) |
| int | unit_test (void) |
| Test the unit manager. | |
| int unit_convert | ( | char * | from, | |
| char * | to, | |||
| double * | pValue | |||
| ) |
Convert a value from one unit to another.
Definition at line 474 of file unit.c.
References unit_convert_ex(), and unit_find().
Referenced by unit_test().
| UNIT * unit_find | ( | char * | unit | ) |
Find a unit.
| unit | the name of the unit |
Definition at line 500 of file unit.c.
References s_unit::name, s_unit::next, unit_derived(), and unit_init().
Referenced by class_define_map(), global_create(), object_get_unit(), and unit_convert().
| void unit_init | ( | void | ) |
Initialize the unit manager.
Definition at line 353 of file unit.c.
References find_file(), output_error(), output_verbose(), output_warning(), throw_exception(), unit_constant(), unit_derived(), and unit_primary().
Referenced by unit_find().
| int unit_test | ( | void | ) |
Test the unit manager.
Definition at line 524 of file unit.c.
References output_test(), output_verbose(), PI, unit_convert(), and VALUE.
Referenced by cmdarg_load().