Skip to content

Commit

Permalink
Merge pull request #355 from crystal-growth/add_density_of_states
Browse files Browse the repository at this point in the history
Add volumetric, areal, and linear densities of states.
  • Loading branch information
iliekturtles authored Oct 28, 2022
2 parents 15b1faa + b08131c commit 997dde0
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/si/areal_density_of_states.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//! Areal density of states (base unit 1 / square meter joule, kg⁻¹ · m⁻⁴ · s²).
quantity! {
/// Areal density of states (base unit 1 / square meter joule, kg⁻¹ · m⁻⁴ · s²).
quantity: ArealDensityOfStates; "areal density of states";
/// Dimension of areal density of states, L⁻⁴M⁻¹T² (base unit 1 / square meter joule, kg⁻¹ · m⁻⁴ · s²).
dimension: ISQ<
N4, // length
N1, // mass
P2, // time
Z0, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
kind: dyn (crate::si::marker::ConstituentConcentrationKind);
units {
@state_per_square_meter_joule: prefix!(none); "1/(m² · J)", "state per square meter joule",
"states per square meter joule";
@state_per_square_centimeter_joule: prefix!(none) / prefix!(centi) / prefix!(centi);
"1/(cm² · J)", "state per square centimeter joule",
"states per square centimeter joule";
@state_per_square_centimeter_electronvolt:
prefix!(none) / prefix!(centi) / prefix!(centi) / 1.602_176_634_E-19; "1/(cm² · eV)",
"state per square centimeter electronvolt", "states per square centimeter electronvolt";
}
}

#[cfg(test)]
mod test {
storage_types! {
use crate::num::One;
use crate::si::areal_density_of_states as ados;
use crate::si::energy as e;
use crate::si::quantities::*;
use crate::si::area as a;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: ArealDensityOfStates<V> = (V::one()
/ Energy::new::<e::joule>(V::one())
/ Area::new::<a::square_meter>(V::one())).into();
}

#[test]
fn check_units() {
test::<a::square_meter, e::joule, ados::state_per_square_meter_joule>();
test::<a::square_centimeter, e::joule, ados::state_per_square_centimeter_joule>();
test::<a::square_centimeter, e::electronvolt, ados::state_per_square_centimeter_electronvolt>();

fn test<A: a::Conversion<V>, E: e::Conversion<V>, ADOS: ados::Conversion<V>>() {
Test::assert_approx_eq(&ArealDensityOfStates::new::<ADOS>(V::one()),
&(V::one()
/ Energy::new::<E>(V::one())
/ Area::new::<A>(V::one())).into());
}
}
}
}
59 changes: 59 additions & 0 deletions src/si/linear_density_of_states.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//! Linear density of states (base unit 1 / meter joule, kg⁻¹ · m⁻³ · s²).
quantity! {
/// Linear density of states (base unit 1 / meter joule, kg⁻¹ · m⁻³ · s²).
quantity: LinearDensityOfStates; "linear density of states";
/// Dimension of linear density of states, L⁻³M⁻¹T² (base unit 1 / meter joule,
/// kg⁻¹ · m⁻³ · s²).
dimension: ISQ<
N3, // length
N1, // mass
P2, // time
Z0, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
kind: dyn (crate::si::marker::ConstituentConcentrationKind);
units {
@state_per_meter_joule: prefix!(none); "1/(m · J)", "state per meter joule",
"states per meter joule";
@state_per_centimeter_joule: prefix!(none) / prefix!(centi); "1/(cm · J)",
"state per centimeter joule", "states per centimeter joule";
@state_per_centimeter_electronvolt: prefix!(none) / prefix!(centi) / 1.602_176_634_E-19;
"1/(cm · eV)", "state per centimeter electronvolt",
"states per centimeter electronvolt";
}
}

