diff --git a/example/user_defined_eos.ipynb b/example/user_defined_eos.ipynb index 71467ae..6feecc7 100644 --- a/example/user_defined_eos.ipynb +++ b/example/user_defined_eos.ipynb @@ -1240,9 +1240,9 @@ ], "metadata": { "kernelspec": { - "display_name": "feos", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "feos" + "name": "python3" }, "language_info": { "codemirror_mode": { diff --git a/src/python/state.rs b/src/python/state.rs index 8eed471..0db45cf 100644 --- a/src/python/state.rs +++ b/src/python/state.rs @@ -525,6 +525,29 @@ macro_rules! impl_state { self.0.ln_phi().view().to_pyarray(py) } + /// Return logarithmic pure substance fugacity coefficient. + /// + /// For each component, the hypothetical liquid fugacity coefficient + /// at mixture temperature and pressure is computed. + /// + /// Returns + /// ------- + /// numpy.ndarray + #[pyo3(text_signature = "($self)")] + fn ln_phi_pure<'py>(&self, py: Python<'py>) -> PyResult<&'py PyArray1> { + Ok(self.0.ln_phi_pure()?.view().to_pyarray(py)) + } + + /// Return logarithmic symmetric activity coefficient. + /// + /// Returns + /// ------- + /// numpy.ndarray + #[pyo3(text_signature = "($self)")] + fn ln_symmetric_activity_coefficient<'py>(&self, py: Python<'py>) -> PyResult<&'py PyArray1> { + Ok(self.0.ln_symmetric_activity_coefficient()?.view().to_pyarray(py)) + } + /// Return derivative of logarithmic fugacity coefficient w.r.t. temperature. /// /// Returns diff --git a/src/state/properties.rs b/src/state/properties.rs index b56cf73..5adffa2 100644 --- a/src/state/properties.rs +++ b/src/state/properties.rs @@ -2,11 +2,12 @@ use super::{Derivative::*, PartialDerivative, State}; use crate::equation_of_state::{EntropyScaling, EquationOfState, MolarWeight}; use crate::errors::EosResult; use crate::EosUnit; -use ndarray::{Array1, Array2}; +use ndarray::{arr1, Array1, Array2}; use num_dual::DualNum; use quantity::{QuantityArray, QuantityArray1, QuantityArray2, QuantityScalar}; use std::iter::FromIterator; use std::ops::{Add, Sub}; +use std::rc::Rc; #[derive(Clone, Copy)] pub(crate) enum Evaluate { @@ -300,6 +301,32 @@ impl State { .unwrap() } + /// Logarithm of the fugacity coefficient of all components treated as pure substance at mixture temperature and pressure. + pub fn ln_phi_pure(&self) -> EosResult> { + let pressure = self.pressure(Contributions::Total); + (0..self.eos.components()) + .map(|i| { + let eos = Rc::new(self.eos.subset(&[i])); + let state = Self::new_npt( + &eos, + self.temperature, + pressure, + &(arr1(&[1.0]) * U::reference_moles()), + crate::DensityInitialization::Liquid, + )?; + Ok(state.ln_phi()[0]) + }) + .collect() + } + + /// Activity coefficient $\ln \gamma_i = \ln \varphi_i(T, p, \mathbf{N}) - \ln \varphi_i(T, p)$ + pub fn ln_symmetric_activity_coefficient(&self) -> EosResult> { + match self.eos.components() { + 1 => Ok(arr1(&[0.0])), + _ => Ok(self.ln_phi() - &self.ln_phi_pure()?), + } + } + /// Partial derivative of the logarithm of the fugacity coefficient w.r.t. temperature: $\left(\frac{\partial\ln\varphi_i}{\partial T}\right)_{p,N_i}$ pub fn dln_phi_dt(&self) -> QuantityArray1 { let func = |s: &Self, evaluate: Evaluate| {