/[escript]/trunk/ripley/test/python/run_simplesolve.py
ViewVC logotype

Diff of /trunk/ripley/test/python/run_simplesolve.py

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

revision 3981 by jfenwick, Fri Sep 21 02:47:54 2012 UTC revision 4938 by jfenwick, Wed May 14 01:13:23 2014 UTC
# Line 1  Line 1 
1    
2  ##############################################################################  ##############################################################################
3  #  #
4  # Copyright (c) 2003-2012 by University of Queensland  # Copyright (c) 2003-2014 by University of Queensland
5  # http://www.uq.edu.au  # http://www.uq.edu.au
6  #  #
7  # Primary Business: Queensland, Australia  # Primary Business: Queensland, Australia
# Line 9  Line 9 
9  # http://www.opensource.org/licenses/osl-3.0.php  # http://www.opensource.org/licenses/osl-3.0.php
10  #  #
11  # Development until 2012 by Earth Systems Science Computational Center (ESSCC)  # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12  # Development since 2012 by School of Earth Sciences  # Development 2012-2013 by School of Earth Sciences
13    # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14  #  #
15  ##############################################################################  ##############################################################################
16    
17  __copyright__="""Copyright (c) 2003-2012 by University of Queensland  __copyright__="""Copyright (c) 2003-2014 by University of Queensland
18  http://www.uq.edu.au  http://www.uq.edu.au
19  Primary Business: Queensland, Australia"""  Primary Business: Queensland, Australia"""
20  __license__="""Licensed under the Open Software License version 3.0  __license__="""Licensed under the Open Software License version 3.0
# Line 34  Test suite for the linearPDE  and pdetoo Line 35  Test suite for the linearPDE  and pdetoo
35    
36  __author__="Lutz Gross, l.gross@uq.edu.au"  __author__="Lutz Gross, l.gross@uq.edu.au"
37    
38  import unittest, sys  import esys.escriptcore.utestselect as unittest, sys
39  from esys.escript import *  from esys.escript import *
40  from esys.ripley import Rectangle,Brick  from esys.ripley import Rectangle,Brick
41  from esys.escript.linearPDEs import LinearPDE, SolverOptions  from esys.escript.linearPDEs import LinearPDE, SolverOptions
# Line 245  class SimpleSolve_Brick_SystemPDE_Paso_P Line 246  class SimpleSolve_Brick_SystemPDE_Paso_P
246          error=Lsup(u-u_ex)          error=Lsup(u-u_ex)
247          self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)          self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
248    
 class SimpleSolve_Rectangle_SinglePDE_Paso_TFQMR_Jacobi(unittest.TestCase):  
      def test_solve(self):  
         domain=Rectangle(n0=NE0*NX-1, n1=NE1*NY-1, d0=NX, d1=NY)  
         x=Solution(domain).getX()  
         # --- set exact solution ----  
         u_ex=Scalar(0,Solution(domain))  
         u_ex=1.+2.*x[0]+3.*x[1]  
         # --- set exact gradient -----------  
         g_ex=Data(0.,(2,),Solution(domain))  
         g_ex[0]=2.  
         g_ex[1]=3.  
         # -------- test gradient --------------------------------  
         g=grad(u_ex)  
         self.assertTrue(Lsup(g_ex-g)<REL_TOL*Lsup(g_ex))  
         # -------- set-up PDE -----------------------------------  
         pde=LinearPDE(domain,numEquations=1)  
         mask=whereZero(x[0])  
         pde.setValue(r=u_ex,q=mask)  
         pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal()))  
         # -------- get the solution ---------------------------  
         pde.getSolverOptions().setTolerance(SOLVER_TOL)  
         pde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)  
         pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)  
         pde.getSolverOptions().setPackage(SolverOptions.PASO)  
         pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)  
         u=pde.getSolution()  
         # -------- test the solution ---------------------------  
         error=Lsup(u-u_ex)  
         self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)  
   
 class SimpleSolve_Rectangle_SystemPDE_Paso_TFQMR_Jacobi(unittest.TestCase):  
      def test_solve(self):  
         domain=Rectangle(n0=NE0*NX-1, n1=NE1*NY-1, d0=NX, d1=NY)  
         x=Solution(domain).getX()  
         # --- set exact solution ----  
         u_ex=Vector(0,Solution(domain))  
         u_ex[0]=1.+2.*x[0]+3.*x[1]  
         u_ex[1]=-1.+3.*x[0]+2.*x[1]  
         # --- set exact gradient -----------  
         g_ex=Data(0.,(2,2),Solution(domain))  
         g_ex[0,0]=2.  
         g_ex[0,1]=3.  
         g_ex[1,0]=3.  
         g_ex[1,1]=2.  
         # -------- test gradient --------------------------------  
         self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))  
         # -------- set-up PDE -----------------------------------  
         pde=LinearPDE(domain,numEquations=2)  
         mask=whereZero(x[0])  
         pde.setValue(r=u_ex,q=mask*numpy.ones(2,))  
         A=Tensor4(0,Function(domain))  
         A[0,:,0,:]=kronecker(2)  
         A[1,:,1,:]=kronecker(2)  
         Y=Vector(0.,Function(domain))  
         Y[0]=u_ex[0]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG  
         Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG  
         pde.setValue(A=A,  
                      D=kronecker(2)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((2,2))*FAC_OFFDIAG,  
                      Y=Y,  
                      y=matrixmult(g_ex,domain.getNormal()))  
         # -------- get the solution ---------------------------  
         pde.getSolverOptions().setTolerance(SOLVER_TOL)  
         pde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)  
         pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)  
         pde.getSolverOptions().setPackage(SolverOptions.PASO)  
         pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)  
         u=pde.getSolution()  
         # -------- test the solution ---------------------------  
         error=Lsup(u-u_ex)  
         self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)  
 class SimpleSolve_Brick_SinglePDE_Paso_TFQMR_Jacobi(unittest.TestCase):  
      def test_solve(self):  
         domain=Brick(n0=NE0*NXb-1, n1=NE1*NYb-1, n2=NE2*NZb-1, d0=NXb, d1=NYb, d2=NZb)  
         x=Solution(domain).getX()  
         u_ex=1.+2.*x[0]+3.*x[1]+4.*x[2]  
         # --- set exact gradient -----------  
         g_ex=Data(0.,(3,),Solution(domain))  
         g_ex[0]=2.  
         g_ex[1]=3.  
         g_ex[2]=4.  
         # -------- test gradient --------------------------------  
         self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))  
         # -------- set-up PDE -----------------------------------  
         pde=LinearPDE(domain,numEquations=1)  
         mask=whereZero(x[0])  
         pde.setValue(r=u_ex,q=mask)  
         pde.setValue(A=kronecker(3),y=inner(g_ex,domain.getNormal()))  
         # -------- get the solution ---------------------------  
         pde.getSolverOptions().setTolerance(SOLVER_TOL)  
         pde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)  
         pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)  
         pde.getSolverOptions().setPackage(SolverOptions.PASO)  
         pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)  
         u=pde.getSolution()  
         # -------- test the solution ---------------------------  
         error=Lsup(u-u_ex)  
         self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)  
           
 class SimpleSolve_Brick_SystemPDE_Paso_TFQMR_Jacobi(unittest.TestCase):  
      def test_solve(self):  
         domain=Brick(n0=NE0*NXb-1, n1=NE1*NYb-1, n2=NE2*NZb-1, d0=NXb, d1=NYb, d2=NZb)  
         x=Solution(domain).getX()  
         # --- set exact solution ----  
         u_ex=Vector(0,Solution(domain))  
         u_ex[0]=1.+2.*x[0]+3.*x[1]+4.*x[2]  
         u_ex[1]=-1.+4.*x[0]+1.*x[1]-2.*x[2]  
         u_ex[2]=5.+8.*x[0]+4.*x[1]+5.*x[2]  
         # --- set exact gradient -----------  
         g_ex=Data(0.,(3,3),Solution(domain))  
         g_ex[0,0]=2.  
         g_ex[0,1]=3.  
         g_ex[0,2]=4.  
         g_ex[1,0]=4.  
         g_ex[1,1]=1.  
         g_ex[1,2]=-2.  
         g_ex[2,0]=8.  
         g_ex[2,1]=4.  
         g_ex[2,2]=5.  
         # -------- test gradient --------------------------------  
         self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))  
         # -------- set-up PDE -----------------------------------  
         pde=LinearPDE(domain,numEquations=3)  
         mask=whereZero(x[0])  
         pde.setValue(r=u_ex,q=mask*numpy.ones(3,))  
         A=Tensor4(0,Function(domain))  
         A[0,:,0,:]=kronecker(3)  
         A[1,:,1,:]=kronecker(3)  
         A[2,:,2,:]=kronecker(3)  
         Y=Vector(0.,Function(domain))  
         Y[0]=u_ex[0]*FAC_DIAG+u_ex[2]*FAC_OFFDIAG+u_ex[1]*FAC_OFFDIAG  
         Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG+u_ex[2]*FAC_OFFDIAG  
         Y[2]=u_ex[2]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG+u_ex[0]*FAC_OFFDIAG  
         pde.setValue(A=A,  
                      D=kronecker(3)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((3,3))*FAC_OFFDIAG,  
                      Y=Y,  
                      y=matrixmult(g_ex,domain.getNormal()))  
         # -------- get the solution ---------------------------  
         pde.getSolverOptions().setTolerance(SOLVER_TOL)  
         pde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)  
         pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)  
         pde.getSolverOptions().setPackage(SolverOptions.PASO)  
         pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)  
         u=pde.getSolution()  
         # -------- test the solution ---------------------------  
         error=Lsup(u-u_ex)  
         self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)  
           
