This repository was archived by the owner on Sep 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmod.rs
More file actions
173 lines (150 loc) · 5.36 KB
/
mod.rs
File metadata and controls
173 lines (150 loc) · 5.36 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
use crate::eos::PcSaftOptions;
use crate::parameters::PcSaftParameters;
use association::AssociationFunctional;
use dispersion::AttractiveFunctional;
use feos_core::joback::Joback;
use feos_core::parameter::Parameter;
use feos_core::{IdealGasContribution, MolarWeight};
use feos_dft::adsorption::FluidParameters;
use feos_dft::fundamental_measure_theory::{FMTContribution, FMTProperties, FMTVersion};
use feos_dft::solvation::PairPotential;
use feos_dft::{FunctionalContribution, HelmholtzEnergyFunctional, MoleculeShape, DFT};
use hard_chain::ChainFunctional;
use ndarray::{Array, Array1, Array2};
use num_dual::DualNum;
use num_traits::One;
use pure_saft_functional::*;
use quantity::si::*;
use std::f64::consts::FRAC_PI_6;
use std::rc::Rc;
mod association;
mod dispersion;
mod hard_chain;
mod polar;
mod pure_saft_functional;
/// PC-SAFT Helmholtz energy functional.
pub struct PcSaftFunctional {
pub parameters: Rc<PcSaftParameters>,
fmt_version: FMTVersion,
options: PcSaftOptions,
contributions: Vec<Box<dyn FunctionalContribution>>,
joback: Joback,
}
impl PcSaftFunctional {
pub fn new(parameters: Rc<PcSaftParameters>) -> DFT<Self> {
Self::with_options(parameters, FMTVersion::WhiteBear, PcSaftOptions::default())
}
pub fn new_full(parameters: Rc<PcSaftParameters>, fmt_version: FMTVersion) -> DFT<Self> {
Self::with_options(parameters, fmt_version, PcSaftOptions::default())
}
pub fn with_options(
parameters: Rc<PcSaftParameters>,
fmt_version: FMTVersion,
saft_options: PcSaftOptions,
) -> DFT<Self> {
let mut contributions: Vec<Box<dyn FunctionalContribution>> = Vec::with_capacity(4);
if matches!(
fmt_version,
FMTVersion::WhiteBear | FMTVersion::AntiSymWhiteBear
) && parameters.m.len() == 1
{
let fmt_assoc = PureFMTAssocFunctional::new(parameters.clone(), fmt_version);
contributions.push(Box::new(fmt_assoc));
if parameters.m.iter().any(|&mi| mi > 1.0) {
let chain = PureChainFunctional::new(parameters.clone());
contributions.push(Box::new(chain));
}
let att = PureAttFunctional::new(parameters.clone());
contributions.push(Box::new(att));
} else {
// Hard sphere contribution
let hs = FMTContribution::new(¶meters, fmt_version);
contributions.push(Box::new(hs));
// Hard chains
if parameters.m.iter().any(|&mi| !mi.is_one()) {
let chain = ChainFunctional::new(parameters.clone());
contributions.push(Box::new(chain));
}
// Dispersion
let att = AttractiveFunctional::new(parameters.clone());
contributions.push(Box::new(att));
// Association
if parameters.nassoc > 0 {
let assoc = AssociationFunctional::new(
parameters.clone(),
saft_options.max_iter_cross_assoc,
saft_options.tol_cross_assoc,
);
contributions.push(Box::new(assoc));
}
}
let joback = match ¶meters.joback_records {
Some(joback_records) => Joback::new(joback_records.clone()),
None => Joback::default(parameters.m.len()),
};
(Self {
parameters,
fmt_version,
options: saft_options,
contributions,
joback,
})
.into()
}
}
impl HelmholtzEnergyFunctional for PcSaftFunctional {
fn subset(&self, component_list: &[usize]) -> DFT<Self> {
Self::with_options(
Rc::new(self.parameters.subset(component_list)),
self.fmt_version,
self.options,
)
}
fn compute_max_density(&self, moles: &Array1<f64>) -> f64 {
self.options.max_eta * moles.sum()
/ (FRAC_PI_6 * &self.parameters.m * self.parameters.sigma.mapv(|v| v.powi(3)) * moles)
.sum()
}
fn contributions(&self) -> &[Box<dyn FunctionalContribution>] {
&self.contributions
}
fn ideal_gas(&self) -> &dyn IdealGasContribution {
&self.joback
}
fn molecule_shape(&self) -> MoleculeShape {
MoleculeShape::NonSpherical(&self.parameters.m)
}
}
impl MolarWeight<SIUnit> for PcSaftFunctional {
fn molar_weight(&self) -> SIArray1 {
self.parameters.molarweight.clone() * GRAM / MOL
}
}
impl FMTProperties for PcSaftParameters {
fn component_index(&self) -> Array1<usize> {
Array::from_shape_fn(self.m.len(), |i| i)
}
fn chain_length(&self) -> Array1<f64> {
self.m.clone()
}
fn hs_diameter<D: DualNum<f64>>(&self, temperature: D) -> Array1<D> {
self.hs_diameter(temperature)
}
}
impl FluidParameters for PcSaftFunctional {
fn epsilon_k_ff(&self) -> Array1<f64> {
self.parameters.epsilon_k.clone()
}
fn sigma_ff(&self) -> &Array1<f64> {
&self.parameters.sigma
}
}
impl PairPotential for PcSaftFunctional {
fn pair_potential(&self, r: &Array1<f64>) -> Array2<f64> {
let sigma = &self.parameters.sigma;
Array::from_shape_fn((self.parameters.m.len(), r.len()), |(i, j)| {
4.0 * self.parameters.epsilon_k[i]
* ((sigma[i] / r[j]).powi(12) - (sigma[i] / r[j]).powi(6))
})
}
}