#[cfg(test)]
mod test {
storage_types! {
use crate::num::One;
use crate::si::linear_density_of_states as ldos;
use crate::si::energy as e;
use crate::si::quantities::*;
use crate::si::length as l;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: LinearDensityOfStates<V> = (V::one()
/ Energy::new::<e::joule>(V::one())
/ Length::new::<l::meter>(V::one())).into();
}

#[test]
fn check_units() {
test::<l::meter, e::joule, ldos::state_per_meter_joule>();
test::<l::centimeter, e::joule, ldos::state_per_centimeter_joule>();
test::<l::centimeter, e::electronvolt, ldos::state_per_centimeter_electronvolt>();

fn test<L: l::Conversion<V>, E: e::Conversion<V>, LDOS: ldos::Conversion<V>>() {
Test::assert_approx_eq(&LinearDensityOfStates::new::<LDOS>(V::one()),
&(V::one()
/ Energy::new::<E>(V::one())
/ Length::new::<L>(V::one())).into());
}
}
}
}
3 changes: 3 additions & 0 deletions src/si/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ system! {
angular_jerk::AngularJerk,
angular_velocity::AngularVelocity,
area::Area,
areal_density_of_states::ArealDensityOfStates,
areal_mass_density::ArealMassDensity,
areal_number_density::ArealNumberDensity,
areal_number_rate::ArealNumberRate,
Expand Down Expand Up @@ -94,6 +95,7 @@ system! {
information_rate::InformationRate,
jerk::Jerk,
length::Length,
linear_density_of_states::LinearDensityOfStates,
linear_mass_density::LinearMassDensity,
linear_number_density::LinearNumberDensity,
linear_number_rate::LinearNumberRate,
Expand Down Expand Up @@ -137,6 +139,7 @@ system! {
velocity::Velocity,
volume::Volume,
volume_rate::VolumeRate,
volumetric_density_of_states::VolumetricDensityOfStates,
volumetric_number_density::VolumetricNumberDensity,
volumetric_number_rate::VolumetricNumberRate,
volumetric_power_density::VolumetricPowerDensity,
Expand Down
62 changes: 62 additions & 0 deletions src/si/volumetric_density_of_states.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//! Volumetric density of states (base unit 1 / cubic meter joule, kg⁻¹ · m⁻⁵ · s²).
quantity! {
/// Volumetric density of states (base unit 1 / cubic meter joule, kg⁻¹ · m⁻⁵ · s²).
quantity: VolumetricDensityOfStates; "volumetric density of states";
/// Dimension of volumetric density of states, L⁻⁵M⁻¹T² (base unit 1 / cubic meter joule,
/// kg⁻¹ · m⁻⁵ · s²).
dimension: ISQ<
N5, // length
N1, // mass
P2, // time
Z0, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
kind: dyn (crate::si::marker::ConstituentConcentrationKind);
units {
@state_per_cubic_meter_joule: prefix!(none); "1/(m³ · J)",
"state per cubic meter joule", "states per cubic meter joule";
@state_per_cubic_centimeter_joule:
prefix!(none) / prefix!(centi) / prefix!(centi) / prefix!(centi); "1/(cm³ · J)",
"state per cubic centimeter joule", "states per cubic centimeter joule";
@state_per_cubic_centimeter_electronvolt:
prefix!(none) / prefix!(centi) / prefix!(centi) / prefix!(centi) / 1.602_176_634_E-19;
"1/(cm³ · eV)", "state per cubic centimeter electronvolt",
"states per cubic centimeter electronvolt";
}
}

#[cfg(test)]
mod test {
storage_types! {
use crate::num::One;
use crate::si::volumetric_density_of_states as vdos;
use crate::si::energy as e;
use crate::si::quantities::*;
use crate::si::volume as v;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: VolumetricDensityOfStates<V> = (V::one()
/ Energy::new::<e::joule>(V::one())
/ Volume::new::<v::cubic_meter>(V::one())).into();
}

#[test]
fn check_units() {
test::<v::cubic_meter, e::joule, vdos::state_per_cubic_meter_joule>();
test::<v::cubic_centimeter, e::joule, vdos::state_per_cubic_centimeter_joule>();
test::<v::cubic_centimeter, e::electronvolt,
vdos::state_per_cubic_centimeter_electronvolt>();

fn test<U: v::Conversion<V>, E: e::Conversion<V>, VDOS: vdos::Conversion<V>>() {
Test::assert_approx_eq(&VolumetricDensityOfStates::new::<VDOS>(V::one()),
&(V::one()
/ Energy::new::<E>(V::one())
/ Volume::new::<U>(V::one())).into());
}
}
}
}

0 comments on commit 997dde0

Please sign in to comment.