Skip to main content

uom/si/
power.rs

1//! Power (base unit watt, m² · kg · s⁻³).
2
3quantity! {
4    /// Power (base unit watt, m² · kg · s⁻³).
5    quantity: Power; "power";
6    /// Dimension of power, L²MT⁻³ (base unit watt, m² · kg · s⁻³).
7    dimension: ISQ<
8        P2,     // length
9        P1,     // mass
10        N3,     // time
11        Z0,     // electric current
12        Z0,     // thermodynamic temperature
13        Z0,     // amount of substance
14        Z0>;    // luminous intensity
15    units {
16        @yottawatt: prefix!(yotta); "YW", "yottawatt", "yottawatts";
17        @zettawatt: prefix!(zetta); "ZW", "zettawatt", "zettawatts";
18        @exawatt: prefix!(exa); "EW", "exawatt", "exawatts";
19        @petawatt: prefix!(peta); "PW", "petawatt", "petawatts";
20        @terawatt: prefix!(tera); "TW", "terawatt", "terawatts";
21        @gigawatt: prefix!(giga); "GW", "gigawatt", "gigawatts";
22        @megawatt: prefix!(mega); "MW", "megawatt", "megawatts";
23        @kilowatt: prefix!(kilo); "kW", "kilowatt", "kilowatts";
24        @hectowatt: prefix!(hecto); "hW", "hectowatt", "hectowatts";
25        @decawatt: prefix!(deca); "daW", "decawatt", "decawatts";
26        /// Derived unit of power.
27        @watt: prefix!(none); "W", "watt", "watts";
28        @deciwatt: prefix!(deci); "dW", "deciwatt", "deciwatts";
29        @centiwatt: prefix!(centi); "cW", "centiwatt", "centiwatts";
30        @milliwatt: prefix!(milli); "mW", "milliwatt", "milliwatts";
31        @microwatt: prefix!(micro); "µW", "microwatt", "microwatts";
32        @nanowatt: prefix!(nano); "nW", "nanowatt", "nanowatts";
33        @picowatt: prefix!(pico); "pW", "picowatt", "picowatts";
34        @femtowatt: prefix!(femto); "fW", "femtowatt", "femtowatts";
35        @attowatt: prefix!(atto); "aW", "attowatt", "attowatts";
36        @zeptowatt: prefix!(zepto); "zW", "zeptowatt", "zeptowatts";
37        @yoctowatt: prefix!(yocto); "yW", "yoctowatt", "yoctowatts";
38
39        @erg_per_second: 1.0_E-7; "erg/s", "erg per second", "ergs per second";
40        @foot_pound_per_hour: 3.766_161_111_111_111_E-4; "ft · lbf/h", "foot pound-force per hour",
41            "foot pounds-force per hour";
42        @foot_pound_per_minute: 2.259_696_666_666_666_6_E-2; "ft · lbf/min",
43            "foot pound-force per minute", "foot pounds-force per minute";
44        @foot_pound_per_second: 1.355_818; "ft · lbf/s", "foot pound-force per second",
45            "foot pounds-force per second";
46        @horsepower: 7.456_999_E2; "hp", "horsepower", "horsepower";
47        @horsepower_boiler: 9.809_50_E3; "hp (S)", "horsepower (boiler)",
48            "horsepower (boiler)";
49        @horsepower_electric: 7.46_E2; "hp (E)", "horsepower (electric)",
50            "horsepower (electric)";
51        @horsepower_metric: 7.354_988_E2; "hp (M)", "metric horsepower", "metric horsepower";
52        @horsepower_imperial: 7.457_0_E2; "hp (I)", "horsepower (Imperial)",
53            "horsepower (Imperial)";
54        @hydraulic_horsepower: 7.460_43_E2; "hp (hydraulic)", "hydraulic horsepower",
55            "hydraulic horsepower";
56    }
57}
58
59#[cfg(test)]
60mod tests {
61    storage_types! {
62        use crate::num::One;
63        use crate::si::energy as e;
64        use crate::si::power as p;
65        use crate::si::quantities::*;
66        use crate::si::time as t;
67        use crate::tests::Test;
68
69        #[test]
70        fn check_dimension() {
71            let _: Power<V> =  Energy::new::<e::joule>(V::one())
72                / Time::new::<t::second>(V::one());
73        }
74
75        #[test]
76        fn check_units() {
77            test::<e::zettajoule, t::second, p::zettawatt>();
78            test::<e::exajoule, t::second, p::exawatt>();
79            test::<e::petajoule, t::second, p::petawatt>();
80            test::<e::terajoule, t::second, p::terawatt>();
81            test::<e::gigajoule, t::second, p::gigawatt>();
82            test::<e::megajoule, t::second, p::megawatt>();
83            test::<e::kilojoule, t::second, p::kilowatt>();
84            test::<e::joule, t::second, p::watt>();
85            test::<e::centijoule, t::second, p::centiwatt>();
86            test::<e::millijoule, t::second, p::milliwatt>();
87            test::<e::microjoule, t::second, p::microwatt>();
88            test::<e::nanojoule, t::second, p::nanowatt>();
89            test::<e::picojoule, t::second, p::picowatt>();
90            test::<e::femtojoule, t::second, p::femtowatt>();
91            test::<e::attojoule, t::second, p::attowatt>();
92            test::<e::zeptojoule, t::second, p::zeptowatt>();
93            test::<e::yoctojoule, t::second, p::yoctowatt>();
94
95            test::<e::erg, t::second, p::erg_per_second>();
96            test::<e::foot_pound, t::hour, p::foot_pound_per_hour>();
97            test::<e::foot_pound, t::minute, p::foot_pound_per_minute>();
98            test::<e::foot_pound, t::second, p::foot_pound_per_second>();
99
100            fn test<E: e::Conversion<V>, T: t::Conversion<V>, P: p::Conversion<V>>() {
101                Test::assert_approx_eq(&Power::new::<P>(V::one()),
102                    &(Energy::new::<E>(V::one()) / Time::new::<T>(V::one())));
103            }
104        }
105    }
106}