KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jscience > physics > units > SI


1 /*
2  * JScience - Java(TM) Tools and Libraries for the Advancement of Sciences.
3  * Copyright (C) 2005 - JScience (http://jscience.org/)
4  * All rights reserved.
5  *
6  * Permission to use, copy, modify, and distribute this software is
7  * freely granted, provided that this notice is preserved.
8  */

9 package org.jscience.physics.units;
10
11 import org.jscience.physics.quantities.*;
12
13 /**
14  * <p> This class contains SI (Système International d'Unités) base units,
15  * and derived units.</p>
16  * <p> It also defines the 20 SI prefixes used to form decimal multiples and
17  * submultiples of SI units. For example:<pre>
18  * import static org.jscience.physics.units.SI.*; // Static import.
19  * ...
20  * Unit&lt;Pressure> HECTO_PASCAL = HECTO(PASCAL);
21  * Unit&lt;Length> KILO_METER = KILO(METER);
22  * </pre>)</p>
23  * See also: <a HREF="http://www.bipm.fr/">BIPM</a>, <a HREF=
24  * "http://physics.nist.gov/cuu/Units/">International System of Units</a>
25  *
26  * @author <a HREF="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
27  * @version 2.0, June 16, 2004
28  */

29 public final class SI {
30
31     /**
32      * Default constructor (prevents this class from being instantiated).
33      */

34     private SI() {
35     }
36
37     ////////////////
38
// BASE UNITS //
39
////////////////
40

41     /**
42      * The base unit for electric current quantities (<code>A</code>).
43      * The Ampere is that constant current which, if maintained in two straight
44      * parallel conductors of infinite length, of negligible circular
45      * cross-section, and placed 1 metre apart in vacuum, would produce between
46      * these conductors a force equal to 2 × 10-7 newton per metre of length.
47      * It is named after the French physicist Andre Ampere (1775-1836).
48      */

49     public static final BaseUnit<ElectricCurrent> AMPERE = new BaseUnit<ElectricCurrent>(
50             "A", Dimension.ELECTRIC_CURRENT, Converter.IDENTITY);
51
52     /**
53      * The base unit for luminous intensity quantities (<code>cd</code>).
54      * The candela is the luminous intensity, in a given direction,
55      * of a source that emits monochromatic radiation of frequency
56      * 540 × 1012 hertz and that has a radiant intensity in that
57      * direction of 1/683 watt per steradian
58      */

59     public static final BaseUnit<LuminousIntensity> CANDELA = new BaseUnit<LuminousIntensity>(
60             "cd", Dimension.LUMINOUS_INTENSITY, Converter.IDENTITY);
61
62     /**
63      * The base unit for thermodynamic temperature quantities (<code>K</code>).
64      * The kelvin is the 1/273.16th of the thermodynamic temperature of the
65      * triple point of water. It is named after the Scottish mathematician and
66      * physicist William Thomson 1st Lord Kelvin (1824-1907)
67      */

68     public static final BaseUnit<Temperature> KELVIN = new BaseUnit<Temperature>(
69             "K", Dimension.TEMPERATURE, Converter.IDENTITY);
70
71     /**
72      * The base unit for mass quantities (<code>kg</code>).
73      * It is the only SI unit with a prefix as part of its name and symbol.
74      * The kilogram is equal to the mass of an international prototype in the
75      * form of a platinum-iridium cylinder kept at Sevres in France.
76      * @see #GRAM
77      */

78     public static final BaseUnit<Mass> KILOGRAM = new BaseUnit<Mass>("kg",
79             Dimension.MASS, Converter.IDENTITY);
80
81     /**
82      * The base unit for length quantities (<code>m</code>).
83      * One meter was redefined in 1983 as the distance traveled by light in
84      * a vacuum in 1/299,792,458 of a second.
85      */

86     public static final BaseUnit<Length> METER = new BaseUnit<Length>("m",
87             Dimension.LENGTH, Converter.IDENTITY);
88
89     /**
90      * The base unit for amount of substance quantities (<code>mol</code>).
91      * The mole is the amount of substance of a system which contains as many
92      * elementary entities as there are atoms in 0.012 kilogram of carbon 12.
93      */

94     public static final BaseUnit<AmountOfSubstance> MOLE = new BaseUnit<AmountOfSubstance>(
95             "mol", Dimension.AMOUNT_OF_SUBSTANCE, Converter.IDENTITY);
96
97     /**
98      * The base unit for duration quantities (<code>s</code>).
99      * It is defined as the duration of 9,192,631,770 cycles of radiation
100      * corresponding to the transition between two hyperfine levels of
101      * the ground state of cesium (1967 Standard).
102      */

103     public static final BaseUnit<Duration> SECOND = new BaseUnit<Duration>("s",
104             Dimension.TIME, Converter.IDENTITY);
105
106     ////////////////////////////////
107
// SI DERIVED ALTERNATE UNITS //
108
////////////////////////////////
109

110     /**
111      * The derived unit for mass quantities (<code>g</code>).
112      * The base unit for mass quantity is {@link #KILOGRAM}.
113      */

114     public static final Unit<Mass> GRAM = KILOGRAM.times(1e-3);
115
116     /**
117      * The unit for plane angle quantities (<code>rad</code>).
118      * One radian is the angle between two radii of a circle such that the
119      * length of the arc between them is equal to the radius.
120      */

121     public static final Unit<Angle> RADIAN = Unit.ONE.alternate("rad");
122
123     /**
124      * The unit for solid angle quantities (<code>sr</code>).
125      * One steradian is the solid angle subtended at the center of a sphere by
126      * an area on the surface of the sphere that is equal to the radius squared.
127      * The total solid angle of a sphere is 4*Pi steradians.
128      */

129     public static final Unit<SolidAngle> STERADIAN = Unit.ONE.alternate("sr");
130
131     /**
132      * The unit for binary information (<code>bit</code>).
133      */

134     public static final Unit<DataAmount> BIT = Unit.ONE.alternate("bit");
135
136     /**
137      * The derived unit for frequency (<code>Hz</code>).
138      * A unit of frequency equal to one cycle per second.
139      * After Heinrich Rudolf Hertz (1857-1894), German physicist who was the
140      * first to produce radio waves artificially.
141      */

142     public static final Unit<Frequency> HERTZ = Unit.ONE.divide(SECOND)
143             .alternate("Hz");
144
145     /**
146      * The derived unit for force (<code>N</code>).
147      * One newton is the force required to give a mass of 1 kilogram an Force
148      * of 1 metre per second per second. It is named after the English
149      * mathematician and physicist Sir Isaac Newton (1642-1727).
150      */

151     public static final Unit<Force> NEWTON = METER.times(KILOGRAM).divide(
152             SECOND.pow(2)).alternate("N");
153
154     /**
155      * The derived unit for pressure, stress (<code>Pa</code>).
156      * One pascal is equal to one newton per square meter. It is named after
157      * the French philosopher and mathematician Blaise Pascal (1623-1662).
158      */

159     public static final Unit<Pressure> PASCAL = NEWTON.divide(METER.pow(2))
160             .alternate("Pa");
161
162     /**
163      * The derived unit for energy, work, quantity of heat (<code>J</code>).
164      * One joule is the amount of work done when an applied force of 1 newton
165      * moves through a distance of 1 metre in the direction of the force.
166      * It is named after the English physicist James Prescott Joule (1818-1889).
167      */

168     public static final Unit<Energy> JOULE = NEWTON.times(METER).alternate("J");
169
170     /**
171      * The derived unit for power, radiant, flux (<code>W</code>).
172      * One watt is equal to one joule per second. It is named after the British
173      * scientist James Watt (1736-1819).
174      */

175     public static final Unit<Power> WATT = JOULE.divide(SECOND).alternate("W");
176
177     /**
178      * The derived unit for electric charge, quantity of electricity
179      * (<code>C</code>).
180      * One Coulomb is equal to the quantity of charge transferred in one second
181      * by a steady current of one ampere. It is named after the French physicist
182      * Charles Augustin de Coulomb (1736-1806).
183      */

184     public static final Unit<ElectricCharge> COULOMB = SECOND.times(AMPERE)
185             .alternate("C");
186
187     /**
188      * The derived unit for electric potential difference, electromotive force
189      * (<code>V</code>).
190      * One Volt is equal to the difference of electric potential between two
191      * points on a conducting wire carrying a constant current of one ampere
192      * when the power dissipated between the points is one watt. It is named
193      * after the Italian physicist Count Alessandro Volta (1745-1827).
194      */

195     public static final Unit<ElectricPotential> VOLT = WATT.divide(AMPERE)
196             .alternate("V");
197
198     /**
199      * The derived unit for capacitance (<code>F</code>).
200      * One Farad is equal to the capacitance of a capacitor having an equal
201      * and opposite charge of 1 coulomb on each plate and a potential difference
202      * of 1 volt between the plates. It is named after the British physicist
203      * and chemist Michael Faraday (1791-1867).
204      */

205     public static final Unit<ElectricCapacitance> FARAD = COULOMB.divide(VOLT)
206             .alternate("F");
207
208     /**
209      * The derived unit for electric resistance (<code>Ω</code>).
210      * One Ohm is equal to the resistance of a conductor in which a current of
211      * one ampere is produced by a potential of one volt across its terminals.
212      * It is named after the German physicist Georg Simon Ohm (1789-1854).
213      */

214     public static final Unit<ElectricResistance> OHM = VOLT.divide(AMPERE)
215             .alternate("Ω");
216
217     /**
218      * The derived unit for electric conductance (<code>S</code>).
219      * One Siemens is equal to one ampere per volt. It is named after
220      * the German engineer Ernst Werner von Siemens (1816-1892).
221      */

222     public static final Unit<ElectricConductance> SIEMENS = AMPERE.divide(VOLT)
223             .alternate("S");
224
225     /**
226      * The derived unit for magnetic flux (<code>Wb</code>).
227      * One Weber is equal to the magnetic flux that in linking a circuit of one
228      * turn produces in it an electromotive force of one volt as it is uniformly
229      * reduced to zero within one second. It is named after the German physicist
230      * Wilhelm Eduard Weber (1804-1891).
231      */

232     public static final Unit<MagneticFlux> WEBER = VOLT.times(SECOND)
233             .alternate("Wb");
234
235     /**
236      * The derived unit for magnetic flux density (<code>T</code>).
237      * One Tesla is equal equal to one weber per square meter. It is named
238      * after the Serbian-born American electrical engineer and physicist
239      * Nikola Tesla (1856-1943).
240      */

241     public static final Unit<MagneticFluxDensity> TESLA = WEBER.divide(
242             METER.pow(2)).alternate("T");
243
244     /**
245      * The derived unit for inductance (<code>H</code>).
246      * One Henry is equal to the inductance for which an induced electromotive
247      * force of one volt is produced when the current is varied at the rate of
248      * one ampere per second. It is named after the American physicist
249      * Joseph Henry (1791-1878).
250      */

251     public static final Unit<ElectricInductance> HENRY = WEBER.divide(AMPERE)
252             .alternate("H");
253
254     /**
255      * The derived unit for Celsius temperature (<code>°C</code>).
256      * This is a unit of temperature such as the freezing point of water
257      * (at one atmosphere of pressure) is 0 °C, while the boiling point is
258      * 100 °C.
259      */

260     public static final Unit<Temperature> CELSIUS = KELVIN.plus(273.15);
261
262     /**
263      * The derived unit for luminous flux (<code>lm</code>).
264      * One Lumen is equal to the amount of light given out through a solid angle
265      * by a source of one candela intensity radiating equally in all directions.
266      */

267     public static final Unit<LuminousFlux> LUMEN = CANDELA.times(STERADIAN)
268             .alternate("lm");
269
270     /**
271      * The derived unit for illuminance (<code>lx</code>).
272      * One Lux is equal to one lumen per square meter.
273      */

274     public static final Unit<Illuminance> LUX = LUMEN.divide(METER.pow(2))
275             .alternate("lx");
276
277     /**
278      * The derived unit for activity of a radionuclide (<code>Bq</code>).
279      * One becquerel is the radiation caused by one disintegration per second.
280      * It is named after the French physicist, Antoine-Henri Becquerel
281      * (1852-1908).
282      */

283     public static final Unit<RadioactiveActivity> BECQUEREL = Unit.ONE.divide(
284             SECOND).alternate("Bq");
285
286     /**
287      * The derived unit for absorbed dose, specific energy (imparted), kerma
288      * (<code>Gy</code>).
289      * One gray is equal to the dose of one joule of energy absorbed per one
290      * kilogram of matter. It is named after the British physician
291      * L. H. Gray (1905-1965).
292      */

293     public static final Unit<RadiationDoseAbsorbed> GRAY = JOULE.divide(
294             KILOGRAM).alternate("Gy");
295
296     /**
297      * The derived unit for dose equivalent (<code>Sv</code>).
298      * One Sievert is equal is equal to the actual dose, in grays, multiplied
299      * by a "quality factor" which is larger for more dangerous forms of
300      * radiation. It is named after the Swedish physicist Rolf Sievert
301      * (1898-1966).
302      */

303     public static final Unit<RadiationDoseEffective> SIEVERT = JOULE.divide(
304             KILOGRAM).alternate("Sv");
305
306     /**
307      * The derived unit for catalytic activity (<code>kat</code>).
308      */

309     public static final Unit<CatalyticActivity> KATAL = MOLE.divide(SECOND)
310             .alternate("kat");
311
312     //////////////////////////////
313
// SI DERIVED PRODUCT UNITS //
314
//////////////////////////////
315

316     /**
317      * The metric unit for velocity quantities (<code>m/s</code>).
318      */

319     public static final Unit<Velocity> METER_PER_SECOND = METER.divide(SECOND);
320
321     /**
322      * The metric unit for acceleration quantities (<code>m/s²</code>).
323      */

324     public static final Unit<Acceleration> METER_PER_SQUARE_SECOND = METER
325             .divide(SECOND.pow(2));
326
327     /**
328      * The metric unit for area quantities (<code>m²</code>).
329      */

330     public static final Unit<Area> SQUARE_METER = METER.pow(2);
331
332     /**
333      * The metric unit for volume quantities (<code>m³</code>).
334      */

335     public static final Unit<Volume> CUBIC_METER = METER.pow(3);
336
337     /////////////////
338
// SI PREFIXES //
339
/////////////////
340

341     /**
342      * Returns the specified unit multiplied by the factor
343      * <code>10<sup>24</sup></code>
344      *
345      * @param unit any unit.
346      * @return <code>unit.multiply(1e24)</code>.
347      */

348     public static <Q extends Quantity> Unit<Q> YOTTA(Unit<Q> unit) {
349         return unit.times(1e24);
350     }
351
352     /**
353      * Returns the specified unit multiplied by the factor
354      * <code>10<sup>21</sup></code>
355      *
356      * @param unit any unit.
357      * @return <code>unit.multiply(1e21)</code>.
358      */

359     public static <Q extends Quantity> Unit<Q> ZETTA(Unit<Q> unit) {
360         return unit.times(1e21);
361     }
362
363     /**
364      * Returns the specified unit multiplied by the factor
365      * <code>10<sup>18</sup></code>
366      *
367      * @param unit any unit.
368      * @return <code>unit.multiply(1e18)</code>.
369      */

370     public static <Q extends Quantity> Unit<Q> EXA(Unit<Q> unit) {
371         return unit.times(1e18);
372     }
373
374     /**
375      * Returns the specified unit multiplied by the factor
376      * <code>10<sup>15</sup></code>
377      *
378      * @param unit any unit.
379      * @return <code>unit.multiply(1e15)</code>.
380      */

381     public static <Q extends Quantity> Unit<Q> PETA(Unit<Q> unit) {
382         return unit.times(1e15);
383     }
384
385     /**
386      * Returns the specified unit multiplied by the factor
387      * <code>10<sup>12</sup></code>
388      *
389      * @param unit any unit.
390      * @return <code>unit.multiply(1e12)</code>.
391      */

392     public static <Q extends Quantity> Unit<Q> TERA(Unit<Q> unit) {
393         return unit.times(1e12);
394     }
395
396     /**
397      * Returns the specified unit multiplied by the factor
398      * <code>10<sup>9</sup></code>
399      *
400      * @param unit any unit.
401      * @return <code>unit.multiply(1e9)</code>.
402      */

403     public static <Q extends Quantity> Unit<Q> GIGA(Unit<Q> unit) {
404         return unit.times(1e9);
405     }
406
407     /**
408      * Returns the specified unit multiplied by the factor
409      * <code>10<sup>6</sup></code>
410      *
411      * @param unit any unit.
412      * @return <code>unit.multiply(1e6)</code>.
413      */

414     public static <Q extends Quantity> Unit<Q> MEGA(Unit<Q> unit) {
415         return unit.times(1e6);
416     }
417
418     /**
419      * Returns the specified unit multiplied by the factor
420      * <code>10<sup>3</sup></code>
421      *
422      * @param unit any unit.
423      * @return <code>unit.multiply(1e3)</code>.
424      */

425     public static <Q extends Quantity> Unit<Q> KILO(Unit<Q> unit) {
426         return unit.times(1e3);
427     }
428
429     /**
430      * Returns the specified unit multiplied by the factor
431      * <code>10<sup>2</sup></code>
432      *
433      * @param unit any unit.
434      * @return <code>unit.multiply(1e2)</code>.
435      */

436     public static <Q extends Quantity> Unit<Q> HECTO(Unit<Q> unit) {
437         return unit.times(1e2);
438     }
439
440     /**
441      * Returns the specified unit multiplied by the factor
442      * <code>10<sup>1</sup></code>
443      *
444      * @param unit any unit.
445      * @return <code>unit.multiply(1e1)</code>.
446      */

447     public static <Q extends Quantity> Unit<Q> DEKA(Unit<Q> unit) {
448         return unit.times(1e1);
449     }
450
451     /**
452      * Returns the specified unit multiplied by the factor
453      * <code>10<sup>-1</sup></code>
454      *
455      * @param unit any unit.
456      * @return <code>unit.multiply(1e-1)</code>.
457      */

458     public static <Q extends Quantity> Unit<Q> DECI(Unit<Q> unit) {
459         return unit.times(1e-1);
460     }
461
462     /**
463      * Returns the specified unit multiplied by the factor
464      * <code>10<sup>-2</sup></code>
465      *
466      * @param unit any unit.
467      * @return <code>unit.multiply(1e-2)</code>.
468      */

469     public static <Q extends Quantity> Unit<Q> CENTI(Unit<Q> unit) {
470         return unit.times(1e-2);
471     }
472
473     /**
474      * Returns the specified unit multiplied by the factor
475      * <code>10<sup>-3</sup></code>
476      *
477      * @param unit any unit.
478      * @return <code>unit.multiply(1e-3)</code>.
479      */

480     public static <Q extends Quantity> Unit<Q> MILLI(Unit<Q> unit) {
481         return unit.times(1e-3);
482     }
483
484     /**
485      * Returns the specified unit multiplied by the factor
486      * <code>10<sup>-6</sup></code>
487      *
488      * @param unit any unit.
489      * @return <code>unit.multiply(1e-6)</code>.
490      */

491     public static <Q extends Quantity> Unit<Q> MICRO(Unit<Q> unit) {
492         return unit.times(1e-6);
493     }
494
495     /**
496      * Returns the specified unit multiplied by the factor
497      * <code>10<sup>-9</sup></code>
498      *
499      * @param unit any unit.
500      * @return <code>unit.multiply(1e-9)</code>.
501      */

502     public static <Q extends Quantity> Unit<Q> NANO(Unit<Q> unit) {
503         return unit.times(1e-9);
504     }
505
506     /**
507      * Returns the specified unit multiplied by the factor
508      * <code>10<sup>-12</sup></code>
509      *
510      * @param unit any unit.
511      * @return <code>unit.multiply(1e-12)</code>.
512      */

513     public static <Q extends Quantity> Unit<Q> PICO(Unit<Q> unit) {
514         return unit.times(1e-12);
515     }
516
517     /**
518      * Returns the specified unit multiplied by the factor
519      * <code>10<sup>-15</sup></code>
520      *
521      * @param unit any unit.
522      * @return <code>unit.multiply(1e-15)</code>.
523      */

524     public static <Q extends Quantity> Unit<Q> FEMTO(Unit<Q> unit) {
525         return unit.times(1e-15);
526     }
527
528     /**
529      * Returns the specified unit multiplied by the factor
530      * <code>10<sup>-18</sup></code>
531      *
532      * @param unit any unit.
533      * @return <code>unit.multiply(1e-18)</code>.
534      */

535     public static <Q extends Quantity> Unit<Q> ATTO(Unit<Q> unit) {
536         return unit.times(1e-18);
537     }
538
539     /**
540      * Returns the specified unit multiplied by the factor
541      * <code>10<sup>-21</sup></code>
542      *
543      * @param unit any unit.
544      * @return <code>unit.multiply(1e-21)</code>.
545      */

546     public static <Q extends Quantity> Unit<Q> ZEPTO(Unit<Q> unit) {
547         return unit.times(1e-21);
548     }
549
550     /**
551      * Returns the specified unit multiplied by the factor
552      * <code>10<sup>-24</sup></code>
553      *
554      * @param unit any unit.
555      * @return <code>unit.multiply(1e-24)</code>.
556      */

557     public static <Q extends Quantity> Unit<Q> YOCTO(Unit<Q> unit) {
558         return unit.times(1e-24);
559     }
560
561     ////////////////////////////////////////////////////////////////////////////
562
// Initializes the unit database for SI units.
563
private static final Unit[] SI_UNITS = { SI.AMPERE, SI.BECQUEREL,
564             SI.CANDELA, SI.COULOMB, SI.FARAD, SI.GRAY, SI.HENRY, SI.HERTZ,
565             SI.JOULE, SI.KATAL, SI.KELVIN, SI.LUMEN, SI.LUX, SI.METER, SI.MOLE,
566             SI.NEWTON, SI.OHM, SI.PASCAL, SI.RADIAN, SI.SECOND, SI.SIEMENS,
567             SI.SIEVERT, SI.STERADIAN, SI.TESLA, SI.VOLT, SI.WATT, SI.WEBER };
568
569     private static final String JavaDoc[] PREFIXES = { "Y", "Z", "E", "P", "T", "G",
570             "M", "k", "h", "da", "d", "c", "m", "µ", "n", "p", "f", "a", "z",
571             "y" };
572
573     private static final double[] FACTORS = { 1e24, 1e21, 1e18, 1e15, 1e12,
574             1e9, 1e6, 1e3, 1e2, 1e1, 1e-1, 1e-2, 1e-3, 1e-6, 1e-9, 1e-12,
575             1e-15, 1e-18, 1e-21, 1e-24 };
576     static {
577         for (int i = 0; i < SI_UNITS.length; i++) {
578             for (int j = 0; j < PREFIXES.length; j++) {
579                 Unit u = SI_UNITS[i].times(FACTORS[j]);
580                 u.label(PREFIXES[j] + SI_UNITS[i]._symbol);
581             }
582         }
583         // Special case for KILOGRAM.
584
SI.GRAM.label("g");
585         for (int i = 0; i < PREFIXES.length; i++) {
586             if (FACTORS[i] != 1e3) { // kg is already defined.
587
SI.KILOGRAM.times(FACTORS[i] * 1e-3).label(PREFIXES[i] + "g");
588             }
589         }
590
591         // Special case for DEGREE_CElSIUS.
592
SI.CELSIUS.label("°C");
593         for (int i = 0; i < PREFIXES.length; i++) {
594             SI.CELSIUS.times(FACTORS[i]).label(PREFIXES[i] + "°C");
595         }
596     }
597
598     ////////////////////////////////////////////////////////////////////////////
599

600     /**
601      * Static method to force class initialization.
602      */

603     static void initializeClass() {
604     }
605
606 }
Popular Tags