How to use the pyamg.gallery.laplacian.poisson function in pyamg

To help you get started, we’ve selected a few pyamg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github raptor-library / raptor / examples / pyamg_basic.py View on Github external
import numpy as np
from pyamg import smoothed_aggregation_solver
from pyamg.gallery import stencil_grid
from pyamg.gallery.diffusion import diffusion_stencil_2d

n=500
X,Y = np.meshgrid(np.linspace(0,1,n),np.linspace(0,1,n))
stencil = diffusion_stencil_2d(type='FE',epsilon=0.001,theta=np.pi/3)
A = stencil_grid(stencil, (n,n), format='csr')

from pyamg.gallery.laplacian import poisson
A = poisson( (n,n) , format ='csr')
b = np.random.rand(A.shape[0])
ml = smoothed_aggregation_solver(A,
        B=X.reshape(n*n,1),
        strength='symmetric',
        aggregate='standard',
        smooth=('jacobi', {'omega': 4.0/3.0,'degree':2}),
        presmoother=('jacobi', {'omega': 4.0/3.0}), 
        postsmoother=('jacobi', {'omega': 4.0/3.0}), 
        Bimprove=None,
        max_levels=10,
        max_coarse=5,
        keep=False)

res = []
x = ml.solve(b, tol=1e-8, residuals=res)
import pyamg_util