-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #327 from crystal-growth/add_electric_dipole_moment
Add Electric Dipole and Quadrupole Moment quantities with related units and tests.
- Loading branch information
Showing
4 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()))); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()))); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters