-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathmod.rs
More file actions
161 lines (150 loc) · 5.76 KB
/
mod.rs
File metadata and controls
161 lines (150 loc) · 5.76 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
mod surface_tension_diagram;
#[macro_export]
macro_rules! impl_planar_interface {
($func:ty) => {
/// A one-dimensional density profile of a vapor-liquid or liquid-liquid interface.
#[pyclass(name = "PlanarInterface")]
pub struct PyPlanarInterface(PlanarInterface<$func>);
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)")]
fn from_tanh(
vle: &PyPhaseEquilibrium,
n_grid: usize,
l_grid: PySINumber,
critical_temperature: PySINumber,
fix_equimolar_surface: Option<bool>,
) -> PyResult<Self> {
let profile = PlanarInterface::from_tanh(
&vle.0,
n_grid,
l_grid.into(),
critical_temperature.into(),
fix_equimolar_surface.unwrap_or(false),
)?;
Ok(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)")]
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))?;
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: PySINumber,
density_profile: PySIArray2,
) -> PyResult<Self> {
let mut profile = PlanarInterface::new(&vle.0, n_grid, l_grid.into())?;
profile.profile.density = density_profile.into();
Ok(PyPlanarInterface(profile))
}
}
#[pymethods]
impl PyPlanarInterface {
#[getter]
fn get_surface_tension(&mut self) -> Option<PySINumber> {
self.0.surface_tension.map(PySINumber::from)
}
#[getter]
fn get_equimolar_radius(&mut self) -> Option<PySINumber> {
self.0.equimolar_radius.map(PySINumber::from)
}
#[getter]
fn get_vle(&self) -> PyPhaseEquilibrium {
PyPhaseEquilibrium(self.0.vle.clone())
}
}
#[pymethods]
impl PyPlanarInterface {
/// Calculates the Gibbs' relative adsorption of component `i' with
/// respect to `j': \Gamma_i^(j)
///
/// Returns
/// -------
/// SIArray2
///
fn relative_adsorption(&self) -> PyResult<PySIArray2> {
Ok(self.0.relative_adsorption()?.into())
}
/// Calculates the interfacial enrichment E_i.
///
/// Returns
/// -------
/// numpy.ndarray
///
fn interfacial_enrichment<'py>(&self, py: Python<'py>) -> PyResult<&'py PyArray1<f64>> {
Ok(self.0.interfacial_enrichment()?.to_pyarray(py))
}
/// Calculates the interfacial thickness (90-10 number density difference)
///
/// Returns
/// -------
/// SINumber
///
fn interfacial_thickness(&self) -> PyResult<PySINumber> {
Ok(self.0.interfacial_thickness()?.into())
}
}
};
}