Skip to content

Commit 10d9679

Browse files
authored
Merge pull request #323 from crystal-growth/add_dynamic_viscosity
Add dynamic viscosity quantity with related units and tests
2 parents d55d64a + ae5fb3f commit 10d9679

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

src/si/dynamic_viscosity.rs

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//! Dynamic viscosity (base unit pascal second, kg · m⁻¹ · s⁻¹).
2+
3+
quantity! {
4+
/// Dynamic viscosity (base unit pascal second, kg · m⁻¹ · s⁻¹).
5+
quantity: DynamicViscosity; "dynamic viscosity";
6+
/// Dimension of dynamic viscosity, L⁻¹MT⁻¹ (base unit pascal second, kg · m⁻¹ · s⁻¹).
7+
dimension: ISQ<
8+
N1, // length
9+
P1, // mass
10+
N1, // time
11+
Z0, // electric current
12+
Z0, // thermodynamic temperature
13+
Z0, // amount of substance
14+
Z0>; // luminous intensity
15+
units {
16+
@pascal_second: prefix!(none); "Pa · s", "pascal second", "pascal seconds";
17+
@millipascal_second: prefix!(milli); "mPa · s", "millipascal second", "millipascal seconds";
18+
@micropascal_second: prefix!(micro); "µPa · s", "micropascal second", "micropascal seconds";
19+
// poise = 0.1 Pa · s
20+
@poise: 1.0_E-1; "P", "poise", "poises";
21+
// centipoise = 1 mPa · s
22+
@centipoise: prefix!(centi) * 1.0_E-1; "cP", "centipoise", "centipoises";
23+
@pound_force_second_per_square_foot: 4.448_222_E0 / 3.048_E-1 / 3.048_E-1; "lbf · s/ft²",
24+
"pound-force second per square foot", "pound-force seconds per square foot";
25+
@pound_force_second_per_square_inch: 4.448_222_E0 / 2.54_E-2 / 2.54_E-2; "lbf · s/in²",
26+
"pound-force second per square inch", "pound-force seconds per square inch";
27+
// Reyn = 1 lbf · s/in²
28+
@reyn: 4.448_222_E0 / 2.54_E-2 / 2.54_E-2; "reyn", "reyn", "reyns";
29+
@pound_per_foot_second: 4.535_924_E-1 / 3.048_E-1; "lb/(ft · s)", "pound per foot second",
30+
"pounds per foot second";
31+
@pound_per_foot_hour: 4.535_924_E-1 / 3.048_E-1 / 3.6_E3; "lb/(ft · h)",
32+
"pound per foot hour", "pounds per foot hour";
33+
@slug_per_foot_second: 1.459_390_E1 / 3.048_E-1; "slug/(ft · s)", "slug per foot second",
34+
"slugs per foot second";
35+
@gram_per_centimeter_second: prefix!(milli) / prefix!(centi); "g/(cm · s)",
36+
"gram per centimeter second", "grams per centimeter second";
37+
}
38+
}
39+
40+
#[cfg(test)]
41+
mod test {
42+
storage_types! {
43+
use crate::num::One;
44+
use crate::si::quantities::*;
45+
use crate::si::dynamic_viscosity as dv;
46+
use crate::si::time as t;
47+
use crate::si::mass as m;
48+
use crate::si::length as l;
49+
use crate::si::pressure as p;
50+
use crate::tests::Test;
51+
52+
#[test]
53+
fn check_dimension() {
54+
let _: DynamicViscosity<V> = Pressure::new::<p::pascal>(V::one())
55+
* Time::new::<t::second>(V::one());
56+
}
57+
58+
#[test]
59+
fn check_units() {
60+
test::<p::pascal, t::second, dv::pascal_second>();
61+
test::<p::millipascal, t::second, dv::millipascal_second>();
62+
test::<p::micropascal, t::second, dv::micropascal_second>();
63+
test::<p::dyne_per_square_centimeter, t::second, dv::poise>();
64+
test::<p::millipascal, t::second,dv::centipoise>();
65+
test::<p::pound_force_per_square_foot, t::second,
66+
dv::pound_force_second_per_square_foot>();
67+
test::<p::pound_force_per_square_inch, t::second,
68+
dv::pound_force_second_per_square_inch>();
69+
test::<p::pound_force_per_square_inch, t::second, dv::reyn>();
70+
71+
fn test<P: p::Conversion<V>, T: t::Conversion<V>, DV: dv::Conversion<V>>() {
72+
Test::assert_approx_eq(&DynamicViscosity::new::<DV>(V::one()),
73+
&(Pressure::new::<P>(V::one())
74+
* Time::new::<T>(V::one())));
75+
}
76+
}
77+
78+
#[test]
79+
fn check_units_mlt() {
80+
test::<m::pound, l::foot, t::second, dv::pound_per_foot_second>();
81+
test::<m::pound, l::foot, t::hour, dv::pound_per_foot_hour>();
82+
test::<m::gram, l::centimeter, t::second, dv::gram_per_centimeter_second>();
83+
test::<m::slug, l::foot, t::second, dv::slug_per_foot_second>();
84+
85+
fn test<M: m::Conversion<V>, L: l::Conversion<V>, T: t::Conversion<V>,
86+
DV: dv::Conversion<V>>()
87+
{
88+
Test::assert_approx_eq(&DynamicViscosity::new::<DV>(V::one()),
89+
&(Mass::new::<M>(V::one())
90+
/ Length::new::<L>(V::one())
91+
/ Time::new::<T>(V::one())));
92+
}
93+
}
94+
}
95+
}

src/si/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ system! {
5959
catalytic_activity_concentration::CatalyticActivityConcentration,
6060
curvature::Curvature,
6161
diffusion_coefficient::DiffusionCoefficient,
62+
dynamic_viscosity::DynamicViscosity,
6263
electric_charge::ElectricCharge,
6364
electric_current::ElectricCurrent,
6465
electric_potential::ElectricPotential,

0 commit comments

Comments
 (0)