Skip to content

Commit

Permalink
Add Electric Field quantity with corresponding units and test.
Browse files Browse the repository at this point in the history
  • Loading branch information
crystal-growth committed Aug 3, 2022
1 parent 2809d31 commit 9dd292d
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
75 changes: 75 additions & 0 deletions src/si/electric_field.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//! 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";

// Eₕ / (e ⋅ a₀)
@atomic_unit_of_electric_field: 5.142_206_747_63_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::length as l;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: ElectricField<V> = ElectricPotential::new::<ep::volt>(V::one())
/ Length::new::<l::meter>(V::one());
}

#[test]
fn check_units() {
test::<ef::volt_per_meter, l::meter, ep::volt>();
test::<ef::volt_per_centimeter, l::centimeter, ep::volt>();
test::<ef::volt_per_millimeter, l::millimeter, ep::volt>();
test::<ef::volt_per_micrometer, l::micrometer, ep::volt>();
test::<ef::kilovolt_per_millimeter, l::millimeter, ep::kilovolt>();
test::<ef::megavolt_per_centimeter, l::centimeter, ep::megavolt>();
test::<ef::megavolt_per_meter, l::meter, ep::megavolt>();

test::<ef::volt_per_mil, l::mil, ep::volt>();


fn test<EF: ef::Conversion<V>, L: l::Conversion<V>, EP: ep::Conversion<V>>() {
Test::assert_approx_eq(&ElectricField::new::<EF>(V::one()),
&(ElectricPotential::new::<EP>(V::one())
/ Length::new::<L>(V::one())));
}
}
}
}
1 change: 1 addition & 0 deletions src/si/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ system! {
curvature::Curvature,
electric_charge::ElectricCharge,
electric_current::ElectricCurrent,
electric_field::ElectricField,
electric_potential::ElectricPotential,
electrical_conductance::ElectricalConductance,
electrical_resistance::ElectricalResistance,
Expand Down

0 comments on commit 9dd292d

Please sign in to comment.