This repository was archived by the owner on Jul 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmod.rs
More file actions
118 lines (110 loc) · 4.1 KB
/
mod.rs
File metadata and controls
118 lines (110 loc) · 4.1 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
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", unsendable)]
pub struct PyPlanarInterface(PlanarInterface<SIUnit, $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.
///
/// Returns
/// -------
/// PlanarInterface
///
#[staticmethod]
#[pyo3(text_signature = "(vle, n_grid, l_grid, critical_temperature)")]
fn from_tanh(
vle: &PyPhaseEquilibrium,
n_grid: usize,
l_grid: PySINumber,
critical_temperature: PySINumber,
) -> PyResult<Self> {
let profile = PlanarInterface::from_tanh(
&vle.0,
n_grid,
l_grid.into(),
critical_temperature.into(),
)?;
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.
///
/// Returns
/// -------
/// PlanarInterface
///
#[staticmethod]
#[pyo3(text_signature = "(vle, n_grid)")]
fn from_pdgt(vle: &PyPhaseEquilibrium, n_grid: usize) -> PyResult<Self> {
let profile = PlanarInterface::from_pdgt(&vle.0, n_grid)?;
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]
#[pyo3(text_signature = "(vle, n_grid, l_grid, density_profile)")]
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())
}
}
};
}