View Javadoc
1   package org.djunits.unit;
2   
3   import static org.djunits.unit.unitsystem.UnitSystem.CGS_EMU;
4   import static org.djunits.unit.unitsystem.UnitSystem.CGS_ESU;
5   import static org.djunits.unit.unitsystem.UnitSystem.SI_DERIVED;
6   
7   import org.djunits.unit.unitsystem.UnitSystem;
8   
9   /**
10   * The units of electrical resistance.
11   * <p>
12   * Copyright (c) 2015-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
14   * <p>
15   * $LastChangedDate: 2019-03-02 19:06:46 +0100 (Sat, 02 Mar 2019) $, @version $Revision: 342 $, by $Author: averbraeck $,
16   * initial version May 15, 2014 <br>
17   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
18   */
19  public class ElectricalResistanceUnit extends LinearUnit<ElectricalResistanceUnit>
20  {
21      /** */
22      private static final long serialVersionUID = 20140607L;
23  
24      /** the unit of mass for the electrical resistance unit, e.g., kilogram. */
25      private final MassUnit massUnit;
26  
27      /** the unit of length for the electrical resistance unit, e.g., meters. */
28      private final LengthUnit lengthUnit;
29  
30      /** the unit of electrical current for the electrical resistance unit, e.g., Ampere. */
31      private final ElectricalCurrentUnit electricalCurrentUnit;
32  
33      /** the unit of time for the electrical resistance unit, e.g., second. */
34      private final DurationUnit durationUnit;
35  
36      /** The SI unit for electrical resistance is Ohm. */
37      public static final ElectricalResistanceUnit SI;
38  
39      /** Ohm. */
40      public static final ElectricalResistanceUnit OHM;
41  
42      /** nano-ohm. */
43      public static final ElectricalResistanceUnit NANOOHM;
44  
45      /** micro-ohm. */
46      public static final ElectricalResistanceUnit MICROOHM;
47  
48      /** milli-ohm. */
49      public static final ElectricalResistanceUnit MILLIOHM;
50  
51      /** kilo-ohm. */
52      public static final ElectricalResistanceUnit KILOOHM;
53  
54      /** mega-ohm. */
55      public static final ElectricalResistanceUnit MEGAOHM;
56  
57      /** giga-ohm. */
58      public static final ElectricalResistanceUnit GIGAOHM;
59  
60      /** ab-ohm. */
61      public static final ElectricalResistanceUnit ABOHM;
62  
63      /** stat-ohm. */
64      public static final ElectricalResistanceUnit STATOHM;
65  
66      static
67      {
68          SI = new ElectricalResistanceUnit(MassUnit.KILOGRAM, LengthUnit.METER, ElectricalCurrentUnit.AMPERE,
69                  DurationUnit.SECOND, "ElectricalResistanceUnit.ohm", SI_DERIVED);
70          OHM = SI;
71          NANOOHM = new ElectricalResistanceUnit("ElectricalResistanceUnit.n_ohm", SI_DERIVED, OHM, 1.0E-9);
72          MICROOHM = new ElectricalResistanceUnit("ElectricalResistanceUnit.mu_ohm", SI_DERIVED, OHM, 1.0E-6);
73          MILLIOHM = new ElectricalResistanceUnit("ElectricalResistanceUnit.m_ohm", SI_DERIVED, OHM, 1.0E-3);
74          KILOOHM = new ElectricalResistanceUnit("ElectricalResistanceUnit.k_ohm", SI_DERIVED, OHM, 1.0E3);
75          MEGAOHM = new ElectricalResistanceUnit("ElectricalResistanceUnit.M_ohm", SI_DERIVED, OHM, 1.0E06);
76          GIGAOHM = new ElectricalResistanceUnit("ElectricalResistanceUnit.G_ohm", SI_DERIVED, OHM, 1.0E9);
77          ABOHM = new ElectricalResistanceUnit("ElectricalResistanceUnit.a_ohm", CGS_EMU, OHM, 1.0E-9);
78          STATOHM = new ElectricalResistanceUnit("ElectricalResistanceUnit.st_ohm", CGS_ESU, OHM, 8.987551787E11);
79      }
80  
81      /**
82       * Define an ElectricalResistanceUnit based on its constituent base units, e.g. an Ohm = km.m^2/A^2.s^3.
83       * @param massUnit MassUnit; the unit of mass for the electrical resistance unit, e.g., kilogram
84       * @param lengthUnit LengthUnit; the unit of length for the electrical resistance unit, e.g., meter
85       * @param electricalCurrentUnit ElectricalCurrentUnit; the unit of electrical current for the electrical resistance unit,
86       *            e.g., Ampere
87       * @param durationUnit DurationUnit; the unit of time for the electrical resistance unit, e.g., second
88       * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
89       * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
90       */
91      private ElectricalResistanceUnit(final MassUnit massUnit, final LengthUnit lengthUnit,
92              final ElectricalCurrentUnit electricalCurrentUnit, final DurationUnit durationUnit, final String abbreviationKey,
93              final UnitSystem unitSystem)
94      {
95          super(abbreviationKey, unitSystem, OHM,
96                  massUnit.getScaleFactor() * lengthUnit.getScaleFactor() * lengthUnit.getScaleFactor()
97                          / (electricalCurrentUnit.getScaleFactor() * electricalCurrentUnit.getScaleFactor()
98                                  * Math.pow(durationUnit.getScaleFactor(), 3.0)));
99          this.massUnit = massUnit;
100         this.lengthUnit = lengthUnit;
101         this.electricalCurrentUnit = electricalCurrentUnit;
102         this.durationUnit = durationUnit;
103     }
104 
105     /**
106      * Define a user-defined ElectricalResistanceUnit based on its constituent base units, e.g. an Ohm = km.m^2/A^2.s^3.
107      * @param massUnit MassUnit; the unit of mass for the electrical resistance unit, e.g., kilogram
108      * @param lengthUnit LengthUnit; the unit of length for the electrical resistance unit, e.g., meter
109      * @param electricalCurrentUnit ElectricalCurrentUnit; the unit of electrical current for the electrical resistance unit,
110      *            e.g., Ampere
111      * @param durationUnit DurationUnit; the unit of time for the electrical resistance unit, e.g., second
112      * @param name String; the long name of the unit
113      * @param abbreviation String; the abbreviation of the unit
114      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
115      */
116     public ElectricalResistanceUnit(final MassUnit massUnit, final LengthUnit lengthUnit,
117             final ElectricalCurrentUnit electricalCurrentUnit, final DurationUnit durationUnit, final String name,
118             final String abbreviation, final UnitSystem unitSystem)
119     {
120         super(name, abbreviation, unitSystem, OHM,
121                 massUnit.getScaleFactor() * lengthUnit.getScaleFactor() * lengthUnit.getScaleFactor()
122                         / (electricalCurrentUnit.getScaleFactor() * electricalCurrentUnit.getScaleFactor()
123                                 * Math.pow(durationUnit.getScaleFactor(), 3.0)));
124         this.massUnit = massUnit;
125         this.lengthUnit = lengthUnit;
126         this.electricalCurrentUnit = electricalCurrentUnit;
127         this.durationUnit = durationUnit;
128     }
129 
130     /**
131      * Define an ElectricalResistanceUnit based on an electrical potential unit and an electrical current unit, e.g. Ohm = V/A.
132      * @param electricalPotentialUnit ElectricalPotentialUnit; the unit of electrical potential difference for the electrical
133      *            resistance unit, e.g., Volt
134      * @param electricalCurrentUnit ElectricalCurrentUnit; the unit of electrical current for the electrical resistance unit,
135      *            e.g., Ampere
136      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
137      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
138      */
139     private ElectricalResistanceUnit(final ElectricalPotentialUnit electricalPotentialUnit,
140             final ElectricalCurrentUnit electricalCurrentUnit, final String abbreviationKey, final UnitSystem unitSystem)
141     {
142         super(abbreviationKey, unitSystem, OHM,
143                 electricalPotentialUnit.getScaleFactor() / electricalCurrentUnit.getScaleFactor());
144         this.massUnit = electricalPotentialUnit.getMassUnit();
145         this.lengthUnit = electricalPotentialUnit.getLengthUnit();
146         this.electricalCurrentUnit = electricalCurrentUnit;
147         this.durationUnit = electricalPotentialUnit.getDurationUnit();
148     }
149 
150     /**
151      * Define a user-defined ElectricalResistanceUnit based on an electrical potential unit and an electrical current unit, e.g.
152      * Ohm = V/A.
153      * @param electricalPotentialUnit ElectricalPotentialUnit; the unit of electrical potential difference for the electrical
154      *            resistance unit, e.g., Volt
155      * @param electricalCurrentUnit ElectricalCurrentUnit; the unit of electrical current for the electrical resistance unit,
156      *            e.g., Ampere
157      * @param name String; the long name of the unit
158      * @param abbreviation String; the abbreviation of the unit
159      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
160      */
161     public ElectricalResistanceUnit(final ElectricalPotentialUnit electricalPotentialUnit,
162             final ElectricalCurrentUnit electricalCurrentUnit, final String name, final String abbreviation,
163             final UnitSystem unitSystem)
164     {
165         super(name, abbreviation, unitSystem, OHM,
166                 electricalPotentialUnit.getScaleFactor() / electricalCurrentUnit.getScaleFactor());
167         this.massUnit = electricalPotentialUnit.getMassUnit();
168         this.lengthUnit = electricalPotentialUnit.getLengthUnit();
169         this.electricalCurrentUnit = electricalCurrentUnit;
170         this.durationUnit = electricalPotentialUnit.getDurationUnit();
171     }
172 
173     /**
174      * Build a ElectricalResistanceUnit with a conversion factor to another ElectricalResistanceUnit.
175      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
176      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
177      * @param referenceUnit ElectricalResistanceUnit; the unit to convert to
178      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
179      *            unit
180      */
181     private ElectricalResistanceUnit(final String abbreviationKey, final UnitSystem unitSystem,
182             final ElectricalResistanceUnit referenceUnit, final double scaleFactorToReferenceUnit)
183     {
184         super(abbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
185         this.massUnit = referenceUnit.getMassUnit();
186         this.lengthUnit = referenceUnit.getLengthUnit();
187         this.electricalCurrentUnit = referenceUnit.getElectricalCurrentUnit();
188         this.durationUnit = referenceUnit.getDurationUnit();
189     }
190 
191     /**
192      * Build a user-defined ElectricalResistanceUnit with a conversion factor to another ElectricalResistanceUnit.
193      * @param name String; the long name of the unit
194      * @param abbreviation String; the abbreviation of the unit
195      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
196      * @param referenceUnit ElectricalResistanceUnit; the unit to convert to
197      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
198      *            unit
199      */
200     public ElectricalResistanceUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
201             final ElectricalResistanceUnit referenceUnit, final double scaleFactorToReferenceUnit)
202     {
203         super(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
204         this.massUnit = referenceUnit.getMassUnit();
205         this.lengthUnit = referenceUnit.getLengthUnit();
206         this.electricalCurrentUnit = referenceUnit.getElectricalCurrentUnit();
207         this.durationUnit = referenceUnit.getDurationUnit();
208     }
209 
210     /**
211      * @return massUnit
212      */
213     public final MassUnit getMassUnit()
214     {
215         return this.massUnit;
216     }
217 
218     /**
219      * @return lengthUnit
220      */
221     public final LengthUnit getLengthUnit()
222     {
223         return this.lengthUnit;
224     }
225 
226     /**
227      * @return electricalCurrentUnit
228      */
229     public final ElectricalCurrentUnit getElectricalCurrentUnit()
230     {
231         return this.electricalCurrentUnit;
232     }
233 
234     /**
235      * @return durationUnit
236      */
237     public final DurationUnit getDurationUnit()
238     {
239         return this.durationUnit;
240     }
241 
242     /** {@inheritDoc} */
243     @Override
244     public final ElectricalResistanceUnit getStandardUnit()
245     {
246         return OHM;
247     }
248 
249     /** {@inheritDoc} */
250     @Override
251     public final String getSICoefficientsString()
252     {
253         return "kgm2/s3A2";
254     }
255 
256 }