nekStab / LightKrylov

Lightweight implementation of Krylov subspace techniques in Fortran.
BSD 3-Clause "New" or "Revised" License
18 stars 0 forks source link

Support preconditioners for linear solvers? #26

Closed loiseaujc closed 1 year ago

loiseaujc commented 1 year ago

At the moment, none of our linear solvers (gmres, bicgstab, and cg) actually support preconditioning. How about creating an abstract_precond type with type-bound procedures apply(x) and undo(x) (or something along those lines)?

If we take gmres as an example (assuming we standardize the interface as suggested in #25), the interface could be

subroutine gmres(A, x, b, info, precond, opts)
    !> Standard arguments.
    ...
    !> Preconditioner
    class(abstract_precond), optional, intent(in) :: precond
    class(abstract_precond), allocatable :: P
    logical :: has_precond = .false.

    !> Check whether a preconditioner has been passed or not.
    if (present(precond)) then
        has_precond = .true. ; P = precond
    endif

    ....

    return
end subroutine gmres

and we have some P%apply(x) and P%undo(x) wherever needed. For the sake of simplicity, I think only right preconditioning should be supported, i.e. $\mathbf{A} \mathbf{P} \mathbf{P}^{-1} \mathbf{x} = \mathbf{b}$ where $\mathbf{P} \simeq \mathbf{A}^{-1}$.

What do you think?

loiseaujc commented 1 year ago

I have just send a PR for this. For the moment, preconditioning is only effective for gmres. I need to dig a bit deeper to see how preconditioning impacts the cg and bicgstab iterations. It will be needed eventually but I think we can get away with just gmres for the time being.