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 potential (voltage).
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 ElectricalPotentialUnit extends LinearUnit<ElectricalPotentialUnit>
20  {
21      /** */
22      private static final long serialVersionUID = 20140607L;
23  
24      /** the unit of mass for the electrical potential difference (voltage) unit, e.g., kilogram. */
25      private final MassUnit massUnit;
26  
27      /** the unit of length for the electrical potential difference (voltage) unit, e.g., meters. */
28      private final LengthUnit lengthUnit;
29  
30      /** the unit of electrical current for the electrical potential difference (voltage) unit, e.g., Ampere. */
31      private final ElectricalCurrentUnit electricalCurrentUnit;
32  
33      /** the unit of time for the electrical potential difference (voltage) unit, e.g., second. */
34      private final DurationUnit durationUnit;
35  
36      /** The SI unit for electrical potential is Volt. */
37      public static final ElectricalPotentialUnit SI;
38  
39      /** Volt. */
40      public static final ElectricalPotentialUnit VOLT;
41  
42      /** nanovolt. */
43      public static final ElectricalPotentialUnit NANOVOLT;
44  
45      /** microvolt. */
46      public static final ElectricalPotentialUnit MICROVOLT;
47  
48      /** millivolt. */
49      public static final ElectricalPotentialUnit MILLIVOLT;
50  
51      /** kilovolt. */
52      public static final ElectricalPotentialUnit KILOVOLT;
53  
54      /** megavolt. */
55      public static final ElectricalPotentialUnit MEGAVOLT;
56  
57      /** gigavolt. */
58      public static final ElectricalPotentialUnit GIGAVOLT;
59  
60      /** statvolt. */
61      public static final ElectricalPotentialUnit STATVOLT;
62  
63      /** abvolt. */
64      public static final ElectricalPotentialUnit ABVOLT;
65  
66      static
67      {
68          SI = new ElectricalPotentialUnit(MassUnit.KILOGRAM, LengthUnit.METER, ElectricalCurrentUnit.AMPERE, DurationUnit.SECOND,
69                  "ElectricalPotentialUnit.V", SI_DERIVED);
70          VOLT = SI;
71          NANOVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.nV", SI_DERIVED, VOLT, 1.0E-9);
72          MICROVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.muV", SI_DERIVED, VOLT, 1.0E-6);
73          MILLIVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.mV", SI_DERIVED, VOLT, 0.001);
74          KILOVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.kV", SI_DERIVED, VOLT, 1000.0);
75          MEGAVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.MV", SI_DERIVED, VOLT, 1.0E6);
76          GIGAVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.GV", SI_DERIVED, VOLT, 1.0E9);
77          STATVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.statV", CGS_ESU, VOLT, 299.792458);
78          ABVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.abV", CGS_EMU, VOLT, 1.0E-8);
79      }
80  
81      /**
82       * Define an ElectricalPotentialUnit based on its constituent base units, e.g. a V = km.m^2/A.s^3.
83       * @param massUnit MassUnit; the unit of mass for the electrical potential difference (voltage) unit, e.g., kilogram
84       * @param lengthUnit LengthUnit; the unit of length for the electrical potential difference (voltage) unit, e.g., meter
85       * @param electricalCurrentUnit ElectricalCurrentUnit; the unit of electrical current for the electrical potential
86       *            difference (voltage) unit, e.g., Ampere
87       * @param durationUnit DurationUnit; the unit of time for the electrical potential difference (voltage) 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      @SuppressWarnings("checkstyle:parameternumber")
92      private ElectricalPotentialUnit(final MassUnit massUnit, final LengthUnit lengthUnit,
93              final ElectricalCurrentUnit electricalCurrentUnit, final DurationUnit durationUnit, final String abbreviationKey,
94              final UnitSystem unitSystem)
95      {
96          super(abbreviationKey, unitSystem, VOLT,
97                  massUnit.getScaleFactor() * lengthUnit.getScaleFactor() * lengthUnit.getScaleFactor()
98                          / (electricalCurrentUnit.getScaleFactor() * 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 ElectricalPotentialUnit based on its constituent base units, e.g. a V = km.m^2/A.s^3.
107      * @param massUnit MassUnit; the unit of mass for the electrical potential difference (voltage) unit, e.g., kilogram
108      * @param lengthUnit LengthUnit; the unit of length for the electrical potential difference (voltage) unit, e.g., meter
109      * @param electricalCurrentUnit ElectricalCurrentUnit; the unit of electrical current for the electrical potential
110      *            difference (voltage) unit, e.g., Ampere
111      * @param durationUnit DurationUnit; the unit of time for the electrical potential difference (voltage) 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 ElectricalPotentialUnit(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, VOLT,
121                 massUnit.getScaleFactor() * lengthUnit.getScaleFactor() * lengthUnit.getScaleFactor()
122                         / (electricalCurrentUnit.getScaleFactor() * Math.pow(durationUnit.getScaleFactor(), 3.0)));
123         this.massUnit = massUnit;
124         this.lengthUnit = lengthUnit;
125         this.electricalCurrentUnit = electricalCurrentUnit;
126         this.durationUnit = durationUnit;
127     }
128 
129     /**
130      * Build an ElectricalPotentialUnit based on power divided by current (V=W/A).
131      * @param powerUnit PowerUnit; the unit of power for the electrical potential difference (voltage) unit, e.g., Watt
132      * @param electricalCurrentUnit ElectricalCurrentUnit; the unit of electrical current for the electrical potential
133      *            difference (voltage) unit, e.g., Ampere
134      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
135      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
136      */
137     private ElectricalPotentialUnit(final PowerUnit powerUnit, final ElectricalCurrentUnit electricalCurrentUnit,
138             final String abbreviationKey, final UnitSystem unitSystem)
139     {
140         super(abbreviationKey, unitSystem, VOLT, powerUnit.getScaleFactor() / electricalCurrentUnit.getScaleFactor());
141         this.massUnit = powerUnit.getMassUnit();
142         this.lengthUnit = powerUnit.getLengthUnit();
143         this.electricalCurrentUnit = electricalCurrentUnit;
144         this.durationUnit = powerUnit.getDurationUnit();
145     }
146 
147     /**
148      * Build a user-defined ElectricalPotentialUnit based on power divided by current (V=W/A).
149      * @param powerUnit PowerUnit; the unit of power for the electrical potential difference (voltage) unit, e.g., Watt
150      * @param electricalCurrentUnit ElectricalCurrentUnit; the unit of electrical current for the electrical potential
151      *            difference (voltage) unit, e.g., Ampere
152      * @param name String; the long name of the unit
153      * @param abbreviation String; the abbreviation of the unit
154      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
155      */
156     public ElectricalPotentialUnit(final PowerUnit powerUnit, final ElectricalCurrentUnit electricalCurrentUnit,
157             final String name, final String abbreviation, final UnitSystem unitSystem)
158     {
159         super(name, abbreviation, unitSystem, VOLT, powerUnit.getScaleFactor() / electricalCurrentUnit.getScaleFactor());
160         this.massUnit = powerUnit.getMassUnit();
161         this.lengthUnit = powerUnit.getLengthUnit();
162         this.electricalCurrentUnit = electricalCurrentUnit;
163         this.durationUnit = powerUnit.getDurationUnit();
164     }
165 
166     /**
167      * Build an ElectricalPotentialUnit with a conversion factor to another ElectricalPotentialUnit, e.g. a kV = 1000 V.
168      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
169      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
170      * @param referenceUnit ElectricalPotentialUnit; the unit to convert to
171      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
172      *            unit
173      */
174     private ElectricalPotentialUnit(final String abbreviationKey, final UnitSystem unitSystem,
175             final ElectricalPotentialUnit referenceUnit, final double scaleFactorToReferenceUnit)
176     {
177         super(abbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
178         this.massUnit = referenceUnit.getMassUnit();
179         this.lengthUnit = referenceUnit.getLengthUnit();
180         this.electricalCurrentUnit = referenceUnit.getElectricalCurrentUnit();
181         this.durationUnit = referenceUnit.getDurationUnit();
182     }
183 
184     /**
185      * Build a user-defined ElectricalPotentialUnit with a conversion factor to another ElectricalPotentialUnit.
186      * @param name String; the long name of the unit
187      * @param abbreviation String; the abbreviation of the unit
188      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
189      * @param referenceUnit ElectricalPotentialUnit; the unit to convert to
190      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
191      *            unit
192      */
193     public ElectricalPotentialUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
194             final ElectricalPotentialUnit referenceUnit, final double scaleFactorToReferenceUnit)
195     {
196         super(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
197         this.massUnit = referenceUnit.getMassUnit();
198         this.lengthUnit = referenceUnit.getLengthUnit();
199         this.electricalCurrentUnit = referenceUnit.getElectricalCurrentUnit();
200         this.durationUnit = referenceUnit.getDurationUnit();
201     }
202 
203     /**
204      * @return massUnit
205      */
206     public final MassUnit getMassUnit()
207     {
208         return this.massUnit;
209     }
210 
211     /**
212      * @return lengthUnit
213      */
214     public final LengthUnit getLengthUnit()
215     {
216         return this.lengthUnit;
217     }
218 
219     /**
220      * @return electricalCurrentUnit
221      */
222     public final ElectricalCurrentUnit getElectricalCurrentUnit()
223     {
224         return this.electricalCurrentUnit;
225     }
226 
227     /**
228      * @return durationUnit
229      */
230     public final DurationUnit getDurationUnit()
231     {
232         return this.durationUnit;
233     }
234 
235     /** {@inheritDoc} */
236     @Override
237     public final ElectricalPotentialUnit getStandardUnit()
238     {
239         return VOLT;
240     }
241 
242     /** {@inheritDoc} */
243     @Override
244     public final String getSICoefficientsString()
245     {
246         return "kgm2/s3A";
247     }
248 
249 }