I am trying to compare the GMRES solver with and without ILU preconditioner. It runs and provides the correct answer when the preconditioner is not applied (x=[1,1,1]). However, I cannot seem to find a way to apply the preconditioner correctly.
How can I get this piece of code to run with the ILU preconditioner?
import numpy as np
import scipy.sparse.linalg as spla
A = np.array([[ 0.4445, 0.4444, -0.2222],
[ 0.4444, 0.4445, -0.2222],
[-0.2222, -0.2222, 0.1112]])
b = np.array([[ 0.6667],
[ 0.6667],
[-0.3332]])
M2 = spla.spilu(A)
x = spla.gmres(A,b,M=M2)
print x
The preconditioner needs some treatment with the solve method:
import numpy as np
import scipy.sparse.linalg as spla
A = np.array([[ 0.4445, 0.4444, -0.2222],
[ 0.4444, 0.4445, -0.2222],
[-0.2222, -0.2222, 0.1112]])
b = np.array([[ 0.6667],
[ 0.6667],
[-0.3332]])
M2 = spla.spilu(A)
M_x = lambda x: M2.solve(x)
M = spla.LinearOperator((3,3), M_x)
x = spla.gmres(A,b,M=M)
print x
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With