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