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.scale.LinearScale;
8 import org.djunits.unit.scale.Scale;
9 import org.djunits.unit.si.SIUnit;
10 import org.djunits.unit.system.UnitSystem;
11
12 /**
13 * Flow mass: The rate of mass passing through a surface per unit time, measured in kilograms per second (kg/s).
14 * <p>
15 * Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
16 * for project information <a href="https://djunits.org" target="_blank">https://djunits.org</a>. The DJUNITS project is
17 * distributed under a <a href="https://djunits.org/docs/license.html" target="_blank">three-clause BSD-style license</a>.
18 * @author Alexander Verbraeck
19 */
20 public class FlowMass extends Quantity<FlowMass>
21 {
22 /** Constant with value zero. */
23 public static final FlowMass ZERO = ofSi(0.0);
24
25 /** Constant with value one. */
26 public static final FlowMass ONE = ofSi(1.0);
27
28 /** Constant with value NaN. */
29 @SuppressWarnings("checkstyle:constantname")
30 public static final FlowMass NaN = ofSi(Double.NaN);
31
32 /** Constant with value POSITIVE_INFINITY. */
33 public static final FlowMass POSITIVE_INFINITY = ofSi(Double.POSITIVE_INFINITY);
34
35 /** Constant with value NEGATIVE_INFINITY. */
36 public static final FlowMass NEGATIVE_INFINITY = ofSi(Double.NEGATIVE_INFINITY);
37
38 /** Constant with value MAX_VALUE. */
39 public static final FlowMass POS_MAXVALUE = ofSi(Double.MAX_VALUE);
40
41 /** Constant with value -MAX_VALUE. */
42 public static final FlowMass NEG_MAXVALUE = ofSi(-Double.MAX_VALUE);
43
44 /** */
45 private static final long serialVersionUID = 600L;
46
47 /**
48 * Instantiate a FlowMass quantity with a unit.
49 * @param valueInUnit the value, expressed in the unit
50 * @param unit the unit in which the value is expressed
51 */
52 public FlowMass(final double valueInUnit, final FlowMass.Unit unit)
53 {
54 super(valueInUnit, unit);
55 }
56
57 /**
58 * Return a FlowMass instance based on an SI value.
59 * @param si the si value
60 * @return the FlowMass instance based on an SI value
61 */
62 public static FlowMass ofSi(final double si)
63 {
64 return new FlowMass(si, FlowMass.Unit.SI);
65 }
66
67 @Override
68 public FlowMass instantiateSi(final double si)
69 {
70 return ofSi(si);
71 }
72
73 @Override
74 public SIUnit siUnit()
75 {
76 return FlowMass.Unit.SI_UNIT;
77 }
78
79 /**
80 * Returns a FlowMass representation of a textual representation of a value with a unit. The String representation that can
81 * be parsed is the double value in the unit, followed by a localized or English abbreviation of the unit. Spaces are
82 * allowed, but not required, between the value and the unit.
83 * @param text the textual representation to parse into a FlowMass
84 * @return the Scalar representation of the value in its unit
85 * @throws IllegalArgumentException when the text cannot be parsed
86 * @throws NullPointerException when the text argument is null
87 */
88 public static FlowMass valueOf(final String text)
89 {
90 return Quantity.valueOf(text, ZERO);
91 }
92
93 /**
94 * Returns a FlowMass based on a value and the textual representation of the unit, which can be localized.
95 * @param valueInUnit the value, expressed in the unit as given by unitString
96 * @param unitString the textual representation of the unit
97 * @return the Scalar representation of the value in its unit
98 * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
99 * @throws NullPointerException when the unitString argument is null
100 */
101 public static FlowMass of(final double valueInUnit, final String unitString)
102 {
103 return Quantity.of(valueInUnit, unitString, ZERO);
104 }
105
106 @Override
107 public FlowMass.Unit getDisplayUnit()
108 {
109 return (FlowMass.Unit) super.getDisplayUnit();
110 }
111
112 /**
113 * Calculate the division of FlowMass and FlowMass, which results in a Dimensionless quantity.
114 * @param v quantity
115 * @return quantity as a division of FlowMass and FlowMass
116 */
117 public final Dimensionless divide(final FlowMass v)
118 {
119 return new Dimensionless(this.si() / v.si(), Unitless.BASE);
120 }
121
122 /**
123 * Calculate the multiplication of FlowMass and Duration, which results in a Mass scalar.
124 * @param v scalar
125 * @return scalar as a multiplication of FlowMass and Duration
126 */
127 public final Mass multiply(final Duration v)
128 {
129 return new Mass(this.si() * v.si(), Mass.Unit.SI);
130 }
131
132 /**
133 * Calculate the division of FlowMass and Frequency, which results in a Mass scalar.
134 * @param v scalar
135 * @return scalar as a division of FlowMass and Frequency
136 */
137 public final Mass divide(final Frequency v)
138 {
139 return new Mass(this.si() / v.si(), Mass.Unit.SI);
140 }
141
142 /**
143 * Calculate the division of FlowMass and Mass, which results in a Frequency scalar.
144 * @param v scalar
145 * @return scalar as a division of FlowMass and Mass
146 */
147 public final Frequency divide(final Mass v)
148 {
149 return new Frequency(this.si() / v.si(), Frequency.Unit.SI);
150 }
151
152 /**
153 * Calculate the multiplication of FlowMass and Speed, which results in a Force scalar.
154 * @param v scalar
155 * @return scalar as a multiplication of FlowMass and Speed
156 */
157 public final Force multiply(final Speed v)
158 {
159 return new Force(this.si() * v.si(), Force.Unit.SI);
160 }
161
162 /**
163 * Calculate the division of FlowMass and FlowVolume, which results in a Density scalar.
164 * @param v scalar
165 * @return scalar as a division of FlowMass and FlowVolume
166 */
167 public final Density divide(final FlowVolume v)
168 {
169 return new Density(this.si() / v.si(), Density.Unit.SI);
170 }
171
172 /**
173 * Calculate the division of FlowMass and Density, which results in a FlowVolume scalar.
174 * @param v scalar
175 * @return scalar as a division of FlowMass and Density
176 */
177 public final FlowVolume divide(final Density v)
178 {
179 return new FlowVolume(this.si() / v.si(), FlowVolume.Unit.SI);
180 }
181
182 /**
183 * Calculate the multiplication of FlowMass and Length, which results in a Momentum scalar.
184 * @param v scalar
185 * @return scalar as a multiplication of FlowMass and Length
186 */
187 public final Momentum multiply(final Length v)
188 {
189 return new Momentum(this.si() * v.si(), Momentum.Unit.SI);
190 }
191
192 /******************************************************************************************************/
193 /********************************************** UNIT CLASS ********************************************/
194 /******************************************************************************************************/
195
196 /**
197 * FlowMass.Unit encodes the units of mass flow.
198 * <p>
199 * Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved.
200 * See for project information <a href="https://djunits.org" target="_blank">https://djunits.org</a>. The DJUNITS project is
201 * distributed under a <a href="https://djunits.org/docs/license.html" target="_blank">three-clause BSD-style license</a>.
202 * @author Alexander Verbraeck
203 */
204 @SuppressWarnings("checkstyle:constantname")
205 public static class Unit extends AbstractUnit<FlowMass.Unit, FlowMass>
206 {
207 /** The dimensions of flow mass: kg/s. */
208 public static final SIUnit SI_UNIT = SIUnit.of("kg/s");
209
210 /** kg/s. */
211 public static final FlowMass.Unit kg_s = new FlowMass.Unit("kg/s", "kilogram per second", 1.0, UnitSystem.SI_DERIVED);
212
213 /** The SI or BASE unit. */
214 public static final FlowMass.Unit SI = kg_s;
215
216 /** lb/s. */
217 public static final FlowMass.Unit lb_s =
218 kg_s.deriveUnit("lb/s", "pound per second", Mass.Unit.CONST_LB, UnitSystem.IMPERIAL);
219
220 /**
221 * Create a new FlowMass unit.
222 * @param id the id or main abbreviation of the unit
223 * @param name the full name of the unit
224 * @param scaleFactorToBaseUnit the scale factor of the unit to convert it TO the base (SI) unit
225 * @param unitSystem the unit system such as SI or IMPERIAL
226 */
227 public Unit(final String id, final String name, final double scaleFactorToBaseUnit, final UnitSystem unitSystem)
228 {
229 super(id, name, new LinearScale(scaleFactorToBaseUnit), unitSystem);
230 }
231
232 /**
233 * Return a derived unit for this unit, with textual abbreviation(s) and a display abbreviation.
234 * @param textualAbbreviation the textual abbreviation of the unit, which doubles as the id
235 * @param displayAbbreviation the display abbreviation of the unit
236 * @param name the full name of the unit
237 * @param scale the scale to use to convert between this unit and the standard (e.g., SI, BASE) unit
238 * @param unitSystem unit system, e.g. SI or Imperial
239 */
240 public Unit(final String textualAbbreviation, final String displayAbbreviation, final String name, final Scale scale,
241 final UnitSystem unitSystem)
242 {
243 super(textualAbbreviation, displayAbbreviation, name, scale, unitSystem);
244 }
245
246 @Override
247 public SIUnit siUnit()
248 {
249 return SI_UNIT;
250 }
251
252 @Override
253 public Unit getBaseUnit()
254 {
255 return SI;
256 }
257
258 /** {@inheritDoc} */
259 @Override
260 public FlowMass ofSi(final double si)
261 {
262 return FlowMass.ofSi(si);
263 }
264
265 @Override
266 public Unit deriveUnit(final String textualAbbreviation, final String displayAbbreviation, final String name,
267 final double scaleFactor, final UnitSystem unitSystem)
268 {
269 if (getScale() instanceof LinearScale ls)
270 {
271 return new FlowMass.Unit(textualAbbreviation, displayAbbreviation, name,
272 new LinearScale(ls.getScaleFactorToBaseUnit() * scaleFactor), unitSystem);
273 }
274 throw new UnitRuntimeException("Only possible to derive a unit from a unit with a linear scale");
275 }
276
277 }
278 }