Skip to content

Commit

Permalink
Merge pull request #369 from crystal-growth/add_volumetric_heat_capacity
Browse files Browse the repository at this point in the history
Add volumetric heat capacity quantity.
  • Loading branch information
iliekturtles authored Jan 9, 2023
2 parents 8c7a2ca + 6cd5995 commit 34538a9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/si/heat_capacity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ quantity! {
"British thermal units (IT) per degree Fahrenheit";

@boltzmann_constant: 1.380_649_E-23; "k", "Boltzmann constant", "Boltzmann constants";

@calorie_per_kelvin: 4.184_E0; "cal/K", "calorie per kelvin", "calories per kelvin";
}
}

Expand Down Expand Up @@ -261,6 +263,8 @@ mod tests {
test::<e::btu, ti::degree_fahrenheit, hc::btu_per_degree_fahrenheit>();
test::<e::btu_it, ti::degree_fahrenheit, hc::btu_it_per_degree_fahrenheit>();

test::<e::calorie, ti::kelvin, hc::calorie_per_kelvin>();

fn test<E: e::Conversion<V>, TI: ti::Conversion<V>, HC: hc::Conversion<V>>() {
Test::assert_approx_eq(&HeatCapacity::new::<HC>(V::one()),
&(Energy::new::<E>(V::one())
Expand Down
1 change: 1 addition & 0 deletions src/si/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ system! {
volume::Volume,
volume_rate::VolumeRate,
volumetric_density_of_states::VolumetricDensityOfStates,
volumetric_heat_capacity::VolumetricHeatCapacity,
volumetric_number_density::VolumetricNumberDensity,
volumetric_number_rate::VolumetricNumberRate,
volumetric_power_density::VolumetricPowerDensity,
Expand Down
8 changes: 8 additions & 0 deletions src/si/specific_heat_capacity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ quantity! {
@btu_it_per_ton_degree_fahrenheit: 1.899_100_799_999_999_999_E0; "Btu (IT)/(t · °F)",
"British thermal unit (IT) per ton degree Fahrenheit",
"British thermal units (IT) per ton degree Fahrenheit";

@calorie_per_kilogram_kelvin: 4.184_E0; "cal/(kg · K)", "calorie per kilogram kelvin",
"calories per kilogram kelvin";
@calorie_per_gram_kelvin: prefix!(kilo) * 4.184_E0; "cal/(g · K)",
"calorie per gram kelvin", "calories per gram kelvin";
}
}

Expand Down Expand Up @@ -218,6 +223,9 @@ mod tests {
test::<e::btu_it, m::ton, ti::degree_fahrenheit,
shc::btu_it_per_ton_degree_fahrenheit>();

test::<e::calorie, m::kilogram, ti::kelvin, shc::calorie_per_kilogram_kelvin>();
test::<e::calorie, m::gram, ti::kelvin, shc::calorie_per_gram_kelvin>();

fn test<
E: e::Conversion<V>,
M: m::Conversion<V>,
Expand Down
53 changes: 53 additions & 0 deletions src/si/volumetric_heat_capacity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//! Volumetric heat capacity (base unit joule per cubic meter kelvin, m⁻¹ · kg · s⁻² · K⁻¹).
quantity! {
/// Volumetric heat capacity (base unit joule per cubic meter kelvin, m⁻¹ · kg · s⁻² · K⁻¹).
quantity: VolumetricHeatCapacity; "volumetric heat capacity";
/// Dimension of volumetric heat capacity, L⁻¹MT⁻²Th⁻¹(base unit joule per cubic meter kelvin,
/// m⁻¹ · kg · s⁻² · K⁻¹).
dimension: ISQ<
N1, // length
P1, // mass
N2, // time
Z0, // electric current
N1, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
units {
@joule_per_cubic_meter_kelvin: prefix!(none); "J/(m³ · K)", "joule per cubic meter kelvin",
"joules per cubic meter kelvin";
@calorie_per_cubic_meter_kelvin: 4.184_E0; "cal/(m³ · K)", "calorie per cubic meter kelvin",
"calories per cubic meter kelvin";
}
}

#[cfg(test)]
mod tests {
storage_types! {
use crate::num::One;
use crate::si::heat_capacity as hc;
use crate::si::volume as vol;
use crate::si::quantities::*;
use crate::si::volumetric_heat_capacity as vhc;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: VolumetricHeatCapacity<V> = HeatCapacity::new::<hc::joule_per_kelvin>(V::one())
/ Volume::new::<vol::cubic_meter>(V::one());
}

#[test]
fn check_heat_capacity_volume_units() {
test::<hc::joule_per_kelvin, vol::cubic_meter, vhc::joule_per_cubic_meter_kelvin>();
test::<hc::calorie_per_kelvin, vol::cubic_meter, vhc::calorie_per_cubic_meter_kelvin>();

fn test<HC: hc::Conversion<V>, VOL: vol::Conversion<V>, VHC: vhc::Conversion<V>>()
{
Test::assert_approx_eq(&VolumetricHeatCapacity::new::<VHC>(V::one()),
&(HeatCapacity::new::<HC>(V::one()) / (Volume::new::<VOL>(V::one())))
);
}
}
}
}

0 comments on commit 34538a9

Please sign in to comment.