Skip to content

Commit

Permalink
Add specific area and specific volume quantities.
Browse files Browse the repository at this point in the history
  • Loading branch information
crystal-growth authored and iliekturtles committed Sep 3, 2022
1 parent 5fd23fa commit e051876
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/si/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ system! {
radiant_exposure::RadiantExposure,
ratio::Ratio,
solid_angle::SolidAngle,
specific_area::SpecificArea,
specific_heat_capacity::SpecificHeatCapacity,
specific_volume::SpecificVolume,
temperature_interval::TemperatureInterval,
thermal_conductivity::ThermalConductivity,
thermodynamic_temperature::ThermodynamicTemperature,
Expand Down
57 changes: 57 additions & 0 deletions src/si/specific_area.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//! Specific area (base unit square meter per kilogram, m² · kg⁻¹).
quantity! {
/// Specific area (base unit square meter per kilogram, m² · kg⁻¹).
quantity: SpecificArea; "specific area";
/// Dimension of specific area, L²M⁻¹ (base unit square meter per kilogram, m² · kg⁻¹).
dimension: ISQ<
P2, // length
N1, // mass
Z0, // time
Z0, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
units {
@square_meter_per_kilogram: prefix!(none); "m²/kg", "square meter per kilogram",
"square meters per kilogram";
@square_centimeter_per_kilogram: prefix!(centi) * prefix!(centi); "cm²/kg",
"square centimeter per kilogram", "square centimeters per kilogram";

@square_meter_per_gram: prefix!(none) / prefix!(milli); "m²/g", "square meter per gram",
"square meters per gram";
@square_centimeter_per_gram: prefix!(centi) * prefix!(centi) / prefix!(milli); "cm²/g",
"square centimeter per gram", "square centimeters per gram";
}
}

#[cfg(test)]
mod tests {
storage_types! {
use crate::num::One;
use crate::si::area as a;
use crate::si::mass as m;
use crate::si::specific_area as sa;
use crate::si::quantities::*;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: SpecificArea<V> = Area::new::<a::square_meter>(V::one()) / Mass::new::<m::kilogram>(V::one());
}

#[test]
fn check_units() {
test::<a::square_meter, m::kilogram, sa::square_meter_per_kilogram>();
test::<a::square_centimeter, m::kilogram, sa::square_centimeter_per_kilogram>();

test::<a::square_meter, m::gram, sa::square_meter_per_gram>();
test::<a::square_centimeter, m::gram, sa::square_centimeter_per_gram>();

fn test<A: a::Conversion<V>, M: m::Conversion<V>, SA: sa::Conversion<V>, >() {
Test::assert_eq(&SpecificArea::new::<SA>(V::one()),
&(Area::new::<A>(V::one()) / Mass::new::<M>(V::one())));
}
}
}
}
58 changes: 58 additions & 0 deletions src/si/specific_volume.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//! Specific volume (base unit cubic meter per kilogram, m³ · kg⁻¹).
quantity! {
/// Specific volume (base unit cubic meter per kilogram, m³ · kg⁻¹).
quantity: SpecificVolume; "specific volume";
/// Dimension of specific volume, L³M⁻¹ (base unit cubic meter per kilogram, m³ · kg⁻¹).
dimension: ISQ<
P3, // length
N1, // mass
Z0, // time
Z0, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
units {
@cubic_meter_per_kilogram: prefix!(none); "m³/kg", "cubic meter per kilogram",
"cubic meters per kilogram";
@cubic_centimeter_per_kilogram: prefix!(centi) * prefix!(centi) * prefix!(centi); "cm³/kg",
"cubic centimeter per kilogram", "cubic centimeters per kilogram";

@cubic_meter_per_gram: prefix!(none) / prefix!(milli); "m³/g", "cubic meter per gram",
"cubic meters per gram";
@cubic_centimeter_per_gram:
prefix!(centi) * prefix!(centi) * prefix!(centi) / prefix!(milli); "cm³/g",
"cubic centimeter per gram", "cubic centimeters per gram";
}
}

#[cfg(test)]
mod tests {
storage_types! {
use crate::num::One;
use crate::si::volume as a;
use crate::si::mass as m;
use crate::si::specific_volume as sv;
use crate::si::quantities::*;
use crate::tests::Test;

#[test]
fn check_dimension() {
let _: SpecificVolume<V> = Volume::new::<a::cubic_meter>(V::one())
/ Mass::new::<m::kilogram>(V::one());
}

#[test]
fn check_units() {
test::<a::cubic_meter, m::kilogram, sv::cubic_meter_per_kilogram>();
test::<a::cubic_centimeter, m::kilogram, sv::cubic_centimeter_per_kilogram>();
test::<a::cubic_meter, m::gram, sv::cubic_meter_per_gram>();
test::<a::cubic_centimeter, m::gram, sv::cubic_centimeter_per_gram>();

fn test<A: a::Conversion<V>, M: m::Conversion<V>, SV: sv::Conversion<V>>() {
Test::assert_eq(&SpecificVolume::new::<SV>(V::one()),
&(Volume::new::<A>(V::one()) / Mass::new::<M>(V::one())));
}
}
}
}

0 comments on commit e051876

Please sign in to comment.