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