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 Energy extends Quantity<Energy>
22 {
23
24 public static final Energy ZERO = ofSi(0.0);
25
26
27 public static final Energy ONE = ofSi(1.0);
28
29
30 @SuppressWarnings("checkstyle:constantname")
31 public static final Energy NaN = ofSi(Double.NaN);
32
33
34 public static final Energy POSITIVE_INFINITY = ofSi(Double.POSITIVE_INFINITY);
35
36
37 public static final Energy NEGATIVE_INFINITY = ofSi(Double.NEGATIVE_INFINITY);
38
39
40 public static final Energy POS_MAXVALUE = ofSi(Double.MAX_VALUE);
41
42
43 public static final Energy NEG_MAXVALUE = ofSi(-Double.MAX_VALUE);
44
45
46 private static final long serialVersionUID = 600L;
47
48
49
50
51
52
53 public Energy(final double valueInUnit, final Energy.Unit unit)
54 {
55 super(valueInUnit, unit);
56 }
57
58
59
60
61
62
63 public static Energy ofSi(final double si)
64 {
65 return new Energy(si, Energy.Unit.SI);
66 }
67
68 @Override
69 public Energy instantiateSi(final double si)
70 {
71 return ofSi(si);
72 }
73
74 @Override
75 public SIUnit siUnit()
76 {
77 return Energy.Unit.SI_UNIT;
78 }
79
80
81
82
83
84
85
86
87
88
89 public static Energy valueOf(final String text)
90 {
91 return Quantity.valueOf(text, ZERO);
92 }
93
94
95
96
97
98
99
100
101
102 public static Energy of(final double valueInUnit, final String unitString)
103 {
104 return Quantity.of(valueInUnit, unitString, ZERO);
105 }
106
107 @Override
108 public Energy.Unit getDisplayUnit()
109 {
110 return (Energy.Unit) super.getDisplayUnit();
111 }
112
113
114
115
116
117
118 public final Dimensionless divide(final Energy v)
119 {
120 return new Dimensionless(this.si() / v.si(), Unitless.BASE);
121 }
122
123
124
125
126
127
128 public final Length divide(final Force v)
129 {
130 return new Length(this.si() / v.si(), Length.Unit.SI);
131 }
132
133
134
135
136
137
138 public final Force divide(final Length v)
139 {
140 return new Force(this.si() / v.si(), Force.Unit.SI);
141 }
142
143
144
145
146
147
148 public final Force multiply(final LinearObjectDensity v)
149 {
150 return new Force(this.si() * v.si(), Force.Unit.SI);
151 }
152
153
154
155
156
157
158 public final Power divide(final Duration v)
159 {
160 return new Power(this.si() / v.si(), Power.Unit.SI);
161 }
162
163
164
165
166
167
168 public final Duration divide(final Power v)
169 {
170 return new Duration(this.si() / v.si(), Duration.Unit.SI);
171 }
172
173
174
175
176
177
178 public final Pressure divide(final Volume v)
179 {
180 return new Pressure(this.si() / v.si(), Pressure.Unit.SI);
181 }
182
183
184
185
186
187
188 public final Volume divide(final Pressure v)
189 {
190 return new Volume(this.si() / v.si(), Volume.Unit.SI);
191 }
192
193
194
195
196
197
198 public final Power multiply(final Frequency v)
199 {
200 return new Power(this.si() * v.si(), Power.Unit.SI);
201 }
202
203
204
205
206
207
208 public final Momentum divide(final Speed v)
209 {
210 return new Momentum(this.si() / v.si(), Momentum.Unit.SI);
211 }
212
213
214
215
216
217
218 public final Speed divide(final Momentum v)
219 {
220 return new Speed(this.si() / v.si(), Speed.Unit.SI);
221 }
222
223
224
225
226
227
228
229
230
231
232
233
234
235 @SuppressWarnings("checkstyle:constantname")
236 public static class Unit extends AbstractUnit<Energy.Unit, Energy>
237 {
238
239 public static final SIUnit SI_UNIT = SIUnit.of("kgm2/s2");
240
241
242 public static final Energy.Unit J = new Energy.Unit("J", "joule", 1.0, UnitSystem.SI_DERIVED);
243
244
245 public static final Energy.Unit SI = J.generateSiPrefixes(false, false);
246
247
248 public static final Energy.Unit muJ = Units.resolve(Energy.Unit.class, "muJ");
249
250
251 public static final Energy.Unit mJ = Units.resolve(Energy.Unit.class, "mJ");
252
253
254 public static final Energy.Unit kJ = Units.resolve(Energy.Unit.class, "kJ");
255
256
257 public static final Energy.Unit MJ = Units.resolve(Energy.Unit.class, "MJ");
258
259
260 public static final Energy.Unit GJ = Units.resolve(Energy.Unit.class, "GJ");
261
262
263 public static final Energy.Unit TJ = Units.resolve(Energy.Unit.class, "TJ");
264
265
266 public static final Energy.Unit PJ = Units.resolve(Energy.Unit.class, "PJ");
267
268
269 public static final Energy.Unit ft_lbf = J.deriveUnit("ft.lbf", "foot pound-force",
270 Length.Unit.CONST_FT * Mass.Unit.CONST_LB * Acceleration.Unit.CONST_GRAVITY, UnitSystem.IMPERIAL);
271
272
273 public static final Energy.Unit in_lbf = J.deriveUnit("in.lbf", "inch pound-force",
274 Length.Unit.CONST_IN * Mass.Unit.CONST_LB * Acceleration.Unit.CONST_GRAVITY, UnitSystem.IMPERIAL);
275
276
277 public static final Energy.Unit BTU_ISO =
278 J.deriveUnit("BTU(ISO)", "British thermal unit (ISO)", 1.0545E3, UnitSystem.IMPERIAL);
279
280
281 public static final Energy.Unit BTU_IT =
282 J.deriveUnit("BTU(IT)", "British thermal unit (Int. Table)", 1.05505585262E3, UnitSystem.IMPERIAL);
283
284
285 public static final Energy.Unit cal_IT = J.deriveUnit("cal(IT)", "calorie (Int. Table)", 4.1868, UnitSystem.IMPERIAL);
286
287
288 public static final Energy.Unit cal = J.deriveUnit("cal", "calorie", 4.184, UnitSystem.OTHER);
289
290
291 public static final Energy.Unit kcal = cal.deriveUnit("kcal", "kilocalorie", 1000.0, UnitSystem.OTHER);
292
293
294 public static final Energy.Unit Wh = new Energy.Unit("Wh", "watt hour", 3600.0, UnitSystem.SI_DERIVED);
295
296
297 public static final Energy.Unit muWh = Wh.deriveUnit("muWh", "\u03BCWh", "microwatt hour", 1E-6, UnitSystem.SI_DERIVED);
298
299
300 public static final Energy.Unit mWh = Wh.deriveUnit("mWh", "milliwatt hour", 1E-3, UnitSystem.SI_DERIVED);
301
302
303 public static final Energy.Unit kWh = Wh.deriveUnit("kWh", "kilowatt hour", 1E3, UnitSystem.SI_DERIVED);
304
305
306 public static final Energy.Unit MWh = Wh.deriveUnit("MWh", "megawatt hour", 1E6, UnitSystem.SI_DERIVED);
307
308
309 public static final Energy.Unit GWh = Wh.deriveUnit("GWh", "gigawatt hour", 1E9, UnitSystem.SI_DERIVED);
310
311
312 public static final Energy.Unit TWh = Wh.deriveUnit("TWh", "terawatt hour", 1E12, UnitSystem.SI_DERIVED);
313
314
315 public static final Energy.Unit PWh = Wh.deriveUnit("PWh", "petawatt hour", 1E15, UnitSystem.SI_DERIVED);
316
317
318 public static final Energy.Unit eV = new Energy.Unit("eV", "electronvolt", 1.602176634E-19, UnitSystem.SI_ACCEPTED);
319
320
321 public static final Energy.Unit keV = eV.deriveUnit("keV", "kiloelectronvolt", 1E3, UnitSystem.SI_ACCEPTED);
322
323
324 public static final Energy.Unit MeV = eV.deriveUnit("MeV", "megaelectronvolt", 1E6, UnitSystem.SI_ACCEPTED);
325
326
327 public static final Energy.Unit GeV = eV.deriveUnit("GeV", "gigaelectronvolt", 1E9, UnitSystem.SI_ACCEPTED);
328
329
330 public static final Energy.Unit sn_m = J.deriveUnit("sn.m", "sthene meter", 1000.0, UnitSystem.MTS);
331
332
333 public static final Energy.Unit erg = J.deriveUnit("erg", "erg", 1.0E-7, UnitSystem.CGS);
334
335
336
337
338
339
340
341
342 public Unit(final String id, final String name, final double scaleFactorToBaseUnit, final UnitSystem unitSystem)
343 {
344 super(id, name, new LinearScale(scaleFactorToBaseUnit), unitSystem);
345 }
346
347
348
349
350
351
352
353
354
355 public Unit(final String textualAbbreviation, final String displayAbbreviation, final String name, final Scale scale,
356 final UnitSystem unitSystem)
357 {
358 super(textualAbbreviation, displayAbbreviation, name, scale, unitSystem);
359 }
360
361 @Override
362 public SIUnit siUnit()
363 {
364 return SI_UNIT;
365 }
366
367 @Override
368 public Unit getBaseUnit()
369 {
370 return SI;
371 }
372
373 @Override
374 public Energy ofSi(final double si)
375 {
376 return Energy.ofSi(si);
377 }
378
379 @Override
380 public Unit deriveUnit(final String textualAbbreviation, final String displayAbbreviation, final String name,
381 final double scaleFactor, final UnitSystem unitSystem)
382 {
383 if (getScale() instanceof LinearScale ls)
384 {
385 return new Energy.Unit(textualAbbreviation, displayAbbreviation, name,
386 new LinearScale(ls.getScaleFactorToBaseUnit() * scaleFactor), unitSystem);
387 }
388 throw new UnitRuntimeException("Only possible to derive a unit from a unit with a linear scale");
389 }
390
391 }
392 }