Skip to content

How to use InverseMap for preconditioner #225

Open
@erny123

Description

@erny123

Are there any examples to use InverseMap as a preconditioner?

From this links:

https://discourse.julialang.org/t/how-to-pass-a-matrix-free-preconditioner-to-iterativesolver-of-krylovkit/63315/7

#81

I've done something like using the diagonal as a preconditioner:

A = LinearMap(10; issymmetric=true, ismutating=true) do C,B
    C[1] = -2B[1] + B[2]
    for i in 2:length(B)-1
        C[i] = B[i-1] - 2B[i] + B[i+1]
    end
    C[end] = B[end-1] - 2B[end]
    return C
end

Pre =  (a) -> LinearMap(10; issymmetric=true, ismutating=true) do C,B
    C[1] =0.0
    for i in 2:length(B)-1
        C[i] = a[i,i]*B[i]
    end
    C[end] = 0.0
    return C
end

aa = Matrix(-2.0*I(10))

foo(x) = InverseMap(Pre(aa); solver=IterativeSolvers.bicgstabl! )*x

struct MyPreconditioner{F}
	fun::F
end
P = MyPreconditioner(foo)

using LinearAlgebra
LinearAlgebra.ldiv!(y, P::MyPreconditioner, x) = y .= P.fun(x)
LinearAlgebra.ldiv!(P::MyPreconditioner, x) = x .= P.fun(x)

b = rand(10)

sol = bicgstabl(A,b,Pl=P, log=true, max_mv_products=400)

but this says that the solution obtaininfor naN

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions