View Javadoc
1   package org.djunits.unit;
2   
3   import org.djunits.quantity.Quantity;
4   import org.djunits.unit.scale.IdentityScale;
5   import org.djunits.unit.si.SIPrefixes;
6   import org.djunits.unit.unitsystem.UnitSystem;
7   
8   /**
9    * The units of power.
10   * <p>
11   * Copyright (c) 2015-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
13   * </p>
14   * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a>
15   */
16  public class PowerUnit extends Unit<PowerUnit>
17  {
18      /** */
19      private static final long serialVersionUID = 20140607L;
20  
21      /** The base, with "kgm2/s3" as the SI signature. */
22      public static final Quantity<PowerUnit> BASE = new Quantity<>("Power", "kgm2/s3");
23  
24      /** The SI unit for power is watt. */
25      public static final PowerUnit SI =
26              new PowerUnit().build(new Unit.Builder<PowerUnit>().setQuantity(BASE).setId("W").setName("watt")
27                      .setUnitSystem(UnitSystem.SI_DERIVED).setSiPrefixes(SIPrefixes.UNIT, 1.0).setScale(IdentityScale.SCALE));
28  
29      /** watt. */
30      public static final PowerUnit WATT = SI;
31  
32      /** microwatt. */
33      public static final PowerUnit MICROWATT = WATT.deriveSI(SIPrefixes.getUnit("mu"), 1.0);
34  
35      /** milliwatt. */
36      public static final PowerUnit MILLIWATT = WATT.deriveSI(SIPrefixes.getUnit("m"), 1.0);
37  
38      /** kiloawatt. */
39      public static final PowerUnit KILOWATT = WATT.deriveSI(SIPrefixes.getUnit("k"), 1.0);
40  
41      /** megawatt. */
42      public static final PowerUnit MEGAWATT = WATT.deriveSI(SIPrefixes.getUnit("M"), 1.0);
43  
44      /** gigawatt. */
45      public static final PowerUnit GIGAWATT = WATT.deriveSI(SIPrefixes.getUnit("G"), 1.0);
46  
47      /** terawatt. */
48      public static final PowerUnit TERAWATT = WATT.deriveSI(SIPrefixes.getUnit("T"), 1.0);
49  
50      /** petawatt. */
51      public static final PowerUnit PETAWATT = WATT.deriveSI(SIPrefixes.getUnit("P"), 1.0);
52  
53      /** foot-pound-force per hour. */
54      public static final PowerUnit FOOT_POUND_FORCE_PER_HOUR =
55              SI.deriveLinear(factorED(EnergyUnit.FOOT_POUND_FORCE, DurationUnit.HOUR), "ft.lbf/h", "foot pound-force per hour",
56                      UnitSystem.IMPERIAL);
57  
58      /** foot-pound-force per minute. */
59      public static final PowerUnit FOOT_POUND_FORCE_PER_MINUTE =
60              SI.deriveLinear(factorED(EnergyUnit.FOOT_POUND_FORCE, DurationUnit.MINUTE), "ft.lbf/min",
61                      "foot pound-force per minute", UnitSystem.IMPERIAL);
62  
63      /** foot-pound-force per second. */
64      public static final PowerUnit FOOT_POUND_FORCE_PER_SECOND =
65              SI.deriveLinear(factorED(EnergyUnit.FOOT_POUND_FORCE, DurationUnit.SECOND), "ft.lbf/s",
66                      "foot pound-force per second", UnitSystem.IMPERIAL);
67  
68      /** horsepower (metric). */
69      public static final PowerUnit HORSEPOWER_METRIC =
70              WATT.deriveLinear(735.49875, "hp(M)", "horsepower (metric)", UnitSystem.OTHER);
71  
72      /** sthene-meter per second. */
73      public static final PowerUnit STHENE_METER_PER_SECOND = SI.deriveLinear(
74              factorED(EnergyUnit.STHENE_METER, DurationUnit.SECOND), "sn.m/s", "sthene-meter per second", UnitSystem.MTS);
75  
76      /** erg per second. */
77      public static final PowerUnit ERG_PER_SECOND =
78              SI.deriveLinear(factorED(EnergyUnit.ERG, DurationUnit.SECOND), "erg/s", "erg per second", UnitSystem.CGS);
79  
80      /**
81       * Determine the conversion factor to the base power unit, given an energy unit and a duration unit.
82       * @param energy EnergyUnit; the used energy unit, e.g. erg
83       * @param duration DurationUnit; the used duration unit, e.g. s
84       * @return double; the conversion factor from the provided units (e.g. erg/s) to the standard unit (e.g., W)
85       */
86      private static double factorED(final EnergyUnit energy, final DurationUnit duration)
87      {
88          return energy.getScale().toStandardUnit(1.0) / duration.getScale().toStandardUnit(1.0);
89      }
90  
91  }