Skip to content

Commit 54b3ecf

Browse files
authored
Add DFT benchmark (#103)
1 parent 016bb44 commit 54b3ecf

3 files changed

Lines changed: 139 additions & 1 deletion

File tree

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ harness = false
6060
name = "dual_numbers"
6161
harness = false
6262

63+
[[bench]]
64+
name = "dft_pore"
65+
harness = false
66+
6367
[profile.release-lto]
6468
inherits = "release"
6569
lto = true

benches/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ cargo bench --profile=release-lto --features=pcsaft --bench=dual_numbers
1414
|--|--|--|
1515
|`dual_numbers`|Helmholtz energy function evaluated using `StateHD` with different dual number types.|`pcsaft`|
1616
|`state_properties`|Properties of `State`. Including state creation using the natural variables of the Helmholtz energy (no density iteration).|`pcsaft`|
17-
|`state_creation`|Different constructors of `State` and `PhaseEquilibrium` including critical point calculations. For pure substances and mixtures.|`pcsaft`|
17+
|`state_creation`|Different constructors of `State` and `PhaseEquilibrium` including critical point calculations. For pure substances and mixtures.|`pcsaft`|
18+
|`dft_pore`|Calculation of density profiles in pores using different functionals and bulk conditions. For pure substances, mixtures and heterosegmented chains.|`pcsaft`, `gc_pcsaft`, `dft`|

benches/dft_pore.rs

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
//! Benchmarks for the calculation of density profiles
2+
//! in pores at different conditions.
3+
use criterion::{criterion_group, criterion_main, Criterion};
4+
use feos::gc_pcsaft::{GcPcSaftFunctional, GcPcSaftFunctionalParameters};
5+
use feos::hard_sphere::{FMTFunctional, FMTVersion};
6+
use feos::pcsaft::{PcSaftFunctional, PcSaftParameters};
7+
use feos_core::parameter::{IdentifierOption, Parameter, ParameterHetero};
8+
use feos_core::{PhaseEquilibrium, State, StateBuilder};
9+
use feos_dft::adsorption::{ExternalPotential, Pore1D, PoreSpecification};
10+
use feos_dft::{DFTSolver, Geometry};
11+
use ndarray::arr1;
12+
use quantity::si::{ANGSTROM, KELVIN, NAV};
13+
use std::sync::Arc;
14+
15+
fn fmt(c: &mut Criterion) {
16+
let mut group = c.benchmark_group("DFT_pore_fmt");
17+
18+
let func = Arc::new(FMTFunctional::new(&arr1(&[1.0]), FMTVersion::WhiteBear));
19+
let pore = Pore1D::new(
20+
Geometry::Cartesian,
21+
10.0 * ANGSTROM,
22+
ExternalPotential::HardWall { sigma_ss: 1.0 },
23+
None,
24+
None,
25+
);
26+
let bulk = State::new_pure(&func, KELVIN, 0.75 / NAV / ANGSTROM.powi(3)).unwrap();
27+
group.bench_function("liquid", |b| {
28+
b.iter(|| pore.initialize(&bulk, None, None).unwrap().solve(None))
29+
});
30+
}
31+
32+
fn pcsaft(c: &mut Criterion) {
33+
let mut group = c.benchmark_group("DFT_pore_pcsaft");
34+
let parameters = PcSaftParameters::from_json(
35+
vec!["butane"],
36+
"./parameters/pcsaft/gross2001.json",
37+
None,
38+
IdentifierOption::Name,
39+
)
40+
.unwrap();
41+
let func = Arc::new(PcSaftFunctional::new(Arc::new(parameters)));
42+
let pore = Pore1D::new(
43+
Geometry::Cartesian,
44+
20.0 * ANGSTROM,
45+
ExternalPotential::LJ93 {
46+
sigma_ss: 3.0,
47+
epsilon_k_ss: 100.0,
48+
rho_s: 0.08,
49+
},
50+
None,
51+
None,
52+
);
53+
let vle = PhaseEquilibrium::pure(&func, 300.0 * KELVIN, None, Default::default()).unwrap();
54+
let bulk = vle.liquid();
55+
group.bench_function("butane_liquid", |b| {
56+
b.iter(|| pore.initialize(bulk, None, None).unwrap().solve(None))
57+
});
58+
let bulk = State::new_pure(&func, 300.0 * KELVIN, vle.vapor().density * 0.2).unwrap();
59+
group.bench_function("butane_vapor", |b| {
60+
b.iter(|| pore.initialize(&bulk, None, None).unwrap().solve(None))
61+
});
62+
63+
let parameters = PcSaftParameters::from_json(
64+
vec!["butane", "pentane"],
65+
"./parameters/pcsaft/gross2001.json",
66+
None,
67+
IdentifierOption::Name,
68+
)
69+
.unwrap();
70+
let func = Arc::new(PcSaftFunctional::new(Arc::new(parameters)));
71+
let vle = PhaseEquilibrium::bubble_point(
72+
&func,
73+
300.0 * KELVIN,
74+
&arr1(&[0.5, 0.5]),
75+
None,
76+
None,
77+
Default::default(),
78+
)
79+
.unwrap();
80+
let bulk = vle.liquid();
81+
group.bench_function("butane_pentane_liquid", |b| {
82+
b.iter(|| pore.initialize(bulk, None, None).unwrap().solve(None))
83+
});
84+
let bulk = StateBuilder::new(&func)
85+
.temperature(300.0 * KELVIN)
86+
.partial_density(&(&vle.vapor().partial_density * 0.2))
87+
.build()
88+
.unwrap();
89+
group.bench_function("butane_pentane_vapor", |b| {
90+
b.iter(|| pore.initialize(&bulk, None, None).unwrap().solve(None))
91+
});
92+
}
93+
94+
fn gc_pcsaft(c: &mut Criterion) {
95+
let mut group = c.benchmark_group("DFT_pore_gc_pcsaft");
96+
group.sample_size(20);
97+
98+
let parameters = GcPcSaftFunctionalParameters::from_json_segments(
99+
&["butane"],
100+
"./parameters/pcsaft/gc_substances.json",
101+
"./parameters/pcsaft/sauer2014_hetero.json",
102+
None,
103+
IdentifierOption::Name,
104+
)
105+
.unwrap();
106+
let func = Arc::new(GcPcSaftFunctional::new(Arc::new(parameters)));
107+
let pore = Pore1D::new(
108+
Geometry::Cartesian,
109+
20.0 * ANGSTROM,
110+
ExternalPotential::LJ93 {
111+
sigma_ss: 3.0,
112+
epsilon_k_ss: 100.0,
113+
rho_s: 0.08,
114+
},
115+
None,
116+
None,
117+
);
118+
let vle = PhaseEquilibrium::pure(&func, 300.0 * KELVIN, None, Default::default()).unwrap();
119+
let bulk = vle.liquid();
120+
let solver = DFTSolver::new(None)
121+
.picard_iteration(None, None, Some(1e-5), None)
122+
.anderson_mixing(None, None, None, None, None);
123+
group.bench_function("butane_liquid", |b| {
124+
b.iter(|| {
125+
pore.initialize(bulk, None, None)
126+
.unwrap()
127+
.solve(Some(&solver))
128+
})
129+
});
130+
}
131+
132+
criterion_group!(bench, fmt, pcsaft, gc_pcsaft);
133+
criterion_main!(bench);

0 commit comments

Comments
 (0)