Skip to content

Commit 2ca92ac

Browse files
Clean up preconditioner code
1 parent 8194943 commit 2ca92ac

File tree

3 files changed

+8
-42
lines changed

3 files changed

+8
-42
lines changed

src/common.jl

+2-4
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,13 @@ function SciMLBase.init(prob::LinearProblem, alg::Union{SciMLLinearSolveAlgorith
8181
reltol=default_tol(eltype(prob.A)),
8282
maxiters=length(prob.b),
8383
verbose=false,
84-
Pl = nothing,
85-
Pr = nothing,
84+
Pl = Identity(),
85+
Pr = Identity(),
8686
kwargs...,
8787
)
8888
@unpack A, b, u0, p = prob
8989

9090
u0 = (u0 !== nothing) ? u0 : zero(b)
91-
Pl = (Pl !== nothing) ? Pl : Identity()
92-
Pr = (Pr !== nothing) ? Pr : Identity()
9391

9492
cacheval = init_cacheval(alg, A, b, u0, Pl, Pr, maxiters, abstol, reltol, verbose)
9593
isfresh = true

src/iterative_wrappers.jl

+6-21
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
## Krylov.jl
22

3-
struct KrylovJL{F,Tl,Tr,I,A,K} <: AbstractKrylovSubspaceMethod
3+
struct KrylovJL{F,I,A,K} <: AbstractKrylovSubspaceMethod
44
KrylovAlg::F
5-
Pl::Tl
6-
Pr::Tr
75
gmres_restart::I
86
window::I
97
args::A
108
kwargs::K
119
end
1210

1311
function KrylovJL(args...; KrylovAlg = Krylov.gmres!,
14-
Pl=nothing, Pr=nothing,
1512
gmres_restart=0, window=0,
1613
kwargs...)
1714

18-
Pl = (Pl === nothing) ? Identity() : Pl
19-
Pr = (Pr === nothing) ? Identity() : Pr
20-
21-
return KrylovJL(KrylovAlg, Pl, Pr, gmres_restart, window,
15+
return KrylovJL(KrylovAlg, gmres_restart, window,
2216
args, kwargs)
2317
end
2418

@@ -105,8 +99,8 @@ function SciMLBase.solve(cache::LinearCache, alg::KrylovJL; kwargs...)
10599
cache = set_cacheval(cache, solver)
106100
end
107101

108-
M = get_preconditioner(alg.Pl, cache.Pl)
109-
N = get_preconditioner(alg.Pr, cache.Pr)
102+
M = cache.Pl
103+
N = cache.Pr
110104

111105
M = (M === Identity()) ? I : inv(M)
112106
N = (N === Identity()) ? I : inv(N)
@@ -145,24 +139,18 @@ end
145139

146140
## IterativeSolvers.jl
147141

148-
struct IterativeSolversJL{F,Tl,Tr,I,A,K} <: AbstractKrylovSubspaceMethod
142+
struct IterativeSolversJL{F,I,A,K} <: AbstractKrylovSubspaceMethod
149143
generate_iterator::F
150-
Pl::Tl
151-
Pr::Tr
152144
gmres_restart::I
153145
args::A
154146
kwargs::K
155147
end
156148

157149
function IterativeSolversJL(args...;
158150
generate_iterator = IterativeSolvers.gmres_iterable!,
159-
Pl=nothing, Pr=nothing,
160151
gmres_restart=0, kwargs...)
161152

162-
Pl = (Pl === nothing) ? Identity() : Pl
163-
Pr = (Pr === nothing) ? Identity() : Pr
164-
165-
return IterativeSolversJL(generate_iterator, Pl, Pr, gmres_restart,
153+
return IterativeSolversJL(generate_iterator, gmres_restart,
166154
args, kwargs)
167155
end
168156

@@ -184,9 +172,6 @@ IterativeSolversJL_MINRES(args...;kwargs...) =
184172
kwargs...)
185173

186174
function init_cacheval(alg::IterativeSolversJL, A, b, u, Pl, Pr, maxiters, abstol, reltol, verbose)
187-
Pl = get_preconditioner(alg.Pl, Pl)
188-
Pr = get_preconditioner(alg.Pr, Pr)
189-
190175
restart = (alg.gmres_restart == 0) ? min(20, size(A,1)) : alg.gmres_restart
191176

192177
kwargs = (abstol=abstol, reltol=reltol, maxiter=maxiters,

src/preconditioners.jl

-17
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,3 @@ function LinearAlgebra.mul!(y, A::InvComposePreconditioner, x)
9595
@unpack P = A
9696
ldiv!(y, P, x)
9797
end
98-
99-
function get_preconditioner(Pi, Po)
100-
101-
ifPi = Pi !== Identity()
102-
ifPo = Po !== Identity()
103-
104-
P =
105-
if ifPi & ifPo
106-
ComposePreconditioner(Pi, Po)
107-
elseif ifPi | ifPo
108-
ifPi ? Pi : Po
109-
else
110-
Identity()
111-
end
112-
113-
return P
114-
end

0 commit comments

Comments
 (0)