View Javadoc
1   package org.djunits.unit;
2   
3   import static org.djunits.unit.unitsystem.UnitSystem.CGS;
4   import static org.djunits.unit.unitsystem.UnitSystem.IMPERIAL;
5   import static org.djunits.unit.unitsystem.UnitSystem.MTS;
6   import static org.djunits.unit.unitsystem.UnitSystem.OTHER;
7   import static org.djunits.unit.unitsystem.UnitSystem.SI_DERIVED;
8   
9   import org.djunits.unit.unitsystem.UnitSystem;
10  
11  /**
12   * The units of pressure.
13   * <p>
14   * Copyright (c) 2015 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
16   * <p>
17   * $LastChangedDate: 2015-10-04 20:48:33 +0200 (Sun, 04 Oct 2015) $, @version $Revision: 87 $, by $Author: averbraeck $, initial
18   * version May 15, 2014 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   */
21  public class PressureUnit extends Unit<PressureUnit>
22  {
23      /** */
24      private static final long serialVersionUID = 20140607L;
25  
26      /** the unit of mass for the pressure unit, e.g., kilogram. */
27      private final MassUnit massUnit;
28  
29      /** the unit of length for the pressure unit, e.g., meter. */
30      private final LengthUnit lengthUnit;
31  
32      /** the unit of time for the pressure unit, e.g., second. */
33      private final TimeUnit timeUnit;
34  
35      /** The SI unit for pressure is Pascal. */
36      public static final PressureUnit SI;
37  
38      /** Pascal. */
39      public static final PressureUnit PASCAL;
40  
41      /** hectoPascal. */
42      public static final PressureUnit HECTOPASCAL;
43  
44      /** kiloPascal. */
45      public static final PressureUnit KILOPASCAL;
46  
47      /** standard atmosphere. */
48      public static final PressureUnit ATMOSPHERE_STANDARD;
49  
50      /** torr. */
51      public static final PressureUnit TORR;
52  
53      /** technical atmosphere. */
54      public static final PressureUnit ATMOSPHERE_TECHNICAL;
55  
56      /** barye. */
57      public static final PressureUnit BARYE;
58  
59      /** bar. */
60      public static final PressureUnit BAR;
61  
62      /** millibar. */
63      public static final PressureUnit MILLIBAR;
64  
65      /** cm Hg. */
66      public static final PressureUnit CENTIMETER_MERCURY;
67  
68      /** mm Hg. */
69      public static final PressureUnit MILLIMETER_MERCURY;
70  
71      /** foot Hg. */
72      public static final PressureUnit FOOT_MERCURY;
73  
74      /** inch Hg. */
75      public static final PressureUnit INCH_MERCURY;
76  
77      /** kilogram-force per square millimeter. */
78      public static final PressureUnit KGF_PER_SQUARE_MM;
79  
80      /** pound per square foot. */
81      public static final PressureUnit POUND_PER_SQUARE_FOOT;
82  
83      /** pound per square inch. */
84      public static final PressureUnit POUND_PER_SQUARE_INCH;
85  
86      /** pieze. */
87      public static final PressureUnit PIEZE;
88  
89      static
90      {
91          SI =
92              new PressureUnit(MassUnit.KILOGRAM, LengthUnit.METER, TimeUnit.SECOND, "PressureUnit.pascal",
93                  "PressureUnit.Pa", SI_DERIVED, true);
94          PASCAL = SI;
95          HECTOPASCAL = new PressureUnit("PressureUnit.hectopascal", "PressureUnit.hPa", SI_DERIVED, PASCAL, 100.0, true);
96          KILOPASCAL = new PressureUnit("PressureUnit.kilopascal", "PressureUnit.kPa", SI_DERIVED, PASCAL, 1000.0, true);
97          ATMOSPHERE_STANDARD =
98              new PressureUnit("PressureUnit.atmosphere_(standard)", "PressureUnit.atm", OTHER, PASCAL, 101325.0, true);
99          TORR =
100             new PressureUnit("PressureUnit.torr", "PressureUnit.Torr", OTHER, ATMOSPHERE_STANDARD, 1.0 / 760.0, true);
101         ATMOSPHERE_TECHNICAL =
102             new PressureUnit(ForceUnit.KILOGRAM_FORCE, AreaUnit.SQUARE_CENTIMETER,
103                 "PressureUnit.atmosphere_(technical)", "PressureUnit.at", OTHER, true);
104         BARYE =
105             new PressureUnit(ForceUnit.DYNE, AreaUnit.SQUARE_CENTIMETER, "PressureUnit.barye", "PressureUnit.Ba", CGS,
106                 true);
107         BAR = new PressureUnit("PressureUnit.bar_(full)", "PressureUnit.bar", OTHER, PASCAL, 1E5, true);
108         MILLIBAR = new PressureUnit("PressureUnit.millibar", "PressureUnit.mbar", OTHER, PressureUnit.BAR, 0.001, true);
109         CENTIMETER_MERCURY =
110             new PressureUnit("PressureUnit.centimeter_mercury", "PressureUnit.cmHg", OTHER, PASCAL, 1333.224, true);
111         MILLIMETER_MERCURY =
112             new PressureUnit("PressureUnit.millimeter_mercury", "PressureUnit.mmHg", OTHER, PASCAL, 133.3224, true);
113         FOOT_MERCURY =
114             new PressureUnit("PressureUnit.foot_mercury", "PressureUnit.ftHg", IMPERIAL, PASCAL, 40.63666E3, true);
115         INCH_MERCURY =
116             new PressureUnit("PressureUnit.inch_mercury", "PressureUnit.inHg", IMPERIAL, PASCAL, 3.386389E3, true);
117         KGF_PER_SQUARE_MM =
118             new PressureUnit(ForceUnit.KILOGRAM_FORCE, AreaUnit.SQUARE_MILLIMETER,
119                 "PressureUnit.kilogram-force_per_square_millimeter", "PressureUnit.kgf/mm^2", OTHER, true);
120         POUND_PER_SQUARE_FOOT =
121             new PressureUnit(ForceUnit.POUND_FORCE, AreaUnit.SQUARE_FOOT, "PressureUnit.pound_per_square_foot",
122                 "PressureUnit.lbf/ft^2", IMPERIAL, true);
123         POUND_PER_SQUARE_INCH =
124             new PressureUnit(ForceUnit.POUND_FORCE, AreaUnit.SQUARE_INCH, "PressureUnit.pound_per_square_inch",
125                 "PressureUnit.lbf/in^2", IMPERIAL, true);
126         PIEZE =
127             new PressureUnit(MassUnit.TONNE, LengthUnit.METER, TimeUnit.SECOND, "PressureUnit.pieze",
128                 "PressureUnit.pz", MTS, true);
129     }
130 
131     /**
132      * Construct a pressure unit from mass, length and time units, e.g., a Pascal = kg/m.s^2.
133      * @param massUnit the unit of mass for the pressure unit, e.g., kilogram
134      * @param lengthUnit the unit of length for the pressure unit, e.g., meter
135      * @param timeUnit the unit of time for the pressure unit, e.g., second
136      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
137      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
138      *            otherwise the abbreviation itself
139      * @param unitSystem the unit system, e.g. SI or Imperial
140      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
141      */
142     private PressureUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final TimeUnit timeUnit,
143         final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
144         final boolean standardUnit)
145     {
146         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, PASCAL, massUnit
147             .getConversionFactorToStandardUnit()
148             / (lengthUnit.getConversionFactorToStandardUnit() * timeUnit.getConversionFactorToStandardUnit() * timeUnit
149                 .getConversionFactorToStandardUnit()), standardUnit);
150         this.massUnit = massUnit;
151         this.lengthUnit = lengthUnit;
152         this.timeUnit = timeUnit;
153     }
154 
155     /**
156      * Construct a user-defined pressure unit from mass, length and time units, e.g., a Pascal = kg/m.s^2.
157      * @param massUnit the unit of mass for the pressure unit, e.g., kilogram
158      * @param lengthUnit the unit of length for the pressure unit, e.g., meter
159      * @param timeUnit the unit of time for the pressure unit, e.g., second
160      * @param name the long name of the unit
161      * @param abbreviation the abbreviation of the unit
162      * @param unitSystem the unit system, e.g. SI or Imperial
163      */
164     public PressureUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final TimeUnit timeUnit,
165         final String name, final String abbreviation, final UnitSystem unitSystem)
166     {
167         this(massUnit, lengthUnit, timeUnit, name, abbreviation, unitSystem, false);
168     }
169 
170     /**
171      * Construct a pressure unit from force and area units, e.g. a Pascal = N/m^2.
172      * @param forceUnit the unit of force for the pressure unit, e.g., Newton
173      * @param areaUnit the unit of area for the pressure unit, e.g., m^2
174      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
175      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
176      *            otherwise the abbreviation itself
177      * @param unitSystem the unit system, e.g. SI or Imperial
178      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
179      */
180     private PressureUnit(final ForceUnit forceUnit, final AreaUnit areaUnit, final String nameOrNameKey,
181         final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
182     {
183         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, PASCAL, forceUnit
184             .getConversionFactorToStandardUnit()
185             / areaUnit.getConversionFactorToStandardUnit(), standardUnit);
186         this.massUnit = forceUnit.getMassUnit();
187         this.lengthUnit = forceUnit.getLengthUnit();
188         this.timeUnit = forceUnit.getTimeUnit();
189     }
190 
191     /**
192      * Construct a user-defined pressure unit from force and area units, e.g. a Pascal = N/m^2.
193      * @param forceUnit the unit of force for the pressure unit, e.g., Newton
194      * @param areaUnit the unit of area for the pressure unit, e.g., m^2
195      * @param name the long name of the unit
196      * @param abbreviation the abbreviation of the unit
197      * @param unitSystem the unit system, e.g. SI or Imperial
198      */
199     public PressureUnit(final ForceUnit forceUnit, final AreaUnit areaUnit, final String name,
200         final String abbreviation, final UnitSystem unitSystem)
201     {
202         this(forceUnit, areaUnit, name, abbreviation, unitSystem, false);
203     }
204 
205     /**
206      * Build a PressureUnit with a conversion factor to another PressureUnit.
207      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
208      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
209      *            otherwise the abbreviation itself
210      * @param unitSystem the unit system, e.g. SI or Imperial
211      * @param referenceUnit the unit to convert to
212      * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
213      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
214      */
215     private PressureUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey,
216         final UnitSystem unitSystem, final PressureUnit referenceUnit, final double conversionFactorToReferenceUnit,
217         final boolean standardUnit)
218     {
219         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit,
220             standardUnit);
221         this.massUnit = referenceUnit.getMassUnit();
222         this.lengthUnit = referenceUnit.getLengthUnit();
223         this.timeUnit = referenceUnit.getTimeUnit();
224     }
225 
226     /**
227      * Build a user-defined PressureUnit with a conversion factor to another PressureUnit.
228      * @param name the long name of the unit
229      * @param abbreviation the abbreviation of the unit
230      * @param unitSystem the unit system, e.g. SI or Imperial
231      * @param referenceUnit the unit to convert to
232      * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
233      */
234     public PressureUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
235         final PressureUnit referenceUnit, final double conversionFactorToReferenceUnit)
236     {
237         this(name, abbreviation, unitSystem, referenceUnit, conversionFactorToReferenceUnit, false);
238     }
239 
240     /**
241      * @return massUnit
242      */
243     public final MassUnit getMassUnit()
244     {
245         return this.massUnit;
246     }
247 
248     /**
249      * @return lengthUnit
250      */
251     public final LengthUnit getLengthUnit()
252     {
253         return this.lengthUnit;
254     }
255 
256     /**
257      * @return timeUnit
258      */
259     public final TimeUnit getTimeUnit()
260     {
261         return this.timeUnit;
262     }
263 
264     /** {@inheritDoc} */
265     @Override
266     public final PressureUnit getStandardUnit()
267     {
268         return PASCAL;
269     }
270 
271     /** {@inheritDoc} */
272     @Override
273     public final String getSICoefficientsString()
274     {
275         return "kg/ms2";
276     }
277 
278 }