View Javadoc
1   package org.djunits.unit;
2   
3   import static org.djunits.unit.unitsystem.UnitSystem.CGS;
4   import static org.djunits.unit.unitsystem.UnitSystem.IMPERIAL;
5   import static org.djunits.unit.unitsystem.UnitSystem.MTS;
6   import static org.djunits.unit.unitsystem.UnitSystem.OTHER;
7   import static org.djunits.unit.unitsystem.UnitSystem.SI_DERIVED;
8   
9   import org.djunits.unit.unitsystem.UnitSystem;
10  
11  /**
12   * The units of power.
13   * <p>
14   * Copyright (c) 2015-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
16   * <p>
17   * $LastChangedDate: 2019-03-02 19:06:46 +0100 (Sat, 02 Mar 2019) $, @version $Revision: 342 $, by $Author: averbraeck $,
18   * initial version May 15, 2014 <br>
19   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
20   */
21  public class PowerUnit extends LinearUnit<PowerUnit>
22  {
23      /** */
24      private static final long serialVersionUID = 20140607L;
25  
26      /** the unit of mass for the power unit, e.g., kilogram. */
27      private final MassUnit massUnit;
28  
29      /** the unit of length for the power unit, e.g., length. */
30      private final LengthUnit lengthUnit;
31  
32      /** the unit of time for the power unit, e.g., second. */
33      private final DurationUnit durationUnit;
34  
35      /** The SI unit for power is watt. */
36      public static final PowerUnit SI;
37  
38      /** femtowatt. */
39      public static final PowerUnit FEMTOWATT;
40  
41      /** picowatt. */
42      public static final PowerUnit PICOWATT;
43  
44      /** nanowatt. */
45      public static final PowerUnit NANOWATT;
46  
47      /** microwatt. */
48      public static final PowerUnit MICROWATT;
49  
50      /** milliwatt. */
51      public static final PowerUnit MILLIWATT;
52  
53      /** watt. */
54      public static final PowerUnit WATT;
55  
56      /** kiloawatt. */
57      public static final PowerUnit KILOWATT;
58  
59      /** megawatt. */
60      public static final PowerUnit MEGAWATT;
61  
62      /** gigawatt. */
63      public static final PowerUnit GIGAWATT;
64  
65      /** terawatt. */
66      public static final PowerUnit TERAWATT;
67  
68      /** petawatt. */
69      public static final PowerUnit PETAWATT;
70  
71      /** foot-pound-force per hour. */
72      public static final PowerUnit FOOT_POUND_FORCE_PER_HOUR;
73  
74      /** foot-pound-force per minute. */
75      public static final PowerUnit FOOT_POUND_FORCE_PER_MINUTE;
76  
77      /** foot-pound-force per second. */
78      public static final PowerUnit FOOT_POUND_FORCE_PER_SECOND;
79  
80      /** horsepower (metric). */
81      public static final PowerUnit HORSEPOWER_METRIC;
82  
83      /** sthene-meter per second. */
84      public static final PowerUnit STHENE_METER_PER_SECOND;
85  
86      /** erg per second. */
87      public static final PowerUnit ERG_PER_SECOND;
88  
89      static
90      {
91          SI = new PowerUnit(MassUnit.KILOGRAM, LengthUnit.METER, DurationUnit.SECOND, "PowerUnit.W", SI_DERIVED);
92          WATT = SI;
93          FEMTOWATT = new PowerUnit("PowerUnit.fW", SI_DERIVED, WATT, 1.0E-15);
94          PICOWATT = new PowerUnit("PowerUnit.pW", SI_DERIVED, WATT, 1.0E-12);
95          NANOWATT = new PowerUnit("PowerUnit.nW", SI_DERIVED, WATT, 1.0E-9);
96          MICROWATT = new PowerUnit("PowerUnit.muW", SI_DERIVED, WATT, 1.0E-6);
97          MILLIWATT = new PowerUnit("PowerUnit.mW", SI_DERIVED, WATT, 1.0E-3);
98          KILOWATT = new PowerUnit("PowerUnit.kW", SI_DERIVED, WATT, 1.0E3);
99          MEGAWATT = new PowerUnit("PowerUnit.MW", SI_DERIVED, WATT, 1.0E6);
100         GIGAWATT = new PowerUnit("PowerUnit.GW", SI_DERIVED, WATT, 1.0E9);
101         TERAWATT = new PowerUnit("PowerUnit.TW", SI_DERIVED, WATT, 1.0E12);
102         PETAWATT = new PowerUnit("PowerUnit.PW", SI_DERIVED, WATT, 1.0E15);
103         FOOT_POUND_FORCE_PER_HOUR =
104                 new PowerUnit(ForceUnit.POUND_FORCE, LengthUnit.FOOT, DurationUnit.HOUR, "PowerUnit.ft.lbf/h", IMPERIAL);
105         FOOT_POUND_FORCE_PER_MINUTE =
106                 new PowerUnit(ForceUnit.POUND_FORCE, LengthUnit.FOOT, DurationUnit.MINUTE, "PowerUnit.ft.lbf/min", IMPERIAL);
107         FOOT_POUND_FORCE_PER_SECOND =
108                 new PowerUnit(ForceUnit.POUND_FORCE, LengthUnit.FOOT, DurationUnit.SECOND, "PowerUnit.ft.lbf/s", IMPERIAL);
109         HORSEPOWER_METRIC = new PowerUnit("PowerUnit.hp", OTHER, WATT, 735.49875);
110         STHENE_METER_PER_SECOND =
111                 new PowerUnit(ForceUnit.STHENE, LengthUnit.METER, DurationUnit.SECOND, "PowerUnit.sn.m/s", MTS);
112         ERG_PER_SECOND = new PowerUnit(ForceUnit.DYNE, LengthUnit.CENTIMETER, DurationUnit.SECOND, "PowerUnit.erg/s", CGS);
113     }
114 
115     /**
116      * Define a PowerUnit based on its constituent base units, e.g. a W = km.m^2/s^3.
117      * @param massUnit MassUnit; the unit of mass for the power unit, e.g., kilogram
118      * @param lengthUnit LengthUnit; the unit of length for the power unit, e.g., meter
119      * @param durationUnit DurationUnit; the unit of time for the power unit, e.g., second
120      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
121      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
122      */
123     private PowerUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit,
124             final String abbreviationKey, final UnitSystem unitSystem)
125     {
126         super(abbreviationKey, unitSystem, WATT, massUnit.getScaleFactor() * lengthUnit.getScaleFactor()
127                 * lengthUnit.getScaleFactor() / Math.pow(durationUnit.getScaleFactor(), 3.0));
128         this.massUnit = massUnit;
129         this.lengthUnit = lengthUnit;
130         this.durationUnit = durationUnit;
131     }
132 
133     /**
134      * Define a user-defined PowerUnit based on its constituent base units, e.g. a W = km.m^2/s^3.
135      * @param massUnit MassUnit; the unit of mass for the power unit, e.g., kilogram
136      * @param lengthUnit LengthUnit; the unit of length for the power unit, e.g., meter
137      * @param durationUnit DurationUnit; the unit of time for the power unit, e.g., second
138      * @param name String; the long name of the unit
139      * @param abbreviation String; the abbreviation of the unit otherwise the abbreviation itself
140      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
141      */
142     public PowerUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit, final String name,
143             final String abbreviation, final UnitSystem unitSystem)
144     {
145         super(name, abbreviation, unitSystem, WATT, massUnit.getScaleFactor() * lengthUnit.getScaleFactor()
146                 * lengthUnit.getScaleFactor() / Math.pow(durationUnit.getScaleFactor(), 3.0));
147         this.massUnit = massUnit;
148         this.lengthUnit = lengthUnit;
149         this.durationUnit = durationUnit;
150     }
151 
152     /**
153      * Define an PowerUnit based on a LengthUnit, a ForceUnit, and a TimeUnit, e.g. a W = N.m/s.
154      * @param forceUnit ForceUnit; the unit of force for the power unit, e.g., Newton
155      * @param lengthUnit LengthUnit; the unit of length for the power unit, e.g., meter
156      * @param durationUnit DurationUnit; the unit of time for the power unit, e.g., second
157      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
158      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
159      */
160     private PowerUnit(final ForceUnit forceUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit,
161             final String abbreviationKey, final UnitSystem unitSystem)
162     {
163         super(abbreviationKey, unitSystem, WATT,
164                 lengthUnit.getScaleFactor() * forceUnit.getScaleFactor() / durationUnit.getScaleFactor());
165         this.massUnit = forceUnit.getMassUnit();
166         this.lengthUnit = forceUnit.getLengthUnit();
167         this.durationUnit = forceUnit.getDurationUnit();
168     }
169 
170     /**
171      * Define a user-defined PowerUnit based on a LengthUnit, a ForceUnit, and a TimeUnit, e.g. a W = N.m/s.
172      * @param lengthUnit LengthUnit; the unit of length for the power unit, e.g., meter
173      * @param forceUnit ForceUnit; the unit of force for the power unit, e.g., Newton
174      * @param durationUnit DurationUnit; the unit of time for the power unit, e.g., second
175      * @param name String; the long name of the unit
176      * @param abbreviation String; the abbreviation of the unit otherwise the abbreviation itself
177      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
178      */
179     public PowerUnit(final LengthUnit lengthUnit, final ForceUnit forceUnit, final DurationUnit durationUnit, final String name,
180             final String abbreviation, final UnitSystem unitSystem)
181     {
182         super(name, abbreviation, unitSystem, WATT,
183                 lengthUnit.getScaleFactor() * forceUnit.getScaleFactor() / durationUnit.getScaleFactor());
184         this.massUnit = forceUnit.getMassUnit();
185         this.lengthUnit = forceUnit.getLengthUnit();
186         this.durationUnit = forceUnit.getDurationUnit();
187     }
188 
189     /**
190      * Build a PowerUnit with a conversion factor to another PowerUnit.
191      * @param abbreviationKey String; the key to the locale file for the abbreviation of the unit
192      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
193      * @param referenceUnit PowerUnit; the unit to convert to
194      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
195      *            unit
196      */
197     private PowerUnit(final String abbreviationKey, final UnitSystem unitSystem, final PowerUnit referenceUnit,
198             final double scaleFactorToReferenceUnit)
199     {
200         super(abbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
201         this.massUnit = referenceUnit.getMassUnit();
202         this.lengthUnit = referenceUnit.getLengthUnit();
203         this.durationUnit = referenceUnit.getDurationUnit();
204     }
205 
206     /**
207      * Build a user-defined PowerUnit with a conversion factor to another PowerUnit.
208      * @param name String; the long name of the unit
209      * @param abbreviation String; the abbreviation of the unit
210      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
211      * @param referenceUnit PowerUnit; the unit to convert to
212      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
213      *            unit
214      */
215     public PowerUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final PowerUnit referenceUnit,
216             final double scaleFactorToReferenceUnit)
217     {
218         super(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit);
219         this.massUnit = referenceUnit.getMassUnit();
220         this.lengthUnit = referenceUnit.getLengthUnit();
221         this.durationUnit = referenceUnit.getDurationUnit();
222     }
223 
224     /**
225      * @return massUnit
226      */
227     public final MassUnit getMassUnit()
228     {
229         return this.massUnit;
230     }
231 
232     /**
233      * @return lengthUnit
234      */
235     public final LengthUnit getLengthUnit()
236     {
237         return this.lengthUnit;
238     }
239 
240     /**
241      * @return durationUnit
242      */
243     public final DurationUnit getDurationUnit()
244     {
245         return this.durationUnit;
246     }
247 
248     /** {@inheritDoc} */
249     @Override
250     public final PowerUnit getStandardUnit()
251     {
252         return WATT;
253     }
254 
255     /** {@inheritDoc} */
256     @Override
257     public final String getSICoefficientsString()
258     {
259         return "kgm2/s3";
260     }
261 
262 }