Skip to content

Commit cc2d5da

Browse files
committed
works
1 parent a886bca commit cc2d5da

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

src/LinearSolve.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export LUFactorization, SVDFactorization, QRFactorization, GenericFactorization,
5050
UMFPACKFactorization, KLUFactorization
5151
export KrylovJL, KrylovJL_CG, KrylovJL_GMRES, KrylovJL_BICGSTAB, KrylovJL_MINRES,
5252
IterativeSolversJL, IterativeSolversJL_CG, IterativeSolversJL_GMRES,
53-
IterativeSolversJL_BICGSTAB, IterativeSolversJL_MINRES
53+
IterativeSolversJL_BICGSTAB, IterativeSolversJL_MINRES,
54+
KrylovKitJL, KrylovKitJL_CG, KrylovKitJL_GMRES
5455

5556
end

src/iterative_wrappers.jl

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,37 +234,40 @@ end
234234

235235
## KrylovKit.jl
236236

237-
struct KrylovKitJL{F,I,K} <: AbstractKrylovSubspaceMethod
237+
struct KrylovKitJL{F,A,I,K} <: AbstractKrylovSubspaceMethod
238238
KrylovAlg::F
239239
gmres_restart::I
240+
args::A
240241
kwargs::K
241242
end
242243

243-
function KrylovKitJL(KrylovAlg = KrylovKit.GMRES, gmres_restart=0, kwargs...)
244-
return KrylovJL(KrylovAlg, gmres_restart, kwargs)
244+
function KrylovKitJL(args...;
245+
KrylovAlg = KrylovKit.GMRES, gmres_restart = 0,
246+
kwargs...)
247+
return KrylovJL(KrylovAlg, gmres_restart, args, kwargs)
245248
end
246249

247-
KrylovKitJL_GMRES(kwargs...) = KrylovKitJL()
248-
KrylovKitJL_CG(kwargs...) = KrylovKitJL(KrylovKitAlg=KrylovKit.CG, kwargs...)
250+
KrylovKitJL_CG(args...;kwargs...) =
251+
KrylovKitJL(args...; KrylovAlg=KrylovKit.CG, kwargs...)
252+
KrylovKitJL_GMRES(args...;kwargs...) =
253+
KrylovKitJL(args...; KrylovAlg=KrylovKit.GMRES, kwargs...)
249254

250255
function SciMLBase.solve(cache::LinearCache, alg::KrylovKitJL, kwargs...)
251256

252257
atol = float(cache.abstol)
253258
rtol = float(cache.reltol)
254259
maxiter = cache.maxiters
255260
verbosity = cache.verbose ? 1 : 0
256-
krylovdim = alg.gmres_restart
261+
krylovdim = (alg.gmres_restart == 0) ? min(20, size(A,1)) : alg.gmres_restart
257262

258263
kwargs = (atol=atol, rtol=rtol, maxiter=maxiter, verbosity=verbosity,
259264
krylovdim = krylovdim, alg.kwargs...)
260265

261-
x, info = KrylovKit.linsolve(cache.A, cache.b, cache.u, alg.KrylovAlg,
262-
[a₀::Number = 0, a₁::Number = 1])
266+
x, info = KrylovKit.linsolve(cache.A, cache.b, cache.u, alg.KrylovAlg)
267+
263268
copy!(cache.u, x)
264269
resid = info.normres
265270
retcode = info.converged == 1 ? :Default : :DidNotConverge
266271
iters = info.numiter
267-
268-
return SciMLBase.build_linear_solution(alg,cache.u, resid,cache;
269-
retcode = retcode, iters = iters)
272+
return SciMLBase.build_linear_solution(alg, cache.u, resid, cache; retcode = retcode, iters = iters)
270273
end

test/basictests.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,19 @@ end
161161
end
162162
end
163163

164+
@testset "KrylovKit" begin
165+
kwargs = (;gmres_restart=5,)
166+
for alg in (
167+
("Default", KrylovKitJL(kwargs...)),
168+
("CG", KrylovKitJL_CG(kwargs...)),
169+
("GMRES",KrylovKitJL_GMRES(kwargs...)),
170+
)
171+
@testset "$(alg[1])" begin
172+
test_interface(alg[2], prob1, prob2)
173+
end
174+
end
175+
end
176+
164177
@testset "PardisoJL" begin
165178
@test_throws UndefVarError alg = PardisoJL()
166179

0 commit comments

Comments
 (0)