1 package org.djunits.value.vdouble.scalar;
2
3 import org.djunits.unit.DimensionlessUnit;
4 import org.djunits.unit.EnergyUnit;
5 import org.djunits.unit.ForceUnit;
6 import org.djunits.unit.PressureUnit;
7
8 /**
9 * Easy access methods for the Pressure DoubleScalar, which is relative by definition. Instead of:
10 *
11 * <pre>
12 * DoubleScalar.Rel<PressureUnit> value = new DoubleScalar.Rel<PressureUnit>(100.0, PressureUnit.SI);
13 * </pre>
14 *
15 * we can now write:
16 *
17 * <pre>
18 * Pressure value = new Pressure(100.0, PressureUnit.SI);
19 * </pre>
20 *
21 * The compiler will automatically recognize which units belong to which quantity, and whether the quantity type and the unit
22 * used are compatible.
23 * <p>
24 * Copyright (c) 2013-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
25 * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
26 * <p>
27 * $LastChangedDate: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, by $Author: averbraeck $,
28 * initial version Sep 5, 2015 <br>
29 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
30 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
31 */
32 public class Pressure extends AbstractDoubleScalarRel<PressureUnit, Pressure>
33 {
34 /** */
35 private static final long serialVersionUID = 20150905L;
36
37 /** constant with value zero. */
38 public static final Pressure ZERO = new Pressure(0.0, PressureUnit.SI);
39
40 /** constant with value NaN. */
41 @SuppressWarnings("checkstyle:constantname")
42 public static final Pressure NaN = new Pressure(Double.NaN, PressureUnit.SI);
43
44 /** constant with value POSITIVE_INFINITY. */
45 public static final Pressure POSITIVE_INFINITY = new Pressure(Double.POSITIVE_INFINITY, PressureUnit.SI);
46
47 /** constant with value NEGATIVE_INFINITY. */
48 public static final Pressure NEGATIVE_INFINITY = new Pressure(Double.NEGATIVE_INFINITY, PressureUnit.SI);
49
50 /** constant with value MAX_VALUE. */
51 public static final Pressure POS_MAXVALUE = new Pressure(Double.MAX_VALUE, PressureUnit.SI);
52
53 /** constant with value -MAX_VALUE. */
54 public static final Pressure NEG_MAXVALUE = new Pressure(-Double.MAX_VALUE, PressureUnit.SI);
55
56 /**
57 * Construct Pressure scalar.
58 * @param value double value
59 * @param unit unit for the double value
60 */
61 public Pressure(final double value, final PressureUnit unit)
62 {
63 super(value, unit);
64 }
65
66 /**
67 * Construct Pressure scalar.
68 * @param value Scalar from which to construct this instance
69 */
70 public Pressure(final Pressure value)
71 {
72 super(value);
73 }
74
75 /** {@inheritDoc} */
76 @Override
77 public final Pressure instantiateRel(final double value, final PressureUnit unit)
78 {
79 return new Pressure(value, unit);
80 }
81
82 /**
83 * Construct Pressure scalar.
84 * @param value double value in SI units
85 * @return the new scalar with the SI value
86 */
87 public static final Pressure createSI(final double value)
88 {
89 return new Pressure(value, PressureUnit.SI);
90 }
91
92 /**
93 * Interpolate between two values.
94 * @param zero the low value
95 * @param one the high value
96 * @param ratio the ratio between 0 and 1, inclusive
97 * @return a Scalar at the ratio between
98 */
99 public static Pressure interpolate(final Pressure zero, final Pressure one, final double ratio)
100 {
101 return new Pressure(zero.getInUnit() * (1 - ratio) + one.getInUnit(zero.getUnit()) * ratio, zero.getUnit());
102 }
103
104 /**
105 * Return the maximum value of two relative scalars.
106 * @param r1 the first scalar
107 * @param r2 the second scalar
108 * @return the maximum value of two relative scalars
109 */
110 public static Pressure max(final Pressure r1, final Pressure r2)
111 {
112 return (r1.gt(r2)) ? r1 : r2;
113 }
114
115 /**
116 * Return the maximum value of more than two relative scalars.
117 * @param r1 the first scalar
118 * @param r2 the second scalar
119 * @param rn the other scalars
120 * @return the maximum value of more than two relative scalars
121 */
122 public static Pressure max(final Pressure r1, final Pressure r2, final Pressure... rn)
123 {
124 Pressure maxr = (r1.gt(r2)) ? r1 : r2;
125 for (Pressure r : rn)
126 {
127 if (r.gt(maxr))
128 {
129 maxr = r;
130 }
131 }
132 return maxr;
133 }
134
135 /**
136 * Return the minimum value of two relative scalars.
137 * @param r1 the first scalar
138 * @param r2 the second scalar
139 * @return the minimum value of two relative scalars
140 */
141 public static Pressure min(final Pressure r1, final Pressure r2)
142 {
143 return (r1.lt(r2)) ? r1 : r2;
144 }
145
146 /**
147 * Return the minimum value of more than two relative scalars.
148 * @param r1 the first scalar
149 * @param r2 the second scalar
150 * @param rn the other scalars
151 * @return the minimum value of more than two relative scalars
152 */
153 public static Pressure min(final Pressure r1, final Pressure r2, final Pressure... rn)
154 {
155 Pressure minr = (r1.lt(r2)) ? r1 : r2;
156 for (Pressure r : rn)
157 {
158 if (r.lt(minr))
159 {
160 minr = r;
161 }
162 }
163 return minr;
164 }
165
166 /**
167 * Calculate the division of Pressure and Pressure, which results in a Dimensionless scalar.
168 * @param v Pressure scalar
169 * @return Dimensionless scalar as a division of Pressure and Pressure
170 */
171 public final Dimensionless divideBy(final Pressure v)
172 {
173 return new Dimensionless(this.si / v.si, DimensionlessUnit.SI);
174 }
175
176 /**
177 * Calculate the multiplication of Pressure and Area, which results in a Force scalar.
178 * @param v Pressure scalar
179 * @return Force scalar as a multiplication of Pressure and Area
180 */
181 public final Force multiplyBy(final Area v)
182 {
183 return new Force(this.si * v.si, ForceUnit.SI);
184 }
185
186 /**
187 * Calculate the multiplication of Pressure and Volume, which results in a Energy scalar.
188 * @param v Pressure scalar
189 * @return Energy scalar as a multiplication of Pressure and Volume
190 */
191 public final Energy multiplyBy(final Volume v)
192 {
193 return new Energy(this.si * v.si, EnergyUnit.SI);
194 }
195
196 }