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