1 package org.djunits.quantity;
2
3 import org.djunits.quantity.def.Quantity;
4 import org.djunits.unit.AbstractUnit;
5 import org.djunits.unit.UnitInterface;
6 import org.djunits.unit.UnitRuntimeException;
7 import org.djunits.unit.Unitless;
8 import org.djunits.unit.Units;
9 import org.djunits.unit.scale.IdentityScale;
10 import org.djunits.unit.scale.LinearScale;
11 import org.djunits.unit.scale.Scale;
12 import org.djunits.unit.si.SIPrefix;
13 import org.djunits.unit.si.SIPrefixes;
14 import org.djunits.unit.si.SIUnit;
15 import org.djunits.unit.system.UnitSystem;
16
17 /**
18 * Electrical resistence measures the opposition to the flow of an electric current, and is expressed in ohm. Its reciprocal
19 * quantity is electrical conductance (expressed in siemens).
20 * <p>
21 * Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
22 * for project information <a href="https://djunits.org" target="_blank">https://djunits.org</a>. The DJUNITS project is
23 * distributed under a <a href="https://djunits.org/docs/license.html" target="_blank">three-clause BSD-style license</a>.
24 * @author Alexander Verbraeck
25 */
26 public class ElectricalResistance extends Quantity<ElectricalResistance>
27 {
28 /** Constant with value zero. */
29 public static final ElectricalResistance ZERO = ofSi(0.0);
30
31 /** Constant with value one. */
32 public static final ElectricalResistance ONE = ofSi(1.0);
33
34 /** Constant with value NaN. */
35 @SuppressWarnings("checkstyle:constantname")
36 public static final ElectricalResistance NaN = ofSi(Double.NaN);
37
38 /** Constant with value POSITIVE_INFINITY. */
39 public static final ElectricalResistance POSITIVE_INFINITY = ofSi(Double.POSITIVE_INFINITY);
40
41 /** Constant with value NEGATIVE_INFINITY. */
42 public static final ElectricalResistance NEGATIVE_INFINITY = ofSi(Double.NEGATIVE_INFINITY);
43
44 /** Constant with value MAX_VALUE. */
45 public static final ElectricalResistance POS_MAXVALUE = ofSi(Double.MAX_VALUE);
46
47 /** Constant with value -MAX_VALUE. */
48 public static final ElectricalResistance NEG_MAXVALUE = ofSi(-Double.MAX_VALUE);
49
50 /** */
51 private static final long serialVersionUID = 600L;
52
53 /**
54 * Instantiate a ElectricalResistance quantity with an SI or base value and a display unit.
55 * @param value the quantity value expressed in the SI or base unit
56 * @param displayUnit the display unit to use
57 * @param useSi use SI value when true, use value in unit when false
58 */
59 public ElectricalResistance(final double value, final ElectricalResistance.Unit displayUnit, final boolean useSi)
60 {
61 super(value, displayUnit, useSi);
62 }
63
64 /**
65 * Instantiate a ElectricalResistance quantity expressed in the given unit.
66 * @param valueInUnit the quantity value expressed in the given unit
67 * @param unit the unit of the value, also acts as the display unit
68 */
69 public ElectricalResistance(final double valueInUnit, final ElectricalResistance.Unit unit)
70 {
71 this(valueInUnit, unit, false);
72 }
73
74 /**
75 * Return a ElectricalResistance instance based on an SI value.
76 * @param si the si value
77 * @return the ElectricalResistance instance based on an SI value
78 */
79 public static ElectricalResistance ofSi(final double si)
80 {
81 return new ElectricalResistance(si, ElectricalResistance.Unit.SI, true);
82 }
83
84 /**
85 * Instantiate a ElectricalResistance quantity with an SI or base value and a display unit.
86 * @param siValue the quantity value expressed in the SI or base unit
87 * @param displayUnit the display unit to use
88 * @return the ElectricalResistance instance based on an SI value with the given display unit
89 */
90 public static ElectricalResistance ofSi(final double siValue, final ElectricalResistance.Unit displayUnit)
91 {
92 return new ElectricalResistance(siValue, displayUnit, true);
93 }
94
95 @Override
96 public ElectricalResistance instantiateSi(final double siValue, final UnitInterface<ElectricalResistance> displayUnit)
97 {
98 return new ElectricalResistance(siValue, (ElectricalResistance.Unit) displayUnit, true);
99 }
100
101 /**
102 * Returns a ElectricalResistance representation of a textual representation of a value with a unit. The String
103 * representation that can be parsed is the double value in the unit, followed by a localized or English abbreviation of the
104 * unit. Spaces are allowed, but not required, between the value and the unit.
105 * @param text the textual representation to parse into a ElectricalResistance
106 * @return the Scalar representation of the value in its unit
107 * @throws IllegalArgumentException when the text cannot be parsed
108 * @throws NullPointerException when the text argument is null
109 */
110 public static ElectricalResistance valueOf(final String text)
111 {
112 return Quantity.valueOf(text, ZERO);
113 }
114
115 /**
116 * Returns a ElectricalResistance based on a value expressed in the unit.
117 * @param valueInUnit the value, expressed in the given unit
118 * @param unit the unit of the value, also acts as the display unit
119 * @return ab ElectricalResistance representation of the value in its unit
120 */
121 public static ElectricalResistance of(final double valueInUnit, final ElectricalResistance.Unit unit)
122 {
123 return new ElectricalResistance(valueInUnit, unit);
124 }
125
126 /**
127 * Returns a ElectricalResistance based on a value and the textual representation of the unit, which can be localized.
128 * @param valueInUnit the value, expressed in the unit as given by unitString
129 * @param unitString the textual representation of the unit
130 * @return the Scalar representation of the value in its unit
131 * @throws IllegalArgumentException when the unit cannot be parsed or is incorrect
132 * @throws NullPointerException when the unitString argument is null
133 */
134 public static ElectricalResistance of(final double valueInUnit, final String unitString)
135 {
136 return Quantity.of(valueInUnit, unitString, ZERO);
137 }
138
139 @Override
140 public ElectricalResistance.Unit getDisplayUnit()
141 {
142 return (ElectricalResistance.Unit) super.getDisplayUnit();
143 }
144
145 /**
146 * Calculate the division of ElectricalResistance and ElectricalResistance, which results in a Dimensionless quantity.
147 * @param v quantity
148 * @return quantity as a division of ElectricalResistance and ElectricalResistance
149 */
150 public Dimensionless divide(final ElectricalResistance v)
151 {
152 return new Dimensionless(this.si() / v.si(), Unitless.BASE);
153 }
154
155 /**
156 * Calculate the multiplication of ElectricalResistance and ElectricalConductance, which results in a Dimensionless scalar.
157 * @param v scalar
158 * @return scalar as a multiplication of ElectricalResistance and ElectricalConductance
159 */
160 public Dimensionless multiply(final ElectricalConductance v)
161 {
162 return new Dimensionless(this.si() * v.si(), Unitless.BASE);
163 }
164
165 /**
166 * Calculate the multiplication of ElectricalResistance and ElectricCurrent, which results in a ElectricPotential scalar.
167 * @param v scalar
168 * @return scalar as a multiplication of ElectricalResistance and ElectricCurrent
169 */
170 public ElectricPotential multiply(final ElectricCurrent v)
171 {
172 return new ElectricPotential(this.si() * v.si(), ElectricPotential.Unit.SI);
173 }
174
175 /**
176 * Calculate the multiplication of ElectricalResistance and Duration, which results in a ElectricalInductance scalar.
177 * @param v scalar
178 * @return scalar as a multiplication of ElectricalResistance and Duration
179 */
180 public ElectricalInductance multiply(final Duration v)
181 {
182 return new ElectricalInductance(this.si() * v.si(), ElectricalInductance.Unit.SI);
183 }
184
185 @Override
186 public ElectricalConductance reciprocal()
187 {
188 return ElectricalConductance.ofSi(1.0 / this.si());
189 }
190
191 /******************************************************************************************************/
192 /********************************************** UNIT CLASS ********************************************/
193 /******************************************************************************************************/
194
195 /**
196 * ElectricalResistance.Unit encodes the opposition to the flow of electric current.
197 * <p>
198 * Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved.
199 * See for project information <a href="https://djunits.org" target="_blank">https://djunits.org</a>. The DJUNITS project is
200 * distributed under a <a href="https://djunits.org/docs/license.html" target="_blank">three-clause BSD-style license</a>.
201 * @author Alexander Verbraeck
202 */
203 @SuppressWarnings("checkstyle:constantname")
204 public static class Unit extends AbstractUnit<ElectricalResistance>
205 {
206 /** The dimensions of the electrical resistance: kgm2/s3A2. */
207 public static final SIUnit SI_UNIT = SIUnit.of("kgm2/s3A2");
208
209 /** Ohm. */
210 public static final ElectricalResistance.Unit ohm = new ElectricalResistance.Unit("ohm", "\u03A9", "ohm",
211 IdentityScale.SCALE, UnitSystem.SI_DERIVED, SIPrefixes.getSiPrefix(""));
212
213 /** The SI or BASE unit. */
214 public static final ElectricalResistance.Unit SI = (Unit) ohm.generateSiPrefixes(false, false);
215
216 /** micro-ohm. */
217 public static final ElectricalResistance.Unit muohm = Units.resolve(ElectricalResistance.Unit.class, "muohm");
218
219 /** milli-ohm. */
220 public static final ElectricalResistance.Unit mohm = Units.resolve(ElectricalResistance.Unit.class, "mohm");
221
222 /** kilo-ohm. */
223 public static final ElectricalResistance.Unit kohm = Units.resolve(ElectricalResistance.Unit.class, "kohm");
224
225 /** mega-ohm. */
226 public static final ElectricalResistance.Unit Mohm = Units.resolve(ElectricalResistance.Unit.class, "Mohm");
227
228 /** giga-ohm. */
229 public static final ElectricalResistance.Unit Gohm = Units.resolve(ElectricalResistance.Unit.class, "Gohm");
230
231 /** ab-ohm. */
232 public static final ElectricalResistance.Unit abohm =
233 ohm.deriveUnit("abohm", "ab\u03A9", "abohm", 1.0E-9, UnitSystem.CGS_EMU, null);
234
235 /** stat-ohm. */
236 public static final ElectricalResistance.Unit statohm =
237 ohm.deriveUnit("stohm", "st\u03A9", "statohm", 8.987551787E11, UnitSystem.CGS_EMU, null);
238
239 /**
240 * Create a new ElectricalResistance unit.
241 * @param id the id or main abbreviation of the unit
242 * @param name the full name of the unit
243 * @param scaleFactorToBaseUnit the scale factor of the unit to convert it TO the base (SI) unit
244 * @param unitSystem the unit system such as SI or IMPERIAL
245 */
246 public Unit(final String id, final String name, final double scaleFactorToBaseUnit, final UnitSystem unitSystem)
247 {
248 super(id, name, scaleFactorToBaseUnit, unitSystem);
249 }
250
251 /**
252 * Return a derived unit for this unit, with textual abbreviation(s) and a display abbreviation.
253 * @param textualAbbreviation the textual abbreviation of the unit, which doubles as the id
254 * @param displayAbbreviation the display abbreviation of the unit
255 * @param name the full name of the unit
256 * @param scale the scale to use to convert from this unit to the standard (e.g., SI, BASE) unit
257 * @param unitSystem unit system, e.g. SI or Imperial
258 * @param siPrefix the SI Prefix of this unit
259 */
260 public Unit(final String textualAbbreviation, final String displayAbbreviation, final String name, final Scale scale,
261 final UnitSystem unitSystem, final SIPrefix siPrefix)
262 {
263 super(textualAbbreviation, displayAbbreviation, name, scale, unitSystem, siPrefix);
264 }
265
266 @Override
267 public SIUnit siUnit()
268 {
269 return SI_UNIT;
270 }
271
272 @Override
273 public Unit getBaseUnit()
274 {
275 return SI;
276 }
277
278 @Override
279 public ElectricalResistance ofSi(final double si, final UnitInterface<ElectricalResistance> displayUnit)
280 {
281 return new ElectricalResistance(si, (Unit) displayUnit, true);
282 }
283
284 @Override
285 public ElectricalResistance.Unit deriveUnit(final String abbreviation, final String name, final double scaleFactor,
286 final UnitSystem unitSystem)
287 {
288 return (Unit) super.deriveUnit(abbreviation, name, scaleFactor, unitSystem);
289 }
290
291 @Override
292 public ElectricalResistance.Unit deriveUnit(final String textualAbbreviation, final String displayAbbreviation,
293 final String name, final double scaleFactor, final UnitSystem unitSystem, final SIPrefix siPrefix)
294 {
295 if (getScale() instanceof LinearScale ls)
296 {
297 return new ElectricalResistance.Unit(textualAbbreviation, displayAbbreviation, name,
298 new LinearScale(ls.getScaleFactorToBaseUnit() * scaleFactor), unitSystem, siPrefix);
299 }
300 throw new UnitRuntimeException("Only possible to derive a unit from a unit with a linear scale");
301 }
302
303 }
304
305 }