1
1
#[ cfg( feature = "with_mumps" ) ]
2
2
use super :: ComplexSolverMUMPS ;
3
3
4
- use super :: { ComplexSparseMatrix , Genie , LinSolParams , StatsLinSol } ;
4
+ use super :: { ComplexCooMatrix , ComplexSolverKLU , ComplexSolverUMFPACK , Genie , LinSolParams , StatsLinSol } ;
5
5
use crate :: StrError ;
6
- use crate :: { ComplexSolverKLU , ComplexSolverUMFPACK } ;
7
6
use russell_lab:: ComplexVector ;
8
7
9
8
/// Defines a unified interface for complex linear system solvers
@@ -24,7 +23,7 @@ pub trait ComplexLinSolTrait: Send {
24
23
/// kept the same for the next calls.
25
24
/// 3. If the structure of the matrix needs to be changed, the solver must
26
25
/// be "dropped" and a new solver allocated.
27
- fn factorize ( & mut self , mat : & mut ComplexSparseMatrix , params : Option < LinSolParams > ) -> Result < ( ) , StrError > ;
26
+ fn factorize ( & mut self , mat : & ComplexCooMatrix , params : Option < LinSolParams > ) -> Result < ( ) , StrError > ;
28
27
29
28
/// Computes the solution of the linear system
30
29
///
@@ -46,13 +45,7 @@ pub trait ComplexLinSolTrait: Send {
46
45
/// * `verbose` -- shows messages
47
46
///
48
47
/// **Warning:** the matrix must be same one used in `factorize`.
49
- fn solve (
50
- & mut self ,
51
- x : & mut ComplexVector ,
52
- mat : & ComplexSparseMatrix ,
53
- rhs : & ComplexVector ,
54
- verbose : bool ,
55
- ) -> Result < ( ) , StrError > ;
48
+ fn solve ( & mut self , x : & mut ComplexVector , rhs : & ComplexVector , verbose : bool ) -> Result < ( ) , StrError > ;
56
49
57
50
/// Updates the stats structure (should be called after solve)
58
51
fn update_stats ( & self , stats : & mut StatsLinSol ) ;
@@ -125,14 +118,14 @@ impl<'a> ComplexLinSolver<'a> {
125
118
pub fn compute (
126
119
genie : Genie ,
127
120
x : & mut ComplexVector ,
128
- mat : & mut ComplexSparseMatrix ,
121
+ mat : & ComplexCooMatrix ,
129
122
rhs : & ComplexVector ,
130
123
params : Option < LinSolParams > ,
131
124
) -> Result < Self , StrError > {
132
125
let mut solver = ComplexLinSolver :: new ( genie) ?;
133
126
solver. actual . factorize ( mat, params) ?;
134
127
let verbose = if let Some ( p) = params { p. verbose } else { false } ;
135
- solver. actual . solve ( x, mat , rhs, verbose) ?;
128
+ solver. actual . solve ( x, rhs, verbose) ?;
136
129
Ok ( solver)
137
130
}
138
131
}
@@ -142,7 +135,7 @@ impl<'a> ComplexLinSolver<'a> {
142
135
#[ cfg( test) ]
143
136
mod tests {
144
137
use super :: ComplexLinSolver ;
145
- use crate :: { ComplexSparseMatrix , Genie , Samples } ;
138
+ use crate :: { Genie , Samples } ;
146
139
use russell_lab:: { complex_vec_approx_eq, cpx, Complex64 , ComplexVector } ;
147
140
148
141
#[ cfg( feature = "with_mumps" ) ]
@@ -151,10 +144,9 @@ mod tests {
151
144
#[ test]
152
145
fn complex_lin_solver_compute_works_klu ( ) {
153
146
let ( coo, _, _, _) = Samples :: complex_symmetric_3x3_full ( ) ;
154
- let mut mat = ComplexSparseMatrix :: from_coo ( coo) ;
155
147
let mut x = ComplexVector :: new ( 3 ) ;
156
148
let rhs = ComplexVector :: from ( & [ cpx ! ( -3.0 , 3.0 ) , cpx ! ( 2.0 , -2.0 ) , cpx ! ( 9.0 , 7.0 ) ] ) ;
157
- ComplexLinSolver :: compute ( Genie :: Klu , & mut x, & mut mat , & rhs, None ) . unwrap ( ) ;
149
+ ComplexLinSolver :: compute ( Genie :: Klu , & mut x, & coo , & rhs, None ) . unwrap ( ) ;
158
150
let x_correct = & [ cpx ! ( 1.0 , 1.0 ) , cpx ! ( 2.0 , -2.0 ) , cpx ! ( 3.0 , 3.0 ) ] ;
159
151
complex_vec_approx_eq ( & x, x_correct, 1e-15 ) ;
160
152
}
@@ -164,21 +156,19 @@ mod tests {
164
156
#[ cfg( feature = "with_mumps" ) ]
165
157
fn complex_lin_solver_compute_works_mumps ( ) {
166
158
let ( coo, _, _, _) = Samples :: complex_symmetric_3x3_lower ( ) ;
167
- let mut mat = ComplexSparseMatrix :: from_coo ( coo) ;
168
159
let mut x = ComplexVector :: new ( 3 ) ;
169
160
let rhs = ComplexVector :: from ( & [ cpx ! ( -3.0 , 3.0 ) , cpx ! ( 2.0 , -2.0 ) , cpx ! ( 9.0 , 7.0 ) ] ) ;
170
- ComplexLinSolver :: compute ( Genie :: Mumps , & mut x, & mut mat , & rhs, None ) . unwrap ( ) ;
161
+ ComplexLinSolver :: compute ( Genie :: Mumps , & mut x, & coo , & rhs, None ) . unwrap ( ) ;
171
162
let x_correct = & [ cpx ! ( 1.0 , 1.0 ) , cpx ! ( 2.0 , -2.0 ) , cpx ! ( 3.0 , 3.0 ) ] ;
172
163
complex_vec_approx_eq ( & x, x_correct, 1e-15 ) ;
173
164
}
174
165
175
166
#[ test]
176
167
fn complex_lin_solver_compute_works_umfpack ( ) {
177
168
let ( coo, _, _, _) = Samples :: complex_symmetric_3x3_full ( ) ;
178
- let mut mat = ComplexSparseMatrix :: from_coo ( coo) ;
179
169
let mut x = ComplexVector :: new ( 3 ) ;
180
170
let rhs = ComplexVector :: from ( & [ cpx ! ( -3.0 , 3.0 ) , cpx ! ( 2.0 , -2.0 ) , cpx ! ( 9.0 , 7.0 ) ] ) ;
181
- ComplexLinSolver :: compute ( Genie :: Umfpack , & mut x, & mut mat , & rhs, None ) . unwrap ( ) ;
171
+ ComplexLinSolver :: compute ( Genie :: Umfpack , & mut x, & coo , & rhs, None ) . unwrap ( ) ;
182
172
let x_correct = & [ cpx ! ( 1.0 , 1.0 ) , cpx ! ( 2.0 , -2.0 ) , cpx ! ( 3.0 , 3.0 ) ] ;
183
173
complex_vec_approx_eq ( & x, x_correct, 1e-15 ) ;
184
174
}
0 commit comments