[Scipy-svn] r3876 - in trunk/scipy/sandbox/multigrid: . tests

scipy-svn@scip... scipy-svn@scip...
Wed Jan 30 11:05:45 CST 2008


Author: wnbell
Date: 2008-01-30 11:05:38 -0600 (Wed, 30 Jan 2008)
New Revision: 3876

Modified:
   trunk/scipy/sandbox/multigrid/adaptive.py
   trunk/scipy/sandbox/multigrid/sa.py
   trunk/scipy/sandbox/multigrid/tests/test_rs.py
   trunk/scipy/sandbox/multigrid/tests/test_sa.py
Log:
reverted back to older SA approach


Modified: trunk/scipy/sandbox/multigrid/adaptive.py
===================================================================
--- trunk/scipy/sandbox/multigrid/adaptive.py	2008-01-30 01:17:40 UTC (rev 3875)
+++ trunk/scipy/sandbox/multigrid/adaptive.py	2008-01-30 17:05:38 UTC (rev 3876)
@@ -40,7 +40,7 @@
 
     for AggOp in AggOps:
         P,B = sa_fit_candidates(AggOp,B)
-        I   = sa_smoothed_prolongator(A,A,P)
+        I   = sa_smoothed_prolongator(A,P)
         A   = I.T.asformat(I.format) * A * I
         As.append(A)
         Ts.append(P)
@@ -164,7 +164,7 @@
         else:
             W_l = aggregation[len(AggOps)]
         P_l,x = sa_fit_candidates(W_l,x)                   #step 4c
-        I_l   = sa_smoothed_prolongator(A_l,A_l,P_l)       #step 4d
+        I_l   = sa_smoothed_prolongator(A_l,P_l)       #step 4d
         A_l   = I_l.T.asformat(I_l.format) * A_l * I_l     #step 4e
         #TODO change variable names I_l -> P, P_l -> T
 

Modified: trunk/scipy/sandbox/multigrid/sa.py
===================================================================
--- trunk/scipy/sandbox/multigrid/sa.py	2008-01-30 01:17:40 UTC (rev 3875)
+++ trunk/scipy/sandbox/multigrid/sa.py	2008-01-30 17:05:38 UTC (rev 3876)
@@ -168,7 +168,7 @@
 
     return Q,R
 
