From b6a18df17bfcd4efc4128fbc07e986a034c66b54 Mon Sep 17 00:00:00 2001 From: Alex Selimov Date: Wed, 1 Apr 2026 23:33:24 -0400 Subject: [PATCH] Add consts and gas_mixtures with initial calculations --- src/consts.rs | 2 + src/lib.rs | 13 +++++- src/mixtures/gas_mixture.rs | 79 +++++++++++++++++++++++++++++++++++++ src/mixtures/mod.rs | 1 + src/properties/mod.rs | 4 +- 5 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 src/consts.rs create mode 100644 src/mixtures/gas_mixture.rs create mode 100644 src/mixtures/mod.rs diff --git a/src/consts.rs b/src/consts.rs new file mode 100644 index 0000000..1cc9a2b --- /dev/null +++ b/src/consts.rs @@ -0,0 +1,2 @@ +// 1 bar ref pressure in Pa +pub const P_REF:f64 = 1e5; diff --git a/src/lib.rs b/src/lib.rs index c92486b..eee60c5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,5 @@ +pub mod consts; +pub mod mixtures; pub mod properties; #[macro_export] @@ -7,7 +9,10 @@ macro_rules! assert_delta { assert!( diff <= $delta, "|{} - {}| = {} > {}", - $left, $right, diff, $delta + $left, + $right, + diff, + $delta ); }}; } @@ -29,7 +34,11 @@ macro_rules! assert_vec_delta { assert!( diff <= $delta, "element {} not within delta: |{} - {}| = {} > {}", - i, l, r, diff, $delta + i, + l, + r, + diff, + $delta ); } }}; diff --git a/src/mixtures/gas_mixture.rs b/src/mixtures/gas_mixture.rs new file mode 100644 index 0000000..cc09169 --- /dev/null +++ b/src/mixtures/gas_mixture.rs @@ -0,0 +1,79 @@ +use crate::{ + consts::P_REF, + properties::{ + thermo_fit::{Phase, SpeciesThermoData}, + transport_fit::SpeciesTransportData, + }, +}; + +pub struct GasMixture { + pub(crate) ns: Vec, + pub(crate) nsum: f64 + pub(crate) species: Vec, + pub(crate) transport_data: Vec, +} + +impl GasMixture { + // Calculate the normalized chemical potential (μ/RT) for each component in the mixture. + // + // Equations 2.11 from reference paper + pub fn gas_chem_potentials_over_rt(&self, temp: f64, pressure: f64) -> Vec { + self.ns + .iter() + .zip(self.species.iter()) + .map(|(n, s)| -> f64 { + match s.phase { + Phase::Gas => { + let p = s + .polynomial_at(temp) + .expect("Gas doesn't have a polynomial"); + p.h_over_rt(temp) - p.s_over_r(temp) + (pressure / P_REF).ln() + (n/self.nsum).ln() + } + Phase::Condensed => todo!(), + } + }) + .collect() + } + + // Calculate the normalized entropy (S/R) for each mixture component + // + // Equations 2.17 from reference paper + pub fn gas_entropies_over_rt(&self, temp: f64, pressure: f64) -> Vec { + self.ns + .iter() + .zip(self.species.iter()) + .map(|(n, s)| -> f64 { + match s.phase { + Phase::Gas => { + let p = s + .polynomial_at(temp) + .expect("Gas doesn't have a polynomial"); + p.s_over_r(temp) - (n/self.nsum).ln() - (pressure/P_REF).ln() + } + Phase::Condensed => todo!(), + } + }) + .collect() + } + + // Calculate the normalized mixture enthalpy (H/RT) + // Note that the enthalpy doesn't have a dependence on the pressure. + // Equation 2.14 from the paper + pub fn mixture_h_over_rt(&self, temp: f64) -> Vec{ + self.ns + .iter() + .zip(self.species.iter()) + .map(|(n, s)| -> f64 { + match s.phase { + Phase::Gas => { + let p = s + .polynomial_at(temp) + .expect("Gas doesn't have a polynomial"); + n*p.h_over_rt(temp) + } + Phase::Condensed => todo!(), + } + }) + .collect() + } +} diff --git a/src/mixtures/mod.rs b/src/mixtures/mod.rs new file mode 100644 index 0000000..2e98a6c --- /dev/null +++ b/src/mixtures/mod.rs @@ -0,0 +1 @@ +pub mod gas_mixture; diff --git a/src/properties/mod.rs b/src/properties/mod.rs index 4d0a782..f160f70 100644 --- a/src/properties/mod.rs +++ b/src/properties/mod.rs @@ -1,9 +1,9 @@ mod data; mod error; pub mod thermo_db; -mod thermo_fit; +pub mod thermo_fit; pub mod transport_db; -mod transport_fit; +pub mod transport_fit; mod utils; pub use error::PropertiesError;