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-01-18 00:35:01 +0100 (Fri, 18 Jan 2019) $, @version $Revision: 324 $, 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 MassUnit; the unit of mass for the pressure unit, e.g., kilogram
124      * @param lengthUnit LengthUnit; the unit of length for the pressure unit, e.g., meter
125      * @param durationUnit DurationUnit; the unit of time for the pressure unit, e.g., second
126      * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
127      *            name itself
128      * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
129      *            unit, otherwise the abbreviation itself
130      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
131      * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
132      *            unit
133      */
134     private PressureUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit,
135             final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
136             final boolean standardUnit)
137     {
138         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, PASCAL,
139                 massUnit.getScaleFactor()
140                         / (lengthUnit.getScaleFactor() * durationUnit.getScaleFactor() * durationUnit.getScaleFactor()),
141                 standardUnit);
142         this.massUnit = massUnit;
143         this.lengthUnit = lengthUnit;
144         this.durationUnit = durationUnit;
145     }
146 
147     /**
148      * Construct a user-defined pressure unit from mass, length and time units, e.g., a Pascal = kg/m.s^2.
149      * @param massUnit MassUnit; the unit of mass for the pressure unit, e.g., kilogram
150      * @param lengthUnit LengthUnit; the unit of length for the pressure unit, e.g., meter
151      * @param durationUnit DurationUnit; the unit of time for the pressure unit, e.g., second
152      * @param name String; the long name of the unit
153      * @param abbreviation String; the abbreviation of the unit
154      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
155      */
156     public PressureUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit,
157             final String name, final String abbreviation, final UnitSystem unitSystem)
158     {
159         this(massUnit, lengthUnit, durationUnit, name, abbreviation, unitSystem, false);
160     }
161 
162     /**
163      * Construct a pressure unit from force and area units, e.g. a Pascal = N/m^2.
164      * @param forceUnit ForceUnit; the unit of force for the pressure unit, e.g., Newton
165      * @param areaUnit AreaUnit; the unit of area for the pressure unit, e.g., m^2
166      * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
167      *            name itself
168      * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
169      *            unit, otherwise the abbreviation itself
170      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
171      * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
172      *            unit
173      */
174     private PressureUnit(final ForceUnit forceUnit, final AreaUnit areaUnit, final String nameOrNameKey,
175             final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
176     {
177         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, PASCAL,
178                 forceUnit.getScaleFactor() / areaUnit.getScaleFactor(), standardUnit);
179         this.massUnit = forceUnit.getMassUnit();
180         this.lengthUnit = areaUnit.getLengthUnit();
181         this.durationUnit = forceUnit.getDurationUnit();
182     }
183 
184     /**
185      * Construct a user-defined pressure unit from force and area units, e.g. a Pascal = N/m^2.
186      * @param forceUnit ForceUnit; the unit of force for the pressure unit, e.g., Newton
187      * @param areaUnit AreaUnit; the unit of area for the pressure unit, e.g., m^2
188      * @param name String; the long name of the unit
189      * @param abbreviation String; the abbreviation of the unit
190      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
191      */
192     public PressureUnit(final ForceUnit forceUnit, final AreaUnit areaUnit, final String name, final String abbreviation,
193             final UnitSystem unitSystem)
194     {
195         this(forceUnit, areaUnit, name, abbreviation, unitSystem, false);
196     }
197 
198     /**
199      * Build a PressureUnit with a conversion factor to another PressureUnit.
200      * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
201      *            name itself
202      * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
203      *            unit, otherwise the abbreviation itself
204      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
205      * @param referenceUnit PressureUnit; the unit to convert to
206      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
207      *            unit
208      * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
209      *            unit
210      */
211     private PressureUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
212             final PressureUnit referenceUnit, final double scaleFactorToReferenceUnit, final boolean standardUnit)
213     {
214         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
215                 standardUnit);
216         this.massUnit = referenceUnit.getMassUnit();
217         this.lengthUnit = referenceUnit.getLengthUnit();
218         this.durationUnit = referenceUnit.getDurationUnit();
219     }
220 
221     /**
222      * Build a user-defined PressureUnit with a conversion factor to another PressureUnit.
223      * @param name String; the long name of the unit
224      * @param abbreviation String; the abbreviation of the unit
225      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
226      * @param referenceUnit PressureUnit; the unit to convert to
227      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
228      *            unit
229      */
230     public PressureUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
231             final PressureUnit referenceUnit, final double scaleFactorToReferenceUnit)
232     {
233         this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
234     }
235 
236     /**
237      * @return massUnit
238      */
239     public final MassUnit getMassUnit()
240     {
241         return this.massUnit;
242     }
243 
244     /**
245      * @return lengthUnit
246      */
247     public final LengthUnit getLengthUnit()
248     {
249         return this.lengthUnit;
250     }
251 
252     /**
253      * @return durationUnit
254      */
255     public final DurationUnit getDurationUnit()
256     {
257         return this.durationUnit;
258     }
259 
260     /** {@inheritDoc} */
261     @Override
262     public final PressureUnit getStandardUnit()
263     {
264         return PASCAL;
265     }
266 
267     /** {@inheritDoc} */
268     @Override
269     public final String getSICoefficientsString()
270     {
271         return "kg/ms2";
272     }
273 
274 }