Skip to content

Commit a886bca

Browse files
committed
initital commit
1 parent 5b9b492 commit a886bca

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/iterative_wrappers.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,40 @@ function purge_history!(iter::IterativeSolvers.GMRESIterable, x, b)
231231
iter.β = iter.residual.current
232232
nothing
233233
end
234+
235+
## KrylovKit.jl
236+
237+
struct KrylovKitJL{F,I,K} <: AbstractKrylovSubspaceMethod
238+
KrylovAlg::F
239+
gmres_restart::I
240+
kwargs::K
241+
end
242+
243+
function KrylovKitJL(KrylovAlg = KrylovKit.GMRES, gmres_restart=0, kwargs...)
244+
return KrylovJL(KrylovAlg, gmres_restart, kwargs)
245+
end
246+
247+
KrylovKitJL_GMRES(kwargs...) = KrylovKitJL()
248+
KrylovKitJL_CG(kwargs...) = KrylovKitJL(KrylovKitAlg=KrylovKit.CG, kwargs...)
249+
250+
function SciMLBase.solve(cache::LinearCache, alg::KrylovKitJL, kwargs...)
251+
252+
atol = float(cache.abstol)
253+
rtol = float(cache.reltol)
254+
maxiter = cache.maxiters
255+
verbosity = cache.verbose ? 1 : 0
256+
krylovdim = alg.gmres_restart
257+
258+
kwargs = (atol=atol, rtol=rtol, maxiter=maxiter, verbosity=verbosity,
259+
krylovdim = krylovdim, alg.kwargs...)
260+
261+
x, info = KrylovKit.linsolve(cache.A, cache.b, cache.u, alg.KrylovAlg,
262+
[a₀::Number = 0, a₁::Number = 1])
263+
copy!(cache.u, x)
264+
resid = info.normres
265+
retcode = info.converged == 1 ? :Default : :DidNotConverge
266+
iters = info.numiter
267+
268+
return SciMLBase.build_linear_solution(alg,cache.u, resid,cache;
269+
retcode = retcode, iters = iters)
270+
end

0 commit comments

Comments
 (0)