UNPKG

6.51 kBJavaScriptView Raw
1'use strict';
2
3var lazy = require('../../utils/object').lazy;
4
5function factory(type, config, load, typed, math) {
6 // helper function to create a unit with a fixed prefix
7 function fixedUnit(str) {
8 var unit = type.Unit.parse(str);
9 unit.fixPrefix = true;
10 return unit;
11 }
12
13 // Source: http://www.wikiwand.com/en/Physical_constant
14
15 // Universal constants
16 setLazyConstant(math, 'speedOfLight', function () {
17 return fixedUnit('299792458 m s^-1');
18 });
19 setLazyConstant(math, 'gravitationConstant', function () {
20 return fixedUnit('6.6738480e-11 m^3 kg^-1 s^-2');
21 });
22 setLazyConstant(math, 'planckConstant', function () {
23 return fixedUnit('6.626069311e-34 J s');
24 });
25 setLazyConstant(math, 'reducedPlanckConstant', function () {
26 return fixedUnit('1.05457172647e-34 J s');
27 });
28
29 // Electromagnetic constants
30 setLazyConstant(math, 'magneticConstant', function () {
31 return fixedUnit('1.2566370614e-6 N A^-2');
32 });
33 setLazyConstant(math, 'electricConstant', function () {
34 return fixedUnit('8.854187817e-12 F m^-1');
35 });
36 setLazyConstant(math, 'vacuumImpedance', function () {
37 return fixedUnit('376.730313461 ohm');
38 });
39 setLazyConstant(math, 'coulomb', function () {
40 return fixedUnit('8.9875517873681764e9 N m^2 C^-2');
41 });
42 setLazyConstant(math, 'elementaryCharge', function () {
43 return fixedUnit('1.60217656535e-19 C');
44 });
45 setLazyConstant(math, 'bohrMagneton', function () {
46 return fixedUnit('9.2740096820e-24 J T^-1');
47 });
48 setLazyConstant(math, 'conductanceQuantum', function () {
49 return fixedUnit('7.748091734625e-5 S');
50 });
51 setLazyConstant(math, 'inverseConductanceQuantum', function () {
52 return fixedUnit('12906.403721742 ohm');
53 });
54 setLazyConstant(math, 'magneticFluxQuantum', function () {
55 return fixedUnit('2.06783375846e-15 Wb');
56 });
57 setLazyConstant(math, 'nuclearMagneton', function () {
58 return fixedUnit('5.0507835311e-27 J T^-1');
59 });
60 setLazyConstant(math, 'klitzing', function () {
61 return fixedUnit('25812.807443484 ohm');
62 });
63 // setLazyConstant(math, 'josephson', function () {return fixedUnit('4.8359787011e-14 Hz V^-1')}) // TODO: support for Hz needed
64
65 // Atomic and nuclear constants
66 setLazyConstant(math, 'bohrRadius', function () {
67 return fixedUnit('5.291772109217e-11 m');
68 });
69 setLazyConstant(math, 'classicalElectronRadius', function () {
70 return fixedUnit('2.817940326727e-15 m');
71 });
72 setLazyConstant(math, 'electronMass', function () {
73 return fixedUnit('9.1093829140e-31 kg');
74 });
75 setLazyConstant(math, 'fermiCoupling', function () {
76 return fixedUnit('1.1663645e-5 GeV^-2');
77 });
78 setLazyConstant(math, 'fineStructure', function () {
79 return 7.297352569824e-3;
80 });
81 setLazyConstant(math, 'hartreeEnergy', function () {
82 return fixedUnit('4.3597443419e-18 J');
83 });
84 setLazyConstant(math, 'protonMass', function () {
85 return fixedUnit('1.67262177774e-27 kg');
86 });
87 setLazyConstant(math, 'deuteronMass', function () {
88 return fixedUnit('3.3435830926e-27 kg');
89 });
90 setLazyConstant(math, 'neutronMass', function () {
91 return fixedUnit('1.6749271613e-27 kg');
92 });
93 setLazyConstant(math, 'quantumOfCirculation', function () {
94 return fixedUnit('3.636947552024e-4 m^2 s^-1');
95 });
96 setLazyConstant(math, 'rydberg', function () {
97 return fixedUnit('10973731.56853955 m^-1');
98 });
99 setLazyConstant(math, 'thomsonCrossSection', function () {
100 return fixedUnit('6.65245873413e-29 m^2');
101 });
102 setLazyConstant(math, 'weakMixingAngle', function () {
103 return 0.222321;
104 });
105 setLazyConstant(math, 'efimovFactor', function () {
106 return 22.7;
107 });
108
109 // Physico-chemical constants
110 setLazyConstant(math, 'atomicMass', function () {
111 return fixedUnit('1.66053892173e-27 kg');
112 });
113 setLazyConstant(math, 'avogadro', function () {
114 return fixedUnit('6.0221412927e23 mol^-1');
115 });
116 setLazyConstant(math, 'boltzmann', function () {
117 return fixedUnit('1.380648813e-23 J K^-1');
118 });
119 setLazyConstant(math, 'faraday', function () {
120 return fixedUnit('96485.336521 C mol^-1');
121 });
122 setLazyConstant(math, 'firstRadiation', function () {
123 return fixedUnit('3.7417715317e-16 W m^2');
124 });
125 // setLazyConstant(math, 'spectralRadiance', function () {return fixedUnit('1.19104286953e-16 W m^2 sr^-1')}) // TODO spectralRadiance
126 setLazyConstant(math, 'loschmidt', function () {
127 return fixedUnit('2.686780524e25 m^-3');
128 });
129 setLazyConstant(math, 'gasConstant', function () {
130 return fixedUnit('8.314462175 J K^-1 mol^-1');
131 });
132 setLazyConstant(math, 'molarPlanckConstant', function () {
133 return fixedUnit('3.990312717628e-10 J s mol^-1');
134 });
135 setLazyConstant(math, 'molarVolume', function () {
136 return fixedUnit('2.241396820e-10 m^3 mol^-1');
137 });
138 setLazyConstant(math, 'sackurTetrode', function () {
139 return -1.164870823;
140 });
141 setLazyConstant(math, 'secondRadiation', function () {
142 return fixedUnit('1.438777013e-2 m K');
143 });
144 setLazyConstant(math, 'stefanBoltzmann', function () {
145 return fixedUnit('5.67037321e-8 W m^-2 K^-4');
146 });
147 setLazyConstant(math, 'wienDisplacement', function () {
148 return fixedUnit('2.897772126e-3 m K');
149 });
150
151 // Adopted values
152 setLazyConstant(math, 'molarMass', function () {
153 return fixedUnit('1e-3 kg mol^-1');
154 });
155 setLazyConstant(math, 'molarMassC12', function () {
156 return fixedUnit('1.2e-2 kg mol^-1');
157 });
158 setLazyConstant(math, 'gravity', function () {
159 return fixedUnit('9.80665 m s^-2');
160 });
161 // atm is defined in Unit.js
162
163 // Natural units
164 setLazyConstant(math, 'planckLength', function () {
165 return fixedUnit('1.61619997e-35 m');
166 });
167 setLazyConstant(math, 'planckMass', function () {
168 return fixedUnit('2.1765113e-8 kg');
169 });
170 setLazyConstant(math, 'planckTime', function () {
171 return fixedUnit('5.3910632e-44 s');
172 });
173 setLazyConstant(math, 'planckCharge', function () {
174 return fixedUnit('1.87554595641e-18 C');
175 });
176 setLazyConstant(math, 'planckTemperature', function () {
177 return fixedUnit('1.41683385e+32 K');
178 });
179}
180
181// create a lazy constant in both math and mathWithTransform
182function setLazyConstant(math, name, resolver) {
183 lazy(math, name, resolver);
184 lazy(math.expression.mathWithTransform, name, resolver);
185}
186
187exports.factory = factory;
188exports.lazy = false; // no lazy loading of constants, the constants themselves are lazy when needed
189exports.math = true; // request access to the math namespace
\No newline at end of file