Skip to content

Commit

Permalink
Add ElectricDisplacementField with related units.
Browse files Browse the repository at this point in the history
  • Loading branch information
crystal-growth authored and iliekturtles committed Sep 3, 2022
1 parent d4bdcd9 commit 2d6d500
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/si/electric_displacement_field.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//! Electric displacement field (base unit coulomb per square meter, m⁻² · A · s).
quantity! {
///Electric displacement field (base unit coulomb per square meter, m⁻² · A · s).
quantity: ElectricDisplacementField; "electric displacement field";
/// Dimension of electric displacement field, L⁻²TI (base unit coulomb per square meter,
/// m⁻² · A · s).
dimension: ISQ<
N2, // length
Z0, // mass
P1, // time
P1, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
units {
@coulomb_per_square_meter: prefix!(none); "C/m²", "coulomb per square meter",
"coulombs per square meter";
@coulomb_per_square_centimeter: prefix!(none) / prefix!(centi) / prefix!(centi); "C/cm²",
"coulomb per square centimeter", "coulombs per square centimeter";
}
}

#[cfg(test)]
mod tests {
storage_types! {
use crate::num::One;
use crate::si::electric_charge as q;
use crate::si::electric_displacement_field as d;
use crate::si::quantities::*;
use crate::si::area as a;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: ElectricDisplacementField<V> = ElectricCharge::new::<q::coulomb>(V::one())
/ Area::new::<a::square_meter>(V::one());
}

#[test]
fn check_units() {
test::<q::coulomb, a::square_meter, d::coulomb_per_square_meter>();
test::<q::coulomb, a::square_centimeter, d::coulomb_per_square_centimeter>();

fn test<Q: q::Conversion<V>, A: a::Conversion<V>, D: d::Conversion<V>>() {
Test::assert_approx_eq(&ElectricDisplacementField::new::<D>(V::one()),
&(ElectricCharge::new::<Q>(V::one()) / Area::new::<A>(V::one())));
}
}
}
}
1 change: 1 addition & 0 deletions src/si/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ system! {
dynamic_viscosity::DynamicViscosity,
electric_charge::ElectricCharge,
electric_current::ElectricCurrent,
electric_displacement_field::ElectricDisplacementField,
electric_permittivity::ElectricPermittivity,
electric_potential::ElectricPotential,
electrical_conductance::ElectricalConductance,
Expand Down

0 comments on commit 2d6d500

Please sign in to comment.