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-2019 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: 2019-03-02 19:06:46 +0100 (Sat, 02 Mar 2019) $, @version $Revision: 342 $, by $Author: averbraeck $,
18   * initial version May 15, 2014 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   */
21  public class PressureUnit extends LinearUnit<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 DurationUnit durationUnit;
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 = new PressureUnit(MassUnit.KILOGRAM, LengthUnit.METER, DurationUnit.SECOND, "PressureUnit.Pa", SI_DERIVED);
92          PASCAL = SI;
93          HECTOPASCAL = new PressureUnit("PressureUnit.hPa", SI_DERIVED, PASCAL, 100.0);
94          KILOPASCAL = new PressureUnit("PressureUnit.kPa", SI_DERIVED, PASCAL, 1000.0);
95          ATMOSPHERE_STANDARD = new PressureUnit("PressureUnit.atm", OTHER, PASCAL, 101325.0);
96          TORR = new PressureUnit("PressureUnit.Torr", OTHER, ATMOSPHERE_STANDARD, 1.0 / 760.0);
97          ATMOSPHERE_TECHNICAL = new PressureUnit(ForceUnit.KILOGRAM_FORCE, AreaUnit.SQUARE_CENTIMETER, "PressureUnit.at", OTHER);
98          BARYE = new PressureUnit(ForceUnit.DYNE, AreaUnit.SQUARE_CENTIMETER, "PressureUnit.Ba", CGS);
99          BAR = new PressureUnit("PressureUnit.bar", OTHER, PASCAL, 1E5);
100         MILLIBAR = new PressureUnit("PressureUnit.mbar", OTHER, PressureUnit.BAR, 0.001);
101         CENTIMETER_MERCURY = new PressureUnit("PressureUnit.cmHg", OTHER, PASCAL, 1333.224);
102         MILLIMETER_MERCURY = new PressureUnit("PressureUnit.mmHg", OTHER, PASCAL, 133.3224);
103         FOOT_MERCURY = new PressureUnit("PressureUnit.ftHg", IMPERIAL, PASCAL, 40.63666E3);
104         INCH_MERCURY = new PressureUnit("PressureUnit.inHg", IMPERIAL, PASCAL, 3.386389E3);
105         KGF_PER_SQUARE_MM =
106                 new PressureUnit(ForceUnit.KILOGRAM_FORCE, AreaUnit.SQUARE_MILLIMETER, "PressureUnit.kgf/mm^2", OTHER);
107         POUND_PER_SQUARE_FOOT =
108                 new PressureUnit(ForceUnit.POUND_FORCE, AreaUnit.SQUARE_FOOT, "PressureUnit.lbf/ft^2", IMPERIAL);
109         POUND_PER_SQUARE_INCH =
110                 new PressureUnit(ForceUnit.POUND_FORCE, AreaUnit.SQUARE_INCH, "PressureUnit.lbf/in^2", IMPERIAL);
111         PIEZE = new PressureUnit(MassUnit.TONNE, LengthUnit.METER, DurationUnit.SECOND, "PressureUnit.pz", MTS);
112     }
113 
114     /**
115      * Construct a pressure unit from mass, length and time units, e.g., a Pascal = kg/m.s^2.
116      * @param massUnit MassUnit; the unit of mass for the pressure unit, e.g., kilogram
117      * @param lengthUnit LengthUnit; the unit of length for the pressure unit, e.g., meter
118      * @param durationUnit DurationUnit; the unit of time for the pressure unit, e.g., second
119      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
120      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
121      */
122     private PressureUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit,
123             final String abbreviationKey, final UnitSystem unitSystem)
124     {
125         super(abbreviationKey, unitSystem, PASCAL, massUnit.getScaleFactor()
126                 / (lengthUnit.getScaleFactor() * durationUnit.getScaleFactor() * durationUnit.getScaleFactor()));
127         this.massUnit = massUnit;
128         this.lengthUnit = lengthUnit;
129         this.durationUnit = durationUnit;
130     }
131 
132     /**
133      * Construct a user-defined pressure unit from mass, length and time units, e.g., a Pascal = kg/m.s^2.
134      * @param massUnit MassUnit; the unit of mass for the pressure unit, e.g., kilogram
135      * @param lengthUnit LengthUnit; the unit of length for the pressure unit, e.g., meter
136      * @param durationUnit DurationUnit; the unit of time for the pressure unit, e.g., second
137      * @param name String; the long name of the unit
138      * @param abbreviation String; the abbreviation of the unit
139      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
140      */
141     public PressureUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit,
142             final String name, final String abbreviation, final UnitSystem unitSystem)
143     {
144         super(name, abbreviation, unitSystem, PASCAL, massUnit.getScaleFactor()
145                 / (lengthUnit.getScaleFactor() * durationUnit.getScaleFactor() * durationUnit.getScaleFactor()));
146         this.massUnit = massUnit;
147         this.lengthUnit = lengthUnit;
148         this.durationUnit = durationUnit;
149     }
150 
151     /**
152      * Construct a pressure unit from force and area units, e.g. a Pascal = N/m^2.
153      * @param forceUnit ForceUnit; the unit of force for the pressure unit, e.g., Newton
154      * @param areaUnit AreaUnit; the unit of area for the pressure unit, e.g., m^2
155      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
156      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
157      */
158     private PressureUnit(final ForceUnit forceUnit, final AreaUnit areaUnit, final String abbreviationKey,
159             final UnitSystem unitSystem)
160     {
161         super(abbreviationKey, unitSystem, PASCAL, forceUnit.getScaleFactor() / areaUnit.getScaleFactor());
162         this.massUnit = forceUnit.getMassUnit();
163         this.lengthUnit = areaUnit.getLengthUnit();
164         this.durationUnit = forceUnit.getDurationUnit();
165     }
166 
167     /**
168      * Construct a user-defined pressure unit from force and area units, e.g. a Pascal = N/m^2.
169      * @param forceUnit ForceUnit; the unit of force for the pressure unit, e.g., Newton
170      * @param areaUnit AreaUnit; the unit of area for the pressure unit, e.g., m^2
171      * @param name String; the long name of the unit
172      * @param abbreviation String; the abbreviation of the unit
173      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
174      */
175     public PressureUnit(final ForceUnit forceUnit, final AreaUnit areaUnit, final String name, final String abbreviation,
176             final UnitSystem unitSystem)
177     {
178         super(name, abbreviation, unitSystem, PASCAL, forceUnit.getScaleFactor() / areaUnit.getScaleFactor());
179         this.massUnit = forceUnit.getMassUnit();
180         this.lengthUnit = areaUnit.getLengthUnit();
181         this.durationUnit = forceUnit.getDurationUnit();
182     }
183 
184     /**
185      * Build a PressureUnit with a conversion factor to another PressureUnit.
186      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
187      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
188      * @param referenceUnit PressureUnit; the unit to convert to
189      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
190      *            unit
191      */
192     private PressureUnit(final String abbreviationKey, final UnitSystem unitSystem, final PressureUnit referenceUnit,
193             final double scaleFactorToReferenceUnit)
194     {
195         super(abbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
196         this.massUnit = referenceUnit.getMassUnit();
197         this.lengthUnit = referenceUnit.getLengthUnit();
198         this.durationUnit = referenceUnit.getDurationUnit();
199     }
200 
201     /**
202      * Build a user-defined PressureUnit with a conversion factor to another PressureUnit.
203      * @param name String; the long name of the unit
204      * @param abbreviation String; the abbreviation of the unit
205      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
206      * @param referenceUnit PressureUnit; the unit to convert to
207      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
208      *            unit
209      */
210     public PressureUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
211             final PressureUnit referenceUnit, final double scaleFactorToReferenceUnit)
212     {
213         super(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
214         this.massUnit = referenceUnit.getMassUnit();
215         this.lengthUnit = referenceUnit.getLengthUnit();
216         this.durationUnit = referenceUnit.getDurationUnit();
217     }
218 
219     /**
220      * @return massUnit
221      */
222     public final MassUnit getMassUnit()
223     {
224         return this.massUnit;
225     }
226 
227     /**
228      * @return lengthUnit
229      */
230     public final LengthUnit getLengthUnit()
231     {
232         return this.lengthUnit;
233     }
234 
235     /**
236      * @return durationUnit
237      */
238     public final DurationUnit getDurationUnit()
239     {
240         return this.durationUnit;
241     }
242 
243     /** {@inheritDoc} */
244     @Override
245     public final PressureUnit getStandardUnit()
246     {
247         return PASCAL;
248     }
249 
250     /** {@inheritDoc} */
251     @Override
252     public final String getSICoefficientsString()
253     {
254         return "kg/ms2";
255     }
256 
257 }