Skip to content

Commit

Permalink
Add quantities for homeless constants: Avogadro, Coulomb, Faraday, Gr…
Browse files Browse the repository at this point in the history
…avitation, Stafan-Boltzmann

fix
  • Loading branch information
crystal-growth committed Sep 3, 2022
1 parent 7c4b27b commit 18a0c13
Show file tree
Hide file tree
Showing 6 changed files with 335 additions and 0 deletions.
96 changes: 96 additions & 0 deletions src/si/coulomb_constant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//! Coulomb constant (base unit kilogram cubic meter per second to the fourth power square ampere, kg · m³ · s⁻⁴ · A⁻²).

quantity! {
/// Coulomb constant (base unit kilogram cubic meter per second to the fourth power square ampere, kg · m³ · s⁻⁴ · A⁻²).
quantity: CoulombConstant; "coulomb constant";
/// Dimension of coulomb constant, ML³T⁻⁴I⁻² (base unit kilogram cubic meter per second to the fourth power square ampere, kg · m³ · s⁻⁴ · A⁻²).
dimension: ISQ<
P3, // length
P1, // mass
N4, // time
N2, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
units {
@kilogram_cubic_meter_per_second_to_the_fourth_power_square_ampere: prefix!(none); "kg·m³·s⁻⁴·A⁻²",
"kilogram cubic meter per second to the fourth power square ampere", "kilograms cubic meter per second to the fourth power square ampere";
@meter_per_farad: prefix!(none); "m/F",
"meter per farad", "meters_per_farad";
@coulomb_constant: 8.987_551_792_261_172_E9 ; "kₑ", // Derived from CODATA as 1/(4πε₀)
"coulomb constant", "coulomb constants";
}
}