249  class SimpleSolve_Rectangle_SinglePDE_Paso_MINRES_Jacobi(unittest.TestCase):  class SimpleSolve_Rectangle_SinglePDE_Paso_MINRES_Jacobi(unittest.TestCase):
250       def test_solve(self):       def test_solve(self):
251          domain=Rectangle(n0=NE0*NX-1, n1=NE1*NY-1, d0=NX, d1=NY)          domain=Rectangle(n0=NE0*NX-1, n1=NE1*NY-1, d0=NX, d1=NY)
# Line 548  if __name__ == '__main__': Line 402  if __name__ == '__main__':
402     suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_SystemPDE_Paso_PCG_Jacobi))     suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_SystemPDE_Paso_PCG_Jacobi))
403     suite.addTest(unittest.makeSuite(SimpleSolve_Brick_SinglePDE_Paso_PCG_Jacobi))     suite.addTest(unittest.makeSuite(SimpleSolve_Brick_SinglePDE_Paso_PCG_Jacobi))
404     suite.addTest(unittest.makeSuite(SimpleSolve_Brick_SystemPDE_Paso_PCG_Jacobi))     suite.addTest(unittest.makeSuite(SimpleSolve_Brick_SystemPDE_Paso_PCG_Jacobi))
    suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_SinglePDE_Paso_TFQMR_Jacobi))  
    suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_SystemPDE_Paso_TFQMR_Jacobi))  
    suite.addTest(unittest.makeSuite(SimpleSolve_Brick_SinglePDE_Paso_TFQMR_Jacobi))  
    suite.addTest(unittest.makeSuite(SimpleSolve_Brick_SystemPDE_Paso_TFQMR_Jacobi))  
405     suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_SinglePDE_Paso_MINRES_Jacobi))     suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_SinglePDE_Paso_MINRES_Jacobi))
406     suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_SinglePDE_Paso_MINRES_Jacobi))     suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_SinglePDE_Paso_MINRES_Jacobi))
407     suite.addTest(unittest.makeSuite(SimpleSolve_Brick_SinglePDE_Paso_MINRES_Jacobi))     suite.addTest(unittest.makeSuite(SimpleSolve_Brick_SinglePDE_Paso_MINRES_Jacobi))

Legend:
Removed from v.3981  
changed lines
  Added in v.4938

  ViewVC Help
Powered by ViewVC 1.1.26