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_DERIVED;
8   
9   import org.opentrafficsim.core.unit.unitsystem.UnitSystem;
10  
11  /**
12   * The units of power.
13   * <p>
14   * Copyright (c) 2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
16   * <p>
17   * @version May 15, 2014 <br>
18   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19   */
20  public class PowerUnit extends Unit<PowerUnit>
21  {
22      /** */
23      private static final long serialVersionUID = 20140607L;
24  
25      /** the unit of mass for the power unit, e.g., kilogram. */
26      private final MassUnit massUnit;
27  
28      /** the unit of length for the power unit, e.g., length. */
29      private final LengthUnit lengthUnit;
30  
31      /** the unit of time for the power unit, e.g., second. */
32      private final TimeUnit timeUnit;
33  
34      /** The SI unit for power is watt. */
35      public static final PowerUnit SI;
36  
37      /** watt. */
38      public static final PowerUnit WATT;
39  
40      /** kilowatt. */
41      public static final PowerUnit KILOWATT;
42  
43      /** megawatt. */
44      public static final PowerUnit MEGAWATT;
45  
46      /** gigawatt. */
47      public static final PowerUnit GIGAWATT;
48  
49      /** foot-pound-force per hour. */
50      public static final PowerUnit FOOT_POUND_FORCE_PER_HOUR;
51  
52      /** foot-pound-force per minute. */
53      public static final PowerUnit FOOT_POUND_FORCE_PER_MINUTE;
54  
55      /** foot-pound-force per second. */
56      public static final PowerUnit FOOT_POUND_FORCE_PER_SECOND;
57  
58      /** horsepower (metric). */
59      public static final PowerUnit HORSEPOWER_METRIC;
60  
61      /** sthene-meter per second. */
62      public static final PowerUnit STHENE_METER_PER_SECOND;
63  
64      /** erg per second. */
65      public static final PowerUnit ERG_PER_SECOND;
66  
67      static
68      {
69          SI =
70                  new PowerUnit(MassUnit.KILOGRAM, LengthUnit.METER, TimeUnit.SECOND, "PowerUnit.watt", "PowerUnit.W",
71                          SI_DERIVED);
72          WATT = SI;
73          KILOWATT = new PowerUnit("PowerUnit.kilowatt", "PowerUnit.kW", SI_DERIVED, WATT, 1000.0);
74          MEGAWATT = new PowerUnit("PowerUnit.megawatt", "PowerUnit.MW", SI_DERIVED, WATT, 1.0E6);
75          GIGAWATT = new PowerUnit("PowerUnit.gigawatt", "PowerUnit.GW", SI_DERIVED, WATT, 1.0E9);
76          FOOT_POUND_FORCE_PER_HOUR =
77                  new PowerUnit(LengthUnit.FOOT, ForceUnit.POUND_FORCE, TimeUnit.HOUR,
78                          "PowerUnit.foot_pound-force_per_hour", "PowerUnit.ft.lbf/h", IMPERIAL);
79          FOOT_POUND_FORCE_PER_MINUTE =
80                  new PowerUnit(LengthUnit.FOOT, ForceUnit.POUND_FORCE, TimeUnit.MINUTE,
81                          "PowerUnit.foot_pound-force_per_minute", "PowerUnit.ft.lbf/min", IMPERIAL);
82          FOOT_POUND_FORCE_PER_SECOND =
83                  new PowerUnit(LengthUnit.FOOT, ForceUnit.POUND_FORCE, TimeUnit.SECOND,
84                          "PowerUnit.foot_pound-force_per_second", "PowerUnit.ft.lbf/s", IMPERIAL);
85          HORSEPOWER_METRIC = new PowerUnit("PowerUnit.horsepower_(metric)", "PowerUnit.hp", OTHER, WATT, 735.49875);
86          STHENE_METER_PER_SECOND =
87                  new PowerUnit(LengthUnit.METER, ForceUnit.STHENE, TimeUnit.SECOND, "PowerUnit.sthene-meter_per_second",
88                          "PowerUnit.sn.m/s", MTS);
89          ERG_PER_SECOND =
90                  new PowerUnit(LengthUnit.CENTIMETER, ForceUnit.DYNE, TimeUnit.SECOND, "PowerUnit.erg_per_second",
91                          "PowerUnit.erg/s", CGS);
92      }
93  
94      /**
95       * @param massUnit the unit of mass for the power unit, e.g., kilogram
96       * @param lengthUnit the unit of length for the power unit, e.g., meter
97       * @param timeUnit the unit of time for the power unit, e.g., second
98       * @param nameKey the key to the locale file for the long name of the unit
99       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
100      * @param unitSystem the unit system, e.g. SI or Imperial
101      */
102     public PowerUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final TimeUnit timeUnit,
103             final String nameKey, final String abbreviationKey, final UnitSystem unitSystem)
104     {
105         super(nameKey, abbreviationKey, unitSystem, WATT, massUnit.getConversionFactorToStandardUnit()
106                 * lengthUnit.getConversionFactorToStandardUnit() * lengthUnit.getConversionFactorToStandardUnit()
107                 / Math.pow(timeUnit.getConversionFactorToStandardUnit(), 3.0), true);
108         this.massUnit = massUnit;
109         this.lengthUnit = lengthUnit;
110         this.timeUnit = timeUnit;
111     }
112 
113     /**
114      * @param lengthUnit the unit of length for the power unit, e.g., meter
115      * @param forceUnit the unit of force for the power unit, e.g., Newton
116      * @param timeUnit the unit of time for the power unit, e.g., second
117      * @param nameKey the key to the locale file for the long name of the unit
118      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
119      * @param unitSystem the unit system, e.g. SI or Imperial
120      */
121     public PowerUnit(final LengthUnit lengthUnit, final ForceUnit forceUnit, final TimeUnit timeUnit,
122             final String nameKey, final String abbreviationKey, final UnitSystem unitSystem)
123     {
124         super(nameKey, abbreviationKey, unitSystem, WATT, lengthUnit.getConversionFactorToStandardUnit()
125                 * forceUnit.getConversionFactorToStandardUnit() / timeUnit.getConversionFactorToStandardUnit(), true);
126         this.massUnit = forceUnit.getMassUnit();
127         this.lengthUnit = forceUnit.getLengthUnit();
128         this.timeUnit = forceUnit.getTimeUnit();
129     }
130 
131     /**
132      * @param nameKey the key to the locale file for the long name of the unit
133      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
134      * @param unitSystem the unit system, e.g. SI or Imperial
135      * @param referenceUnit the unit to convert to
136      * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given
137      *            reference unit
138      */
139     public PowerUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
140             final PowerUnit referenceUnit, final double conversionFactorToReferenceUnit)
141     {
142         super(nameKey, abbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit, true);
143         this.massUnit = referenceUnit.getMassUnit();
144         this.lengthUnit = referenceUnit.getLengthUnit();
145         this.timeUnit = referenceUnit.getTimeUnit();
146     }
147 
148     /**
149      * @return massUnit
150      */
151     public final MassUnit getMassUnit()
152     {
153         return this.massUnit;
154     }
155 
156     /**
157      * @return lengthUnit
158      */
159     public final LengthUnit getLengthUnit()
160     {
161         return this.lengthUnit;
162     }
163 
164     /**
165      * @return timeUnit
166      */
167     public final TimeUnit getTimeUnit()
168     {
169         return this.timeUnit;
170     }
171 
172     /** {@inheritDoc} */
173     @Override
174     public final PowerUnit getStandardUnit()
175     {
176         return WATT;
177     }
178 
179     /** {@inheritDoc} */
180     @Override
181     public final String getSICoefficientsString()
182     {
183         return "kgm2/s3";
184     }
185 
186 }