/[escript]/trunk/finley/test/python/run_amg.py
ViewVC logotype

Diff of /trunk/finley/test/python/run_amg.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3435 by gross, Tue Dec 7 10:24:32 2010 UTC revision 3436 by plaub, Mon Jan 10 02:06:07 2011 UTC
# Line 55  except KeyError: Line 55  except KeyError:
55  FINLEY_TEST_MESH_PATH=os.path.join(FINLEY_TEST_DATA,"data_meshes")  FINLEY_TEST_MESH_PATH=os.path.join(FINLEY_TEST_DATA,"data_meshes")
56    
57  # number of elements in the spatial directions  # number of elements in the spatial directions
58  NE_TOTAL=5000  NE_TOTAL=4096
59    
60  class Test_AMG(unittest.TestCase):  class Test_AMG(unittest.TestCase):
61    
# Line 86  class Test_AMG(unittest.TestCase): Line 86  class Test_AMG(unittest.TestCase):
86          u=pde.getSolution()          u=pde.getSolution()
87          # -------- test the solution ---------------------------          # -------- test the solution ---------------------------
88          error=Lsup(u-u_ex)/Lsup(u_ex)          error=Lsup(u-u_ex)/Lsup(u_ex)
89          self.failUnless(error<self.RES_TOL*Lsup(u_ex), "solution error %s is too big."%error)          self.assertTrue(error<self.RES_TOL, "solution error %s is too big."%error)
90    
91     def test_PoissonSqueezedX(self):     def test_PoissonSqueezedX(self):
92          x=self.domain.getX().copy()          x=self.domain.getX().copy()
# Line 118  class Test_AMG(unittest.TestCase): Line 118  class Test_AMG(unittest.TestCase):
118          u=pde.getSolution()          u=pde.getSolution()
119          # -------- test the solution ---------------------------          # -------- test the solution ---------------------------
120          error=Lsup(u-u_ex)/Lsup(u_ex)          error=Lsup(u-u_ex)/Lsup(u_ex)
121          self.failUnless(error<self.RES_TOL*Lsup(u_ex), "solution error %s is too big."%error)          self.assertTrue(error<self.RES_TOL, "solution error %s is too big."%error)
122    
123    
124     def test_Poisson2(self):     def test_Poisson2(self):
# Line 153  class Test_AMG(unittest.TestCase): Line 153  class Test_AMG(unittest.TestCase):
153          u=pde.getSolution()          u=pde.getSolution()
154          # -------- test the solution ---------------------------          # -------- test the solution ---------------------------
155          error=Lsup(u-u_ex)/Lsup(u_ex)          error=Lsup(u-u_ex)/Lsup(u_ex)
156          self.failUnless(error<self.RES_TOL*Lsup(u_ex), "solution error %s is too big."%error)          self.assertTrue(error<self.RES_TOL, "solution error %s is too big."%error)
157    
158     def test_Poisson3(self):     def test_Poisson3(self):
159          x=Solution(self.domain).getX()          x=Solution(self.domain).getX()
# Line 190  class Test_AMG(unittest.TestCase): Line 190  class Test_AMG(unittest.TestCase):
190          u=pde.getSolution()          u=pde.getSolution()
191          # -------- test the solution ---------------------------          # -------- test the solution ---------------------------
192          error=Lsup(u-u_ex)/Lsup(u_ex)          error=Lsup(u-u_ex)/Lsup(u_ex)
193          self.failUnless(error<self.RES_TOL*Lsup(u_ex), "solution error %s is too big."%error)          self.assertTrue(error<self.RES_TOL, "solution error %s is too big."%error)
194    
195     def test_Poisson4(self):     def test_Poisson4(self):
196          x=Solution(self.domain).getX()          x=Solution(self.domain).getX()
# Line 230  class Test_AMG(unittest.TestCase): Line 230  class Test_AMG(unittest.TestCase):
230          u=pde.getSolution()          u=pde.getSolution()
231          # -------- test the solution ---------------------------          # -------- test the solution ---------------------------
232          error=Lsup(u-u_ex)/Lsup(u_ex)          error=Lsup(u-u_ex)/Lsup(u_ex)
233          self.failUnless(error<self.RES_TOL*Lsup(u_ex), "solution error %s is too big."%error)          self.assertTrue(error<self.RES_TOL, "solution error %s is too big."%error)
234    
235     def test_WeakCoupled2(self):     def test_WeakCoupled2(self):
236          x=Solution(self.domain).getX()          x=Solution(self.domain).getX()
# Line 270  class Test_AMG(unittest.TestCase): Line 270  class Test_AMG(unittest.TestCase):
270          u=pde.getSolution()          u=pde.getSolution()
271          # -------- test the solution ---------------------------          # -------- test the solution ---------------------------
272          error=Lsup(u-u_ex)/Lsup(u_ex)          error=Lsup(u-u_ex)/Lsup(u_ex)
273          self.failUnless(error<self.RES_TOL*Lsup(u_ex), "solution error %s is too big."%error)          self.assertTrue(error<self.RES_TOL, "solution error %s is too big."%error)
274    
275     def test_WeakCoupled3(self):     def test_WeakCoupled3(self):
276          x=Solution(self.domain).getX()          x=Solution(self.domain).getX()
# Line 314  class Test_AMG(unittest.TestCase): Line 314  class Test_AMG(unittest.TestCase):
314          u=pde.getSolution()          u=pde.getSolution()
315          # -------- test the solution ---------------------------          # -------- test the solution ---------------------------
316          error=Lsup(u-u_ex)/Lsup(u_ex)          error=Lsup(u-u_ex)/Lsup(u_ex)
317          self.failUnless(error<self.RES_TOL*Lsup(u_ex), "solution error %s is too big."%error)          self.assertTrue(error<self.RES_TOL, "solution error %s is too big."%error)
318    
319     def test_WeakCoupled4(self):     def test_WeakCoupled4(self):
320          x=Solution(self.domain).getX()          x=Solution(self.domain).getX()
# Line 362  class Test_AMG(unittest.TestCase): Line 362  class Test_AMG(unittest.TestCase):
362          u=pde.getSolution()          u=pde.getSolution()
363          # -------- test the solution ---------------------------          # -------- test the solution ---------------------------
364          error=Lsup(u-u_ex)/Lsup(u_ex)          error=Lsup(u-u_ex)/Lsup(u_ex)
365          self.failUnless(error<self.RES_TOL*Lsup(u_ex), "solution error %s is too big."%error)          self.assertTrue(error<self.RES_TOL, "solution error %s is too big."%error)
366    
367     def test_StrongCoupled2(self):     def test_StrongCoupled2(self):
368          x=Solution(self.domain).getX()          x=Solution(self.domain).getX()
# Line 402  class Test_AMG(unittest.TestCase): Line 402  class Test_AMG(unittest.TestCase):
402          u=pde.getSolution()          u=pde.getSolution()
403          # -------- test the solution ---------------------------          # -------- test the solution ---------------------------
404          error=Lsup(u-u_ex)/Lsup(u_ex)          error=Lsup(u-u_ex)/Lsup(u_ex)
405          self.failUnless(error<self.RES_TOL*Lsup(u_ex), "solution error %s is too big."%error)          self.assertTrue(error<self.RES_TOL, "solution error %s is too big."%error)
406    
407     def test_StrongCoupled3(self):     def test_StrongCoupled3(self):
408          x=Solution(self.domain).getX()          x=Solution(self.domain).getX()
# Line 446  class Test_AMG(unittest.TestCase): Line 446  class Test_AMG(unittest.TestCase):
446          u=pde.getSolution()          u=pde.getSolution()
447          # -------- test the solution ---------------------------          # -------- test the solution ---------------------------
448          error=Lsup(u-u_ex)/Lsup(u_ex)          error=Lsup(u-u_ex)/Lsup(u_ex)
449          self.failUnless(error<self.RES_TOL*Lsup(u_ex), "solution error %s is too big."%error)          self.assertTrue(error<self.RES_TOL, "solution error %s is too big."%error)
450     def test_StrongCoupled4(self):     def test_StrongCoupled4(self):
451          x=Solution(self.domain).getX()          x=Solution(self.domain).getX()
452          # --- set exact solution ----          # --- set exact solution ----
# Line 493  class Test_AMG(unittest.TestCase): Line 493  class Test_AMG(unittest.TestCase):
493          u=pde.getSolution()          u=pde.getSolution()
494          # -------- test the solution ---------------------------          # -------- test the solution ---------------------------
495          error=Lsup(u-u_ex)/Lsup(u_ex)          error=Lsup(u-u_ex)/Lsup(u_ex)
496          self.failUnless(error<self.RES_TOL*Lsup(u_ex), "solution error %s is too big."%error)          self.assertTrue(error<self.RES_TOL, "solution error %s is too big."%error)
497    
498       def test_Square(self):
499            # PDE constants
500            h1 = 0.5
501            h2 = 0.5
502            beta = 1.
503            alpha1 = 2.
504            alpha2 = 1.
505    
506            # domain masks and domain-specific constants
507            x = Solution(self.domain).getX(); x0 = x[0]; x1 = x[1]
508            omega2 = wherePositive(x0-h1)*wherePositive(x1-h2)
509            omega1 = 1-omega2
510            ratio = alpha1/alpha2
511            alpha = alpha1*omega1 + alpha2*omega2
512    
513            # --- set exact solution ----
514            a1 = 1.
515            d1 = 1.
516            b1 = -d1*h2
517            c1 = -d1*h1
518    
519            a2 = a1 - (1.-ratio)*d1*h1*h2
520            b2 = ratio*b1
521            c2 = ratio*c1
522            d2 = ratio*d1
523            
524            u_ex = omega1*(a1 + b1*x0 + c1*x1 + d1*x0*x1) + \
525                    omega2*(a2 + b2*x0 + c2*x1 + d2*x0*x1)
526    
527            # create PDE:
528            pde = LinearPDE(self.domain,numEquations=1)
529    
530            # set the value to that of the solution on the boundary
531            q = whereZero(x0) + whereZero(x1) + \
532                whereZero(sup(x0)-x0) + whereZero(sup(x1)-x1)
533            pde.setValue(q=q,r=u_ex)
534                  
535            # create X points in the centre of the grid elements
536            xe = Function(self.domain).getX()
537            x0 = xe[0]
538            x1 = xe[1]
539    
540            # redefine omega so that apha is more precise on the diagonal (?)
541            omega2 = wherePositive(x0-h1)*wherePositive(x1-h2)
542            omega1 = 1-omega2
543            ratio = alpha1/alpha2
544            alpha = alpha1*omega1 + alpha2*omega2
545            
546            # set up PDE coefficients
547            pde.setValue(A=alpha*kronecker(self.domain), D=beta, Y=beta*u_ex)
548            pde.setSymmetryOn()
549    
550            # -------- get the solution ---------------------------
551            pde.getSolverOptions().setTolerance(self.SOLVER_TOL)
552            pde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
553            if (USE_AMG): pde.getSolverOptions().setPreconditioner(SolverOptions.AMG)
554            pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
555            if MIN_MATRIX_SIZE!= None: pde.getSolverOptions().setMinCoarseMatrixSize(MIN_MATRIX_SIZE)
556            if MIN_SPARSITY!=None: pde.getSolverOptions().setMinCoarseMatrixSparsity(MIN_SPARSITY)
557            if MAX_LEVEL!=None: pde.getSolverOptions().setMinCoarseMatrixSparsity(MIN_SPARSITY)
558            
559            u = pde.getSolution()
560            
561            # -------- test the solution ---------------------------
562            error=Lsup(u-u_ex)/Lsup(u_ex)
563            self.assertTrue(error<self.RES_TOL, "solution error %s is too big."%error)
564            
565    
566  class Test_AMGOnFinleyHex2DOrder1(Test_AMG):  class Test_AMGOnFinleyHex2DOrder1(Test_AMG):
567     RES_TOL=5.e-7     RES_TOL=5.e-7

Legend:
Removed from v.3435  
changed lines
  Added in v.3436

  ViewVC Help
Powered by ViewVC 1.1.26