Hi all,
I would like to access coefficients of a preconditioner constructed using the ILUZero package.
ILUZero returns an object of type ::ILU0Precon{Float64, Int64, Float64} which contains a sparse representations of both L and U. However, I wonder how to access these numbers? This object does not seem be indexable and I don’t know how to recover both L and U as two independent SparseMatrixCSC. Would someone have a clue?
Just a clue: you could just try to write a method like
upper(ilu)=SparseMatrixCSC(ilu.m, ilu.n,ilu.u_colptr, ilu.u_rowval, ilu.u_nzval)
Similar for lower. I would check if the backsubstitution would be the same.
1 Like
Thanks a lot! That does the job. By the way is there a way to list all fields in a structure of this type? I have tried both fieldnames and keys but non of these seem to apply to ::ILU0Precon{Float64, Int64, Float64}.
Call propertynames(object) on an object of that type (not on the type). (Some of the “fields” might actually be computed on the fly, and should still be listed by propertynames.)
1 Like
Thanks and, yes, it is good to check for the solves. Using both L and U in successive substitutions yields the expected result.
using LinearAlgebra, SparseArrays, ILUZero
upper(ilu) = SparseMatrixCSC(ilu.m, ilu.n, ilu.u_colptr, ilu.u_rowval, ilu.u_nzval)
lower(ilu) = SparseMatrixCSC(ilu.m, ilu.n, ilu.l_colptr, ilu.l_rowval, ilu.l_nzval)
let
# Generate matrix and rhs
n = 100
cW = -1.0*ones(n-1)
cC = 2.0*ones(n ) ; cC[1] += 1; cC[end] += 1
M = SparseMatrixCSC(Tridiagonal(cW[:], cC[:], cW[:]))
b = 3.0*ones(n )
LU = ilu0(M)
# Standard solve
x1 = LU\b
# Split matrix in L and U parts
U = upper(LU)
L = lower(LU) + I(n)
x2 = U\(L\b)
# Compare
@show norm(x1-x2)
end
1 Like