#[cfg(test)]
mod test {
storage_types! {
use crate::num::One;
use crate::si::electric_current as i;
use crate::si::electric_permittivity as epsilon;

use crate::si::coulomb_constant as ke;
use crate::si::quantities::*;
use crate::si::mass as m;
use crate::si::time as t;
use crate::si::volume as v;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: CoulombConstant<V> = Mass::new::<m::kilogram>(V::one())
* Volume::new::<v::cubic_meter>(V::one())
/ Time::new::<t::second>(V::one())
/ Time::new::<t::second>(V::one())
/ Time::new::<t::second>(V::one())
/ Time::new::<t::second>(V::one())
/ ElectricCurrent::new::<i::ampere>(V::one())
/ ElectricCurrent::new::<i::ampere>(V::one());
}

#[test]
fn check_units() {
test::<m::kilogram, v::cubic_meter, t::second, i::ampere, ke::kilogram_cubic_meter_per_second_to_the_fourth_power_square_ampere>();

fn test<M: m::Conversion<V>, VOL: v::Conversion<V>, T: t::Conversion<V>, I: i::Conversion<V>, KE: ke::Conversion<V>>() {
Test::assert_approx_eq(&CoulombConstant::new::<KE>(V::one()),
&(Mass::new::<M>(V::one())
* Volume::new::<VOL>(V::one())
/ Time::new::<T>(V::one())
/ Time::new::<T>(V::one())
/ Time::new::<T>(V::one())
/ Time::new::<T>(V::one())
/ ElectricCurrent::new::<I>(V::one())
/ ElectricCurrent::new::<I>(V::one())));
}
}

#[test]
fn check_units_farad_meter() {
test::<epsilon::farad_per_meter, ke::kilogram_cubic_meter_per_second_to_the_fourth_power_square_ampere>();
test::<epsilon::farad_per_meter, ke::meter_per_farad>();

fn test<EPS: epsilon::Conversion<V>, KE: ke::Conversion<V>>() {
Test::assert_approx_eq(&CoulombConstant::new::<KE>(V::one()),
&(V::one()
/ ElectricPermittivity::new::<EPS>(V::one())
));
}
}

#[test]
fn check_units_ke() {
test::<epsilon::vacuum_electric_permittivity, ke::coulomb_constant>();

fn test<EPS: epsilon::Conversion<V>, KE: ke::Conversion<V>>() {
Test::assert_approx_eq(&CoulombConstant::new::<KE>(V::one()),
&(

// 1 / (4 · π)
7.957_747_154_594_768_E-2 * V::one() / ElectricPermittivity::new::<EPS>(V::one())
));
}
}

}
}
5 changes: 5 additions & 0 deletions src/si/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ system! {
capacitance::Capacitance,
catalytic_activity::CatalyticActivity,
catalytic_activity_concentration::CatalyticActivityConcentration,
coulomb_constant::CoulombConstant,
curvature::Curvature,
diffusion_coefficient::DiffusionCoefficient,
dynamic_viscosity::DynamicViscosity,
Expand Down Expand Up @@ -103,23 +104,27 @@ system! {
mass_flux::MassFlux,
mass_rate::MassRate,
molar_concentration::MolarConcentration,
molar_electric_charge::MolarElectricCharge,
molar_energy::MolarEnergy,
molar_flux::MolarFlux,
molar_heat_capacity::MolarHeatCapacity,
molar_mass::MolarMass,
molar_volume::MolarVolume,
momentum::Momentum,
newtonian_constant_of_gravitation::NewtonianConstantOfGravitation,
power::Power,
pressure::Pressure,
radiant_exposure::RadiantExposure,
ratio::Ratio,
reciprocal_amount_of_substance::ReciprocalAmountOfSubstance,
solid_angle::SolidAngle,
specific_area::SpecificArea,
specific_heat_capacity::SpecificHeatCapacity,
specific_volume::SpecificVolume,
surface_electric_current_density::SurfaceElectricCurrentDensity,
temperature_coefficient::TemperatureCoefficient,
temperature_gradient::TemperatureGradient,
stefan_boltzmann_constant::StefanBoltzmannConstant,
temperature_interval::TemperatureInterval,
thermal_conductivity::ThermalConductivity,
thermodynamic_temperature::ThermodynamicTemperature,
Expand Down
65 changes: 65 additions & 0 deletions src/si/molar_electric_charge.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//! Molar electric charge (base unit coulomb per mole, s · A · mol⁻¹).

quantity! {
/// Molar electric charge (base unit coulomb per mole, s · A · mol⁻¹).
quantity: MolarElectricCharge; "molar electric charge";
/// Dimension of molar electric charge, TIN⁻¹ (base unit coulomb per mole, s · A · mol⁻¹).
dimension: ISQ<
Z0, // length
Z0, // mass
P1, // time
P1, // electric current
Z0, // thermodynamic temperature
N1, // amount of substance
Z0>; // luminous intensity
units {
@coulomb_per_mole: prefix!(none); "C/mol",
"coulomb per mole", "coulombs per mole";
@faraday_constant: 96_485.332_123_310_03 ; "F", // CODATA value 96_485.332_12
"faraday constant", "faraday constants";

}
}

#[cfg(test)]
mod test {
storage_types! {
use crate::num::One;

use crate::si::amount_of_substance as aos;
use crate::si::quantities::*;
use crate::si::electric_charge as q;
use crate::si::molar_electric_charge as mec;
use crate::si::reciprocal_amount_of_substance as raos;

use crate::tests::Test;

#[test]
fn check_dimension() {
let _: MolarElectricCharge<V> = ElectricCharge::new::<q::coulomb>(V::one())
/ AmountOfSubstance::new::<aos::mole>(V::one());
}

#[test]
fn check_units() {
test::<q::coulomb, aos::mole, mec::coulomb_per_mole>();

fn test<Q: q::Conversion<V>, AOS: aos::Conversion<V>, MEC: mec::Conversion<V>>() {
Test::assert_approx_eq(&MolarElectricCharge::new::<MEC>(V::one()),
&(ElectricCharge::new::<Q>(V::one())
/ AmountOfSubstance::new::<AOS>(V::one())));
}
}

#[test]
fn check_units_na() {
test::<q::elementary_charge, raos::avogadro_constant, mec::faraday_constant>();

fn test<Q: q::Conversion<V>, RAOS: raos::Conversion<V>, MEC: mec::Conversion<V>>() {
Test::assert_approx_eq(&MolarElectricCharge::new::<MEC>(V::one()),
&(ElectricCharge::new::<Q>(V::one())
* ReciprocalAmountOfSubstance::new::<RAOS>(V::one())));
}
}
}
}
59 changes: 59 additions & 0 deletions src/si/newtonian_constant_of_gravitation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//! Newtonian constant of gravitation (base unit cubic meter per kilogram square second, m³ · kg⁻¹ · s⁻²).

quantity! {
/// Newtonian constant of gravitation (base unit cubic meter per kilogram square second, m³ · kg⁻¹ · s⁻²).
quantity: NewtonianConstantOfGravitation; "newtonian constant of gravitation";
/// Dimension of newtonian constant of gravitation, L³M⁻¹T⁻² (base unit cubic meter per kilogram square second, m³ · kg⁻¹ · s⁻²).
dimension: ISQ<
P3, // length
N1, // mass
N2, // time
Z0, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
units {
@cubic_meter_pre_kilogram_square_second: prefix!(none); "m³·kg⁻¹·s⁻²",
"cubic meter per kilogram square second", "cubic meters per kilogram square second";
@newtonian_constant_of_gravitation: 6.674_30_E-11; "G",
"newtonian constant of gravitation", "newtonian constants of gravitation";
}
}

#[cfg(test)]
mod test {
storage_types! {
use crate::num::One;
use crate::si::mass as m;
use crate::si::newtonian_constant_of_gravitation as g;
use crate::si::quantities::*;
use crate::si::time as t;
use crate::si::length as l;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: NewtonianConstantOfGravitation<V> = Length::new::<l::meter>(V::one())
* Length::new::<l::meter>(V::one())
* Length::new::<l::meter>(V::one())
/ Mass::new::<m::kilogram>(V::one())
/ Time::new::<t::second>(V::one())
/ Time::new::<t::second>(V::one());
}

#[test]
fn check_units() {
test::<l::meter, m::kilogram, t::second, g::cubic_meter_pre_kilogram_square_second>();

fn test<L: l::Conversion<V>, M: m::Conversion<V>, T: t::Conversion<V>, G: g::Conversion<V>>() {
Test::assert_approx_eq(&NewtonianConstantOfGravitation::new::<G>(V::one()),
&(Length::new::<L>(V::one())
* Length::new::<L>(V::one())
* Length::new::<L>(V::one())
/ Mass::new::<M>(V::one())
/ Time::new::<T>(V::one())
/ Time::new::<T>(V::one())));
}
}
}
}
50 changes: 50 additions & 0 deletions src/si/reciprocal_amount_of_substance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//! Reciprocal amount of substance (base unit reciprocal mole, mol⁻¹).

quantity! {
/// Reciprocal amount of substance (base unit reciprocal mole, mol⁻¹).
quantity: ReciprocalAmountOfSubstance; "reciprocal amount of substance";
/// Dimension of reciprocal amount of substance, N⁻¹ (base unit reciprocal mole, mol⁻¹).
dimension: ISQ<
Z0, // length
Z0, // mass
Z0, // time
Z0, // electric current
Z0, // thermodynamic temperature
N1, // amount of substance
Z0>; // luminous intensity
units {
@reciprocal_mole: prefix!(none); "mol⁻¹",
"reciprocal mole", "reciprocal moles";
@avogadro_constant: 6.022_140_76_E23; "Nᴀ",
"Avogadro constant", "Avogadro constants";
}
}

#[cfg(test)]
mod test {
storage_types! {
use crate::num::One;
use crate::si::amount_of_substance as aos;
use crate::si::quantities::*;
use crate::si::reciprocal_amount_of_substance as raos;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: ReciprocalAmountOfSubstance<V> = V::one()
/ AmountOfSubstance::new::<aos::mole>(V::one());
}

#[test]
fn check_units() {
test::<aos::mole, raos::reciprocal_mole>();
test::<aos::particle, raos::avogadro_constant>();

fn test<AOS: aos::Conversion<V>, RAOS: raos::Conversion<V>>() {
Test::assert_approx_eq(&ReciprocalAmountOfSubstance::new::<RAOS>(V::one()),
&(V::one()
/ AmountOfSubstance::new::<AOS>(V::one())));
}
}
}
}
60 changes: 60 additions & 0 deletions src/si/stefan_boltzmann_constant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//! Stefan-Boltzmann constant (base unit watt per square meter kelvin to the fourth power, kg · s⁻³ · K⁻⁴).

