-
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.
Add quantities for homeless constants: Avogadro, Coulomb, Faraday, Gr…
…avitation, Stafan-Boltzmann fix
- Loading branch information
1 parent
7c4b27b
commit 18a0c13
Showing
6 changed files
with
335 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
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()) | ||
)); | ||
} | ||
} | ||
|
||
} | ||
} |
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,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()))); | ||
} | ||
} | ||
} | ||
} |
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,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()))); | ||
} | ||
} | ||
} | ||
} |
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,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()))); | ||
} | ||
} | ||
} | ||
} |
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,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()) | ||
)); | ||
} | ||
} | ||
} | ||
} |