1 package org.djunits.quantity;
2
3 import org.djunits.quantity.def.Quantity;
4 import org.djunits.unit.AbstractUnit;
5 import org.djunits.unit.UnitRuntimeException;
6 import org.djunits.unit.Unitless;
7 import org.djunits.unit.Units;
8 import org.djunits.unit.scale.LinearScale;
9 import org.djunits.unit.scale.Scale;
10 import org.djunits.unit.si.SIUnit;
11 import org.djunits.unit.system.UnitSystem;
12
13
14
15
16
17
18
19
20
21 public class Pressure extends Quantity<Pressure>
22 {
23
24 public static final Pressure ZERO = Pressure.ofSi(0.0);
25
26
27 public static final Pressure ONE = Pressure.ofSi(1.0);
28
29
30 @SuppressWarnings("checkstyle:constantname")
31 public static final Pressure NaN = Pressure.ofSi(Double.NaN);
32
33
34 public static final Pressure POSITIVE_INFINITY = Pressure.ofSi(Double.POSITIVE_INFINITY);
35
36
37 public static final Pressure NEGATIVE_INFINITY = Pressure.ofSi(Double.NEGATIVE_INFINITY);
38
39
40 public static final Pressure POS_MAXVALUE = Pressure.ofSi(Double.MAX_VALUE);
41
42
43 public static final Pressure NEG_MAXVALUE = Pressure.ofSi(-Double.MAX_VALUE);
44
45
46 private static final long serialVersionUID = 600L;
47
48
49
50
51
52
53 public Pressure(final double valueInUnit, final Pressure.Unit unit)
54 {
55 super(valueInUnit, unit);
56 }
57
58
59
60
61
62
63 public Pressure(final double valueInUnit, final String abbreviation)
64 {
65 this(valueInUnit, Units.resolve(Pressure.Unit.class, abbreviation));
66 }
67
68
69
70
71
72 public Pressure(final Pressure value)
73 {
74 super(value.si(), Pressure.Unit.SI);
75 setDisplayUnit(value.getDisplayUnit());
76 }
77
78
79
80
81
82
83 public static Pressure ofSi(final double si)
84 {
85 return new Pressure(si, Pressure.Unit.SI);
86 }
87
88 @Override
89 public Pressure instantiateSi(final double si)
90 {
91 return ofSi(si);
92 }
93
94 @Override
95 public SIUnit siUnit()
96 {
97 return Pressure.Unit.SI_UNIT;
98 }
99
100
101
102
103
104
105
106
107
108
109 public static Pressure valueOf(final String text)
110 {
111 return Quantity.valueOf(text, ZERO);
112 }
113
114
115
116
117
118
119
120
121
122 public static Pressure of(final double valueInUnit, final String unitString)
123 {
124 return Quantity.of(valueInUnit, unitString, ZERO);
125 }
126
127 @Override
128 public Pressure.Unit getDisplayUnit()
129 {
130 return (Pressure.Unit) super.getDisplayUnit();
131 }
132
133
134
135
136
137
138 public final Dimensionless divide(final Pressure v)
139 {
140 return new Dimensionless(this.si() / v.si(), Unitless.BASE);
141 }
142
143
144
145
146
147
148 public final Force multiply(final Area v)
149 {
150 return new Force(this.si() * v.si(), Force.Unit.SI);
151 }
152
153
154
155
156
157
158 public final Energy multiply(final Volume v)
159 {
160 return new Energy(this.si() * v.si(), Energy.Unit.SI);
161 }
162
163
164
165
166
167
168
169
170
171
172
173
174
175 @SuppressWarnings("checkstyle:constantname")
176 public static class Unit extends AbstractUnit<Pressure.Unit, Pressure>
177 {
178
179 public static final SIUnit SI_UNIT = SIUnit.of("kg/ms2");
180
181
182 public static final Pressure.Unit Pa = new Pressure.Unit("Pa", "pascal", 1.0, UnitSystem.SI_DERIVED);
183
184
185 public static final Pressure.Unit SI = Pa.generateSiPrefixes(false, false);
186
187
188 public static final Pressure.Unit hPa = Units.resolve(Pressure.Unit.class, "hPa");
189
190
191 public static final Pressure.Unit kPa = Units.resolve(Pressure.Unit.class, "kPa");
192
193
194 public static final Pressure.Unit atm = Pa.deriveUnit("atm", "atmosphere (standard)", 101325.0, UnitSystem.OTHER);
195
196
197 public static final Pressure.Unit torr = atm.deriveUnit("torr", "Torr", 1.0 / 760.0, UnitSystem.OTHER);
198
199
200 public static final Pressure.Unit at =
201 Pa.deriveUnit("at", "atmosphere (technical)", Acceleration.Unit.CONST_GRAVITY / 1.0E-4, UnitSystem.OTHER);
202
203
204 public static final Pressure.Unit Ba = Pa.deriveUnit("Ba", "barye", 1.0E-5 / 1.0E-4, UnitSystem.CGS);
205
206
207 public static final Pressure.Unit bar = Pa.deriveUnit("bar", "bar", 1.0E5, UnitSystem.OTHER);
208
209
210 public static final Pressure.Unit mbar = bar.deriveUnit("mbar", "millibar", 1.0E-3, UnitSystem.OTHER);
211
212
213 public static final Pressure.Unit cmHg = Pa.deriveUnit("cmHg", "centimeter mercury", 1333.224, UnitSystem.OTHER);
214
215
216 public static final Pressure.Unit mmHg = Pa.deriveUnit("mmHg", "millimeter mercury", 133.3224, UnitSystem.OTHER);
217
218
219 public static final Pressure.Unit ftHg = Pa.deriveUnit("ftHg", "foot mercury", 40.63666E3, UnitSystem.IMPERIAL);
220
221
222 public static final Pressure.Unit inHg = Pa.deriveUnit("inHg", "inch mercury", 3.386389E3, UnitSystem.IMPERIAL);
223
224
225 public static final Pressure.Unit kgf_mm2 = Pa.deriveUnit("kgf/mm2", "kilogram-force per square millimeter",
226 Acceleration.Unit.CONST_GRAVITY / 1.0E-6, UnitSystem.OTHER);
227
228
229 public static final Pressure.Unit lbf_ft2 = Pa.deriveUnit("lbf/ft2", "pound-force per square foot",
230 Mass.Unit.CONST_LB * Acceleration.Unit.CONST_GRAVITY / (Length.Unit.CONST_FT * Length.Unit.CONST_FT),
231 UnitSystem.IMPERIAL);
232
233
234 public static final Pressure.Unit lbf_in2 = Pa.deriveUnit("lbf/in2", "pound-force per square inch",
235 Mass.Unit.CONST_LB * Acceleration.Unit.CONST_GRAVITY / (Length.Unit.CONST_IN * Length.Unit.CONST_IN),
236 UnitSystem.IMPERIAL);
237
238
239 public static final Pressure.Unit psi = lbf_in2;
240
241
242 public static final Pressure.Unit pz = Pa.deriveUnit("pz", "pi\u00E8ze", 1000.0, UnitSystem.MTS);
243
244
245
246
247
248
249
250
251 public Unit(final String id, final String name, final double scaleFactorToBaseUnit, final UnitSystem unitSystem)
252 {
253 super(id, name, new LinearScale(scaleFactorToBaseUnit), unitSystem);
254 }
255
256
257
258
259
260
261
262
263
264 public Unit(final String textualAbbreviation, final String displayAbbreviation, final String name, final Scale scale,
265 final UnitSystem unitSystem)
266 {
267 super(textualAbbreviation, displayAbbreviation, name, scale, unitSystem);
268 }
269
270 @Override
271 public SIUnit siUnit()
272 {
273 return SI_UNIT;
274 }
275
276 @Override
277 public Unit getBaseUnit()
278 {
279 return SI;
280 }
281
282 @Override
283 public Pressure ofSi(final double si)
284 {
285 return Pressure.ofSi(si);
286 }
287
288 @Override
289 public Unit deriveUnit(final String textualAbbreviation, final String displayAbbreviation, final String name,
290 final double scaleFactor, final UnitSystem unitSystem)
291 {
292 if (getScale() instanceof LinearScale ls)
293 {
294 return new Pressure.Unit(textualAbbreviation, displayAbbreviation, name,
295 new LinearScale(ls.getScaleFactorToBaseUnit() * scaleFactor), unitSystem);
296 }
297 throw new UnitRuntimeException("Only possible to derive a unit from a unit with a linear scale");
298 }
299
300 }
301 }