# [Scipy-svn] r3258 - trunk/scipy/sandbox/multigrid

scipy-svn@scip... scipy-svn@scip...
Wed Aug 22 14:56:46 CDT 2007

```Author: wnbell
Date: 2007-08-22 14:56:43 -0500 (Wed, 22 Aug 2007)
New Revision: 3258

Modified:
trunk/scipy/sandbox/multigrid/multilevel.py
trunk/scipy/sandbox/multigrid/simple_test.py
Log:
minor changes

Modified: trunk/scipy/sandbox/multigrid/multilevel.py
===================================================================
--- trunk/scipy/sandbox/multigrid/multilevel.py	2007-08-22 19:42:37 UTC (rev 3257)
+++ trunk/scipy/sandbox/multigrid/multilevel.py	2007-08-22 19:56:43 UTC (rev 3258)
@@ -1,5 +1,10 @@
+__all__ = ['poisson_problem1D','poisson_problem2D',
+           'ruge_stuben_solver','smoothed_aggregation_solver',
+           'multilevel_solver']
+
+
from numpy.linalg import norm
-from numpy import zeros_like
+from numpy import zeros,zeros_like,array
import scipy
import numpy

@@ -10,17 +15,17 @@

def poisson_problem1D(N):
"""
-    Return a sparse CSC matrix for the 1d poisson problem
+    Return a sparse CSR matrix for the 1d poisson problem
with standard 3-point finite difference stencil on a
grid with N points.
"""
D = 2*numpy.ones(N)
O =  -numpy.ones(N)
-    return scipy.sparse.spdiags([D,O,O],[0,-1,1],N,N)
+    return scipy.sparse.spdiags([D,O,O],[0,-1,1],N,N).tocsr()

def poisson_problem2D(N):
"""
-    Return a sparse CSC matrix for the 2d poisson problem
+    Return a sparse CSR matrix for the 2d poisson problem
with standard 5-point finite difference stencil on a
square N-by-N grid.
"""
@@ -28,7 +33,7 @@
T =  -numpy.ones(N*N)
O =  -numpy.ones(N*N)
T[N-1::N] = 0
-    return scipy.sparse.spdiags([D,O,T,T,O],[0,-N,-1,1,N],N*N,N*N)
+    return scipy.sparse.spdiags([D,O,T,T,O],[0,-N,-1,1,N],N*N,N*N).tocsr()

def ruge_stuben_solver(A,max_levels=10,max_coarse=500):
As = [A]

Modified: trunk/scipy/sandbox/multigrid/simple_test.py
===================================================================
--- trunk/scipy/sandbox/multigrid/simple_test.py	2007-08-22 19:42:37 UTC (rev 3257)
+++ trunk/scipy/sandbox/multigrid/simple_test.py	2007-08-22 19:56:43 UTC (rev 3258)
@@ -2,13 +2,11 @@
from multigrid import *
from scipy import *

-A = poisson_problem(100).T
-s = scalar_solver(A)
+A = poisson_problem2D(200)
+rs_solver = ruge_stuben_solver(A)
b = rand(A.shape[0])
-x,res = s.solve(b,return_residuals=True)
-r = (b - A*x)
-print abs(r).max()
+x,res = rs_solver.solve(b,return_residuals=True)
+print res

-

```