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 pathsolver.rs
More file actions
144 lines (135 loc) · 3.6 KB
/
solver.rs
File metadata and controls
144 lines (135 loc) · 3.6 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
use crate::DFTSolver;
use feos_core::Verbosity;
use pyo3::prelude::*;
/// Settings for the DFT solver.
///
/// Parameters
/// ----------
/// verbosity: Verbosity, optional
/// The verbosity level of the solver.
///
/// 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.unwrap_or_default()))
}
/// 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
/// max_iter: int, optional
/// The maximum number of iterations.
/// tol: float, optional
/// The tolerance.
/// beta: float, optional
/// The damping factor.
///
/// Returns
/// -------
/// DFTSolver
#[pyo3(text_signature = "($self, log=None, max_iter=None, tol=None, beta=None)")]
fn picard_iteration(
&self,
max_rel: Option<f64>,
log: Option<bool>,
max_iter: Option<usize>,
tol: Option<f64>,
beta: Option<f64>,
) -> Self {
let mut solver = self.0.clone().picard_iteration(max_rel);
if let Some(log) = log {
if log {
solver = solver.log();
}
}
if let Some(max_iter) = max_iter {
solver = solver.max_iter(max_iter);
}
if let Some(tol) = tol {
solver = solver.tol(tol);
}
if let Some(beta) = beta {
solver = solver.beta(beta);
}
Self(solver)
}
fn log_iter(&self) -> Self {
let mut solver = self.0.clone();
solver.verbosity = Verbosity::Iter;
Self(solver)
}
fn log_result(&self) -> Self {
let mut solver = self.0.clone();
solver.verbosity = Verbosity::Result;
Self(solver)
}
/// Add Anderson mixing to the solver object.
///
/// Parameters
/// ----------
/// mmax: int, optional
/// The maximum number of old solutions that are used.
/// log: bool, optional
/// Iterate the logarithm of the density profile
/// max_iter: int, optional
/// The maximum number of iterations.
/// tol: float, optional
/// The tolerance.
/// beta: float, optional
/// The damping factor.
///
/// Returns
/// -------
/// DFTSolver
#[pyo3(text_signature = "($self, mmax=None, log=None, max_iter=None, tol=None, beta=None)")]
fn anderson_mixing(
&self,
mmax: Option<usize>,
log: Option<bool>,
max_iter: Option<usize>,
tol: Option<f64>,
beta: Option<f64>,
) -> Self {
let mut solver = self.0.clone().anderson_mixing(mmax);
if let Some(log) = log {
if log {
solver = solver.log();
}
}
if let Some(max_iter) = max_iter {
solver = solver.max_iter(max_iter);
}
if let Some(tol) = tol {
solver = solver.tol(tol);
}
if let Some(beta) = beta {
solver = solver.beta(beta);
}
Self(solver)
}
fn _repr_markdown_(&self) -> String {
self.0._repr_markdown_()
}
fn __repr__(&self) -> PyResult<String> {
Ok(self.0.to_string())
}
}