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-2018 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: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, 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.watt", "PowerUnit.W",
92                  SI_DERIVED, true);
93          WATT = SI;
94          FEMTOWATT = new PowerUnit("PowerUnit.femtowatt", "PowerUnit.fW", SI_DERIVED, WATT, 1.0E-15, true);
95          PICOWATT = new PowerUnit("PowerUnit.picowatt", "PowerUnit.pW", SI_DERIVED, WATT, 1.0E-12, true);
96          NANOWATT = new PowerUnit("PowerUnit.nanowatt", "PowerUnit.nW", SI_DERIVED, WATT, 1.0E-9, true);
97          MICROWATT = new PowerUnit("PowerUnit.microwatt", "PowerUnit.muW", SI_DERIVED, WATT, 1.0E-6, true);
98          MILLIWATT = new PowerUnit("PowerUnit.milliwatt", "PowerUnit.mW", SI_DERIVED, WATT, 1.0E-3, true);
99          KILOWATT = new PowerUnit("PowerUnit.kilowatt", "PowerUnit.kW", SI_DERIVED, WATT, 1.0E3, true);
100         MEGAWATT = new PowerUnit("PowerUnit.megawatt", "PowerUnit.MW", SI_DERIVED, WATT, 1.0E6, true);
101         GIGAWATT = new PowerUnit("PowerUnit.gigawatt", "PowerUnit.GW", SI_DERIVED, WATT, 1.0E9, true);
102         TERAWATT = new PowerUnit("PowerUnit.terawatt", "PowerUnit.TW", SI_DERIVED, WATT, 1.0E12, true);
103         PETAWATT = new PowerUnit("PowerUnit.petawatt", "PowerUnit.PW", SI_DERIVED, WATT, 1.0E15, true);
104         FOOT_POUND_FORCE_PER_HOUR = new PowerUnit(ForceUnit.POUND_FORCE, LengthUnit.FOOT, DurationUnit.HOUR,
105                 "PowerUnit.foot_pound-force_per_hour", "PowerUnit.ft.lbf/h", IMPERIAL, true);
106         FOOT_POUND_FORCE_PER_MINUTE = new PowerUnit(ForceUnit.POUND_FORCE, LengthUnit.FOOT, DurationUnit.MINUTE,
107                 "PowerUnit.foot_pound-force_per_minute", "PowerUnit.ft.lbf/min", IMPERIAL, true);
108         FOOT_POUND_FORCE_PER_SECOND = new PowerUnit(ForceUnit.POUND_FORCE, LengthUnit.FOOT, DurationUnit.SECOND,
109                 "PowerUnit.foot_pound-force_per_second", "PowerUnit.ft.lbf/s", IMPERIAL, true);
110         HORSEPOWER_METRIC = new PowerUnit("PowerUnit.horsepower_(metric)", "PowerUnit.hp", OTHER, WATT, 735.49875, true);
111         STHENE_METER_PER_SECOND = new PowerUnit(ForceUnit.STHENE, LengthUnit.METER, DurationUnit.SECOND,
112                 "PowerUnit.sthene-meter_per_second", "PowerUnit.sn.m/s", MTS, true);
113         ERG_PER_SECOND = new PowerUnit(ForceUnit.DYNE, LengthUnit.CENTIMETER, DurationUnit.SECOND, "PowerUnit.erg_per_second",
114                 "PowerUnit.erg/s", CGS, true);
115     }
116 
117     /**
118      * Define a PowerUnit based on its constituent base units, e.g. a W = km.m^2/s^3.
119      * @param massUnit the unit of mass for the power unit, e.g., kilogram
120      * @param lengthUnit the unit of length for the power unit, e.g., meter
121      * @param durationUnit the unit of time for the power unit, e.g., second
122      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
123      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
124      *            otherwise the abbreviation itself
125      * @param unitSystem the unit system, e.g. SI or Imperial
126      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
127      */
128     private PowerUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit,
129             final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
130             final boolean standardUnit)
131     {
132         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, WATT, massUnit.getScaleFactor()
133                 * lengthUnit.getScaleFactor() * lengthUnit.getScaleFactor() / Math.pow(durationUnit.getScaleFactor(), 3.0),
134                 standardUnit);
135         this.massUnit = massUnit;
136         this.lengthUnit = lengthUnit;
137         this.durationUnit = durationUnit;
138     }
139 
140     /**
141      * Define a user-defined PowerUnit based on its constituent base units, e.g. a W = km.m^2/s^3.
142      * @param massUnit the unit of mass for the power unit, e.g., kilogram
143      * @param lengthUnit the unit of length for the power unit, e.g., meter
144      * @param durationUnit the unit of time for the power unit, e.g., second
145      * @param name the long name of the unit
146      * @param abbreviation the abbreviation of the unit otherwise the abbreviation itself
147      * @param unitSystem the unit system, e.g. SI or Imperial
148      */
149     public PowerUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit, final String name,
150             final String abbreviation, final UnitSystem unitSystem)
151     {
152         this(massUnit, lengthUnit, durationUnit, name, abbreviation, unitSystem, false);
153     }
154 
155     /**
156      * Define an PowerUnit based on a LengthUnit, a ForceUnit, and a TimeUnit, e.g. a W = N.m/s.
157      * @param forceUnit the unit of force for the power unit, e.g., Newton
158      * @param lengthUnit the unit of length for the power unit, e.g., meter
159      * @param durationUnit the unit of time for the power unit, e.g., second
160      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
161      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
162      *            otherwise the abbreviation itself
163      * @param unitSystem the unit system, e.g. SI or Imperial
164      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
165      */
166     private PowerUnit(final ForceUnit forceUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit,
167             final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
168             final boolean standardUnit)
169     {
170         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, WATT,
171                 lengthUnit.getScaleFactor() * forceUnit.getScaleFactor() / durationUnit.getScaleFactor(), standardUnit);
172         this.massUnit = forceUnit.getMassUnit();
173         this.lengthUnit = forceUnit.getLengthUnit();
174         this.durationUnit = forceUnit.getDurationUnit();
175     }
176 
177     /**
178      * Define a user-defined PowerUnit based on a LengthUnit, a ForceUnit, and a TimeUnit, e.g. a W = N.m/s.
179      * @param lengthUnit the unit of length for the power unit, e.g., meter
180      * @param forceUnit the unit of force for the power unit, e.g., Newton
181      * @param durationUnit the unit of time for the power unit, e.g., second
182      * @param name the long name of the unit
183      * @param abbreviation the abbreviation of the unit otherwise the abbreviation itself
184      * @param unitSystem the unit system, e.g. SI or Imperial
185      */
186     public PowerUnit(final LengthUnit lengthUnit, final ForceUnit forceUnit, final DurationUnit durationUnit, final String name,
187             final String abbreviation, final UnitSystem unitSystem)
188     {
189         this(forceUnit, lengthUnit, durationUnit, name, abbreviation, unitSystem, false);
190     }
191 
192     /**
193      * Build a PowerUnit with a conversion factor to another PowerUnit.
194      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
195      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
196      *            otherwise the abbreviation itself
197      * @param unitSystem the unit system, e.g. SI or Imperial
198      * @param referenceUnit the unit to convert to
199      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
200      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
201      */
202     private PowerUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
203             final PowerUnit referenceUnit, final double scaleFactorToReferenceUnit, final boolean standardUnit)
204     {
205         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
206                 standardUnit);
207         this.massUnit = referenceUnit.getMassUnit();
208         this.lengthUnit = referenceUnit.getLengthUnit();
209         this.durationUnit = referenceUnit.getDurationUnit();
210     }
211 
212     /**
213      * Build a user-defined PowerUnit with a conversion factor to another PowerUnit.
214      * @param name the long name of the unit
215      * @param abbreviation the abbreviation of the unit
216      * @param unitSystem the unit system, e.g. SI or Imperial
217      * @param referenceUnit the unit to convert to
218      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
219      */
220     public PowerUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final PowerUnit referenceUnit,
221             final double scaleFactorToReferenceUnit)
222     {
223         this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
224     }
225 
226     /**
227      * @return massUnit
228      */
229     public final MassUnit getMassUnit()
230     {
231         return this.massUnit;
232     }
233 
234     /**
235      * @return lengthUnit
236      */
237     public final LengthUnit getLengthUnit()
238     {
239         return this.lengthUnit;
240     }
241 
242     /**
243      * @return durationUnit
244      */
245     public final DurationUnit getDurationUnit()
246     {
247         return this.durationUnit;
248     }
249 
250     /** {@inheritDoc} */
251     @Override
252     public final PowerUnit getStandardUnit()
253     {
254         return WATT;
255     }
256 
257     /** {@inheritDoc} */
258     @Override
259     public final String getSICoefficientsString()
260     {
261         return "kgm2/s3";
262     }
263 
264 }