-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathsolver.rs
More file actions
177 lines (165 loc) · 4.58 KB
/
solver.rs
File metadata and controls
177 lines (165 loc) · 4.58 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
use crate::{DFTSolver, DFTSolverLog};
use feos_core::Verbosity;
use numpy::{PyArray1, ToPyArray};
use pyo3::prelude::*;
use quantity::python::PySIArray1;
/// Settings for the DFT solver.
///
/// Parameters
/// ----------
/// verbosity: Verbosity, optional
/// The verbosity level of the solver.
/// Defaults to Verbosity.None.
///
/// Returns
/// -------
/// DFTSolver
#[pyclass(name = "DFTSolver")]
#[derive(Clone)]
#[pyo3(text_signature = "(verbosity=None)")]
pub struct PyDFTSolver(pub DFTSolver);
#[pymethods]
impl PyDFTSolver {
#[new]
fn new(verbosity: Option<Verbosity>) -> Self {
Self(DFTSolver::new(verbosity))
}
/// The default solver.
///
/// Returns
/// -------
/// DFTSolver
#[classattr]
fn default() -> Self {
Self(DFTSolver::default())
}
/// Add a picard iteration to the solver object.
///
/// Parameters
/// ----------
/// log: bool, optional
/// Iterate the logarithm of the density profile.
/// Defaults to False.
/// max_iter: int, optional
/// The maximum number of iterations.
/// Defaults to 500.
/// tol: float, optional
/// The tolerance.
/// Defaults to 1e-11.
/// damping_coefficient: float, optional
/// Constant damping coefficient.
/// If no damping coefficient is provided, a line
/// search is used to determine the step size.
///
/// Returns
/// -------
/// DFTSolver
#[pyo3(text_signature = "($self, log=None, max_iter=None, tol=None, damping_coefficient=None)")]
fn picard_iteration(
&self,
log: Option<bool>,
max_iter: Option<usize>,
tol: Option<f64>,
damping_coefficient: Option<f64>,
) -> Self {
Self(
self.0
.clone()
.picard_iteration(log, max_iter, tol, damping_coefficient),
)
}
/// Add Anderson mixing to the solver object.
///
/// Parameters
/// ----------
/// log: bool, optional
/// Iterate the logarithm of the density profile
/// Defaults to False.
/// max_iter: int, optional
/// The maximum number of iterations.
/// Defaults to 150.
/// tol: float, optional
/// The tolerance.
/// Defaults to 1e-11.
/// damping_coefficient: float, optional
/// The damping coefficient.
/// Defaults to 0.15.
/// mmax: int, optional
/// The maximum number of old solutions that are used.
/// Defaults to 100.
///
/// Returns
/// -------
/// DFTSolver
#[pyo3(
text_signature = "($self, log=None, max_iter=None, tol=None, damping_coefficient=None, mmax=None)"
)]
fn anderson_mixing(
&self,
log: Option<bool>,
max_iter: Option<usize>,
tol: Option<f64>,
damping_coefficient: Option<f64>,
mmax: Option<usize>,
) -> Self {
Self(
self.0
.clone()
.anderson_mixing(log, max_iter, tol, damping_coefficient, mmax),
)
}
/// Add Newton solver to the solver object.
///
/// Parameters
/// ----------
/// log: bool, optional
/// Iterate the logarithm of the density profile
/// Defaults to False.
/// max_iter: int, optional
/// The maximum number of iterations.
/// Defaults to 50.
/// max_iter_gmres: int, optional
/// The maximum number of iterations for the GMRES solver.
/// Defaults to 200.
/// tol: float, optional
/// The tolerance.
/// Defaults to 1e-11.
///
/// Returns
/// -------
/// DFTSolver
#[pyo3(text_signature = "($self, log=None, max_iter=None, max_iter_gmres=None, tol=None)")]
fn newton(
&self,
log: Option<bool>,
max_iter: Option<usize>,
max_iter_gmres: Option<usize>,
tol: Option<f64>,
) -> Self {
Self(self.0.clone().newton(log, max_iter, max_iter_gmres, tol))
}
fn _repr_markdown_(&self) -> String {
self.0._repr_markdown_()
}
fn __repr__(&self) -> PyResult<String> {
Ok(self.0.to_string())
}
}
#[pyclass(name = "DFTSolverLog")]
#[derive(Clone)]
pub struct PyDFTSolverLog(pub DFTSolverLog);
#[pymethods]
impl PyDFTSolverLog {
#[getter]
fn get_residual<'py>(&self, py: Python<'py>) -> &'py PyArray1<f64> {
self.0.residual().to_pyarray(py)
}
#[getter]
fn get_time(&self) -> PySIArray1 {
self.0.time().into()
}
#[getter]
fn get_solver(&self) -> Vec<&'static str> {
self.0.solver().to_vec()
}
}