Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IDR(s) from IterativeSolvers #404

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ EnumX = "1"
FastLapackInterface = "1, 2"
GPUArraysCore = "0.1"
HYPRE = "1.4.0"
IterativeSolvers = "0.9.2"
IterativeSolvers = "0.9.3"
KLU = "0.3.0, 0.4"
Krylov = "0.9"
KrylovKit = "0.5, 0.6"
Expand Down
1 change: 1 addition & 0 deletions docs/src/solvers/solvers.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ IterativeSolversJL_CG
IterativeSolversJL_GMRES
IterativeSolversJL_BICGSTAB
IterativeSolversJL_MINRES
IterativeSolversJL_IDRS
IterativeSolversJL
```

Expand Down
17 changes: 16 additions & 1 deletion ext/LinearSolveIterativeSolversExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
generate_iterator = IterativeSolvers.gmres_iterable!,
kwargs...)
end
function LinearSolve.IterativeSolversJL_IDRS(args...; kwargs...)
IterativeSolversJL(args...;
generate_iterator = IterativeSolvers.idrs_iterable!,
kwargs...)
end

function LinearSolve.IterativeSolversJL_BICGSTAB(args...; kwargs...)
IterativeSolversJL(args...;
generate_iterator = IterativeSolvers.bicgstabl_iterator!,
Expand All @@ -47,6 +53,7 @@
reltol,
verbose::Bool, assumptions::OperatorAssumptions)
restart = (alg.gmres_restart == 0) ? min(20, size(A, 1)) : alg.gmres_restart
s = :idrs_s in keys(alg.kwargs) ? alg.kwargs.idrs_s : 4 # shadow space

kwargs = (abstol = abstol, reltol = reltol, maxiter = maxiters,
alg.kwargs...)
Expand All @@ -59,6 +66,14 @@
elseif alg.generate_iterator === IterativeSolvers.gmres_iterable!
alg.generate_iterator(u, A, b; Pl = Pl, Pr = Pr, restart = restart,
kwargs...)
elseif alg.generate_iterator === IterativeSolvers.idrs_iterable!
!!LinearSolve._isidentity_struct(Pr) &&
@warn "$(alg.generate_iterator) doesn't support right preconditioning"

Check warning on line 71 in ext/LinearSolveIterativeSolversExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/LinearSolveIterativeSolversExt.jl#L71

Added line #L71 was not covered by tests
history = IterativeSolvers.ConvergenceHistory(partial=true)
history[:abstol] = abstol
history[:reltol] = reltol
IterativeSolvers.idrs_iterable!(history, u, A, b, s, Pl, abstol, reltol, maxiters;
alg.kwargs...)
elseif alg.generate_iterator === IterativeSolvers.bicgstabl_iterator!
!!LinearSolve._isidentity_struct(Pr) &&
@warn "$(alg.generate_iterator) doesn't support right preconditioning"
Expand Down Expand Up @@ -95,7 +110,7 @@
end
cache.verbose && println()

resid = cache.cacheval.residual
resid = cache.cacheval isa IterativeSolvers.IDRSIterable ? cache.cacheval.R : cache.cacheval.residual
if resid isa IterativeSolvers.Residual
resid = resid.current
end
Expand Down
2 changes: 1 addition & 1 deletion src/LinearSolve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export LinearSolveFunction, DirectLdiv!
export KrylovJL, KrylovJL_CG, KrylovJL_MINRES, KrylovJL_GMRES,
KrylovJL_BICGSTAB, KrylovJL_LSMR, KrylovJL_CRAIGMR,
IterativeSolversJL, IterativeSolversJL_CG, IterativeSolversJL_GMRES,
IterativeSolversJL_BICGSTAB, IterativeSolversJL_MINRES,
IterativeSolversJL_BICGSTAB, IterativeSolversJL_MINRES, IterativeSolversJL_IDRS,
KrylovKitJL, KrylovKitJL_CG, KrylovKitJL_GMRES

export HYPREAlgorithm
Expand Down
15 changes: 15 additions & 0 deletions src/extension_algs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,21 @@ A wrapper over the IterativeSolvers.jl GMRES.
"""
function IterativeSolversJL_GMRES end

"""
```julia
IterativeSolversJL_IDRS(args...; Pl = nothing, kwargs...)
```

A wrapper over the IterativeSolvers.jl IDR(S).


!!! note

Using this solver requires adding the package IterativeSolvers.jl, i.e. `using IterativeSolvers`

"""
function IterativeSolversJL_IDRS end

"""
```julia
IterativeSolversJL_BICGSTAB(args...; Pl = nothing, Pr = nothing, kwargs...)
Expand Down
3 changes: 2 additions & 1 deletion test/basictests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ end
kwargs = (; gmres_restart = 5)
for alg in (("Default", IterativeSolversJL(kwargs...)),
("CG", IterativeSolversJL_CG(kwargs...)),
("GMRES", IterativeSolversJL_GMRES(kwargs...))
("GMRES", IterativeSolversJL_GMRES(kwargs...)),
("IDRS", IterativeSolversJL_IDRS(kwargs...))
# ("BICGSTAB",IterativeSolversJL_BICGSTAB(kwargs...)),
# ("MINRES",IterativeSolversJL_MINRES(kwargs...)),
)
Expand Down
Loading