Skip to content

Commit

Permalink
Add dynamic viscosity quantity with related units and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
crystal-growth committed Aug 3, 2022
1 parent 2809d31 commit b5500ee
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
98 changes: 98 additions & 0 deletions src/si/dynamic_viscosity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//! Dynamic viscosity (base unit pascal second, kg · m⁻¹ · s⁻¹).
quantity! {
/// Dynamic viscosity (base unit pascal second, kg · m⁻¹ · s⁻¹).
quantity: DynamicViscosity; "dynamic viscosity";
/// Dimension of dynamic viscosity, ML⁻¹T⁻¹ (base unit pascal second, kg · m⁻¹ · s⁻¹).
dimension: ISQ<
N1, // length
P1, // mass
N1, // time
Z0, // electric current
Z0, // thermodynamic temperature
Z0, // amount of substance
Z0>; // luminous intensity
units {
@pascal_second: prefix!(none); "Pa·s",
"pascal second", "pascal seconds";
@millipascal_second: prefix!(milli); "mPa·s",
"millipascal second", "millipascal seconds";
@micropascal_second: prefix!(micro); "µPa·s",
"micropascal second", "micropascal seconds";
// poise = 0.1 Pa · s
@poise: 1.0_E-1; "P",
"poise", "poises";
// centipoise = 1 mPa · s
@centipoise: prefix!(centi) * 1.0_E-1; "cP",
"centipoise", "centipoises";
@pound_force_second_per_square_foot: 4.448_222_E0 / 3.048_E-1 / 3.048_E-1; "lbf·s/ft²",
"pound-force second per square foot", "pound-force seconds per square foot";
@pound_force_second_per_square_inch: 4.448_222_E0 / 2.54_E-2 / 2.54_E-2; "lbf·s/in²",
"pound-force second per square inch", "pound-force seconds per square inch";
// Reyn = 1 lbf·s/in²
@reyn: 4.448_222_E0 / 2.54_E-2 / 2.54_E-2; "reyn",
"reyn", "reyn";
@pound_per_foot_second: 4.535_924_E-1 / 3.048_E-1; "lb/(ft·s)",
"pound per foot second", "pounds per foot second";
@pound_per_foot_hour: 4.535_924_E-1 / 3.048_E-1 / 3600.0; "lb/(ft·h)",
"pound per foot hour", "pounds per foot hour";
@slug_per_foot_second: 1.459_390_E1 / 3.048_E-1; "slug/(ft·s)",
"slug per foot second", "slugs per foot second";
@gram_per_centimeter_second: prefix!(milli) / prefix!(centi); "g/(cm·s)",
"gram per centimeter second", "grams per centimeter second";
}
}

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

#[test]
fn check_dimension() {
let _: DynamicViscosity<V> = Pressure::new::<p::pascal>(V::one())
* Time::new::<t::second>(V::one());
}

#[test]
fn check_units() {
test::<dv::pascal_second, t::second, p::pascal>();
test::<dv::millipascal_second, t::second, p::millipascal>();
test::<dv::micropascal_second, t::second, p::micropascal>();
test::<dv::poise, t::second, p::dyne_per_square_centimeter>();
test::<dv::centipoise, t::second, p::millipascal>();
test::<dv::pound_force_second_per_square_foot, t::second, p::pound_force_per_square_foot>();
test::<dv::pound_force_second_per_square_inch, t::second, p::pound_force_per_square_inch>();
test::<dv::reyn, t::second, p::pound_force_per_square_inch>();

fn test<DV: dv::Conversion<V>, T: t::Conversion<V>, P: p::Conversion<V>>() {
Test::assert_approx_eq(&DynamicViscosity::new::<DV>(V::one()),
&(Pressure::new::<P>(V::one())
* Time::new::<T>(V::one())));
}
}

#[test]
fn check_units_mlt() {
test::<dv::pound_per_foot_second, t::second, m::pound, l::foot>();
test::<dv::pound_per_foot_hour, t::hour, m::pound, l::foot>();
test::<dv::gram_per_centimeter_second, t::second, m::gram, l::centimeter>();
test::<dv::slug_per_foot_second, t::second, m::slug, l::foot>();

fn test<DV: dv::Conversion<V>, T: t::Conversion<V>, M: m::Conversion<V>, L: l::Conversion<V>>() {
Test::assert_approx_eq(&DynamicViscosity::new::<DV>(V::one()),
&(Mass::new::<M>(V::one())
/ Length::new::<L>(V::one())
/ Time::new::<T>(V::one())));
}
}

}
}
1 change: 1 addition & 0 deletions src/si/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ system! {
catalytic_activity::CatalyticActivity,
catalytic_activity_concentration::CatalyticActivityConcentration,
curvature::Curvature,
dynamic_viscosity::DynamicViscosity,
electric_charge::ElectricCharge,
electric_current::ElectricCurrent,
electric_potential::ElectricPotential,
Expand Down

0 comments on commit b5500ee

Please sign in to comment.