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