Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement ILU preconditioner for GMRES in Python 2.7?

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
like image 907
fonsi Avatar asked Dec 14 '25 20:12

fonsi


1 Answers

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
like image 171
fonsi Avatar answered Dec 17 '25 11:12

fonsi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!