如何在 Python 2.7 中为 GMRES 实现 ILU 预处理器? [英] How to implement ILU preconditioner for GMRES in Python 2.7?

查看:57
本文介绍了如何在 Python 2.7 中为 GMRES 实现 ILU 预处理器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试比较有和没有 ILU 预处理器的 GMRES 求解器.当未应用预处理器时,它会运行并提供正确答案 (x=[1,1,1]).但是,我似乎找不到正确应用预处理器的方法.

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.

我怎样才能让这段代码与 ILU 预处理器一起运行?

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

推荐答案

预处理器需要使用 solve 方法进行一些处理:

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

这篇关于如何在 Python 2.7 中为 GMRES 实现 ILU 预处理器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