View Javadoc
1   package org.opentrafficsim.core.unit;
2   
3   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.CGS;
4   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.IMPERIAL;
5   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.MTS;
6   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.OTHER;
7   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_ACCEPTED;
8   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_DERIVED;
9   
10  import org.opentrafficsim.core.unit.unitsystem.UnitSystem;
11  
12  /**
13   * The units of energy.
14   * <p>
15   * Copyright (c) 2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
16   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
17   * <p>
18   * @version May 15, 2014 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   */
21  public class EnergyUnit extends Unit<EnergyUnit>
22  {
23      /** */
24      private static final long serialVersionUID = 20140604L;
25  
26      /** the unit of mass for the energy unit, e.g., kilogram. */
27      private final MassUnit massUnit;
28  
29      /** the unit of length for the energy unit, e.g., length. */
30      private final LengthUnit lengthUnit;
31  
32      /** the unit of time for the energy unit, e.g., second. */
33      private final TimeUnit timeUnit;
34  
35      /** The SI unit for energy is Joule. */
36      public static final EnergyUnit SI;
37  
38      /** Joule. */
39      public static final EnergyUnit JOULE;
40  
41      /** foot-pound force. */
42      public static final EnergyUnit FOOT_POUND_FORCE;
43  
44      /** inch-pound force. */
45      public static final EnergyUnit INCH_POUND_FORCE;
46  
47      /** British thermal unit (ISO). */
48      public static final EnergyUnit BTU_ISO;
49  
50      /** British thermal unit (International Table). */
51      public static final EnergyUnit BTU_IT;
52  
53      /** calorie (International Table). */
54      public static final EnergyUnit CALORIE_IT;
55  
56      /** kilocalorie. */
57      public static final EnergyUnit KILOCALORIE;
58  
59      /** watt-hour. */
60      public static final EnergyUnit WATT_HOUR;
61  
62      /** kilowatt-hour. */
63      public static final EnergyUnit KILOWATT_HOUR;
64  
65      /** megawatt-hour. */
66      public static final EnergyUnit MEGAWATT_HOUR;
67  
68      /** gigawatt-hour. */
69      public static final EnergyUnit GIGAWATT_HOUR;
70  
71      /** terawatt-hour. */
72      public static final EnergyUnit TERAWATT_HOUR;
73  
74      /** milliwatt-hour. */
75      public static final EnergyUnit MILLIWATT_HOUR;
76  
77      /** microwatt-hour. */
78      public static final EnergyUnit MICROWATT_HOUR;
79  
80      /** electronvolt. */
81      public static final EnergyUnit ELECTRONVOLT;
82  
83      /** milli-electronvolt. */
84      public static final EnergyUnit MILLI_ELECTRONVOLT;
85  
86      /** kilo-electronvolt. */
87      public static final EnergyUnit KILO_ELECTRONVOLT;
88  
89      /** mega-electronvolt. */
90      public static final EnergyUnit MEGA_ELECTRONVOLT;
91  
92      /** giga-electronvolt. */
93      public static final EnergyUnit GIGA_ELECTRONVOLT;
94  
95      /** tera-electronvolt. */
96      public static final EnergyUnit TERA_ELECTRONVOLT;
97  
98      /** peta-electronvolt. */
99      public static final EnergyUnit PETA_ELECTRONVOLT;
100 
101     /** exa-electronvolt. */
102     public static final EnergyUnit EXA_ELECTRONVOLT;
103 
104     /** sthene-meter (mts). */
105     public static final EnergyUnit STHENE_METER;
106 
107     /** erg (cgs). */
108     public static final EnergyUnit ERG;
109 
110     static
111     {
112         SI =
113                 new EnergyUnit(MassUnit.KILOGRAM, LengthUnit.METER, TimeUnit.SECOND, "EnergyUnit.Joule",
114                         "EnergyUnit.J", SI_DERIVED);
115         JOULE = SI;
116         FOOT_POUND_FORCE =
117                 new EnergyUnit(LengthUnit.FOOT, ForceUnit.POUND_FORCE, "EnergyUnit.foot_pound-force",
118                         "EnergyUnit.ft.lbf", IMPERIAL);
119         INCH_POUND_FORCE =
120                 new EnergyUnit(LengthUnit.INCH, ForceUnit.POUND_FORCE, "EnergyUnit.inch_pound-force",
121                         "EnergyUnit.in.lbf", IMPERIAL);
122         BTU_ISO =
123                 new EnergyUnit("EnergyUnit.British_thermal_unit_(ISO)", "EnergyUnit.BTU(ISO)", IMPERIAL, JOULE,
124                         1.0545E3);
125         BTU_IT =
126                 new EnergyUnit("EnergyUnit.British_thermal_unit_(International_Table)", "EnergyUnit.BTU(IT)", IMPERIAL,
127                         JOULE, 1.05505585262E3);
128         CALORIE_IT =
129                 new EnergyUnit("EnergyUnit.calorie_(International_Table)", "EnergyUnit.cal(IT)", OTHER, JOULE, 4.1868);
130         KILOCALORIE = new EnergyUnit("EnergyUnit.kilocalorie", "EnergyUnit.kcal", OTHER, CALORIE_IT, 1000.0);
131         WATT_HOUR = new EnergyUnit("EnergyUnit.watt-hour", "EnergyUnit.Wh", SI_DERIVED, JOULE, 3600.0);
132         KILOWATT_HOUR = new EnergyUnit("EnergyUnit.kilowatt-hour", "EnergyUnit.kWh", SI_DERIVED, WATT_HOUR, 1000.0);
133         MEGAWATT_HOUR = new EnergyUnit("EnergyUnit.megawatt-hour", "EnergyUnit.MWh", SI_DERIVED, WATT_HOUR, 1.0E6);
134         GIGAWATT_HOUR = new EnergyUnit("EnergyUnit.gigawatt-hour", "EnergyUnit.GWh", SI_DERIVED, WATT_HOUR, 1.0E9);
135         TERAWATT_HOUR = new EnergyUnit("EnergyUnit.terawatt-hour", "EnergyUnit.TWh", SI_DERIVED, WATT_HOUR, 1.0E12);
136         MILLIWATT_HOUR = new EnergyUnit("EnergyUnit.milliwatt-hour", "EnergyUnit.mWh", SI_DERIVED, WATT_HOUR, 1.0E-3);
137         MICROWATT_HOUR = new EnergyUnit("EnergyUnit.microwatt-hour", "EnergyUnit.muWh", SI_DERIVED, WATT_HOUR, 1.0E-6);
138         ELECTRONVOLT =
139                 new EnergyUnit("EnergyUnit.electronvolt", "EnergyUnit.eV", SI_ACCEPTED, JOULE, 1.602176565314E-19);
140         MILLI_ELECTRONVOLT =
141                 new EnergyUnit("EnergyUnit.milli-electronvolt", "EnergyUnit.meV", SI_ACCEPTED, ELECTRONVOLT, 1.0E-3);
142         KILO_ELECTRONVOLT =
143                 new EnergyUnit("EnergyUnit.kilo-electronvolt", "EnergyUnit.keV", SI_ACCEPTED, ELECTRONVOLT, 1.0E3);
144         MEGA_ELECTRONVOLT =
145                 new EnergyUnit("EnergyUnit.mega-electronvolt", "EnergyUnit.MeV", SI_ACCEPTED, ELECTRONVOLT, 1.0E6);
146         GIGA_ELECTRONVOLT =
147                 new EnergyUnit("EnergyUnit.giga-electronvolt", "EnergyUnit.GeV", SI_ACCEPTED, ELECTRONVOLT, 1.0E9);
148         TERA_ELECTRONVOLT =
149                 new EnergyUnit("EnergyUnit.tera-electronvolt", "EnergyUnit.TeV", SI_ACCEPTED, ELECTRONVOLT, 1.0E12);
150         PETA_ELECTRONVOLT =
151                 new EnergyUnit("EnergyUnit.peta-electronvolt", "EnergyUnit.PeV", SI_ACCEPTED, ELECTRONVOLT, 1.0E15);
152         EXA_ELECTRONVOLT =
153                 new EnergyUnit("EnergyUnit.exa-electronvolt", "EnergyUnit.EeV", SI_ACCEPTED, ELECTRONVOLT, 1.0E18);
154         STHENE_METER = new EnergyUnit("EnergyUnit.sthene_meter", "EnergyUnit.sn.m", MTS, JOULE, 1000.0);
155         ERG = new EnergyUnit("EnergyUnit.erg_(full)", "EnergyUnit.erg", CGS, JOULE, 1.0E-7);
156     }
157 
158     /**
159      * @param massUnit the unit of mass for the energy unit, e.g., kilogram
160      * @param lengthUnit the unit of length for the energy unit, e.g., meter
161      * @param timeUnit the unit of time for the energy unit, e.g., second
162      * @param nameKey the key to the locale file for the long name of the unit
163      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
164      * @param unitSystem the unit system, e.g. SI or Imperial
165      */
166     public EnergyUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final TimeUnit timeUnit,
167             final String nameKey, final String abbreviationKey, final UnitSystem unitSystem)
168     {
169         super(nameKey, abbreviationKey, unitSystem, JOULE, massUnit.getConversionFactorToStandardUnit()
170                 * lengthUnit.getConversionFactorToStandardUnit() * lengthUnit.getConversionFactorToStandardUnit()
171                 / (timeUnit.getConversionFactorToStandardUnit() * timeUnit.getConversionFactorToStandardUnit()), true);
172         this.massUnit = massUnit;
173         this.lengthUnit = lengthUnit;
174         this.timeUnit = timeUnit;
175     }
176 
177     /**
178      * @param lengthUnit the unit of length for the energy unit, e.g., m
179      * @param forceUnit the unit of force for the energy unit, e.g., Newton
180      * @param nameKey the key to the locale file for the long name of the unit
181      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
182      * @param unitSystem the unit system, e.g. SI or Imperial
183      */
184     public EnergyUnit(final LengthUnit lengthUnit, final ForceUnit forceUnit, final String nameKey,
185             final String abbreviationKey, final UnitSystem unitSystem)
186     {
187         super(nameKey, abbreviationKey, unitSystem, JOULE, forceUnit.getConversionFactorToStandardUnit()
188                 * lengthUnit.getConversionFactorToStandardUnit(), true);
189         this.massUnit = forceUnit.getMassUnit();
190         this.lengthUnit = forceUnit.getLengthUnit();
191         this.timeUnit = forceUnit.getTimeUnit();
192     }
193 
194     /**
195      * @param nameKey the key to the locale file for the long name of the unit
196      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
197      * @param unitSystem the unit system, e.g. SI or Imperial
198      * @param referenceUnit the unit to convert to
199      * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given
200      *            reference unit
201      */
202     public EnergyUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
203             final EnergyUnit referenceUnit, final double conversionFactorToReferenceUnit)
204     {
205         super(nameKey, abbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit, true);
206         this.massUnit = referenceUnit.getMassUnit();
207         this.lengthUnit = referenceUnit.getLengthUnit();
208         this.timeUnit = referenceUnit.getTimeUnit();
209     }
210 
211     /**
212      * @return massUnit
213      */
214     public final MassUnit getMassUnit()
215     {
216         return this.massUnit;
217     }
218 
219     /**
220      * @return lengthUnit
221      */
222     public final LengthUnit getLengthUnit()
223     {
224         return this.lengthUnit;
225     }
226 
227     /**
228      * @return timeUnit
229      */
230     public final TimeUnit getTimeUnit()
231     {
232         return this.timeUnit;
233     }
234 
235     /** {@inheritDoc} */
236     @Override
237     public final EnergyUnit getStandardUnit()
238     {
239         return JOULE;
240     }
241 
242     /** {@inheritDoc} */
243     @Override
244     public final String getSICoefficientsString()
245     {
246         return "kgm2/s2";
247     }
248 
249 }