-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathmod.rs
More file actions
153 lines (132 loc) · 4.64 KB
/
Copy pathmod.rs
File metadata and controls
153 lines (132 loc) · 4.64 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
use super::eos::GcPcSaftOptions;
use crate::association::Association;
use crate::hard_sphere::{FMTContribution, FMTVersion, HardSphereProperties, MonomerShape};
use feos_core::parameter::ParameterHetero;
use feos_core::{Components, MolarWeight};
use feos_dft::adsorption::FluidParameters;
use feos_dft::{FunctionalContribution, HelmholtzEnergyFunctional, MoleculeShape, DFT};
use ndarray::Array1;
use num_dual::DualNum;
use petgraph::graph::UnGraph;
use quantity::si::{SIArray1, GRAM, MOL};
use std::f64::consts::FRAC_PI_6;
use std::sync::Arc;
mod dispersion;
mod hard_chain;
mod parameter;
use dispersion::AttractiveFunctional;
use hard_chain::ChainFunctional;
pub use parameter::GcPcSaftFunctionalParameters;
/// gc-PC-SAFT Helmholtz energy functional.
pub struct GcPcSaftFunctional {
pub parameters: Arc<GcPcSaftFunctionalParameters>,
fmt_version: FMTVersion,
options: GcPcSaftOptions,
contributions: Vec<Box<dyn FunctionalContribution>>,
}
impl GcPcSaftFunctional {
pub fn new(parameters: Arc<GcPcSaftFunctionalParameters>) -> DFT<Self> {
Self::with_options(
parameters,
FMTVersion::WhiteBear,
GcPcSaftOptions::default(),
)
}
pub fn with_options(
parameters: Arc<GcPcSaftFunctionalParameters>,
fmt_version: FMTVersion,
saft_options: GcPcSaftOptions,
) -> DFT<Self> {
let mut contributions: Vec<Box<dyn FunctionalContribution>> = Vec::with_capacity(4);
// Hard sphere contribution
let hs = FMTContribution::new(¶meters, fmt_version);
contributions.push(Box::new(hs));
// Hard chains
let chain = ChainFunctional::new(¶meters);
contributions.push(Box::new(chain));
// Dispersion
let att = AttractiveFunctional::new(¶meters);
contributions.push(Box::new(att));
// Association
if !parameters.association.is_empty() {
let assoc = Association::new(
¶meters,
¶meters.association,
saft_options.max_iter_cross_assoc,
saft_options.tol_cross_assoc,
);
contributions.push(Box::new(assoc));
}
DFT(Self {
parameters,
fmt_version,
options: saft_options,
contributions,
})
}
}
impl Components for GcPcSaftFunctional {
fn components(&self) -> usize {
self.parameters.chemical_records.len()
}
fn subset(&self, component_list: &[usize]) -> Self {
Self::with_options(
Arc::new(self.parameters.subset(component_list)),
self.fmt_version,
self.options,
)
.0
}
}
impl HelmholtzEnergyFunctional for GcPcSaftFunctional {
fn molecule_shape(&self) -> MoleculeShape {
MoleculeShape::Heterosegmented(&self.parameters.component_index)
}
fn compute_max_density(&self, moles: &Array1<f64>) -> f64 {
let p = &self.parameters;
let moles_segments: Array1<f64> = p.component_index.iter().map(|&i| moles[i]).collect();
self.options.max_eta * moles.sum()
/ (FRAC_PI_6 * &p.m * p.sigma.mapv(|v| v.powi(3)) * moles_segments).sum()
}
fn contributions(&self) -> &[Box<dyn FunctionalContribution>] {
&self.contributions
}
fn bond_lengths(&self, temperature: f64) -> UnGraph<(), f64> {
// temperature dependent segment diameter
let d = self.parameters.hs_diameter(temperature);
self.parameters.bonds.map(
|_, _| (),
|e, _| {
let (i, j) = self.parameters.bonds.edge_endpoints(e).unwrap();
let di = d[i.index()];
let dj = d[j.index()];
0.5 * (di + dj)
},
)
}
}
impl MolarWeight for GcPcSaftFunctional {
fn molar_weight(&self) -> SIArray1 {
self.parameters.molarweight.clone() * GRAM / MOL
}
}
impl HardSphereProperties for GcPcSaftFunctionalParameters {
fn monomer_shape<N: DualNum<f64>>(&self, _: N) -> MonomerShape<N> {
let m = self.m.mapv(N::from);
MonomerShape::Heterosegmented([m.clone(), m.clone(), m.clone(), m], &self.component_index)
}
fn hs_diameter<D: DualNum<f64> + Copy>(&self, temperature: D) -> Array1<D> {
let ti = temperature.recip() * -3.0;
Array1::from_shape_fn(self.sigma.len(), |i| {
-((ti * self.epsilon_k[i]).exp() * 0.12 - 1.0) * self.sigma[i]
})
}
}
impl FluidParameters for GcPcSaftFunctional {
fn epsilon_k_ff(&self) -> Array1<f64> {
self.parameters.epsilon_k.clone()
}
fn sigma_ff(&self) -> &Array1<f64> {
&self.parameters.sigma
}
}