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.SI_DERIVED;
6   
7   import org.opentrafficsim.core.unit.unitsystem.UnitSystem;
8   
9   /**
10   * Standard acceleration units based on distance and time.
11   * <p>
12   * Copyright (c) 2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
14   * <p>
15   * @version May 15, 2014 <br>
16   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
17   */
18  public class AccelerationUnit extends Unit<AccelerationUnit>
19  {
20      /** */
21      private static final long serialVersionUID = 20140607L;
22  
23      /** the actual length unit, e.g. KILOMETER. */
24      private final LengthUnit lengthUnit;
25  
26      /** the actual time unit, e.g. HOUR. */
27      private final TimeUnit timeUnit;
28  
29      /** The SI unit for acceleration is m/s^2. */
30      public static final AccelerationUnit SI;
31  
32      /** m/s^2. */
33      public static final AccelerationUnit METER_PER_SECOND_2;
34  
35      /** km/h^2. */
36      public static final AccelerationUnit KM_PER_HOUR_2;
37  
38      /** ft/s^2. */
39      public static final AccelerationUnit FOOT_PER_SECOND_2;
40  
41      /** in/s^2. */
42      public static final AccelerationUnit INCH_PER_SECOND_2;
43  
44      /** mi/h^2. */
45      public static final AccelerationUnit MILE_PER_HOUR_2;
46  
47      /** mi/s^2. */
48      public static final AccelerationUnit MILE_PER_SECOND_2;
49  
50      /** kt/s. */
51      public static final AccelerationUnit KNOT_PER_SECOND;
52  
53      /** mi/h/s. */
54      public static final AccelerationUnit MILE_PER_HOUR_PER_SECOND;
55  
56      /** standard gravity. */
57      public static final AccelerationUnit STANDARD_GRAVITY;
58  
59      /** standard gravity. */
60      public static final AccelerationUnit GAL;
61  
62      static
63      {
64          SI =
65                  new AccelerationUnit(LengthUnit.METER, TimeUnit.SECOND, "AccelerationUnit.meter_per_second_squared",
66                          "AccelerationUnit.m/s^2", SI_DERIVED);
67          METER_PER_SECOND_2 = SI;
68          KM_PER_HOUR_2 =
69                  new AccelerationUnit(LengthUnit.KILOMETER, TimeUnit.HOUR, "AccelerationUnit.km_per_hour_squared",
70                          "AccelerationUnit.km/h^2", SI_DERIVED);
71          FOOT_PER_SECOND_2 =
72                  new AccelerationUnit(LengthUnit.FOOT, TimeUnit.SECOND, "AccelerationUnit.foot_per_second_squared",
73                          "AccelerationUnit.ft/s^2", IMPERIAL);
74          INCH_PER_SECOND_2 =
75                  new AccelerationUnit(LengthUnit.INCH, TimeUnit.SECOND, "AccelerationUnit.inch_per_second_squared",
76                          "AccelerationUnit.in/s^2", IMPERIAL);
77          MILE_PER_HOUR_2 =
78                  new AccelerationUnit(LengthUnit.MILE, TimeUnit.HOUR, "AccelerationUnit.mile_per_hour_squared",
79                          "AccelerationUnit.mi/h^2", IMPERIAL);
80          MILE_PER_SECOND_2 =
81                  new AccelerationUnit(LengthUnit.MILE, TimeUnit.SECOND, "AccelerationUnit.mile_per_second_squared",
82                          "AccelerationUnit.mi/s^2", IMPERIAL);
83          KNOT_PER_SECOND =
84                  new AccelerationUnit(SpeedUnit.KNOT, TimeUnit.SECOND, "AccelerationUnit.knot_per_second",
85                          "AccelerationUnit.kt/s", IMPERIAL);
86          MILE_PER_HOUR_PER_SECOND =
87                  new AccelerationUnit(SpeedUnit.MILE_PER_HOUR, TimeUnit.SECOND,
88                          "AccelerationUnit.mile_per_hour_per_second", "AccelerationUnit.mi/h/s", IMPERIAL);
89          STANDARD_GRAVITY =
90                  new AccelerationUnit("AccelerationUnit.standard_gravity", "AccelerationUnit.g", SI_DERIVED,
91                          METER_PER_SECOND_2, 9.80665);
92          GAL =
93                  new AccelerationUnit(LengthUnit.CENTIMETER, TimeUnit.SECOND, "AccelerationUnit.gal",
94                          "AccelerationUnit.Gal", CGS);
95      }
96  
97      /**
98       * Define acceleration units based on length and time. You can define units like meter/second^2 here.
99       * @param lengthUnit the unit of length for the acceleration unit, e.g., meter
100      * @param timeUnit the unit of time for the acceleration unit, e.g., second
101      * @param nameKey the key to the locale file for the long name of the unit
102      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
103      * @param unitSystem the unit system, e.g. SI or Imperial
104      */
105     public AccelerationUnit(final LengthUnit lengthUnit, final TimeUnit timeUnit, final String nameKey,
106             final String abbreviationKey, final UnitSystem unitSystem)
107     {
108         super(nameKey, abbreviationKey, unitSystem, METER_PER_SECOND_2, lengthUnit.getConversionFactorToStandardUnit()
109                 / (timeUnit.getConversionFactorToStandardUnit() * timeUnit.getConversionFactorToStandardUnit()), true);
110         this.lengthUnit = lengthUnit;
111         this.timeUnit = timeUnit;
112     }
113 
114     /**
115      * Define acceleration units based on speed and time. You can define units like (mile/hour)/second here.
116      * @param speedUnit the unit of speed for the acceleration unit, e.g., knot
117      * @param timeUnit the unit of time for the acceleration unit, e.g., second
118      * @param nameKey the key to the locale file for the long name of the unit
119      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
120      * @param unitSystem the unit system, e.g. SI or Imperial
121      */
122     public AccelerationUnit(final SpeedUnit speedUnit, final TimeUnit timeUnit, final String nameKey,
123             final String abbreviationKey, final UnitSystem unitSystem)
124     {
125         super(nameKey, abbreviationKey, unitSystem, METER_PER_SECOND_2, speedUnit.getConversionFactorToStandardUnit()
126                 / timeUnit.getConversionFactorToStandardUnit(), true);
127         this.lengthUnit = speedUnit.getLengthUnit();
128         this.timeUnit = timeUnit;
129     }
130 
131     /**
132      * Create a new AccelerationUnit.
133      * @param nameKey the key to the locale file for the long name of the unit
134      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
135      * @param unitSystem the unit system, e.g. SI or Imperial
136      * @param referenceUnit the unit to convert to
137      * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given
138      *            reference unit
139      */
140     public AccelerationUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
141             final AccelerationUnit referenceUnit, final double conversionFactorToReferenceUnit)
142     {
143         super(nameKey, abbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit, true);
144         this.lengthUnit = referenceUnit.getLengthUnit();
145         this.timeUnit = referenceUnit.getTimeUnit();
146     }
147 
148     /**
149      * @return lengthUnit
150      */
151     public final LengthUnit getLengthUnit()
152     {
153         return this.lengthUnit;
154     }
155 
156     /**
157      * @return timeUnit
158      */
159     public final TimeUnit getTimeUnit()
160     {
161         return this.timeUnit;
162     }
163 
164     /** {@inheritDoc} */
165     @Override
166     public final AccelerationUnit getStandardUnit()
167     {
168         return METER_PER_SECOND_2;
169     }
170 
171     /** {@inheritDoc} */
172     @Override
173     public final String getSICoefficientsString()
174     {
175         return "m/s2";
176     }
177 
178 }