View Javadoc
1   package org.opentrafficsim.core.unit;
2   
3   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.CGS_EMU;
4   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.CGS_ESU;
5   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_DERIVED;
6   
7   import org.opentrafficsim.core.unit.unitsystem.UnitSystem;
8   
9   /**
10   * The units of electrical potential (voltage).
11   * <p>
12   * Copyright (c) 2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
14   * <p>
15   * @version May 15, 2014 <br>
16   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
17   */
18  public class ElectricalPotentialUnit extends Unit<ElectricalPotentialUnit>
19  {
20      /** */
21      private static final long serialVersionUID = 20140607L;
22  
23      /** the unit of mass for the electrical potential difference (voltage) unit, e.g., kilogram. */
24      private final MassUnit massUnit;
25  
26      /** the unit of length for the electrical potential difference (voltage) unit, e.g., meters. */
27      private final LengthUnit lengthUnit;
28  
29      /** the unit of electrical current for the electrical potential difference (voltage) unit, e.g., Ampere. */
30      private final ElectricalCurrentUnit electricalCurrentUnit;
31  
32      /** the unit of time for the electrical potential difference (voltage) unit, e.g., second. */
33      private final TimeUnit timeUnit;
34  
35      /** The SI unit for electrical potential is Volt. */
36      public static final ElectricalPotentialUnit SI;
37  
38      /** Volt. */
39      public static final ElectricalPotentialUnit VOLT;
40  
41      /** microvolt. */
42      public static final ElectricalPotentialUnit MICROVOLT;
43  
44      /** millivolt. */
45      public static final ElectricalPotentialUnit MILLIVOLT;
46  
47      /** kilovolt. */
48      public static final ElectricalPotentialUnit KILOVOLT;
49  
50      /** megavolt. */
51      public static final ElectricalPotentialUnit MEGAVOLT;
52  
53      /** statvolt. */
54      public static final ElectricalPotentialUnit STATVOLT;
55  
56      /** abvolt. */
57      public static final ElectricalPotentialUnit ABVOLT;
58  
59      static
60      {
61          SI =
62                  new ElectricalPotentialUnit(MassUnit.KILOGRAM, LengthUnit.METER, ElectricalCurrentUnit.AMPERE,
63                          TimeUnit.SECOND, "ElectricalPotentialUnit.volt", "ElectricalPotentialUnit.V", SI_DERIVED);
64          VOLT = SI;
65          MICROVOLT =
66                  new ElectricalPotentialUnit("ElectricalPotentialUnit.microvolt", "ElectricalPotentialUnit.muV",
67                          SI_DERIVED, VOLT, 1.0E-6);
68          MILLIVOLT =
69                  new ElectricalPotentialUnit("ElectricalPotentialUnit.millivolt", "ElectricalPotentialUnit.mV",
70                          SI_DERIVED, VOLT, 0.001);
71          KILOVOLT =
72                  new ElectricalPotentialUnit("ElectricalPotentialUnit.kilovolt", "ElectricalPotentialUnit.kV",
73                          SI_DERIVED, VOLT, 1000.0);
74          MEGAVOLT =
75                  new ElectricalPotentialUnit("ElectricalPotentialUnit.megavolt", "ElectricalPotentialUnit.MV",
76                          SI_DERIVED, VOLT, 1.0E6);
77          STATVOLT =
78                  new ElectricalPotentialUnit("ElectricalPotentialUnit.statvolt", "ElectricalPotentialUnit.statV",
79                          CGS_ESU, VOLT, 299.792458);
80          ABVOLT =
81                  new ElectricalPotentialUnit("ElectricalPotentialUnit.abvolt", "ElectricalPotentialUnit.abV", CGS_EMU,
82                          VOLT, 1.0E-8);
83      }
84  
85      /**
86       * @param massUnit the unit of mass for the electrical potential difference (voltage) unit, e.g., kilogram
87       * @param lengthUnit the unit of length for the electrical potential difference (voltage) unit, e.g., meter
88       * @param electricalCurrentUnit the unit of electrical current for the electrical potential difference (voltage)
89       *            unit, e.g., Ampere
90       * @param timeUnit the unit of time for the electrical potential difference (voltage) unit, e.g., second
91       * @param nameKey the key to the locale file for the long name of the unit
92       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
93       * @param unitSystem the unit system, e.g. SI or Imperial
94       */
95      public ElectricalPotentialUnit(final MassUnit massUnit, final LengthUnit lengthUnit,
96              final ElectricalCurrentUnit electricalCurrentUnit, final TimeUnit timeUnit, final String nameKey,
97              final String abbreviationKey, final UnitSystem unitSystem)
98      {
99          super(nameKey, abbreviationKey, unitSystem, VOLT, massUnit.getConversionFactorToStandardUnit()
100                 * lengthUnit.getConversionFactorToStandardUnit()
101                 * lengthUnit.getConversionFactorToStandardUnit()
102                 / (electricalCurrentUnit.getConversionFactorToStandardUnit() * Math.pow(
103                         timeUnit.getConversionFactorToStandardUnit(), 3.0)), true);
104         this.massUnit = massUnit;
105         this.lengthUnit = lengthUnit;
106         this.electricalCurrentUnit = electricalCurrentUnit;
107         this.timeUnit = timeUnit;
108     }
109 
110     /**
111      * @param powerUnit the unit of power for the electrical potential difference (voltage) unit, e.g., Watt
112      * @param electricalCurrentUnit the unit of electrical current for the electrical potential difference (voltage)
113      *            unit, e.g., Ampere
114      * @param nameKey the key to the locale file for the long name of the unit
115      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
116      * @param unitSystem the unit system, e.g. SI or Imperial
117      */
118     public ElectricalPotentialUnit(final PowerUnit powerUnit, final ElectricalCurrentUnit electricalCurrentUnit,
119             final String nameKey, final String abbreviationKey, final UnitSystem unitSystem)
120     {
121         super(nameKey, abbreviationKey, unitSystem, VOLT, powerUnit.getConversionFactorToStandardUnit()
122                 / electricalCurrentUnit.getConversionFactorToStandardUnit(), true);
123         this.massUnit = powerUnit.getMassUnit();
124         this.lengthUnit = powerUnit.getLengthUnit();
125         this.electricalCurrentUnit = electricalCurrentUnit;
126         this.timeUnit = powerUnit.getTimeUnit();
127     }
128 
129     /**
130      * @param nameKey the key to the locale file for the long name of the unit
131      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
132      * @param unitSystem the unit system, e.g. SI or Imperial
133      * @param referenceUnit the unit to convert to
134      * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given
135      *            reference unit
136      */
137     public ElectricalPotentialUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
138             final ElectricalPotentialUnit referenceUnit, final double conversionFactorToReferenceUnit)
139     {
140         super(nameKey, abbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit, true);
141         this.massUnit = referenceUnit.getMassUnit();
142         this.lengthUnit = referenceUnit.getLengthUnit();
143         this.electricalCurrentUnit = referenceUnit.getElectricalCurrentUnit();
144         this.timeUnit = referenceUnit.getTimeUnit();
145     }
146 
147     /**
148      * @return massUnit
149      */
150     public final MassUnit getMassUnit()
151     {
152         return this.massUnit;
153     }
154 
155     /**
156      * @return lengthUnit
157      */
158     public final LengthUnit getLengthUnit()
159     {
160         return this.lengthUnit;
161     }
162 
163     /**
164      * @return electricalCurrentUnit
165      */
166     public final ElectricalCurrentUnit getElectricalCurrentUnit()
167     {
168         return this.electricalCurrentUnit;
169     }
170 
171     /**
172      * @return timeUnit
173      */
174     public final TimeUnit getTimeUnit()
175     {
176         return this.timeUnit;
177     }
178 
179     /** {@inheritDoc} */
180     @Override
181     public final ElectricalPotentialUnit getStandardUnit()
182     {
183         return VOLT;
184     }
185 
186     /** {@inheritDoc} */
187     @Override
188     public final String getSICoefficientsString()
189     {
190         return "kg.m2.s-3.A-1";
191     }
192 
193 }