Skip to content

Commit

Permalink
Add molar heat capacity and related units.
Browse files Browse the repository at this point in the history
Resolves #262.
  • Loading branch information
iliekturtles committed Aug 5, 2021
1 parent a7a4ccf commit eea7bd8
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/si/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ system! {
mass_rate::MassRate,
molar_concentration::MolarConcentration,
molar_energy::MolarEnergy,
molar_heat_capacity::MolarHeatCapacity,
molar_mass::MolarMass,
momentum::Momentum,
power::Power,
Expand Down
118 changes: 118 additions & 0 deletions src/si/molar_heat_capacity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//! Molar heat capacity (base unit joule per kelvin mole, m² · kg · s⁻² · K⁻¹ · mol⁻¹).
quantity! {
/// Molar heat capacity (base unit joule per kelvin mole, m² · kg · s⁻² · K⁻¹ · mol⁻¹).
quantity: MolarHeatCapacity; "molar heat capacity";
/// Dimension of molar heat capacity, L²MT⁻²Th⁻¹N⁻¹ (base unit joule per kelvin mole,
/// m² · kg · s⁻² · K⁻¹ · mol⁻¹).
dimension: ISQ<
P2, // length
P1, // mass
N2, // time
Z0, // electric current
N1, // thermodynamic temperature
N1, // amount of substance
Z0>; // luminous intensity
units {
@yottajoule_per_kelvin_mole: prefix!(yotta); "YJ/(K · mol)", "yottajoule per kelvin mole",
"yottajoules per kelvin mole";
@zettajoule_per_kelvin_mole: prefix!(zetta); "ZJ/(K · mol)", "zettajoule per kelvin mole",
"zettajoules per kelvin mole";
@exajoule_per_kelvin_mole: prefix!(exa); "EJ/(K · mol)", "exajoule per kelvin mole",
"exajoules per kelvin mole";
@petajoule_per_kelvin_mole: prefix!(peta); "PJ/(K · mol)", "petajoule per kelvin mole",
"petajoules per kelvin mole";
@terajoule_per_kelvin_mole: prefix!(tera); "TJ/(K · mol)", "terajoule per kelvin mole",
"terajoules per kelvin mole";
@gigajoule_per_kelvin_mole: prefix!(giga); "GJ/(K · mol)", "gigajoule per kelvin mole",
"gigajoules per kelvin mole";
@megajoule_per_kelvin_mole: prefix!(mega); "MJ/(K · mol)", "megajoule per kelvin mole",
"megajoules per kelvin mole";
@kilojoule_per_kelvin_mole: prefix!(kilo); "kJ/(K · mol)", "kilojoule per kelvin mole",
"kilojoules per kelvin mole";
@hectojoule_per_kelvin_mole: prefix!(hecto); "hJ/(K · mol)", "hectojoule per kelvin mole",
"hectojoules per kelvin mole";
@decajoule_per_kelvin_mole: prefix!(deca); "daJ/(K · mol)", "decajoule per kelvin mole",
"decajoules per kelvin mole";
/// Derived unit of molar heat capacity.
@joule_per_kelvin_mole: prefix!(none); "J/(K · mol)", "joule per kelvin mole",
"joules per kelvin mole";
@decijoule_per_kelvin_mole: prefix!(deci); "dJ/(K · mol)", "decijoule per kelvin mole",
"decijoules per kelvin mole";
@centijoule_per_kelvin_mole: prefix!(centi); "cJ/(K · mol)", "centijoule per kelvin mole",
"centijoules per kelvin mole";
@millijoule_per_kelvin_mole: prefix!(milli); "mJ/(K · mol)", "millijoule per kelvin mole",
"millijoules per kelvin mole";
@microjoule_per_kelvin_mole: prefix!(micro); "µJ/(K · mol)", "microjoule per kelvin mole",
"microjoules per kelvin mole";
@nanojoule_per_kelvin_mole: prefix!(nano); "nJ/(K · mol)", "nanojoule per kelvin mole",
"nanojoules per kelvin mole";
@picojoule_per_kelvin_mole: prefix!(pico); "pJ/(K · mol)", "picojoule per kelvin mole",
"picojoules per kelvin mole";
@femtojoule_per_kelvin_mole: prefix!(femto); "fJ/(K · mol)", "femtojoule per kelvin mole",
"femtojoules per kelvin mole";
@attojoule_per_kelvin_mole: prefix!(atto); "aJ/(K · mol)", "attojoule per kelvin mole",
"attojoules per kelvin mole";
@zeptojoule_per_kelvin_mole: prefix!(zepto); "zJ/(K · mol)", "zeptojoule per kelvin mole",
"zeptojoules per kelvin mole";
@yoctojoule_per_kelvin_mole: prefix!(yocto); "yJ/(K · mol)", "yoctojoule per kelvin mole",
"yoctojoules per kelvin mole";

@calorie_per_kelvin_mole: 4.184_E0; "cal/(K · mol)", "calorie per kelvin mole",
"calories per kelvin mole";
}
}

#[cfg(test)]
mod tests {
storage_types! {
use crate::num::One;
use crate::si::amount_of_substance as a;
use crate::si::energy as e;
use crate::si::molar_heat_capacity as m;
use crate::si::quantities::*;
use crate::si::temperature_interval as t;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: MolarHeatCapacity<V> = Energy::new::<e::joule>(V::one())
/ (TemperatureInterval::new::<t::kelvin>(V::one())
* AmountOfSubstance::new::<a::mole>(V::one()));
}

#[test]
fn check_units() {
test::<e::yottajoule, t::kelvin, a::mole, m::yottajoule_per_kelvin_mole>();
test::<e::zettajoule, t::kelvin, a::mole, m::zettajoule_per_kelvin_mole>();
test::<e::exajoule, t::kelvin, a::mole, m::exajoule_per_kelvin_mole>();
test::<e::petajoule, t::kelvin, a::mole, m::petajoule_per_kelvin_mole>();
test::<e::terajoule, t::kelvin, a::mole, m::terajoule_per_kelvin_mole>();
test::<e::gigajoule, t::kelvin, a::mole, m::gigajoule_per_kelvin_mole>();
test::<e::megajoule, t::kelvin, a::mole, m::megajoule_per_kelvin_mole>();
test::<e::kilojoule, t::kelvin, a::mole, m::kilojoule_per_kelvin_mole>();
test::<e::hectojoule, t::kelvin, a::mole, m::hectojoule_per_kelvin_mole>();
test::<e::decajoule, t::kelvin, a::mole, m::decajoule_per_kelvin_mole>();
test::<e::joule, t::kelvin, a::mole, m::joule_per_kelvin_mole>();
test::<e::decijoule, t::kelvin, a::mole, m::decijoule_per_kelvin_mole>();
test::<e::centijoule, t::kelvin, a::mole, m::centijoule_per_kelvin_mole>();
test::<e::millijoule, t::kelvin, a::mole, m::millijoule_per_kelvin_mole>();
test::<e::microjoule, t::kelvin, a::mole, m::microjoule_per_kelvin_mole>();
test::<e::nanojoule, t::kelvin, a::mole, m::nanojoule_per_kelvin_mole>();
test::<e::picojoule, t::kelvin, a::mole, m::picojoule_per_kelvin_mole>();
test::<e::femtojoule, t::kelvin, a::mole, m::femtojoule_per_kelvin_mole>();
test::<e::attojoule, t::kelvin, a::mole, m::attojoule_per_kelvin_mole>();
test::<e::zeptojoule, t::kelvin, a::mole, m::zeptojoule_per_kelvin_mole>();
test::<e::yoctojoule, t::kelvin, a::mole, m::yoctojoule_per_kelvin_mole>();

test::<e::calorie, t::kelvin, a::mole, m::calorie_per_kelvin_mole>();

fn test<E: e::Conversion<V>, T: t::Conversion<V>, A: a::Conversion<V>, M: m::Conversion<V>>() {
Test::assert_approx_eq(&MolarHeatCapacity::new::<M>(V::one()),
&(Energy::new::<E>(V::one())
/ (TemperatureInterval::new::<T>(V::one())
* AmountOfSubstance::new::<A>(V::one()))));
}
}
}
}

0 comments on commit eea7bd8

Please sign in to comment.