-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathstate_properties.rs
More file actions
123 lines (115 loc) · 3.99 KB
/
state_properties.rs
File metadata and controls
123 lines (115 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use criterion::{criterion_group, criterion_main, Criterion};
use feos::pcsaft::{PcSaft, PcSaftParameters};
use feos_core::{
parameter::{IdentifierOption, Parameter},
Contributions, EquationOfState, State,
};
use ndarray::arr1;
use quantity::si::*;
use std::sync::Arc;
type S = State<PcSaft>;
/// Evaluate a property of a state given the EoS, the property to compute,
/// temperature, volume, moles, and the contributions to consider.
fn property<E: EquationOfState, T, F: Fn(&State<E>, Contributions) -> T>(
(eos, property, t, v, n, contributions): (
&Arc<E>,
F,
SINumber,
SINumber,
&SIArray1,
Contributions,
),
) -> T {
let state = State::new_nvt(eos, t, v, n).unwrap();
property(&state, contributions)
}
/// Evaluate a property with of a state given the EoS, the property to compute,
/// temperature, volume, moles.
fn property_no_contributions<E: EquationOfState, T, F: Fn(&State<E>) -> T>(
(eos, property, t, v, n): (&Arc<E>, F, SINumber, SINumber, &SIArray1),
) -> T {
let state = State::new_nvt(eos, t, v, n).unwrap();
property(&state)
}
fn properties_pcsaft(c: &mut Criterion) {
let parameters = PcSaftParameters::from_json(
vec!["methane", "ethane", "propane"],
"./parameters/pcsaft/gross2001.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_methane_ethane_propane");
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("partial_molar_volume", |b| {
b.iter(|| {
property((
&eos,
S::partial_molar_volume,
t,
v,
&m,
Contributions::ResidualNvt,
))
})
});
}
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("partial_molar_volume", |b| {
b.iter(|| {
property((
&eos,
S::partial_molar_volume,
t,
v,
&m,
Contributions::ResidualNvt,
))
})
});
}
criterion_group!(bench, properties_pcsaft, properties_pcsaft_polar);
criterion_main!(bench);