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-01-18 00:35:01 +0100 (Fri, 18 Jan 2019) $, @version $Revision: 324 $, 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 MassUnit; the unit of mass for the power unit, e.g., kilogram
120      * @param lengthUnit LengthUnit; the unit of length for the power unit, e.g., meter
121      * @param durationUnit DurationUnit; the unit of time for the power unit, e.g., second
122      * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
123      *            name itself
124      * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
125      *            unit, otherwise the abbreviation itself
126      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
127      * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
128      *            unit
129      */
130     private PowerUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit,
131             final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
132             final boolean standardUnit)
133     {
134         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, WATT, massUnit.getScaleFactor()
135                 * lengthUnit.getScaleFactor() * lengthUnit.getScaleFactor() / Math.pow(durationUnit.getScaleFactor(), 3.0),
136                 standardUnit);
137         this.massUnit = massUnit;
138         this.lengthUnit = lengthUnit;
139         this.durationUnit = durationUnit;
140     }
141 
142     /**
143      * Define a user-defined PowerUnit based on its constituent base units, e.g. a W = km.m^2/s^3.
144      * @param massUnit MassUnit; the unit of mass for the power unit, e.g., kilogram
145      * @param lengthUnit LengthUnit; the unit of length for the power unit, e.g., meter
146      * @param durationUnit DurationUnit; the unit of time for the power unit, e.g., second
147      * @param name String; the long name of the unit
148      * @param abbreviation String; the abbreviation of the unit otherwise the abbreviation itself
149      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
150      */
151     public PowerUnit(final MassUnit massUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit, final String name,
152             final String abbreviation, final UnitSystem unitSystem)
153     {
154         this(massUnit, lengthUnit, durationUnit, name, abbreviation, unitSystem, false);
155     }
156 
157     /**
158      * Define an PowerUnit based on a LengthUnit, a ForceUnit, and a TimeUnit, e.g. a W = N.m/s.
159      * @param forceUnit ForceUnit; the unit of force for the power unit, e.g., Newton
160      * @param lengthUnit LengthUnit; the unit of length for the power unit, e.g., meter
161      * @param durationUnit DurationUnit; the unit of time for the power unit, e.g., second
162      * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
163      *            name itself
164      * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
165      *            unit, otherwise the abbreviation itself
166      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
167      * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
168      *            unit
169      */
170     private PowerUnit(final ForceUnit forceUnit, final LengthUnit lengthUnit, final DurationUnit durationUnit,
171             final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
172             final boolean standardUnit)
173     {
174         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, WATT,
175                 lengthUnit.getScaleFactor() * forceUnit.getScaleFactor() / durationUnit.getScaleFactor(), standardUnit);
176         this.massUnit = forceUnit.getMassUnit();
177         this.lengthUnit = forceUnit.getLengthUnit();
178         this.durationUnit = forceUnit.getDurationUnit();
179     }
180 
181     /**
182      * Define a user-defined PowerUnit based on a LengthUnit, a ForceUnit, and a TimeUnit, e.g. a W = N.m/s.
183      * @param lengthUnit LengthUnit; the unit of length for the power unit, e.g., meter
184      * @param forceUnit ForceUnit; the unit of force for the power unit, e.g., Newton
185      * @param durationUnit DurationUnit; the unit of time for the power unit, e.g., second
186      * @param name String; the long name of the unit
187      * @param abbreviation String; the abbreviation of the unit otherwise the abbreviation itself
188      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
189      */
190     public PowerUnit(final LengthUnit lengthUnit, final ForceUnit forceUnit, final DurationUnit durationUnit, final String name,
191             final String abbreviation, final UnitSystem unitSystem)
192     {
193         this(forceUnit, lengthUnit, durationUnit, name, abbreviation, unitSystem, false);
194     }
195 
196     /**
197      * Build a PowerUnit with a conversion factor to another PowerUnit.
198      * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
199      *            name itself
200      * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
201      *            unit, otherwise the abbreviation itself
202      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
203      * @param referenceUnit PowerUnit; the unit to convert to
204      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
205      *            unit
206      * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
207      *            unit
208      */
209     private PowerUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
210             final PowerUnit referenceUnit, final double scaleFactorToReferenceUnit, final boolean standardUnit)
211     {
212         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
213                 standardUnit);
214         this.massUnit = referenceUnit.getMassUnit();
215         this.lengthUnit = referenceUnit.getLengthUnit();
216         this.durationUnit = referenceUnit.getDurationUnit();
217     }
218 
219     /**
220      * Build a user-defined PowerUnit with a conversion factor to another PowerUnit.
221      * @param name String; the long name of the unit
222      * @param abbreviation String; the abbreviation of the unit
223      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
224      * @param referenceUnit PowerUnit; the unit to convert to
225      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
226      *            unit
227      */
228     public PowerUnit(final String name, final String abbreviation, final UnitSystem unitSystem, final PowerUnit referenceUnit,
229             final double scaleFactorToReferenceUnit)
230     {
231         this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
232     }
233 
234     /**
235      * @return massUnit
236      */
237     public final MassUnit getMassUnit()
238     {
239         return this.massUnit;
240     }
241 
242     /**
243      * @return lengthUnit
244      */
245     public final LengthUnit getLengthUnit()
246     {
247         return this.lengthUnit;
248     }
249 
250     /**
251      * @return durationUnit
252      */
253     public final DurationUnit getDurationUnit()
254     {
255         return this.durationUnit;
256     }
257 
258     /** {@inheritDoc} */
259     @Override
260     public final PowerUnit getStandardUnit()
261     {
262         return WATT;
263     }
264 
265     /** {@inheritDoc} */
266     @Override
267     public final String getSICoefficientsString()
268     {
269         return "kgm2/s3";
270     }
271 
272 }