View Javadoc
1   package org.opentrafficsim.core.unit;
2   
3   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.IMPERIAL;
4   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_ACCEPTED;
5   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_DERIVED;
6   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.US_CUSTOMARY;
7   
8   import org.opentrafficsim.core.unit.unitsystem.UnitSystem;
9   
10  /**
11   * The volume flow rate is the volume of fluid which passes through a given surface per unit of time (wikipedia).
12   * <p>
13   * Copyright (c) 2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
14   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
15   * <p>
16   * @version May 15, 2014 <br>
17   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
18   */
19  public class FlowVolumeUnit extends Unit<FlowVolumeUnit>
20  {
21      /** */
22      private static final long serialVersionUID = 20140607L;
23  
24      /** the unit of length for the flow unit, e.g., meter. */
25      private final LengthUnit lengthUnit;
26  
27      /** the unit of time for the flow unit, e.g., second. */
28      private final TimeUnit timeUnit;
29  
30      /** The SI unit for volume flow rate is m^3/s. */
31      public static final FlowVolumeUnit SI;
32  
33      /** m^3/s. */
34      public static final FlowVolumeUnit CUBIC_METER_PER_SECOND;
35  
36      /** m^3/min. */
37      public static final FlowVolumeUnit CUBIC_METER_PER_MINUTE;
38  
39      /** m^3/hour. */
40      public static final FlowVolumeUnit CUBIC_METER_PER_HOUR;
41  
42      /** m^3/day. */
43      public static final FlowVolumeUnit CUBIC_METER_PER_DAY;
44  
45      /** L/s. */
46      public static final FlowVolumeUnit LITER_PER_SECOND;
47  
48      /** L/min. */
49      public static final FlowVolumeUnit LITER_PER_MINUTE;
50  
51      /** L/hour. */
52      public static final FlowVolumeUnit LITER_PER_HOUR;
53  
54      /** L/day. */
55      public static final FlowVolumeUnit LITER_PER_DAY;
56  
57      /** ft^3/s. */
58      public static final FlowVolumeUnit CUBIC_FEET_PER_SECOND;
59  
60      /** ft^3/min. */
61      public static final FlowVolumeUnit CUBIC_FEET_PER_MINUTE;
62  
63      /** in^3/s. */
64      public static final FlowVolumeUnit CUBIC_INCH_PER_SECOND;
65  
66      /** in^3/min. */
67      public static final FlowVolumeUnit CUBIC_INCH_PER_MINUTE;
68  
69      /** gallon/s (US). */
70      public static final FlowVolumeUnit GALLON_PER_SECOND;
71  
72      /** gallon/min (US). */
73      public static final FlowVolumeUnit GALLON_PER_MINUTE;
74  
75      /** gallon/hour (US). */
76      public static final FlowVolumeUnit GALLON_PER_HOUR;
77  
78      /** gallon/day (US). */
79      public static final FlowVolumeUnit GALLON_PER_DAY;
80  
81      static
82      {
83          SI =
84                  new FlowVolumeUnit(LengthUnit.METER, TimeUnit.SECOND, "FlowVolumeUnit.cubic_meter_per_second",
85                          "FlowVolumeUnit.m^3/s", SI_DERIVED);
86          CUBIC_METER_PER_SECOND = SI;
87          CUBIC_METER_PER_MINUTE =
88                  new FlowVolumeUnit(LengthUnit.METER, TimeUnit.MINUTE, "FlowVolumeUnit.cubic_meter_per_minute",
89                          "FlowVolumeUnit.m^3/min", SI_ACCEPTED);
90          CUBIC_METER_PER_HOUR =
91                  new FlowVolumeUnit(LengthUnit.METER, TimeUnit.HOUR, "FlowVolumeUnit.cubic_meter_per_hour",
92                          "FlowVolumeUnit.m^3/h", SI_ACCEPTED);
93          CUBIC_METER_PER_DAY =
94                  new FlowVolumeUnit(LengthUnit.METER, TimeUnit.DAY, "FlowVolumeUnit.cubic_meter_per_day",
95                          "FlowVolumeUnit.m^3/d", SI_ACCEPTED);
96          LITER_PER_SECOND =
97                  new FlowVolumeUnit(VolumeUnit.LITER, TimeUnit.SECOND, "FlowVolumeUnit.liter_per_second",
98                          "FlowVolumeUnit.L/s", SI_ACCEPTED);
99          LITER_PER_MINUTE =
100                 new FlowVolumeUnit(VolumeUnit.LITER, TimeUnit.MINUTE, "FlowVolumeUnit.liter_per_minute",
101                         "FlowVolumeUnit.L/min", SI_ACCEPTED);
102         LITER_PER_HOUR =
103                 new FlowVolumeUnit(VolumeUnit.LITER, TimeUnit.HOUR, "FlowVolumeUnit.liter_per_hour",
104                         "FlowVolumeUnit.L/h", SI_ACCEPTED);
105         LITER_PER_DAY =
106                 new FlowVolumeUnit(VolumeUnit.LITER, TimeUnit.DAY, "FlowVolumeUnit.liter_per_day",
107                         "FlowVolumeUnit.L/d", SI_ACCEPTED);
108         CUBIC_FEET_PER_SECOND =
109                 new FlowVolumeUnit(LengthUnit.FOOT, TimeUnit.SECOND, "FlowVolumeUnit.cubic_feet_per_second",
110                         "FlowVolumeUnit.ft^3/s", IMPERIAL);
111         CUBIC_FEET_PER_MINUTE =
112                 new FlowVolumeUnit(LengthUnit.FOOT, TimeUnit.MINUTE, "FlowVolumeUnit.cubic_feet_per_minute",
113                         "FlowVolumeUnit.ft^3/min", IMPERIAL);
114         CUBIC_INCH_PER_SECOND =
115                 new FlowVolumeUnit(LengthUnit.INCH, TimeUnit.SECOND, "FlowVolumeUnit.cubic_inch_per_second",
116                         "FlowVolumeUnit.in^3/s", IMPERIAL);
117         CUBIC_INCH_PER_MINUTE =
118                 new FlowVolumeUnit(LengthUnit.INCH, TimeUnit.MINUTE, "FlowVolumeUnit.cubic_inch_per_minute",
119                         "FlowVolumeUnit.in^3/min", IMPERIAL);
120         GALLON_PER_SECOND =
121                 new FlowVolumeUnit(VolumeUnit.GALLON_US_FLUID, TimeUnit.SECOND,
122                         "FlowVolumeUnit.gallon_(US)_per_second", "FlowVolumeUnit.gal/s", US_CUSTOMARY);
123         GALLON_PER_MINUTE =
124                 new FlowVolumeUnit(VolumeUnit.GALLON_US_FLUID, TimeUnit.MINUTE,
125                         "FlowVolumeUnit.gallon_(US)_per_minute", "FlowVolumeUnit.gal/min", US_CUSTOMARY);
126         GALLON_PER_HOUR =
127                 new FlowVolumeUnit(VolumeUnit.GALLON_US_FLUID, TimeUnit.HOUR, "FlowVolumeUnit.gallon_(US)_per_hour",
128                         "FlowVolumeUnit.gal/h", US_CUSTOMARY);
129         GALLON_PER_DAY =
130                 new FlowVolumeUnit(VolumeUnit.GALLON_US_FLUID, TimeUnit.DAY, "FlowVolumeUnit.gallon_(US)_per_day",
131                         "FlowVolumeUnit.gal/d", US_CUSTOMARY);
132     }
133 
134     /**
135      * Create a flow-volumeunit based on length (cubed) per time unit.
136      * @param lengthUnit the unit of length for the flow unit, e.g., meter
137      * @param timeUnit the unit of time for the flow unit, e.g., second
138      * @param nameKey the key to the locale file for the long name of the unit
139      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
140      * @param unitSystem the unit system, e.g. SI or Imperial
141      */
142     public FlowVolumeUnit(final LengthUnit lengthUnit, final TimeUnit timeUnit, final String nameKey,
143             final String abbreviationKey, final UnitSystem unitSystem)
144     {
145         super(nameKey, abbreviationKey, unitSystem, CUBIC_METER_PER_SECOND, Math.pow(
146                 lengthUnit.getConversionFactorToStandardUnit(), 3.0)
147                 / timeUnit.getConversionFactorToStandardUnit(), true);
148         this.lengthUnit = lengthUnit;
149         this.timeUnit = timeUnit;
150     }
151 
152     /**
153      * Create a flow-volumeunit based as a volume unit per time unit.
154      * @param volumeUnit the unit of volume for the flow unit, e.g., cubic meter
155      * @param timeUnit the unit of time for the flow unit, e.g., second
156      * @param nameKey the key to the locale file for the long name of the unit
157      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
158      * @param unitSystem the unit system, e.g. SI or Imperial
159      */
160     public FlowVolumeUnit(final VolumeUnit volumeUnit, final TimeUnit timeUnit, final String nameKey,
161             final String abbreviationKey, final UnitSystem unitSystem)
162     {
163         super(nameKey, abbreviationKey, unitSystem, CUBIC_METER_PER_SECOND, volumeUnit
164                 .getConversionFactorToStandardUnit() / timeUnit.getConversionFactorToStandardUnit(), true);
165         this.lengthUnit = volumeUnit.getLengthUnit();
166         this.timeUnit = timeUnit;
167     }
168 
169     /**
170      * Create a flow-volumeunit based on another flow-volumeunit.
171      * @param nameKey the key to the locale file for the long name of the unit
172      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
173      * @param unitSystem the unit system, e.g. SI or Imperial
174      * @param referenceUnit the unit to convert to
175      * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given
176      *            reference unit
177      */
178     public FlowVolumeUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
179             final FlowVolumeUnit referenceUnit, final double conversionFactorToReferenceUnit)
180     {
181         super(nameKey, abbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit, true);
182         this.lengthUnit = referenceUnit.getLengthUnit();
183         this.timeUnit = referenceUnit.getTimeUnit();
184     }
185 
186     /**
187      * @return lengthUnit
188      */
189     public final LengthUnit getLengthUnit()
190     {
191         return this.lengthUnit;
192     }
193 
194     /**
195      * @return timeUnit
196      */
197     public final TimeUnit getTimeUnit()
198     {
199         return this.timeUnit;
200     }
201 
202     /** {@inheritDoc} */
203     @Override
204     public final FlowVolumeUnit getStandardUnit()
205     {
206         return CUBIC_METER_PER_SECOND;
207     }
208 
209     /** {@inheritDoc} */
210     @Override
211     public final String getSICoefficientsString()
212     {
213         return "m3/s";
214     }
215 
216 }