View Javadoc
1   package org.djunits.unit;
2   
3   import static org.djunits.unit.unitsystem.UnitSystem.IMPERIAL;
4   import static org.djunits.unit.unitsystem.UnitSystem.SI_ACCEPTED;
5   import static org.djunits.unit.unitsystem.UnitSystem.SI_DERIVED;
6   import static org.djunits.unit.unitsystem.UnitSystem.US_CUSTOMARY;
7   
8   import org.djunits.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) 2015-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
14   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
15   * <p>
16   * $LastChangedDate: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, by $Author: averbraeck $,
17   * initial version May 15, 2014 <br>
18   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
19   */
20  public class FlowVolumeUnit extends LinearUnit<FlowVolumeUnit>
21  {
22      /** */
23      private static final long serialVersionUID = 20140607L;
24  
25      /** the unit of length for the flow unit, e.g., meter. */
26      private final LengthUnit lengthUnit;
27  
28      /** the unit of time for the flow unit, e.g., second. */
29      private final DurationUnit durationUnit;
30  
31      /** The SI unit for volume flow rate is m^3/s. */
32      public static final FlowVolumeUnit SI;
33  
34      /** m^3/s. */
35      public static final FlowVolumeUnit CUBIC_METER_PER_SECOND;
36  
37      /** m^3/min. */
38      public static final FlowVolumeUnit CUBIC_METER_PER_MINUTE;
39  
40      /** m^3/hour. */
41      public static final FlowVolumeUnit CUBIC_METER_PER_HOUR;
42  
43      /** m^3/day. */
44      public static final FlowVolumeUnit CUBIC_METER_PER_DAY;
45  
46      /** L/s. */
47      public static final FlowVolumeUnit LITER_PER_SECOND;
48  
49      /** L/min. */
50      public static final FlowVolumeUnit LITER_PER_MINUTE;
51  
52      /** L/hour. */
53      public static final FlowVolumeUnit LITER_PER_HOUR;
54  
55      /** L/day. */
56      public static final FlowVolumeUnit LITER_PER_DAY;
57  
58      /** ft^3/s. */
59      public static final FlowVolumeUnit CUBIC_FEET_PER_SECOND;
60  
61      /** ft^3/min. */
62      public static final FlowVolumeUnit CUBIC_FEET_PER_MINUTE;
63  
64      /** in^3/s. */
65      public static final FlowVolumeUnit CUBIC_INCH_PER_SECOND;
66  
67      /** in^3/min. */
68      public static final FlowVolumeUnit CUBIC_INCH_PER_MINUTE;
69  
70      /** gallon/s (US). */
71      public static final FlowVolumeUnit GALLON_PER_SECOND;
72  
73      /** gallon/min (US). */
74      public static final FlowVolumeUnit GALLON_PER_MINUTE;
75  
76      /** gallon/hour (US). */
77      public static final FlowVolumeUnit GALLON_PER_HOUR;
78  
79      /** gallon/day (US). */
80      public static final FlowVolumeUnit GALLON_PER_DAY;
81  
82      static
83      {
84          SI = new FlowVolumeUnit(LengthUnit.METER, DurationUnit.SECOND, "FlowVolumeUnit.cubic_meter_per_second",
85                  "FlowVolumeUnit.m^3/s", SI_DERIVED, true);
86          CUBIC_METER_PER_SECOND = SI;
87          CUBIC_METER_PER_MINUTE = new FlowVolumeUnit(LengthUnit.METER, DurationUnit.MINUTE,
88                  "FlowVolumeUnit.cubic_meter_per_minute", "FlowVolumeUnit.m^3/min", SI_ACCEPTED, true);
89          CUBIC_METER_PER_HOUR = new FlowVolumeUnit(LengthUnit.METER, DurationUnit.HOUR, "FlowVolumeUnit.cubic_meter_per_hour",
90                  "FlowVolumeUnit.m^3/h", SI_ACCEPTED, true);
91          CUBIC_METER_PER_DAY = new FlowVolumeUnit(LengthUnit.METER, DurationUnit.DAY, "FlowVolumeUnit.cubic_meter_per_day",
92                  "FlowVolumeUnit.m^3/d", SI_ACCEPTED, true);
93          LITER_PER_SECOND = new FlowVolumeUnit(VolumeUnit.LITER, DurationUnit.SECOND, "FlowVolumeUnit.liter_per_second",
94                  "FlowVolumeUnit.L/s", SI_ACCEPTED, true);
95          LITER_PER_MINUTE = new FlowVolumeUnit(VolumeUnit.LITER, DurationUnit.MINUTE, "FlowVolumeUnit.liter_per_minute",
96                  "FlowVolumeUnit.L/min", SI_ACCEPTED, true);
97          LITER_PER_HOUR = new FlowVolumeUnit(VolumeUnit.LITER, DurationUnit.HOUR, "FlowVolumeUnit.liter_per_hour",
98                  "FlowVolumeUnit.L/h", SI_ACCEPTED, true);
99          LITER_PER_DAY = new FlowVolumeUnit(VolumeUnit.LITER, DurationUnit.DAY, "FlowVolumeUnit.liter_per_day",
100                 "FlowVolumeUnit.L/d", SI_ACCEPTED, true);
101         CUBIC_FEET_PER_SECOND = new FlowVolumeUnit(LengthUnit.FOOT, DurationUnit.SECOND, "FlowVolumeUnit.cubic_feet_per_second",
102                 "FlowVolumeUnit.ft^3/s", IMPERIAL, true);
103         CUBIC_FEET_PER_MINUTE = new FlowVolumeUnit(LengthUnit.FOOT, DurationUnit.MINUTE, "FlowVolumeUnit.cubic_feet_per_minute",
104                 "FlowVolumeUnit.ft^3/min", IMPERIAL, true);
105         CUBIC_INCH_PER_SECOND = new FlowVolumeUnit(LengthUnit.INCH, DurationUnit.SECOND, "FlowVolumeUnit.cubic_inch_per_second",
106                 "FlowVolumeUnit.in^3/s", IMPERIAL, true);
107         CUBIC_INCH_PER_MINUTE = new FlowVolumeUnit(LengthUnit.INCH, DurationUnit.MINUTE, "FlowVolumeUnit.cubic_inch_per_minute",
108                 "FlowVolumeUnit.in^3/min", IMPERIAL, true);
109         GALLON_PER_SECOND = new FlowVolumeUnit(VolumeUnit.GALLON_US_FLUID, DurationUnit.SECOND,
110                 "FlowVolumeUnit.gallon_(US)_per_second", "FlowVolumeUnit.gal/s", US_CUSTOMARY, true);
111         GALLON_PER_MINUTE = new FlowVolumeUnit(VolumeUnit.GALLON_US_FLUID, DurationUnit.MINUTE,
112                 "FlowVolumeUnit.gallon_(US)_per_minute", "FlowVolumeUnit.gal/min", US_CUSTOMARY, true);
113         GALLON_PER_HOUR = new FlowVolumeUnit(VolumeUnit.GALLON_US_FLUID, DurationUnit.HOUR,
114                 "FlowVolumeUnit.gallon_(US)_per_hour", "FlowVolumeUnit.gal/h", US_CUSTOMARY, true);
115         GALLON_PER_DAY = new FlowVolumeUnit(VolumeUnit.GALLON_US_FLUID, DurationUnit.DAY, "FlowVolumeUnit.gallon_(US)_per_day",
116                 "FlowVolumeUnit.gal/d", US_CUSTOMARY, true);
117     }
118 
119     /**
120      * Create a flow-volumeunit based on length (cubed) per time unit.
121      * @param lengthUnit the unit of length for the flow unit, e.g., meter
122      * @param durationUnit the unit of time for the flow unit, e.g., second
123      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
124      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
125      *            otherwise the abbreviation itself
126      * @param unitSystem the unit system, e.g. SI or Imperial
127      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
128      */
129     private FlowVolumeUnit(final LengthUnit lengthUnit, final DurationUnit durationUnit, final String nameOrNameKey,
130             final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
131     {
132         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, CUBIC_METER_PER_SECOND,
133                 Math.pow(lengthUnit.getScaleFactor(), 3.0) / durationUnit.getScaleFactor(), standardUnit);
134         this.lengthUnit = lengthUnit;
135         this.durationUnit = durationUnit;
136     }
137 
138     /**
139      * Create a user-defined flow-volumeunit based on length (cubed) per time unit.
140      * @param lengthUnit the unit of length for the flow unit, e.g., meter
141      * @param durationUnit the unit of time for the flow unit, e.g., second
142      * @param name the long name of the unit
143      * @param abbreviation the abbreviation of the unit
144      * @param unitSystem the unit system, e.g. SI or Imperial
145      */
146     public FlowVolumeUnit(final LengthUnit lengthUnit, final DurationUnit durationUnit, final String name,
147             final String abbreviation, final UnitSystem unitSystem)
148     {
149         this(lengthUnit, durationUnit, name, abbreviation, unitSystem, false);
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 durationUnit the unit of time for the flow unit, e.g., second
156      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
157      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
158      *            otherwise the abbreviation itself
159      * @param unitSystem the unit system, e.g. SI or Imperial
160      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
161      */
162     private FlowVolumeUnit(final VolumeUnit volumeUnit, final DurationUnit durationUnit, final String nameOrNameKey,
163             final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
164     {
165         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, CUBIC_METER_PER_SECOND,
166                 volumeUnit.getScaleFactor() / durationUnit.getScaleFactor(), standardUnit);
167         this.lengthUnit = volumeUnit.getLengthUnit();
168         this.durationUnit = durationUnit;
169     }
170 
171     /**
172      * Create a user-defined flow-volumeunit based as a volume unit per time unit.
173      * @param volumeUnit the unit of volume for the flow unit, e.g., cubic meter
174      * @param durationUnit the unit of time for the flow unit, e.g., second
175      * @param name the long name of the unit
176      * @param abbreviation the abbreviation of the unit
177      * @param unitSystem the unit system, e.g. SI or Imperial
178      */
179     public FlowVolumeUnit(final VolumeUnit volumeUnit, final DurationUnit durationUnit, final String name,
180             final String abbreviation, final UnitSystem unitSystem)
181     {
182         this(volumeUnit, durationUnit, name, abbreviation, unitSystem, false);
183     }
184 
185     /**
186      * Create a flow-volumeunit based on another flow-volumeunit.
187      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
188      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
189      *            otherwise the abbreviation itself
190      * @param unitSystem the unit system, e.g. SI or Imperial
191      * @param referenceUnit the unit to convert to
192      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
193      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
194      */
195     private FlowVolumeUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
196             final FlowVolumeUnit referenceUnit, final double scaleFactorToReferenceUnit, final boolean standardUnit)
197     {
198         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
199                 standardUnit);
200         this.lengthUnit = referenceUnit.getLengthUnit();
201         this.durationUnit = referenceUnit.getDurationUnit();
202     }
203 
204     /**
205      * Build a user-defined unit with a conversion factor to another unit.
206      * @param name the long name of the unit
207      * @param abbreviation the abbreviation of the unit
208      * @param unitSystem the unit system, e.g. SI or Imperial
209      * @param referenceUnit the unit to convert to
210      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
211      */
212     public FlowVolumeUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
213             final FlowVolumeUnit referenceUnit, final double scaleFactorToReferenceUnit)
214     {
215         this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
216     }
217 
218     /**
219      * @return lengthUnit
220      */
221     public final LengthUnit getLengthUnit()
222     {
223         return this.lengthUnit;
224     }
225 
226     /**
227      * @return durationUnit
228      */
229     public final DurationUnit getDurationUnit()
230     {
231         return this.durationUnit;
232     }
233 
234     /** {@inheritDoc} */
235     @Override
236     public final FlowVolumeUnit getStandardUnit()
237     {
238         return CUBIC_METER_PER_SECOND;
239     }
240 
241     /** {@inheritDoc} */
242     @Override
243     public final String getSICoefficientsString()
244     {
245         return "m3/s";
246     }
247 
248 }