Skip to content

Commit

Permalink
Merge pull request #327 from crystal-growth/add_electric_dipole_moment
Browse files Browse the repository at this point in the history
Add Electric Dipole and Quadrupole Moment quantities with related units and tests.
  • Loading branch information
iliekturtles authored Oct 26, 2022
2 parents 8a90b2e + 0333417 commit d8a3328
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/si/electric_charge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ mod tests {
test::<i::atomic_unit_of_charge_per_second, t::second, q::atomic_unit_of_charge>();
test::<i::ampere, t::hour, q::ampere_hour>();
test::<i::abampere, t::second, q::abcoulomb>();
test::<i::elementary_charge_per_second, t::second, q::elementary_charge>();
test::<i::statampere, t::second, q::statcoulomb>();

fn test<I: i::Conversion<V>, T: t::Conversion<V>, Q: q::Conversion<V>>() {
Expand Down
62 changes: 62 additions & 0 deletions src/si/electric_dipole_moment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//! Electric dipole moment (base unit coulomb meter, m · s · A).
quantity! {
/// Electric dipole moment (base unit coulomb meter, m · s · A).
quantity: ElectricDipoleMoment; "electric dipole moment";
/// Dimension of electric dipole moment, LTI (base unit coulomb meter, m · s · A).
dimension: ISQ<
P1, // length
Z0, // mass
P1, // time
P1, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
units {
@coulomb_meter: prefix!(none); "C · m", "coulomb meter", "coulomb meters";

@atomic_unit_of_charge_centimeter: 1.602_176_634_E-19 * prefix!(centi);
"a.u. of charge · cm", "atomic unit of charge centimeter",
"atomic unit of charge centimeters";
@elementary_charge_centimeter: 1.602_176_634_E-19 * prefix!(centi); "e · cm",
"elementary charge centimeter", "elementary charge centimeters";
@debye: 1.0 / 299_792_458.0 * 1.0_E-21; "D", "debye", "debyes";
/// Hartree unit of electric dipole moment e·a₀, where e is elementary charge and a₀ is Bohr
/// radius.
@atomic_unit_of_electric_dipole_moment: 8.478_353_625_540_766_E-30; "e · a₀",
"atomic unit of electric dipole moment", "atomic units of electric dipole moment";
}
}

#[cfg(test)]
mod test {
storage_types! {
use crate::num::One;
use crate::si::electric_dipole_moment as edm;
use crate::si::electric_charge as ec;
use crate::si::length as l;
use crate::si::quantities::*;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: ElectricDipoleMoment<V> = ElectricCharge::new::<ec::coulomb>(V::one())
* Length::new::<l::meter>(V::one());
}

#[test]
fn check_units() {
test::<ec::coulomb, l::meter, edm::coulomb_meter>();
test::<ec::statcoulomb, l::angstrom, edm::debye>();
test::<ec::elementary_charge, l::centimeter, edm::elementary_charge_centimeter>();
test::<ec::elementary_charge, l::centimeter, edm::atomic_unit_of_charge_centimeter>();
test::<ec::elementary_charge, l::bohr_radius,
edm::atomic_unit_of_electric_dipole_moment>();

fn test<EC: ec::Conversion<V>, L: l::Conversion<V>, EDM: edm::Conversion<V>>() {
Test::assert_approx_eq(&ElectricDipoleMoment::new::<EDM>(V::one()),
&(ElectricCharge::new::<EC>(V::one()) * Length::new::<L>(V::one())));
}
}
}
}
67 changes: 67 additions & 0 deletions src/si/electric_quadrupole_moment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//! Electric quadrupole moment (base unit coulomb square meter, m² · s · A).
quantity! {
/// Electric quadrupole moment (base unit coulomb square meter, m² · s · A).
quantity: ElectricQuadrupoleMoment; "electric quadrupole moment";
/// Dimension of electric quadrupole moment, LTI (base unit coulomb square meter, m² · s · A).
dimension: ISQ<
P2, // length
Z0, // mass
P1, // time
P1, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
units {
@coulomb_square_meter: prefix!(none); "C · m²", "coulomb square meter",
"coulomb square meters";
@elementary_charge_barn: 1.602_176_634_E-19 * 1.0_E-28; "e · b", "elementary charge barn",
"elementary charge barns";
/// Hartree unit of electric quadrupole moment e · a₀², where e is elementary charge and a₀
/// is Bohr radius.
@atomic_unit_of_electric_quadrupole_moment: 4.486_551_524_613_E-40; "e · a₀²",
"atomic unit of electric quadrupole moment",
"atomic units of electric quadrupole moment";
}
}

#[cfg(test)]
mod test {
storage_types! {
use crate::num::One;
use crate::si::electric_quadrupole_moment as edm;
use crate::si::electric_charge as ec;
use crate::si::area as a;
use crate::si::length as l;
use crate::si::quantities::*;
use crate::tests::Test;

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

#[test]
fn check_units() {
test::<ec::coulomb, a::square_meter, edm::coulomb_square_meter>();
test::<ec::elementary_charge, a::barn, edm::elementary_charge_barn>();

fn test<EC: ec::Conversion<V>, A: a::Conversion<V>, EDM: edm::Conversion<V>>() {
Test::assert_approx_eq(&ElectricQuadrupoleMoment::new::<EDM>(V::one()),
&(ElectricCharge::new::<EC>(V::one()) * Area::new::<A>(V::one())));
}
}

#[test]
fn check_units_charge_length() {
test::<ec::elementary_charge, l::bohr_radius, edm::elementary_charge_barn>();

fn test<EC: ec::Conversion<V>, L: l::Conversion<V>, EDM: edm::Conversion<V>>() {
Test::assert_approx_eq(&ElectricQuadrupoleMoment::new::<EDM>(V::one()),
&(ElectricCharge::new::<EC>(V::one()) * Length::new::<L>(V::one())
* Length::new::<L>(V::one())));
}
}
}
}
2 changes: 2 additions & 0 deletions src/si/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ system! {
electric_charge_linear_density::ElectricChargeLinearDensity,
electric_charge_volumetric_density::ElectricChargeVolumetricDensity,
electric_current::ElectricCurrent,
electric_dipole_moment::ElectricDipoleMoment,
electric_displacement_field::ElectricDisplacementField,
electric_field::ElectricField,
electric_flux::ElectricFlux,
electric_permittivity::ElectricPermittivity,
electric_potential::ElectricPotential,
electric_quadrupole_moment::ElectricQuadrupoleMoment,
electrical_conductance::ElectricalConductance,
electrical_conductivity::ElectricalConductivity,
electrical_resistance::ElectricalResistance,
Expand Down

0 comments on commit d8a3328

Please sign in to comment.