Skip to content

Commit

Permalink
Added verbose option for GMRES
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiManyer committed Sep 20, 2023
1 parent 9b8d530 commit 68788db
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/LinearSolvers/GMRESSolvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ struct GMRESSolver <: Gridap.Algebra.LinearSolver
m ::Int
Pl ::Gridap.Algebra.LinearSolver
tol::Float64
verbose::Bool
end

function GMRESSolver(m,Pl;tol=1e-6,verbose=false)
return GMRESSolver(m,Pl,tol,verbose)
end

struct GMRESSymbolicSetup <: Gridap.Algebra.SymbolicSetup
Expand Down Expand Up @@ -47,25 +52,25 @@ end

function Gridap.Algebra.solve!(x::AbstractVector,ns::GMRESNumericalSetup,b::AbstractVector)
solver, A, Pl, caches = ns.solver, ns.A, ns.Pl_ns, ns.caches
m, tol = solver.m, solver.tol
m, tol, verbose = solver.m, solver.tol, solver.verbose
w, V, Z, H, g, c, s = caches
println(" > Starting GMRES solver: ")
verbose && println(" > Starting GMRES solver: ")

# Initial residual
mul!(w,A,x); w .= b .- w

β = norm(w)
iter = 0
while> tol)
println(" > Iteration ", iter," - Residual: ", β)
verbose && println(" > Iteration ", iter," - Residual: ", β)
fill!(H,0.0)

# Arnoldi process
fill!(g,0.0); g[1] = β
V[1] .= w ./ β
j = 1
while ( j < m+1 && β > tol )
println(" > Inner iteration ", j," - Residual: ", β)
verbose && println(" > Inner iteration ", j," - Residual: ", β)
# Arnoldi orthogonalization by Modified Gram-Schmidt
solve!(Z[j],Pl,V[j])
mul!(w,A,Z[j])
Expand Down Expand Up @@ -106,8 +111,8 @@ function Gridap.Algebra.solve!(x::AbstractVector,ns::GMRESNumericalSetup,b::Abst

iter += 1
end
println(" Exiting GMRES solver.")
println(" > Num Iter: ", iter," - Final residual: ", β)
verbose && println(" > Num Iter: ", iter," - Final residual: ", β)
verbose && println(" Exiting GMRES solver.")

return x
end

0 comments on commit 68788db

Please sign in to comment.