quantity! {
/// Stefan-Boltzmann constant (base unit watt per square meter kelvin to the fourth power, kg · s⁻³ · K⁻⁴).
quantity: StefanBoltzmannConstant; "Stefan-Boltzmann constant";
/// Dimension of Stefan-Boltzmann constant, MT⁻³Th⁻⁴ (base unit watt per square meter kelvin to the fourth power, kg · s⁻³ · K⁻⁴).
dimension: ISQ<
Z0, // length
P1, // mass
N3, // time
Z0, // electric current
N4, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
units {
@watt_per_square_meter_kelvin_to_the_fourth_power: prefix!(none); "W/(m²·K⁴)",
"watt per square meter kelvin to the fourth power", "watt per square meter kelvin to the fourth power";
@stefan_boltzmann_constant: 5.670_374_419_E-8; "σ",
"stefan-boltzmann constant", "stefan-boltzmann constants";
}
}

#[cfg(test)]
mod test {
storage_types! {
use crate::num::One;
use crate::si::power as p;
use crate::si::stefan_boltzmann_constant as sigma;
use crate::si::quantities::*;
use crate::si::thermodynamic_temperature as t;
use crate::si::area as area;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: StefanBoltzmannConstant<V> = Power::new::<p::watt>(V::one())
/ Area::new::<area::square_meter>(V::one())
/ ThermodynamicTemperature::new::<t::kelvin>(V::one())
/ ThermodynamicTemperature::new::<t::kelvin>(V::one())
/ ThermodynamicTemperature::new::<t::kelvin>(V::one())
/ ThermodynamicTemperature::new::<t::kelvin>(V::one());
}

#[test]
fn check_units() {
test::<p::watt, area::square_meter, t::kelvin, sigma::watt_per_square_meter_kelvin_to_the_fourth_power>();

fn test<P: p::Conversion<V>, A: area::Conversion<V>, T: t::Conversion<V>, SIGMA: sigma::Conversion<V>>() {
Test::assert_approx_eq(&StefanBoltzmannConstant::new::<SIGMA>(V::one()),
&(Power::new::<P>(V::one())
/ Area::new::<A>(V::one())
/ ThermodynamicTemperature::new::<T>(V::one())
/ ThermodynamicTemperature::new::<T>(V::one())
/ ThermodynamicTemperature::new::<T>(V::one())
/ ThermodynamicTemperature::new::<T>(V::one())
));
}
}
}
}

0 comments on commit 18a0c13

Please sign in to comment.