Repository navigation
Expand file tree
/
Copy pathmod.rs
More file actions
182 lines (170 loc) · 5.27 KB
/
Copy pathmod.rs
File metadata and controls
182 lines (170 loc) · 5.27 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
174
175
176
177
178
179
180
181
182
use super::profile::{impl_1d_profile, impl_profile};
use super::{PyDFTSolver, PyDFTSolverLog};
use crate::error::PyFeosError;
use crate::ideal_gas::IdealGasModel;
use crate::phase_equilibria::PyPhaseEquilibrium;
use crate::residual::ResidualModel;
use crate::state::{PyContributions, PyState};
use feos_core::{EquationOfState, ReferenceSystem};
use feos_dft::interface::PlanarInterface;
use nalgebra::{DMatrix, DVector};
use ndarray::*;
use numpy::*;
use pyo3::*;
use quantity::*;
use std::sync::Arc;
mod surface_tension_diagram;
pub use surface_tension_diagram::PySurfaceTensionDiagram;
/// A one-dimensional density profile of a vapor-liquid or liquid-liquid interface.
#[pyclass(name = "PlanarInterface")]
pub struct PyPlanarInterface(
PlanarInterface<Arc<EquationOfState<Vec<IdealGasModel>, ResidualModel>>>,
);
impl_1d_profile!(PyPlanarInterface, [get_z]);
#[pymethods]
impl PyPlanarInterface {
/// Initialize a planar interface with a hyperbolic tangent.
///
/// Parameters
/// ----------
/// vle : PhaseEquilibrium
/// The bulk phase equilibrium.
/// n_grid : int
/// The number of grid points.
/// l_grid: SINumber
/// The width of the calculation domain.
/// critical_temperature: SINumber
/// An estimate for the critical temperature of the system.
/// Used to guess the width of the interface.
/// fix_equimolar_surface: bool, optional
/// If True use additional constraints to fix the
/// equimolar surface of the system.
/// Defaults to False.
///
/// Returns
/// -------
/// PlanarInterface
///
#[staticmethod]
#[pyo3(
text_signature = "(vle, n_grid, l_grid, critical_temperature, fix_equimolar_surface=None)"
)]
#[pyo3(signature = (vle, n_grid, l_grid, critical_temperature, fix_equimolar_surface=None))]
fn from_tanh(
vle: &PyPhaseEquilibrium,
n_grid: usize,
l_grid: Length,
critical_temperature: Temperature,
fix_equimolar_surface: Option<bool>,
) -> Self {
let profile = PlanarInterface::from_tanh(
&vle.0,
n_grid,
l_grid,
critical_temperature,
fix_equimolar_surface.unwrap_or(false),
);
PyPlanarInterface(profile)
}
/// Initialize a planar interface with a pDGT calculation.
///
/// Parameters
/// ----------
/// vle : PhaseEquilibrium
/// The bulk phase equilibrium.
/// n_grid : int
/// The number of grid points.
/// fix_equimolar_surface: bool, optional
/// If True use additional constraints to fix the
/// equimolar surface of the system.
/// Defaults to False.
///
/// Returns
/// -------
/// PlanarInterface
///
#[staticmethod]
#[pyo3(text_signature = "(vle, n_grid, fix_equimolar_surface=None)")]
#[pyo3(signature = (vle, n_grid, fix_equimolar_surface=None))]
fn from_pdgt(
vle: &PyPhaseEquilibrium,
n_grid: usize,
fix_equimolar_surface: Option<bool>,
) -> PyResult<Self> {
let profile =
PlanarInterface::from_pdgt(&vle.0, n_grid, fix_equimolar_surface.unwrap_or(false))
.map_err(PyFeosError::from)?;
Ok(PyPlanarInterface(profile))
}
/// Initialize a planar interface with a provided density profile.
///
/// Parameters
/// ----------
/// vle : PhaseEquilibrium
/// The bulk phase equilibrium.
/// n_grid : int
/// The number of grid points.
/// l_grid: SINumber
/// The width of the calculation domain.
/// density_profile: SIArray2
/// Initial condition for the density profile iterations
///
/// Returns
/// -------
/// PlanarInterface
///
#[staticmethod]
fn from_density_profile(
vle: &PyPhaseEquilibrium,
n_grid: usize,
l_grid: Length,
density_profile: Density<Array2<f64>>,
) -> Self {
let mut profile = PlanarInterface::new(&vle.0, n_grid, l_grid);
profile.profile.density = density_profile;
PyPlanarInterface(profile)
}
}
#[pymethods]
impl PyPlanarInterface {
#[getter]
fn get_surface_tension(&mut self) -> Option<SurfaceTension> {
self.0.surface_tension
}
#[getter]
fn get_equimolar_radius(&mut self) -> Option<Length> {
self.0.equimolar_radius
}
#[getter]
fn get_vle(&self) -> PyPhaseEquilibrium {
PyPhaseEquilibrium(self.0.vle.clone())
}
/// Calculates the Gibbs relative adsorption of component i with
/// respect to j: \Gamma_i^(j)
///
/// Returns
/// -------
/// SIArray2
///
fn relative_adsorption(&self) -> Moles<Array2<f64>> {
self.0.relative_adsorption()
}
/// Calculates the interfacial enrichment E_i.
///
/// Returns
/// -------
/// numpy.ndarray
///
fn interfacial_enrichment<'py>(&self, py: Python<'py>) -> Bound<'py, PyArray1<f64>> {
self.0.interfacial_enrichment().to_pyarray(py)
}
/// Calculates the interfacial thickness (90-10 number density difference)
///
/// Returns
/// -------
/// SINumber
///
fn interfacial_thickness(&self) -> PyResult<Length> {
Ok(self.0.interfacial_thickness().map_err(PyFeosError::from)?)
}
}