Skip to content

Commit 32aa9b4

Browse files
committed
precond handling
1 parent 36e4dd7 commit 32aa9b4

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/wrappers.jl

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ struct ComposePreconditioner{Ti,To}
1212
outer::To
1313
end
1414

15-
Base.eltype(A::ComposePreconditioner) = Float64 #eltype(A.inner)
15+
Base.eltype(A::ComposePreconditioner) = promote_type(eltype(A.inner), eltype(A.outer))
1616
Base.adjoint(A::ComposePreconditioner) = ComposePreconditioner(A.outer', A.inner')
1717
Base.inv(A::ComposePreconditioner) = InvComposePreconditioner(A)
1818

@@ -148,8 +148,16 @@ function SciMLBase.solve(cache::LinearCache, alg::KrylovJL; kwargs...)
148148
cache = set_cacheval(cache, solver)
149149
end
150150

151-
M = InvComposePreconditioner(alg.Pl, cache.Pl) # left precond
152-
N = InvComposePreconditioner(alg.Pr, cache.Pr) # right
151+
M = I # left precond
152+
N = I # right precond
153+
154+
if (cache.Pl != I) | (alg.Pl != I)
155+
M = InvComposePreconditioner(alg.Pl, cache.Pl)
156+
end
157+
158+
if (cache.Pr != I) | (alg.Pr != I)
159+
N = InvComposePreconditioner(alg.Pr, cache.Pr)
160+
end
153161

154162
atol = cache.abstol
155163
rtol = cache.reltol
@@ -161,7 +169,7 @@ function SciMLBase.solve(cache::LinearCache, alg::KrylovJL; kwargs...)
161169
alg.kwargs...)
162170

163171
if cache.cacheval isa Krylov.CgSolver
164-
N != LinearAlgebra.I &&
172+
N != I &&
165173
@warn "$(alg.KrylovAlg) doesn't support right preconditioning."
166174
Krylov.solve!(args...; M=M,
167175
kwargs...)
@@ -172,7 +180,7 @@ function SciMLBase.solve(cache::LinearCache, alg::KrylovJL; kwargs...)
172180
Krylov.solve!(args...; M=M, N=N,
173181
kwargs...)
174182
elseif cache.cacheval isa Krylov.MinresSolver
175-
N != LinearAlgebra.I &&
183+
N != I &&
176184
@warn "$(alg.KrylovAlg) doesn't support right preconditioning."
177185
Krylov.solve!(args...; M=M,
178186
kwargs...)
@@ -223,8 +231,16 @@ IterativeSolversJL_MINRES(args...;kwargs...) =
223231
function init_cacheval(alg::IterativeSolversJL, cache::LinearCache)
224232
@unpack A, b, u = cache
225233

226-
Pl = ComposePreconditioner(alg.Pl, cache.Pl)
227-
Pr = ComposePreconditioner(alg.Pr, cache.Pr)
234+
Pl = IterativeSolvers.Identity()
235+
Pr = IterativeSolvers.Identity()
236+
237+
if (cache.Pl != I) | (alg.Pl != IterativeSolvers.Identity())
238+
Pl = ComposePreconditioner(alg.Pl, cache.Pl)
239+
end
240+
241+
if (cache.Pr != I) | (alg.Pr != IterativeSolvers.Identity())
242+
Pr = ComposePreconditioner(alg.Pr, cache.Pr)
243+
end
228244

229245
abstol = cache.abstol
230246
reltol = cache.reltol

0 commit comments

Comments
 (0)