[Scipy-svn] r3832 - in trunk/scipy/sandbox/multigrid: gallery gallery/tests tests

scipy-svn@scip... scipy-svn@scip...
Mon Jan 14 14:01:34 CST 2008


Author: wnbell
Date: 2008-01-14 14:01:29 -0600 (Mon, 14 Jan 2008)
New Revision: 3832

Added:
   trunk/scipy/sandbox/multigrid/gallery/laplacian.py
   trunk/scipy/sandbox/multigrid/gallery/tests/test_laplacian.py
Removed:
   trunk/scipy/sandbox/multigrid/gallery/poisson.py
   trunk/scipy/sandbox/multigrid/gallery/tests/test_poisson.py
Modified:
   trunk/scipy/sandbox/multigrid/gallery/__init__.py
   trunk/scipy/sandbox/multigrid/tests/test_sa.py
Log:
moved poisson.py to laplacian.py


Modified: trunk/scipy/sandbox/multigrid/gallery/__init__.py
===================================================================
--- trunk/scipy/sandbox/multigrid/gallery/__init__.py	2008-01-14 19:54:37 UTC (rev 3831)
+++ trunk/scipy/sandbox/multigrid/gallery/__init__.py	2008-01-14 20:01:29 UTC (rev 3832)
@@ -2,7 +2,7 @@
 
 from info import __doc__
 
-from poisson import *
+from laplacian import *
 from elasticity import *
 
 __all__ = filter(lambda s:not s.startswith('_'),dir())

Copied: trunk/scipy/sandbox/multigrid/gallery/laplacian.py (from rev 3831, trunk/scipy/sandbox/multigrid/gallery/poisson.py)

Deleted: trunk/scipy/sandbox/multigrid/gallery/poisson.py
===================================================================
--- trunk/scipy/sandbox/multigrid/gallery/poisson.py	2008-01-14 19:54:37 UTC (rev 3831)
+++ trunk/scipy/sandbox/multigrid/gallery/poisson.py	2008-01-14 20:01:29 UTC (rev 3832)
@@ -1,84 +0,0 @@
-__all__ = ['poisson']
-
-from scipy import arange, empty, intc, ravel, prod
-from scipy.sparse import coo_matrix
-
-
-def poisson( grid, spacing=None, dtype=float, format=None):
-    """Finite Difference approximation to the Poisson problem on a 
-    regular n-dimensional grid with Dirichlet boundary conditions.
-   
-    
-    Parameters
-    ==========
-        - grid : tuple
-            - grid dimensions e.g. (100,100)
-
-
-    Examples
-    ========
-
-    >>> # 4 nodes in one dimension
-    >>> poisson( (4,) ).todense()
-    matrix([[ 2., -1.,  0.,  0.],
-            [-1.,  2., -1.,  0.],
-            [ 0., -1.,  2., -1.],
-            [ 0.,  0., -1.,  2.]])
-
-    >>> # rectangular two dimensional grid 
-    >>> poisson( (2,3) ).todense()
-    matrix([[ 4., -1.,  0., -1.,  0.,  0.],
-            [-1.,  4., -1.,  0., -1.,  0.],
-            [ 0., -1.,  4.,  0.,  0., -1.],
-            [-1.,  0.,  0.,  4., -1.,  0.],
-            [ 0., -1.,  0., -1.,  4., -1.],
-            [ 0.,  0., -1.,  0., -1.,  4.]])
-
-    """
-    grid = tuple(grid)
-
-    D = len(grid) # grid dimension
-
-    if D < 1 or min(grid) < 1:
-        raise ValueError,'invalid grid shape: %s' % str(grid)
-
-    nodes = arange(prod(grid)).reshape(*grid)
-
-    nnz = nodes.size 
-    for i in range(D):
-        nnz += 2 * prod( grid[:i] + grid[i+1:] ) * (grid[i] - 1)
-    
-    row  = empty(nnz, dtype=intc)
-    col  = empty(nnz, dtype=intc)
-    data = empty(nnz, dtype=dtype)
-    
-    row[:nodes.size]  = ravel(nodes)
-    col[:nodes.size]  = ravel(nodes)
-    data[:nodes.size] = 2*D
-    data[nodes.size:] = -1
-    
-    ptr = nodes.size
-    
-    for i in range(D):
-        s0 = [slice(None)] * i + [slice(0,-1)  ] + [slice(None)] * (D - i - 1)
-        s1 = [slice(None)] * i + [slice(1,None)] + [slice(None)] * (D - i - 1)
-    
-        n0 = nodes[s0]
-        n1 = nodes[s1]
-    
-        row0 = row[ ptr:ptr + n0.size].reshape(n0.shape)
-        col0 = col[ ptr:ptr + n0.size].reshape(n0.shape)
-        ptr += n0.size
-    
-        row1 = row[ ptr:ptr + n0.size].reshape(n0.shape)
-        col1 = col[ ptr:ptr + n0.size].reshape(n0.shape)
-        ptr += n0.size
-    
-        row0[:] = n0
-        col0[:] = n1
-    
-        row1[:] = n1
-        col1[:] = n0
-    
-    return coo_matrix((data,(row,col)),shape=(nodes.size,nodes.size)).asformat(format)
-

