@@ -7,33 +7,56 @@ struct Solver{S,T,P,PS}
77 max_coarse:: Int64
88end
99
10- function ruge_stuben (A:: SparseMatrixCSC{Ti,Tv} , :: Type{Val{bs}} = Val{1 };
10+ function ruge_stuben (_A:: Union{TA, Symmetric{Ti, TA}, Hermitian{Ti, TA}} ,
11+ :: Type{Val{bs}} = Val{1 };
1112 strength = Classical (0.25 ),
1213 CF = RS (),
1314 presmoother = GaussSeidel (),
1415 postsmoother = GaussSeidel (),
1516 max_levels = 10 ,
1617 max_coarse = 10 ,
17- coarse_solver = Pinv) where {Ti,Tv,bs}
18+ coarse_solver = Pinv) where {Ti,Tv,bs,TA <: SparseMatrixCSC{Ti,Tv} }
1819
1920 s = Solver (strength, CF, presmoother,
2021 postsmoother, max_levels, max_levels)
2122
22- levels = Vector {Level{Ti,Tv}} ()
23+ if _A isa Symmetric && Ti <: Real || _A isa Hermitian
24+ A = _A. data
25+ At = A
26+ symmetric = true
27+ @static if VERSION < v " 0.7-"
28+ levels = Vector {Level{TA, TA}} ()
29+ else
30+ levels = Vector {Level{TA, Adjoint{Ti, TA}, TA}} ()
31+ end
32+ else
33+ symmetric = false
34+ A = _A
35+ At = adjoint (A)
36+ @static if VERSION < v " 0.7-"
37+ levels = Vector {Level{TA, TA, TA}} ()
38+ else
39+ levels = Vector {Level{TA, Adjoint{Ti, TA}, TA}} ()
40+ end
41+ end
2342 w = MultiLevelWorkspace (Val{bs}, eltype (A))
2443
2544 while length (levels) + 1 < max_levels && size (A, 1 ) > max_coarse
2645 residual! (w, size (A, 1 ))
27- A = extend_heirarchy! (levels, strength, CF, A)
46+ A = extend_heirarchy! (levels, strength, CF, A, symmetric )
2847 coarse_x! (w, size (A, 1 ))
2948 coarse_b! (w, size (A, 1 ))
3049 end
3150
3251 MultiLevel (levels, A, coarse_solver (A), presmoother, postsmoother, w)
3352end
3453
35- function extend_heirarchy! (levels:: Vector{Level{Ti,Tv}} , strength, CF, A:: SparseMatrixCSC{Ti,Tv} ) where {Ti,Tv}
36- At = copy (A' )
54+ function extend_heirarchy! (levels, strength, CF, A:: SparseMatrixCSC{Ti,Tv} , symmetric) where {Ti,Tv}
55+ if symmetric
56+ At = A
57+ else
58+ At = adjoint (A)
59+ end
3760 S, T = strength (At)
3861 splitting = CF (S)
3962 P, R = direct_interpolation (At, T, splitting)
@@ -48,7 +71,7 @@ function direct_interpolation(At, T, splitting)
4871 Pp = rs_direct_interpolation_pass1 (T, splitting)
4972 Px, Pj, Pp = rs_direct_interpolation_pass2 (At, T, splitting, Pp)
5073 R = SparseMatrixCSC (maximum (Pj), size (At, 1 ), Pp, Pj, Px)
51- P = copy (R ' )
74+ P = R '
5275
5376 P, R
5477end
0 commit comments