Skip to content
This repository was archived by the owner on Jun 14, 2022. It is now read-only.
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add activity coefficient
  • Loading branch information
g-bauer committed Apr 6, 2022
commit aa423960876faecbdbaf6cee40fc261f4834673a
26 changes: 25 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,24 @@ 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,
)?;
state.ln_phi()[0]
})
.collect()
}

/// 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 Expand Up @@ -471,6 +490,11 @@ impl<U: EosUnit, E: EquationOfState> State<U, E> {
.unwrap()
}

/// Activity coefficient $\ln \gamma_i = \ln \varphi_i(T, p, \mathbf{N}) - \ln \varphi_i(T, p)$
pub fn ln_symmetric_activity_coefficient(&self) -> Array1<f64> {
self.ln_phi() - self.ln_phi_pure()
}

/// Helmholtz energy $A$ evaluated for each contribution of the equation of state.
pub fn helmholtz_energy_contributions(&self) -> Vec<(String, QuantityScalar<U>)> {
let new_state = self.derive0();
Expand Down