Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor cleanup of the PC-SAFT implementation #108

Merged
merged 2 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
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
35 changes: 34 additions & 1 deletion benches/state_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,38 @@ fn properties_pcsaft(c: &mut Criterion) {
});
}

criterion_group!(bench, properties_pcsaft);
fn properties_pcsaft_polar(c: &mut Criterion) {
let parameters = PcSaftParameters::from_json(
vec!["acetone", "butanal", "dimethyl ether"],
"./parameters/pcsaft/gross2006.json",
None,
IdentifierOption::Name,
)
.unwrap();
let eos = Arc::new(PcSaft::new(Arc::new(parameters)));
let t = 300.0 * KELVIN;
let density = 71.18 * KILO * MOL / METER.powi(3);
let v = 100.0 * MOL / density;
let x = arr1(&[1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0]);
let m = &x * 100.0 * MOL;

let mut group = c.benchmark_group("state_properties_pcsaft_polar");
group.bench_function("a", |b| {
b.iter(|| property((&eos, S::helmholtz_energy, t, v, &m, Contributions::Total)))
});
group.bench_function("compressibility", |b| {
b.iter(|| property((&eos, S::compressibility, t, v, &m, Contributions::Total)))
});
group.bench_function("ln_phi", |b| {
b.iter(|| property_no_contributions((&eos, S::ln_phi, t, v, &m)))
});
group.bench_function("c_v", |b| {
b.iter(|| property((&eos, S::c_v, t, v, &m, Contributions::ResidualNvt)))
});
group.bench_function("molar_volume", |b| {
b.iter(|| property((&eos, S::molar_volume, t, v, &m, Contributions::ResidualNvt)))
});
}

criterion_group!(bench, properties_pcsaft, properties_pcsaft_polar);
criterion_main!(bench);
31 changes: 13 additions & 18 deletions src/association/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ impl AssociationParameters {

for (i, record) in records.iter().enumerate() {
if let Some(record) = record.as_ref() {
assoc_comp.push(i);
sigma_assoc.push(sigma[i]);
kappa_ab.push(record.kappa_ab);
epsilon_k_ab.push(record.epsilon_k_ab);
na.push(record.na.unwrap_or(1.0));
nb.push(record.nb.unwrap_or(1.0));
if record.kappa_ab > 0.0 && record.epsilon_k_ab > 0.0 {
g-bauer marked this conversation as resolved.
Show resolved Hide resolved
assoc_comp.push(i);
sigma_assoc.push(sigma[i]);
kappa_ab.push(record.kappa_ab);
epsilon_k_ab.push(record.epsilon_k_ab);
na.push(record.na.unwrap_or(1.0));
nb.push(record.nb.unwrap_or(1.0));
}
}
}

Expand Down Expand Up @@ -238,21 +240,14 @@ impl<P> fmt::Display for Association<P> {

impl<P: HardSphereProperties> Association<P> {
pub fn assoc_site_frac_ab<D: DualNum<f64>>(deltarho: D, na: f64, nb: f64) -> D {
if deltarho.re() > f64::EPSILON.sqrt() {
(((deltarho * (na - nb) + 1.0).powi(2) + deltarho * nb * 4.0).sqrt()
- (deltarho * (nb - na) + 1.0))
/ (deltarho * na * 2.0)
} else {
D::one() + deltarho * nb * (deltarho * (nb + na) - 1.0)
}
(((deltarho * (na - nb) + 1.0).powi(2) + deltarho * nb * 4.0).sqrt()
g-bauer marked this conversation as resolved.
Show resolved Hide resolved
+ (deltarho * (nb - na) + 1.0))
.recip()
* (2.0 * nb / na)
}

pub fn assoc_site_frac_a<D: DualNum<f64>>(deltarho: D, na: f64) -> D {
if deltarho.re() > f64::EPSILON.sqrt() {
((deltarho * na * 4.0 + 1.0).powi(2) - 1.0).sqrt() / (deltarho * na * 2.0)
} else {
D::one() + deltarho * na * (deltarho * na * 2.0 - 1.0)
}
((deltarho * 4.0 * na + 1.0).sqrt() + 1.0).recip() * 2.0
g-bauer marked this conversation as resolved.
Show resolved Hide resolved
}

#[allow(clippy::too_many_arguments)]
Expand Down
Loading