1
1
2
- # TODO : composed preconditioners, preconditioner setter for cache,
3
- # detailed tests for wrappers
4
-
5
2
# # Preconditioners
6
3
7
4
struct ScaleVector{T}
8
5
s:: T
9
6
isleft:: Bool
10
7
end
11
8
12
- function LinearAlgebra. ldiv! (v:: ScaleVector , x)
9
+ function LinearAlgebra. ldiv! (P:: ScaleVector , x)
10
+ P. s == one (eltype (P. s)) && return x
11
+
12
+ if P. isleft
13
+ @. x = x * P. s # @.. doesnt speed up scalar computation
14
+ else
15
+ @. x = x / P. s
16
+ end
13
17
end
14
18
15
- function LinearAlgebra. ldiv! (y, v:: ScaleVector , x)
19
+ function LinearAlgebra. ldiv! (y, P:: ScaleVector , x)
20
+ P. s == one (eltype (P. s)) && return y = x
21
+
22
+ if P. isleft
23
+ @. y = x / P. s
24
+ else
25
+ @. y = x * P. s
26
+ end
16
27
end
17
28
18
29
struct ComposePreconditioner{Ti,To}
@@ -21,12 +32,19 @@ struct ComposePreconditioner{Ti,To}
21
32
isleft:: Bool
22
33
end
23
34
24
- function LinearAlgebra. ldiv! (v:: ComposePreconditioner , x)
25
- @unpack inner, outer, isleft = v
35
+ function LinearAlgebra. ldiv! (P:: ComposePreconditioner , x)
36
+ @unpack inner, outer, isleft = P
37
+ if isleft
38
+ ldiv! (outer, x)
39
+ ldiv! (inner, x)
40
+ else
41
+ ldiv! (inner, x)
42
+ ldiv! (outer, x)
43
+ end
26
44
end
27
45
28
- function LinearAlgebra. ldiv! (y, v :: ComposePreconditioner , x)
29
- @unpack inner, outer, isleft = v
46
+ function LinearAlgebra. ldiv! (y, P :: ComposePreconditioner , x)
47
+ @unpack inner, outer, isleft = P
30
48
end
31
49
32
50
# # Krylov.jl
@@ -132,6 +150,9 @@ function SciMLBase.solve(cache::LinearCache, alg::KrylovJL; kwargs...)
132
150
cache = set_cacheval (cache, solver)
133
151
end
134
152
153
+ # Pl = ComposePreconditioner(alg.Pl, cache.Pl, true)
154
+ # Pr = ComposePreconditioner(alg.Pr, cache.Pr, false)
155
+
135
156
atol = cache. abstol
136
157
rtol = cache. reltol
137
158
itmax = cache. maxiters
@@ -204,8 +225,11 @@ IterativeSolversJL_MINRES(args...;kwargs...) =
204
225
function init_cacheval (alg:: IterativeSolversJL , cache:: LinearCache )
205
226
@unpack A, b, u = cache
206
227
207
- Pl = (alg. Pl == LinearAlgebra. I) ? IterativeSolvers. Identity () : alg. Pl
208
- Pr = (alg. Pr == LinearAlgebra. I) ? IterativeSolvers. Identity () : alg. Pr
228
+ Pl = alg. Pl
229
+ Pr = alg. Pr
230
+
231
+ # Pl = ComposePreconditioner(alg.Pl, cache.Pl, true)
232
+ # Pr = ComposePreconditioner(alg.Pr, cache.Pr, false)
209
233
210
234
abstol = cache. abstol
211
235
reltol = cache. reltol
0 commit comments