@@ -13,11 +13,14 @@ struct MultiLevel{S, Pre, Post, Ti, Tv}
13
13
end
14
14
15
15
abstract type CoarseSolver end
16
- struct Pinv <: CoarseSolver
16
+ struct Pinv{T} <: CoarseSolver
17
+ pinvA:: Matrix{T}
18
+ Pinv (A) = new {eltype(A)} (pinv (Matrix (A)))
17
19
end
20
+ (p:: Pinv )(x, b) = mul! (x, p. pinvA, b)
18
21
19
22
MultiLevel (l:: Vector{Level{Ti,Tv}} , A:: SparseMatrixCSC{Ti,Tv} , presmoother, postsmoother) where {Ti,Tv} =
20
- MultiLevel (l, A, Pinv (), presmoother, postsmoother)
23
+ MultiLevel (l, A, Pinv (A ), presmoother, postsmoother)
21
24
Base. length (ml) = length (ml. levels) + 1
22
25
23
26
function Base. show (io:: IO , ml:: MultiLevel )
@@ -113,9 +116,9 @@ function solve(ml::MultiLevel, b::AbstractVector{T},
113
116
lvl = 1
114
117
while length (residuals) <= maxiter && residuals[end ] > tol
115
118
if length (ml) == 1
116
- x = coarse_solver ( ml. coarse_solver, A , b)
119
+ ml. coarse_solver (x , b)
117
120
else
118
- x = __solve (cycle , ml, x , b, lvl)
121
+ __solve! (x , ml, cycle , b, lvl)
119
122
end
120
123
push! (residuals, T (norm (b - A * x)))
121
124
end
@@ -127,7 +130,7 @@ function solve(ml::MultiLevel, b::AbstractVector{T},
127
130
return x
128
131
end
129
132
end
130
- function __solve (v :: V , ml, x , b, lvl)
133
+ function __solve! (x , ml, v :: V , b, lvl)
131
134
132
135
A = ml. levels[lvl]. A
133
136
ml. presmoother (A, x, b)
@@ -137,9 +140,9 @@ function __solve(v::V, ml, x, b, lvl)
137
140
coarse_x = zeros (eltype (coarse_b), size (coarse_b))
138
141
139
142
if lvl == length (ml. levels)
140
- coarse_x = coarse_solver ( ml. coarse_solver, ml . final_A , coarse_b)
143
+ ml. coarse_solver (coarse_x , coarse_b)
141
144
else
142
- coarse_x = __solve (v , ml, coarse_x , coarse_b, lvl + 1 )
145
+ coarse_x = __solve! (coarse_x , ml, v , coarse_b, lvl + 1 )
143
146
end
144
147
145
148
x .+ = ml. levels[lvl]. P * coarse_x
@@ -148,5 +151,3 @@ function __solve(v::V, ml, x, b, lvl)
148
151
149
152
x
150
153
end
151
-
152
- coarse_solver (:: Pinv , A, b) = pinv (Matrix (A)) * b
0 commit comments