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-2019 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: 2019-03-02 19:06:46 +0100 (Sat, 02 Mar 2019) $, @version $Revision: 342 $, 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.m^3/s", SI_DERIVED);
85          CUBIC_METER_PER_SECOND = SI;
86          CUBIC_METER_PER_MINUTE =
87                  new FlowVolumeUnit(LengthUnit.METER, DurationUnit.MINUTE, "FlowVolumeUnit.m^3/min", SI_ACCEPTED);
88          CUBIC_METER_PER_HOUR = new FlowVolumeUnit(LengthUnit.METER, DurationUnit.HOUR, "FlowVolumeUnit.m^3/h", SI_ACCEPTED);
89          CUBIC_METER_PER_DAY = new FlowVolumeUnit(LengthUnit.METER, DurationUnit.DAY, "FlowVolumeUnit.m^3/d", SI_ACCEPTED);
90          LITER_PER_SECOND = new FlowVolumeUnit(VolumeUnit.LITER, DurationUnit.SECOND, "FlowVolumeUnit.L/s", SI_ACCEPTED);
91          LITER_PER_MINUTE = new FlowVolumeUnit(VolumeUnit.LITER, DurationUnit.MINUTE, "FlowVolumeUnit.L/min", SI_ACCEPTED);
92          LITER_PER_HOUR = new FlowVolumeUnit(VolumeUnit.LITER, DurationUnit.HOUR, "FlowVolumeUnit.L/h", SI_ACCEPTED);
93          LITER_PER_DAY = new FlowVolumeUnit(VolumeUnit.LITER, DurationUnit.DAY, "FlowVolumeUnit.L/d", SI_ACCEPTED);
94          CUBIC_FEET_PER_SECOND = new FlowVolumeUnit(LengthUnit.FOOT, DurationUnit.SECOND, "FlowVolumeUnit.ft^3/s", IMPERIAL);
95          CUBIC_FEET_PER_MINUTE = new FlowVolumeUnit(LengthUnit.FOOT, DurationUnit.MINUTE, "FlowVolumeUnit.ft^3/min", IMPERIAL);
96          CUBIC_INCH_PER_SECOND = new FlowVolumeUnit(LengthUnit.INCH, DurationUnit.SECOND, "FlowVolumeUnit.in^3/s", IMPERIAL);
97          CUBIC_INCH_PER_MINUTE = new FlowVolumeUnit(LengthUnit.INCH, DurationUnit.MINUTE, "FlowVolumeUnit.in^3/min", IMPERIAL);
98          GALLON_PER_SECOND =
99                  new FlowVolumeUnit(VolumeUnit.GALLON_US_FLUID, DurationUnit.SECOND, "FlowVolumeUnit.gal/s", US_CUSTOMARY);
100         GALLON_PER_MINUTE =
101                 new FlowVolumeUnit(VolumeUnit.GALLON_US_FLUID, DurationUnit.MINUTE, "FlowVolumeUnit.gal/min", US_CUSTOMARY);
102         GALLON_PER_HOUR =
103                 new FlowVolumeUnit(VolumeUnit.GALLON_US_FLUID, DurationUnit.HOUR, "FlowVolumeUnit.gal/h", US_CUSTOMARY);
104         GALLON_PER_DAY = new FlowVolumeUnit(VolumeUnit.GALLON_US_FLUID, DurationUnit.DAY, "FlowVolumeUnit.gal/d", US_CUSTOMARY);
105     }
106 
107     /**
108      * Create a flow-volumeunit based on length (cubed) per time unit.
109      * @param lengthUnit LengthUnit; the unit of length for the flow unit, e.g., meter
110      * @param durationUnit DurationUnit; the unit of time for the flow unit, e.g., second
111      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
112      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
113      */
114     private FlowVolumeUnit(final LengthUnit lengthUnit, final DurationUnit durationUnit, final String abbreviationKey,
115             final UnitSystem unitSystem)
116     {
117         super(abbreviationKey, unitSystem, CUBIC_METER_PER_SECOND,
118                 Math.pow(lengthUnit.getScaleFactor(), 3.0) / durationUnit.getScaleFactor());
119         this.lengthUnit = lengthUnit;
120         this.durationUnit = durationUnit;
121     }
122 
123     /**
124      * Create a user-defined flow-volumeunit based on length (cubed) per time unit.
125      * @param lengthUnit LengthUnit; the unit of length for the flow unit, e.g., meter
126      * @param durationUnit DurationUnit; the unit of time for the flow unit, e.g., second
127      * @param name String; the long name of the unit
128      * @param abbreviation String; the abbreviation of the unit
129      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
130      */
131     public FlowVolumeUnit(final LengthUnit lengthUnit, final DurationUnit durationUnit, final String name,
132             final String abbreviation, final UnitSystem unitSystem)
133     {
134         super(name, abbreviation, unitSystem, CUBIC_METER_PER_SECOND,
135                 Math.pow(lengthUnit.getScaleFactor(), 3.0) / durationUnit.getScaleFactor());
136         this.lengthUnit = lengthUnit;
137         this.durationUnit = durationUnit;
138     }
139 
140     /**
141      * Create a flow-volumeunit based as a volume unit per time unit.
142      * @param volumeUnit VolumeUnit; the unit of volume for the flow unit, e.g., cubic meter
143      * @param durationUnit DurationUnit; the unit of time for the flow unit, e.g., second
144      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
145      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
146      */
147     private FlowVolumeUnit(final VolumeUnit volumeUnit, final DurationUnit durationUnit, final String abbreviationKey,
148             final UnitSystem unitSystem)
149     {
150         super(abbreviationKey, unitSystem, CUBIC_METER_PER_SECOND, volumeUnit.getScaleFactor() / durationUnit.getScaleFactor());
151         this.lengthUnit = volumeUnit.getLengthUnit();
152         this.durationUnit = durationUnit;
153     }
154 
155     /**
156      * Create a user-defined flow-volumeunit based as a volume unit per time unit.
157      * @param volumeUnit VolumeUnit; the unit of volume for the flow unit, e.g., cubic meter
158      * @param durationUnit DurationUnit; the unit of time for the flow unit, e.g., second
159      * @param name String; the long name of the unit
160      * @param abbreviation String; the abbreviation of the unit
161      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
162      */
163     public FlowVolumeUnit(final VolumeUnit volumeUnit, final DurationUnit durationUnit, final String name,
164             final String abbreviation, final UnitSystem unitSystem)
165     {
166         super(name, abbreviation, unitSystem, CUBIC_METER_PER_SECOND,
167                 volumeUnit.getScaleFactor() / durationUnit.getScaleFactor());
168         this.lengthUnit = volumeUnit.getLengthUnit();
169         this.durationUnit = durationUnit;
170     }
171 
172     /**
173      * Create a flow-volumeunit based on another flow-volumeunit.
174      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
175      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
176      * @param referenceUnit FlowVolumeUnit; the unit to convert to
177      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
178      *            unit
179      */
180     private FlowVolumeUnit(final String abbreviationKey, final UnitSystem unitSystem, final FlowVolumeUnit referenceUnit,
181             final double scaleFactorToReferenceUnit)
182     {
183         super(abbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
184         this.lengthUnit = referenceUnit.getLengthUnit();
185         this.durationUnit = referenceUnit.getDurationUnit();
186     }
187 
188     /**
189      * Build a user-defined unit with a conversion factor to another unit.
190      * @param name String; the long name of the unit
191      * @param abbreviation String; the abbreviation of the unit
192      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
193      * @param referenceUnit FlowVolumeUnit; the unit to convert to
194      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
195      *            unit
196      */
197     public FlowVolumeUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
198             final FlowVolumeUnit referenceUnit, final double scaleFactorToReferenceUnit)
199     {
200         super(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
201         this.lengthUnit = referenceUnit.getLengthUnit();
202         this.durationUnit = referenceUnit.getDurationUnit();
203     }
204 
205     /**
206      * @return lengthUnit
207      */
208     public final LengthUnit getLengthUnit()
209     {
210         return this.lengthUnit;
211     }
212 
213     /**
214      * @return durationUnit
215      */
216     public final DurationUnit getDurationUnit()
217     {
218         return this.durationUnit;
219     }
220 
221     /** {@inheritDoc} */
222     @Override
223     public final FlowVolumeUnit getStandardUnit()
224     {
225         return CUBIC_METER_PER_SECOND;
226     }
227 
228     /** {@inheritDoc} */
229     @Override
230     public final String getSICoefficientsString()
231     {
232         return "m3/s";
233     }
234 
235 }