From 646e05a3e9d5182b7afb41cfb5976f5e697a113b Mon Sep 17 00:00:00 2001 From: Vlad Voronenkov Date: Wed, 3 Aug 2022 17:26:31 +0200 Subject: [PATCH] Add Electric Field quantity with corresponding units and test. --- src/si/electric_field.rs | 89 ++++++++++++++++++++++++++++++++++++++++ src/si/mod.rs | 1 + 2 files changed, 90 insertions(+) create mode 100644 src/si/electric_field.rs diff --git a/src/si/electric_field.rs b/src/si/electric_field.rs new file mode 100644 index 00000000..7e99d4fd --- /dev/null +++ b/src/si/electric_field.rs @@ -0,0 +1,89 @@ +//! Electric field (base unit volt per meter, m ⋅ kg ⋅ s⁻³ ⋅ A⁻¹). + +quantity! { + /// Electric field (base unit volt per meter, m ⋅ kg ⋅ s⁻³ ⋅ A⁻¹). + quantity: ElectricField; "electric field"; + /// Dimension of electric field, LMT⁻³I⁻¹ (base unit volt per meter, m ⋅ kg ⋅ s⁻³ ⋅ A⁻¹). + dimension: ISQ< + P1, // length + P1, // mass + N3, // time + N1, // electric current + Z0, // thermodynamic temperature + Z0, // amount of substance + Z0>; // luminous intensity + units { + @volt_per_meter: prefix!(none); "V/m", "volt per meter", "volts per meter"; + @volt_per_centimeter: prefix!(none) / prefix!(centi); "V/cm", "volt per centimeter", + "volts per centimeter"; + @volt_per_millimeter: prefix!(none) / prefix!(milli); "V/mm", "volt per millimeter", + "volts per millimeter"; + @volt_per_micrometer: prefix!(none) / prefix!(micro); "V/μm", "volt per micrometer", + "volts per micrometer"; + @kilovolt_per_millimeter: prefix!(kilo) / prefix!(milli); "kV/mm", + "kilovolt per millimeter", "kilovolts per millimeter"; + @megavolt_per_meter: prefix!(mega); "MV/m", "megavolt per meter", "megavolts per meter"; + @megavolt_per_centimeter: prefix!(mega) / prefix!(centi); "MV/cm", + "megavolt per centimeter", "megavolts per centimeter"; + @volt_per_mil: prefix!(none) / 2.54_E-5; "V/mil", "volt per mil", "volts per mil"; + + /// Hartree atomic unit of electric field Eₕ / (e ⋅ a₀), where Eₕ is Hartree energy, e is + /// elementary charge, and a₀ is Bohr radius. + @atomic_unit_of_electric_field: 5.142_206_747_632_595_E11; "a.u. of electric field", + "atomic unit of electric field", "atomic units of electric field"; + } +} + +#[cfg(test)] +mod test { + storage_types! { + use crate::num::One; + use crate::si::electric_field as ef; + use crate::si::quantities::*; + use crate::si::electric_potential as ep; + use crate::si::energy as en; + use crate::si::electric_charge as ec; + use crate::si::length as l; + use crate::tests::Test; + + #[test] + fn check_dimension() { + let _: ElectricField = ElectricPotential::new::(V::one()) + / Length::new::(V::one()); + } + + #[test] + fn check_units() { + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + test::(); + + fn test, L: l::Conversion, EF: ef::Conversion>() { + Test::assert_approx_eq(&ElectricField::new::(V::one()), + &(ElectricPotential::new::(V::one()) + / Length::new::(V::one()))); + } + } + + #[test] + fn check_units_eql() { + test::(); + test::(); + + fn test, Q: ec::Conversion, L: l::Conversion, + EF: ef::Conversion>() + { + Test::assert_approx_eq(&ElectricField::new::(V::one()), + &(Energy::new::(V::one()) + / ElectricCharge::new::(V::one()) + / Length::new::(V::one()))); + } + } + } +} diff --git a/src/si/mod.rs b/src/si/mod.rs index d7783a5c..1ae0f6bc 100644 --- a/src/si/mod.rs +++ b/src/si/mod.rs @@ -70,6 +70,7 @@ system! { electric_charge_volumetric_density::ElectricChargeVolumetricDensity, electric_current::ElectricCurrent, electric_displacement_field::ElectricDisplacementField, + electric_field::ElectricField, electric_flux::ElectricFlux, electric_permittivity::ElectricPermittivity, electric_potential::ElectricPotential,