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-01-18 00:35:01 +0100 (Fri, 18 Jan 2019) $, @version $Revision: 324 $, 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.volt", "ElectricalPotentialUnit.V", SI_DERIVED, true);
70          VOLT = SI;
71          NANOVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.nanovolt", "ElectricalPotentialUnit.nV", SI_DERIVED,
72                  VOLT, 1.0E-9, true);
73          MICROVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.microvolt", "ElectricalPotentialUnit.muV", SI_DERIVED,
74                  VOLT, 1.0E-6, true);
75          MILLIVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.millivolt", "ElectricalPotentialUnit.mV", SI_DERIVED,
76                  VOLT, 0.001, true);
77          KILOVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.kilovolt", "ElectricalPotentialUnit.kV", SI_DERIVED,
78                  VOLT, 1000.0, true);
79          MEGAVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.megavolt", "ElectricalPotentialUnit.MV", SI_DERIVED,
80                  VOLT, 1.0E6, true);
81          GIGAVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.gigavolt", "ElectricalPotentialUnit.GV", SI_DERIVED,
82                  VOLT, 1.0E9, true);
83          STATVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.statvolt", "ElectricalPotentialUnit.statV", CGS_ESU,
84                  VOLT, 299.792458, true);
85          ABVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.abvolt", "ElectricalPotentialUnit.abV", CGS_EMU, VOLT,
86                  1.0E-8, true);
87      }
88  
89      /**
90       * Define an ElectricalPotentialUnit based on its constituent base units, e.g. a V = km.m^2/A.s^3.
91       * @param massUnit MassUnit; the unit of mass for the electrical potential difference (voltage) unit, e.g., kilogram
92       * @param lengthUnit LengthUnit; the unit of length for the electrical potential difference (voltage) unit, e.g., meter
93       * @param electricalCurrentUnit ElectricalCurrentUnit; the unit of electrical current for the electrical potential
94       *            difference (voltage) unit, e.g., Ampere
95       * @param durationUnit DurationUnit; the unit of time for the electrical potential difference (voltage) unit, e.g., second
96       * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
97       *            name itself
98       * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
99       *            unit, otherwise the abbreviation itself
100      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
101      * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
102      *            unit
103      */
104     @SuppressWarnings("checkstyle:parameternumber")
105     private ElectricalPotentialUnit(final MassUnit massUnit, final LengthUnit lengthUnit,
106             final ElectricalCurrentUnit electricalCurrentUnit, final DurationUnit durationUnit, final String nameOrNameKey,
107             final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
108     {
109         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, VOLT,
110                 massUnit.getScaleFactor() * lengthUnit.getScaleFactor() * lengthUnit.getScaleFactor()
111                         / (electricalCurrentUnit.getScaleFactor() * Math.pow(durationUnit.getScaleFactor(), 3.0)),
112                 standardUnit);
113         this.massUnit = massUnit;
114         this.lengthUnit = lengthUnit;
115         this.electricalCurrentUnit = electricalCurrentUnit;
116         this.durationUnit = durationUnit;
117     }
118 
119     /**
120      * Define a user-defined ElectricalPotentialUnit based on its constituent base units, e.g. a V = km.m^2/A.s^3.
121      * @param massUnit MassUnit; the unit of mass for the electrical potential difference (voltage) unit, e.g., kilogram
122      * @param lengthUnit LengthUnit; the unit of length for the electrical potential difference (voltage) unit, e.g., meter
123      * @param electricalCurrentUnit ElectricalCurrentUnit; the unit of electrical current for the electrical potential
124      *            difference (voltage) unit, e.g., Ampere
125      * @param durationUnit DurationUnit; the unit of time for the electrical potential difference (voltage) unit, e.g., second
126      * @param name String; the long name of the unit
127      * @param abbreviation String; the abbreviation of the unit
128      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
129      */
130     public ElectricalPotentialUnit(final MassUnit massUnit, final LengthUnit lengthUnit,
131             final ElectricalCurrentUnit electricalCurrentUnit, final DurationUnit durationUnit, final String name,
132             final String abbreviation, final UnitSystem unitSystem)
133     {
134         this(massUnit, lengthUnit, electricalCurrentUnit, durationUnit, name, abbreviation, unitSystem, false);
135     }
136 
137     /**
138      * Build an ElectricalPotentialUnit based on power divided by current (V=W/A).
139      * @param powerUnit PowerUnit; the unit of power for the electrical potential difference (voltage) unit, e.g., Watt
140      * @param electricalCurrentUnit ElectricalCurrentUnit; the unit of electrical current for the electrical potential
141      *            difference (voltage) unit, e.g., Ampere
142      * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
143      *            name itself
144      * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
145      *            unit, otherwise the abbreviation itself
146      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
147      * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
148      *            unit
149      */
150     private ElectricalPotentialUnit(final PowerUnit powerUnit, final ElectricalCurrentUnit electricalCurrentUnit,
151             final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
152             final boolean standardUnit)
153     {
154         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, VOLT,
155                 powerUnit.getScaleFactor() / electricalCurrentUnit.getScaleFactor(), standardUnit);
156         this.massUnit = powerUnit.getMassUnit();
157         this.lengthUnit = powerUnit.getLengthUnit();
158         this.electricalCurrentUnit = electricalCurrentUnit;
159         this.durationUnit = powerUnit.getDurationUnit();
160     }
161 
162     /**
163      * Build a user-defined ElectricalPotentialUnit based on power divided by current (V=W/A).
164      * @param powerUnit PowerUnit; the unit of power for the electrical potential difference (voltage) unit, e.g., Watt
165      * @param electricalCurrentUnit ElectricalCurrentUnit; the unit of electrical current for the electrical potential
166      *            difference (voltage) unit, e.g., Ampere
167      * @param name String; the long name of the unit
168      * @param abbreviation String; the abbreviation of the unit
169      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
170      */
171     public ElectricalPotentialUnit(final PowerUnit powerUnit, final ElectricalCurrentUnit electricalCurrentUnit,
172             final String name, final String abbreviation, final UnitSystem unitSystem)
173     {
174         this(powerUnit, electricalCurrentUnit, name, abbreviation, unitSystem, false);
175     }
176 
177     /**
178      * Build an ElectricalPotentialUnit with a conversion factor to another ElectricalPotentialUnit, e.g. a kV = 1000 V.
179      * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
180      *            name itself
181      * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
182      *            unit, otherwise the abbreviation itself
183      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
184      * @param referenceUnit ElectricalPotentialUnit; the unit to convert to
185      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
186      *            unit
187      * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
188      *            unit
189      */
190     private ElectricalPotentialUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey,
191             final UnitSystem unitSystem, final ElectricalPotentialUnit referenceUnit, final double scaleFactorToReferenceUnit,
192             final boolean standardUnit)
193     {
194         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
195                 standardUnit);
196         this.massUnit = referenceUnit.getMassUnit();
197         this.lengthUnit = referenceUnit.getLengthUnit();
198         this.electricalCurrentUnit = referenceUnit.getElectricalCurrentUnit();
199         this.durationUnit = referenceUnit.getDurationUnit();
200     }
201 
202     /**
203      * Build a user-defined ElectricalPotentialUnit with a conversion factor to another ElectricalPotentialUnit.
204      * @param name String; the long name of the unit
205      * @param abbreviation String; the abbreviation of the unit
206      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
207      * @param referenceUnit ElectricalPotentialUnit; the unit to convert to
208      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
209      *            unit
210      */
211     public ElectricalPotentialUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
212             final ElectricalPotentialUnit referenceUnit, final double scaleFactorToReferenceUnit)
213     {
214         this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
215     }
216 
217     /**
218      * @return massUnit
219      */
220     public final MassUnit getMassUnit()
221     {
222         return this.massUnit;
223     }
224 
225     /**
226      * @return lengthUnit
227      */
228     public final LengthUnit getLengthUnit()
229     {
230         return this.lengthUnit;
231     }
232 
233     /**
234      * @return electricalCurrentUnit
235      */
236     public final ElectricalCurrentUnit getElectricalCurrentUnit()
237     {
238         return this.electricalCurrentUnit;
239     }
240 
241     /**
242      * @return durationUnit
243      */
244     public final DurationUnit getDurationUnit()
245     {
246         return this.durationUnit;
247     }
248 
249     /** {@inheritDoc} */
250     @Override
251     public final ElectricalPotentialUnit getStandardUnit()
252     {
253         return VOLT;
254     }
255 
256     /** {@inheritDoc} */
257     @Override
258     public final String getSICoefficientsString()
259     {
260         return "kgm2/s3A";
261     }
262 
263 }