Skip to content
This repository was archived by the owner on Jun 14, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/user_defined_eos.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1240,9 +1240,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "feos",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "feos"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand Down
23 changes: 23 additions & 0 deletions src/python/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f64>> {
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<f64>> {
Ok(self.0.ln_symmetric_activity_coefficient()?.view().to_pyarray(py))
}

/// Return derivative of logarithmic fugacity coefficient w.r.t. temperature.
///
/// Returns
Expand Down
29 changes: 28 additions & 1 deletion src/state/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -300,6 +301,32 @@ impl<U: EosUnit, E: EquationOfState> State<U, E> {
.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<Array1<f64>> {
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<Array1<f64>> {
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<U> {
let func = |s: &Self, evaluate: Evaluate| {
Expand Down