-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathpore.rs
More file actions
252 lines (228 loc) · 8.79 KB
/
pore.rs
File metadata and controls
252 lines (228 loc) · 8.79 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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#[macro_export]
macro_rules! impl_pore {
($func:ty, $py_func:ty) => {
/// Parameters required to specify a 1D pore.
///
/// Parameters
/// ----------
/// geometry : Geometry
/// The pore geometry.
/// pore_size : SINumber
/// The width of the slit pore in cartesian coordinates,
/// or the pore radius in spherical and cylindrical coordinates.
/// potential : ExternalPotential
/// The potential used to model wall-fluid interactions.
/// n_grid : int, optional
/// The number of grid points.
/// potential_cutoff : float, optional
/// Maximum value for the external potential.
///
/// Returns
/// -------
/// Pore1D
///
#[pyclass(name = "Pore1D")]
#[pyo3(text_signature = "(geometry, pore_size, potential, n_grid=None, potential_cutoff=None)")]
pub struct PyPore1D(Pore1D);
#[pyclass(name = "PoreProfile1D")]
pub struct PyPoreProfile1D(PoreProfile1D<$func>);
impl_1d_profile!(PyPoreProfile1D, [get_r, get_z]);
#[pymethods]
impl PyPore1D {
#[new]
fn new(
geometry: Geometry,
pore_size: PySINumber,
potential: PyExternalPotential,
n_grid: Option<usize>,
potential_cutoff: Option<f64>,
) -> Self {
Self(Pore1D::new(
geometry,
pore_size.into(),
potential.0,
n_grid,
potential_cutoff,
))
}
/// Initialize the pore for the given bulk state.
///
/// Parameters
/// ----------
/// bulk : State
/// The bulk state in equilibrium with the pore.
/// density : SIArray2, optional
/// Initial values for the density profile.
/// external_potential : numpy.ndarray[float], optional
/// The external potential in the pore. Used to
/// save computation time in the case of costly
/// evaluations of external potentials.
///
/// Returns
/// -------
/// PoreProfile1D
#[pyo3(text_signature = "($self, bulk, density=None, external_potential=None)")]
fn initialize(
&self,
bulk: &PyState,
density: Option<PySIArray2>,
external_potential: Option<&PyArray2<f64>>,
) -> PyResult<PyPoreProfile1D> {
Ok(PyPoreProfile1D(self.0.initialize(
&bulk.0,
density.as_deref(),
external_potential.map(|e| e.to_owned_array()).as_ref(),
)?))
}
#[getter]
fn get_geometry(&self)-> Geometry {
self.0.geometry
}
#[getter]
fn get_pore_size(&self)-> PySINumber {
self.0.pore_size.into()
}
#[getter]
fn get_potential(&self)-> PyExternalPotential {
PyExternalPotential(self.0.potential.clone())
}
#[getter]
fn get_n_grid(&self)-> Option<usize> {
self.0.n_grid
}
#[getter]
fn get_potential_cutoff(&self)-> Option<f64> {
self.0.potential_cutoff
}
/// The pore volume using Helium at 298 K as reference.
#[getter]
fn get_pore_volume(&self) -> PyResult<PySINumber> {
Ok(self.0.pore_volume()?.into())
}
}
#[pymethods]
impl PyPoreProfile1D {
#[getter]
fn get_grand_potential(&self) -> Option<PySINumber> {
self.0.grand_potential.map(PySINumber::from)
}
#[getter]
fn get_interfacial_tension(&self) -> Option<PySINumber> {
self.0.interfacial_tension.map(PySINumber::from)
}
#[getter]
fn get_partial_molar_enthalpy_of_adsorption(&self) -> PyResult<PySIArray1> {
Ok(self.0.partial_molar_enthalpy_of_adsorption()?.into())
}
#[getter]
fn get_enthalpy_of_adsorption(&self) -> PyResult<PySINumber> {
Ok(self.0.enthalpy_of_adsorption()?.into())
}
}
/// Parameters required to specify a 3D pore.
///
/// Parameters
/// ----------
/// system_size : [SINumber; 3]
/// The size of the unit cell.
/// n_grid : [int; 3]
/// The number of grid points in each direction.
/// coordinates : numpy.ndarray[float]
/// The positions of all interaction sites in the solid.
/// sigma_ss : numpy.ndarray[float]
/// The size parameters of all interaction sites.
/// epsilon_k_ss : numpy.ndarray[float]
/// The energy parameter of all interaction sites.
/// potential_cutoff: float, optional
/// Maximum value for the external potential.
/// cutoff_radius: SINumber, optional
/// The cutoff radius for the calculation of solid-fluid interactions.
///
/// Returns
/// -------
/// Pore3D
///
#[pyclass(name = "Pore3D")]
#[pyo3(text_signature = "(system_size, n_grid, coordinates, sigma_ss, epsilon_k_ss, potential_cutoff=None, cutoff_radius=None)")]
pub struct PyPore3D(Pore3D);
#[pyclass(name = "PoreProfile3D")]
pub struct PyPoreProfile3D(PoreProfile3D<$func>);
impl_3d_profile!(PyPoreProfile3D, get_x, get_y, get_z);
#[pymethods]
impl PyPore3D {
#[new]
fn new(
system_size: [PySINumber; 3],
n_grid: [usize; 3],
coordinates: &PySIArray2,
sigma_ss: &PyArray1<f64>,
epsilon_k_ss: &PyArray1<f64>,
potential_cutoff: Option<f64>,
cutoff_radius: Option<PySINumber>,
) -> Self {
Self(Pore3D::new(
[system_size[0].into(), system_size[1].into(), system_size[2].into()],
n_grid,
coordinates.clone().into(),
sigma_ss.to_owned_array(),
epsilon_k_ss.to_owned_array(),
potential_cutoff,
cutoff_radius.map(|c| c.into()),
))
}
/// Initialize the pore for the given bulk state.
///
/// Parameters
/// ----------
/// bulk : State
/// The bulk state in equilibrium with the pore.
/// density : SIArray4, optional
/// Initial values for the density profile.
/// external_potential : numpy.ndarray[float], optional
/// The external potential in the pore. Used to
/// save computation time in the case of costly
/// evaluations of external potentials.
///
/// Returns
/// -------
/// PoreProfile3D
#[pyo3(text_signature = "($self, bulk, density=None, external_potential=None)")]
fn initialize(
&self,
bulk: &PyState,
density: Option<PySIArray4>,
external_potential: Option<&PyArray4<f64>>,
) -> PyResult<PyPoreProfile3D> {
Ok(PyPoreProfile3D(self.0.initialize(
&bulk.0,
density.as_deref(),
external_potential.map(|e| e.to_owned_array()).as_ref(),
)?))
}
/// The pore volume using Helium at 298 K as reference.
#[getter]
fn get_pore_volume(&self) -> PyResult<PySINumber> {
Ok(self.0.pore_volume()?.into())
}
}
#[pymethods]
impl PyPoreProfile3D {
#[getter]
fn get_grand_potential(&self) -> Option<PySINumber> {
self.0.grand_potential.map(PySINumber::from)
}
#[getter]
fn get_interfacial_tension(&self) -> Option<PySINumber> {
self.0.interfacial_tension.map(PySINumber::from)
}
#[getter]
fn get_partial_molar_enthalpy_of_adsorption(&self) -> PyResult<PySIArray1> {
Ok(self.0.partial_molar_enthalpy_of_adsorption()?.into())
}
#[getter]
fn get_enthalpy_of_adsorption(&self) -> PyResult<PySINumber> {
Ok(self.0.enthalpy_of_adsorption()?.into())
}
}
};
}