Skip to content
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- Fixed numerical roundoff errors in the analytic solution of association site fractions for asymmetric association schemes. [#393](https://github.com/feos-org/feos/pull/393)

## [0.10.2] - 2026-10-12
### Fixed
- Fixed off-by-one error for the convergence-check in `_density_iteration`. [#386](https://github.com/feos-org/feos/pull/386)
Expand Down
17 changes: 12 additions & 5 deletions crates/feos/src/association/dft.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use feos_core::parameter::GenericParameters;
use feos_core::FeosResult;
use feos_core::parameter::GenericParameters;
use feos_dft::{FunctionalContribution, WeightFunction, WeightFunctionInfo, WeightFunctionShape};
use ndarray::{Array1, Array2, ArrayBase, ArrayView2, Axis, Data, Ix1, Slice};
use num_dual::DualNum;
Expand Down Expand Up @@ -297,10 +297,17 @@ impl<'a, A: AssociationStrength> YuWuAssociationFunctional<'a, A> {
* self.model.association_strength_ij(temperature, i, j, par);

// no cross association, two association sites
let aux = &delta * (&rhob - &rhoa) + 1.0;
let xa = ((&aux * &aux + &delta * &rhoa * 4.0).map(N::sqrt) + &aux).map(N::recip) * 2.0;
let aux = -aux + 2.0;
let xb = ((&aux * &aux + delta * &rhob * 4.0).map(N::sqrt) + aux).map(N::recip) * 2.0;
let (xa, xb) = if rhoa.sum().re() > rhob.sum().re() {
let aux = &delta * (&rhoa - &rhob) + 1.0;
let xb = ((&aux * &aux + &delta * &rhob * 4.0).map(N::sqrt) + aux).map(N::recip) * 2.0;
let xa = (&delta * &rhob * &xb + 1.0).map(N::recip);
(xa, xb)
} else {
let aux = &delta * (&rhob - &rhoa) + 1.0;
let xa = ((&aux * &aux + &delta * &rhoa * 4.0).map(N::sqrt) + aux).map(N::recip) * 2.0;
let xb = (&delta * &rhoa * &xa + 1.0).map(N::recip);
(xa, xb)
};

let f = |x: N| x.ln() - x * 0.5 + 0.5;
rhoa * xa.mapv(f) + rhob * xb.mapv(f)
Expand Down
11 changes: 9 additions & 2 deletions crates/feos/src/association/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,15 @@ impl Association {

// fraction of non-bonded association sites
let sqrt = ((delta * (rhoa - rhob) + 1.0).powi(2) + delta * rhob * 4.0).sqrt();
let xa = (sqrt + (delta * (rhob - rhoa) + 1.0)).recip() * 2.0;
let xb = (sqrt + (delta * (rhoa - rhob) + 1.0)).recip() * 2.0;
let (xa, xb) = if rhoa > rhob {
let xb = (sqrt + delta * (rhoa - rhob) + 1.0).recip() * 2.0;
let xa = (delta * rhob * xb + 1.0).recip();
(xa, xb)
} else {
let xa = (sqrt + delta * (rhob - rhoa) + 1.0).recip() * 2.0;
let xb = (delta * rhoa * xa + 1.0).recip();
(xa, xb)
};

rhoa * (xa.ln() - xa * 0.5 + 0.5) + rhob * (xb.ln() - xb * 0.5 + 0.5)
}
Expand Down
Loading