View Javadoc
1   package org.djunits.unit;
2   
3   import org.djunits.unit.quantity.Quantity;
4   import org.djunits.unit.scale.IdentityScale;
5   import org.djunits.unit.scale.LinearScale;
6   import org.djunits.unit.si.SIPrefixes;
7   import org.djunits.unit.unitsystem.UnitSystem;
8   
9   /**
10   * The units of energy.
11   * <p>
12   * Copyright (c) 2015-2023 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
14   * <p>
15   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
16   */
17  public class EnergyUnit extends Unit<EnergyUnit>
18  {
19      /** */
20      private static final long serialVersionUID = 20140604L;
21  
22      /** The base, with "kgm2/s2" as the SI signature. */
23      public static final Quantity<EnergyUnit> BASE = new Quantity<>("Energy", "kgm2/s2");
24  
25      /** The SI unit for energy is Joule (J) = kgm2/s2. */
26      public static final EnergyUnit SI =
27              new EnergyUnit().build(new Unit.Builder<EnergyUnit>().setQuantity(BASE).setId("J").setName("joule")
28                      .setUnitSystem(UnitSystem.SI_DERIVED).setSiPrefixes(SIPrefixes.UNIT, 1.0).setScale(IdentityScale.SCALE));
29  
30      /** Joule. */
31      public static final EnergyUnit JOULE = SI;
32  
33      /** microjoule. */
34      public static final EnergyUnit MICROJOULE = JOULE.deriveSI(SIPrefixes.getUnit("mu"), 1.0);
35  
36      /** millijoule. */
37      public static final EnergyUnit MILLIJOULE = JOULE.deriveSI(SIPrefixes.getUnit("m"), 1.0);
38  
39      /** kilojoule. */
40      public static final EnergyUnit KILOJOULE = JOULE.deriveSI(SIPrefixes.getUnit("k"), 1.0);
41  
42      /** megajoule. */
43      public static final EnergyUnit MEGAJOULE = JOULE.deriveSI(SIPrefixes.getUnit("M"), 1.0);
44  
45      /** gigajoule. */
46      public static final EnergyUnit GIGAJOULE = JOULE.deriveSI(SIPrefixes.getUnit("G"), 1.0);
47  
48      /** terajoule. */
49      public static final EnergyUnit TERAJOULE = JOULE.deriveSI(SIPrefixes.getUnit("T"), 1.0);
50  
51      /** petajoule. */
52      public static final EnergyUnit PETAJOULE = JOULE.deriveSI(SIPrefixes.getUnit("P"), 1.0);
53  
54      /** foot-pound force. */
55      public static final EnergyUnit FOOT_POUND_FORCE = JOULE.deriveLinear(factorFL(ForceUnit.POUND_FORCE, LengthUnit.FOOT),
56              "ft.lbf", "foot pound-force", UnitSystem.IMPERIAL);
57  
58      /** inch-pound force. */
59      public static final EnergyUnit INCH_POUND_FORCE = JOULE.deriveLinear(factorFL(ForceUnit.POUND_FORCE, LengthUnit.INCH),
60              "in.lbf", "inch pound-force", UnitSystem.IMPERIAL);
61  
62      /** British thermal unit (ISO). */
63      public static final EnergyUnit BTU_ISO =
64              JOULE.deriveLinear(1.0545E3, "BTU(ISO)", "British thermal unit (ISO)", UnitSystem.IMPERIAL);
65  
66      /** British thermal unit (International Table). */
67      public static final EnergyUnit BTU_IT =
68              JOULE.deriveLinear(1.05505585262E3, "BTU(IT)", "British thermal unit (International Table)", UnitSystem.IMPERIAL);
69  
70      /** calorie (International Table). */
71      public static final EnergyUnit CALORIE_IT =
72              JOULE.deriveLinear(4.1868, "cal(IT)", "calorie (International Table)", UnitSystem.IMPERIAL);
73  
74      /** calorie. */
75      public static final EnergyUnit CALORIE = JOULE.deriveLinear(4.184, "cal", "calorie", UnitSystem.OTHER);
76  
77      /** kilocalorie. */
78      public static final EnergyUnit KILOCALORIE = CALORIE.deriveLinear(1000.0, "kcal", "kilocalorie");
79  
80      /** watt-hour. */
81      public static final EnergyUnit WATT_HOUR = new EnergyUnit().build(new Unit.Builder<EnergyUnit>().setQuantity(BASE)
82              .setId("Wh").setName("watt-hour").setUnitSystem(UnitSystem.SI_DERIVED).setSiPrefixes(SIPrefixes.UNIT, 1.0)
83              .setScale(new LinearScale(3600.0)));
84  
85      /** microwatt-hour. */
86      public static final EnergyUnit MICROWATT_HOUR = WATT_HOUR.deriveSI(SIPrefixes.getUnit("mu"), 1.0);
87  
88      /** milliwatt-hour. */
89      public static final EnergyUnit MILLIWATT_HOUR = WATT_HOUR.deriveSI(SIPrefixes.getUnit("m"), 1.0);
90  
91      /** kilowatt-hour. */
92      public static final EnergyUnit KILOWATT_HOUR = WATT_HOUR.deriveSI(SIPrefixes.getUnit("k"), 1.0);
93  
94      /** megawatt-hour. */
95      public static final EnergyUnit MEGAWATT_HOUR = WATT_HOUR.deriveSI(SIPrefixes.getUnit("M"), 1.0);
96  
97      /** gigawatt-hour. */
98      public static final EnergyUnit GIGAWATT_HOUR = WATT_HOUR.deriveSI(SIPrefixes.getUnit("G"), 1.0);
99  
100     /** terawatt-hour. */
101     public static final EnergyUnit TERAWATT_HOUR = WATT_HOUR.deriveSI(SIPrefixes.getUnit("T"), 1.0);
102 
103     /** petawatt-hour. */
104     public static final EnergyUnit PETAWATT_HOUR = WATT_HOUR.deriveSI(SIPrefixes.getUnit("P"), 1.0);
105 
106     /** electronvolt. */
107     public static final EnergyUnit ELECTRONVOLT = new EnergyUnit().build(new Unit.Builder<EnergyUnit>().setQuantity(BASE)
108             .setId("eV").setName("electronvolt").setUnitSystem(UnitSystem.SI_ACCEPTED).setSiPrefixes(SIPrefixes.UNIT, 1.0)
109             .setScale(new LinearScale(1.602176634E-19)));
110 
111     /** micro-electronvolt. */
112     public static final EnergyUnit MICROELECTRONVOLT = ELECTRONVOLT.deriveSI(SIPrefixes.getUnit("mu"), 1.0);
113 
114     /** milli-electronvolt. */
115     public static final EnergyUnit MILLIELECTRONVOLT = ELECTRONVOLT.deriveSI(SIPrefixes.getUnit("m"), 1.0);
116 
117     /** kilo-electronvolt. */
118     public static final EnergyUnit KILOELECTRONVOLT = ELECTRONVOLT.deriveSI(SIPrefixes.getUnit("k"), 1.0);
119 
120     /** mega-electronvolt. */
121     public static final EnergyUnit MEGAELECTRONVOLT = ELECTRONVOLT.deriveSI(SIPrefixes.getUnit("M"), 1.0);
122 
123     /** giga-electronvolt. */
124     public static final EnergyUnit GIGAELECTRONVOLT = ELECTRONVOLT.deriveSI(SIPrefixes.getUnit("G"), 1.0);
125 
126     /** sthene-meter (mts). */
127     public static final EnergyUnit STHENE_METER = JOULE.deriveLinear(1000.0, "sn.m", "sthene meter", UnitSystem.MTS);
128 
129     /** erg (cgs). */
130     public static final EnergyUnit ERG = JOULE.deriveLinear(1.0E-7, "erg", "erg", UnitSystem.CGS);
131 
132     /**
133      * Determine the conversion factor to the base energy unit, given a force unit and a length unit.
134      * @param force ForceUnit; the used force unit, e.g. lbf
135      * @param distance LengthUnit; the used length unit, e.g. ft
136      * @return double; the conversion factor from the provided units (e.g. ft.lbf) to the standard unit (e.g., J)
137      */
138     private static double factorFL(final ForceUnit force, final LengthUnit distance)
139     {
140         return force.getScale().toStandardUnit(1.0) * distance.getScale().toStandardUnit(1.0);
141     }
142 
143 }