From f69b217beaad9a1a56bc19f0304b026172fcde1e Mon Sep 17 00:00:00 2001 From: Vlad Voronenkov Date: Fri, 5 Aug 2022 21:34:54 +0200 Subject: [PATCH] Add ElectricCurrentDensity quantity with related units. --- src/si/electric_current_density.rs | 54 ++++++++++++++++++++++++++++++ src/si/mod.rs | 1 + 2 files changed, 55 insertions(+) create mode 100644 src/si/electric_current_density.rs diff --git a/src/si/electric_current_density.rs b/src/si/electric_current_density.rs new file mode 100644 index 00000000..c4ef062a --- /dev/null +++ b/src/si/electric_current_density.rs @@ -0,0 +1,54 @@ +//! Electric current density (base unit ampere per square meter, m⁻² · A). + +quantity! { + /// Electric current density (base unit ampere per square meter, m⁻² · A). + quantity: ElectricCurrentDensity; "electric current density"; + /// Dimension of electric current density, L⁻²I (base unit ampere per square meter, A · m⁻²). + dimension: ISQ< + N2, // length + Z0, // mass + Z0, // time + P1, // electric current + Z0, // thermodynamic temperature + Z0, // amount of substance + Z0>; // luminous intensity + kind: dyn (crate::si::marker::ConstituentConcentrationKind); + units { + @ampere_per_square_meter: prefix!(none); "A/m²", "ampere per square meter", + "amperes per square meter"; + @ampere_per_square_centimeter: prefix!(none) / prefix!(centi) / prefix!(centi); "A/cm²", + "ampere per square centimeter", "amperes per square centimeter"; + @ampere_per_square_millimeter: prefix!(none) / prefix!(milli) / prefix!(milli); "A/mm²", + "ampere per square millimeter", "amperes per square millimeter"; + } +} + +#[cfg(test)] +mod tests { + storage_types! { + use crate::num::One; + use crate::si::area as a; + use crate::si::electric_current as i; + use crate::si::electric_current_density as ecd; + use crate::si::quantities::*; + use crate::tests::Test; + + #[test] + fn check_dimension() { + let _: ElectricCurrentDensity = (ElectricCurrent::new::(V::one()) + / Area::new::(V::one())).into(); + } + + #[test] + fn check_units() { + test::(); + test::(); + test::(); + + fn test, I: i::Conversion, A: a::Conversion>() { + Test::assert_approx_eq(&ElectricCurrentDensity::new::(V::one()), + &(ElectricCurrent::new::(V::one()) / Area::new::(V::one())).into()); + } + } + } +} diff --git a/src/si/mod.rs b/src/si/mod.rs index 18b09fbb..0254eb7b 100644 --- a/src/si/mod.rs +++ b/src/si/mod.rs @@ -69,6 +69,7 @@ system! { electric_charge_linear_density::ElectricChargeLinearDensity, electric_charge_volumetric_density::ElectricChargeVolumetricDensity, electric_current::ElectricCurrent, + electric_current_density::ElectricCurrentDensity, electric_dipole_moment::ElectricDipoleMoment, electric_displacement_field::ElectricDisplacementField, electric_field::ElectricField,