Copied: trunk/scipy/sandbox/multigrid/gallery/tests/test_laplacian.py (from rev 3831, trunk/scipy/sandbox/multigrid/gallery/tests/test_poisson.py)
===================================================================
--- trunk/scipy/sandbox/multigrid/gallery/tests/test_poisson.py	2008-01-14 19:54:37 UTC (rev 3831)
+++ trunk/scipy/sandbox/multigrid/gallery/tests/test_laplacian.py	2008-01-14 20:01:29 UTC (rev 3832)
@@ -0,0 +1,25 @@
+from scipy.testing import *
+
+from scipy import matrix
+
+from scipy.sandbox.multigrid.gallery.laplacian import *
+
+class TestPoisson(TestCase):
+    def test_poisson(self):
+        cases = []
+
+        cases.append( ((1,),matrix([[2]])) )
+        cases.append( ((2,),matrix([[ 2,-1],
+                                    [-1, 2]])) )
+        cases.append( ((4,),matrix([[ 2,-1, 0, 0],
+                                    [-1, 2,-1, 0],
+                                    [ 0,-1, 2,-1],
+                                    [ 0, 0,-1, 2]])) )
+        
+        for grid,expected in cases:
+            assert_equal( poisson(grid).todense(), expected )
+
+
+
+if __name__ == '__main__':
+    unittest.main()

Deleted: trunk/scipy/sandbox/multigrid/gallery/tests/test_poisson.py
===================================================================
--- trunk/scipy/sandbox/multigrid/gallery/tests/test_poisson.py	2008-01-14 19:54:37 UTC (rev 3831)
+++ trunk/scipy/sandbox/multigrid/gallery/tests/test_poisson.py	2008-01-14 20:01:29 UTC (rev 3832)
@@ -1,25 +0,0 @@
-from scipy.testing import *
-
-from scipy import matrix
-
-from scipy.sandbox.multigrid.gallery.poisson import *
-
-class TestPoisson(TestCase):
-    def test_poisson(self):
-        cases = []
-
-        cases.append( ((1,),matrix([[2]])) )
-        cases.append( ((2,),matrix([[ 2,-1],
-                                    [-1, 2]])) )
-        cases.append( ((4,),matrix([[ 2,-1, 0, 0],
-                                    [-1, 2,-1, 0],
-                                    [ 0,-1, 2,-1],
-                                    [ 0, 0,-1, 2]])) )
-        
-        for grid,expected in cases:
-            assert_equal( poisson(grid).todense(), expected )
-
-
-
-if __name__ == '__main__':
-    unittest.main()

Modified: trunk/scipy/sandbox/multigrid/tests/test_sa.py
===================================================================
--- trunk/scipy/sandbox/multigrid/tests/test_sa.py	2008-01-14 19:54:37 UTC (rev 3831)
+++ trunk/scipy/sandbox/multigrid/tests/test_sa.py	2008-01-14 20:01:29 UTC (rev 3832)
@@ -22,7 +22,7 @@
 from scipy.sandbox.multigrid.multilevel import smoothed_aggregation_solver
 from scipy.sandbox.multigrid.utils import diag_sparse
 
-from scipy.sandbox.multigrid.gallery.poisson import poisson
+from scipy.sandbox.multigrid.gallery import poisson
 
 #def sparsity(A):
 #    A = A.copy()



More information about the Scipy-svn mailing list