-def sa_smoothed_prolongator(A,C,T,epsilon=0.0,omega=4.0/3.0):
+def sa_smoothed_prolongator(A,T,epsilon=0.0,omega=4.0/3.0):
     """For a given matrix A and tentative prolongator T return the
     smoothed prolongator P
 
@@ -185,7 +185,7 @@
     A_filtered = sa_filtered_matrix(A,epsilon) #use filtered matrix for anisotropic problems
 
     # TODO use scale_rows()
-    D = diag_sparse(A_filtered)
+    D = A_filtered.diagonal()
     D_inv = 1.0 / D
     D_inv[D == 0] = 0
 
@@ -290,7 +290,7 @@
         C     = strength(A)
         AggOp = aggregate(C)
         T,B   = tentative(AggOp,B)
-        P     = smooth(A,C,T)
+        P     = smooth(A,T)
 
         R = P.T.asformat(P.format)
 

Modified: trunk/scipy/sandbox/multigrid/tests/test_rs.py
===================================================================
--- trunk/scipy/sandbox/multigrid/tests/test_rs.py	2008-01-30 01:17:40 UTC (rev 3875)
+++ trunk/scipy/sandbox/multigrid/tests/test_rs.py	2008-01-30 17:05:38 UTC (rev 3876)
@@ -30,9 +30,7 @@
 
             avg_convergence_ratio = (residuals[-1]/residuals[0])**(1.0/len(residuals))
             
-            print "avg",avg_convergence_ratio
+            assert(avg_convergence_ratio < 0.10)
 
-            assert(avg_convergence_ratio < 0.15)
-
 if __name__ == '__main__':
     nose.run(argv=['', __file__])

Modified: trunk/scipy/sandbox/multigrid/tests/test_sa.py
===================================================================
--- trunk/scipy/sandbox/multigrid/tests/test_sa.py	2008-01-30 01:17:40 UTC (rev 3875)
+++ trunk/scipy/sandbox/multigrid/tests/test_sa.py	2008-01-30 17:05:38 UTC (rev 3876)
@@ -18,7 +18,7 @@
 import scipy.sandbox.multigrid
 from scipy.sandbox.multigrid.sa import *
 from scipy.sandbox.multigrid.utils import diag_sparse
-from scipy.sandbox.multigrid.gallery import poisson
+from scipy.sandbox.multigrid.gallery import poisson, linear_elasticity
 
 #def sparsity(A):
 #    A = A.copy()
@@ -57,15 +57,6 @@
                 assert_almost_equal(S_result.todense(),S_expected.todense())
                 #assert_array_equal(sparsity(S_result).todense(),sparsity(S_expected).todense())
 
-        ## two aggregates in 1D
-        #A = poisson( (6,), format='csr')
-        #AggOp = csr_matrix((ones(6),array([0,0,0,1,1,1]),arange(7)),shape=(6,2))
-        #candidates = ones((6,1))
-
-        #T_result,coarse_candidates_result = sa_fit_candidates(AggOp,candidates)
-        #T_expected = csr_matrix((sqrt(1.0/3.0)*ones(6),array([0,0,0,1,1,1]),arange(7)),shape=(6,2))
-        #assert_almost_equal(T_result.todense(),T_expected.todense())
-
         ##check simple block examples
         #A = csr_matrix(arange(16).reshape(4,4))
         #A = A + A.T
@@ -90,9 +81,6 @@
             S_result   = sa_standard_aggregation(C)
             assert_array_equal(S_result.todense(),S_expected.todense())
 
-            #A = A.tobsr( blocksize=(1,1) )
-            #S_result   = sa_constant_interpolation(A,epsilon)
-            #assert_array_equal(S_result.todense(),S_expected.todense())
 
 
 #    def test_user_aggregation(self):
@@ -180,6 +168,7 @@
 
         self.cases.append(( poisson( (10000,),  format='csr'), None))
         self.cases.append(( poisson( (100,100), format='csr'), None))
+        self.cases.append( linear_elasticity( (100,100), format='bsr') )
         # TODO add unstructured tests
 
 
@@ -194,14 +183,14 @@
             x = rand(A.shape[0])
             b = A*rand(A.shape[0]) #zeros_like(x)
 
-            x_sol,residuals = ml.solve(b,x0=x,maxiter=20,tol=1e-12,return_residuals=True)
+            x_sol,residuals = ml.solve(b,x0=x,maxiter=20,tol=1e-10,return_residuals=True)
 
             avg_convergence_ratio = (residuals[-1]/residuals[0])**(1.0/len(residuals))
             
-            assert(avg_convergence_ratio < 0.25)
+            assert(avg_convergence_ratio < 0.3)
 
     def test_DAD(self):
-        A = poisson( (100,100), format='csr' )        
+        A = poisson( (200,200), format='csr' )        
 
         x = rand(A.shape[0])
         b = rand(A.shape[0])
@@ -215,11 +204,9 @@
  
         #TODO force 2 level method and check that result is the same
  
-        #sa1 = smoothed_aggregation_solver(A, B, max_levels=2, rescale=False)
-        sa2 = smoothed_aggregation_solver(D*A*D, D_inv * B, max_levels=2)
+        sa = smoothed_aggregation_solver(D*A*D, D_inv * B, max_levels=2)
  
-        #assert_almost_equal( sa2.Ps[0], sa1.Ps[0] 
-        x_sol,residuals = sa2.solve(b,x0=x,maxiter=10,tol=1e-12,return_residuals=True)
+        x_sol,residuals = sa.solve(b,x0=x,maxiter=10,tol=1e-12,return_residuals=True)
  
         avg_convergence_ratio = (residuals[-1]/residuals[0])**(1.0/len(residuals))
         



More information about the Scipy-svn mailing list