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