Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
Finished impl. Added test cases.
  • Loading branch information
g-bauer committed Apr 12, 2024
commit 0828d679144b5246b0aba3b9a116c2785085696b
35 changes: 17 additions & 18 deletions src/hard_sphere/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,31 +119,29 @@ impl<P> HardSphere<P> {
}

impl<P: HardSphereProperties> HardSphere<P> {
/// Returns the Helmholtz energy, packing fractions, and temperature dependent diameters without redundant calculations.
#[inline]
pub fn helmholtz_energy_and_properties<D: DualNum<f64> + Copy>(
&self,
state: &StateHD<D>,
) -> (D, [D; 4], Array1<D>) {
let p = &self.parameters;
let temperature = state.temperature;

// diameter
let diameter = p.hs_diameter(temperature);
let diameter = p.hs_diameter(state.temperature);

// zeta
let component_index = p.component_index();
let geometry_coefficients = p.geometry_coefficients(temperature);
let geometry_coefficients = p.geometry_coefficients(state.temperature);
let mut zeta = [D::zero(); 4];
for i in 0..diameter.len() {
for (z, &k) in zeta.iter_mut().zip([0, 1, 2, 3].iter()) {
*z += state.partial_density[component_index[i]]
*z += state.molefracs[component_index[i]]
* diameter[i].powi(k)
* (geometry_coefficients[k as usize][i] * FRAC_PI_6);
}
}

let frac_1mz3 = -(zeta[3] - 1.0).recip();
// todo: cover case of density = 0.
let zeta_23 = zeta[2] / zeta[3];
Comment thread
prehner marked this conversation as resolved.
let density = state.partial_density.sum();
zeta.iter_mut().for_each(|z| *z *= density);
let frac_1mz3 = -(zeta[3] - 1.0).recip();
let a = state.volume / std::f64::consts::FRAC_PI_6
* (zeta[1] * zeta[2] * frac_1mz3 * 3.0
+ zeta[2].powi(2) * frac_1mz3.powi(2) * zeta_23
Expand All @@ -153,14 +151,15 @@ impl<P: HardSphereProperties> HardSphere<P> {

#[inline]
pub fn helmholtz_energy<D: DualNum<f64> + Copy>(&self, state: &StateHD<D>) -> D {
let p = &self.parameters;
let zeta = p.zeta(state.temperature, &state.partial_density, [0, 1, 2, 3]);
let frac_1mz3 = -(zeta[3] - 1.0).recip();
let zeta_23 = p.zeta_23(state.temperature, &state.molefracs);
state.volume * 6.0 / std::f64::consts::PI
* (zeta[1] * zeta[2] * frac_1mz3 * 3.0
+ zeta[2].powi(2) * frac_1mz3.powi(2) * zeta_23
+ (zeta[2] * zeta_23.powi(2) - zeta[0]) * (zeta[3] * (-1.0)).ln_1p())
self.helmholtz_energy_and_properties(state).0
// let p = &self.parameters;
// let zeta = p.zeta(state.temperature, &state.partial_density, [0, 1, 2, 3]);
// let frac_1mz3 = -(zeta[3] - 1.0).recip();
// let zeta_23 = p.zeta_23(state.temperature, &state.molefracs);
// state.volume * 6.0 / std::f64::consts::PI
// * (zeta[1] * zeta[2] * frac_1mz3 * 3.0
// + zeta[2].powi(2) * frac_1mz3.powi(2) * zeta_23
// + (zeta[2] * zeta_23.powi(2) - zeta[0]) * (zeta[3] * (-1.0)).ln_1p())
Comment thread
prehner marked this conversation as resolved.
Outdated
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/python/eos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,24 @@ impl PyEquationOfState {
Self(Arc::new(EquationOfState::new(ideal_gas, residual)))
}

/// SAFT-VR Mie equation of state.
///
/// Parameters
/// ----------
/// parameters : SaftVRMieParameters
/// The parameters of the PC-SAFT equation of state to use.
/// max_eta : float, optional
/// Maximum packing fraction. Defaults to 0.5.
/// max_iter_cross_assoc : unsigned integer, optional
/// Maximum number of iterations for cross association. Defaults to 50.
/// tol_cross_assoc : float
/// Tolerance for convergence of cross association. Defaults to 1e-10.
///
/// Returns
/// -------
/// EquationOfState
/// The SAFT-VR Mie equation of state that can be used to compute thermodynamic
/// states.
#[cfg(feature = "saftvrmie")]
#[staticmethod]
#[pyo3(
Expand Down
Loading