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

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

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

trunk/esys2/finley/test/python/SimpleSolve.py revision 149 by jgs, Thu Sep 1 03:31:39 2005 UTC trunk/finley/test/python/SimpleSolve.py revision 298 by gross, Fri Dec 2 05:42:11 2005 UTC
# Line 3  Line 3 
3  import sys  import sys
4  import os  import os
5  import unittest  import unittest
6    import time
7    
8  from esys.escript import *  from esys.escript import *
9  from esys.escript.linearPDEs import *  from esys.escript.linearPDEs import *
10  from esys import finley  from esys import finley
11    
12    starttime = time.clock()
13    
14  print "\nSimpleSolve.py"  print "\nSimpleSolve.py"
15  print "--------------"  print "--------------"
16    
17  alpha=0.07  alpha=0.7
18  error_tol=1.e-5  error_tol=1.e-5
19    
20  # generate mesh  # generate mesh
# Line 20  error_tol=1.e-5 Line 23  error_tol=1.e-5
23  # mydomain=finley.Rectangle(140,140)  # mydomain=finley.Rectangle(140,140)
24    
25  # print "\nGenerate mesh: finley.Rectangle(4,4,1)=>"  # print "\nGenerate mesh: finley.Rectangle(4,4,1)=>"
26  # mydomain=finley.Rectangle(10,10,1)  mydomain=finley.Rectangle(150,10,1)
27  mydomain=finley.Rectangle(190,190,1)  # mydomain=finley.Rectangle(190,190,1)
28    
29  print "\nGenerate mesh: finley.Rectangle(151,151,1)=>"  print "\nGenerate mesh: finley.Rectangle(151,151,1)=>"
30  # mydomain=finley.Rectangle(151,151,1)  # mydomain=finley.Rectangle(151,151,1)
# Line 47  u_ex=Scalar(1,n,True) Line 50  u_ex=Scalar(1,n,True)
50  print "x=e.getX():"  print "x=e.getX():"
51  x=e.getX()  x=e.getX()
52    
53  print "norm_u_ex=u_ex.Lsup():"  print "norm_u_ex=Lsup(u_ex):"
54  norm_u_ex=u_ex.Lsup()  norm_u_ex=Lsup(u_ex)
55    
56  print "\nGenerate a test solution (1)"  print "\nGenerate a test solution (1)"
57  print "----------------------------"  print "----------------------------"
# Line 56  print "----------------------------" Line 59  print "----------------------------"
59  print "mypde=LinearPDE( A=[[1.,0.8],[0.4,1.]], D=alpha, Y=alpha, domain=mydomain)"  print "mypde=LinearPDE( A=[[1.,0.8],[0.4,1.]], D=alpha, Y=alpha, domain=mydomain)"
60  mypde=LinearPDE(mydomain)  mypde=LinearPDE(mydomain)
61  mypde.setDebugOn()  mypde.setDebugOn()
62  mypde.setValue(A=[[1.,0.8],[0.4,1.]],D=alpha,Y=alpha)  mypde.setValue(A=[[1.,0.1],[0.04,1.]],D=alpha,Y=alpha)
63    
64  print "mypde.checkSymmetry()"  print "mypde.checkSymmetry()"
65  print mypde.checkSymmetry()  print mypde.checkSymmetry()
66    
67  print "\nIterative Solver (1)=>"  print "\nIterative Solver (1)=>"
68    mypde.setSolverMethod(mypde.BICGSTAB)
69  u_i=mypde.getSolution(verbose=True,iter_max=3000,preconditioner=mypde.ILU0)  u_i=mypde.getSolution(verbose=True,iter_max=3000,preconditioner=mypde.ILU0)
70    
71  print "\nDirect Solver (1)=>"  print "\nDirect Solver (1)=>"
# Line 70  u_d=mypde.getSolution(verbose=True) Line 74  u_d=mypde.getSolution(verbose=True)
74    
75  print "\n***************************************************************"  print "\n***************************************************************"
76  error=u_ex-u_d  error=u_ex-u_d
77  error_norm=error.Lsup()/norm_u_ex  error_norm=Lsup(error)/norm_u_ex
78  print "norm of the error for direct solver is   : ",error_norm  print "norm of the error for direct solver is   : ",error_norm
79  if error_norm > error_tol:  if error_norm > error_tol:
80    print "### error norm exceeded maximum tolerance ###"    print "### error norm exceeded maximum tolerance ###"
81    sys.exit(1)    sys.exit(1)
82  error=u_ex-u_i  error=u_ex-u_i
83  error_norm=error.Lsup()/norm_u_ex  error_norm=Lsup(error)/norm_u_ex
84  print "norm of the error for iterative solver is: ",error_norm  print "norm of the error for iterative solver is: ",error_norm
85  if error_norm > error_tol:  if error_norm > error_tol:
86    print "### error norm exceeded maximum tolerance ###"    print "### error norm exceeded maximum tolerance ###"
# Line 91  print "--------------------------------- Line 95  print "---------------------------------
95  print "x=n.getX():"  print "x=n.getX():"
96  x=n.getX()  x=n.getX()
97    
98  print "msk=x[0].whereZero()+(x[0]-1.).whereZero()"  print " msk=whereZero(x[0])+whereZero(x[0]-1.)"
99  msk=x[0].whereZero()+(x[0]-1.).whereZero()  msk=whereZero(x[0])+whereZero(x[0]-1.)
100    
101  print "mypde=LinearPDE(A=[[1.,0.],[0.,1.]],q=msk,r=u_ex)"  print "mypde=LinearPDE(A=[[1.,0.],[0.,1.]],q=msk,r=u_ex)"
102  mypde=LinearPDE(mydomain)  mypde=LinearPDE(mydomain)
# Line 119  u_d=mypde.getSolution(verbose=True) Line 123  u_d=mypde.getSolution(verbose=True)
123  print "\nIterative Solver (2)=>"  print "\nIterative Solver (2)=>"
124    
125  mypde.setSymmetryOn()  mypde.setSymmetryOn()
126  mypde.setSolverMethod(mypde.DEFAULT_METHOD)  mypde.setSolverMethod(mypde.ITERATIVE)
127  u_i=mypde.getSolution(verbose=True,iter_max=3000)  u_i=mypde.getSolution(verbose=True,iter_max=3000)
128    
129  print "\n******************************************************************"  print "\n******************************************************************"
130  error=u_ex-u_d  error=u_ex-u_d
131  error_norm=error.Lsup()/norm_u_ex  error_norm=Lsup(error)/norm_u_ex
132  print "norm of the error for direct solver is   : ",error_norm  print "norm of the error for direct solver is   : ",error_norm
133  if error_norm > error_tol:  if error_norm > error_tol:
134    print "### error norm exceeded maximum tolerance ###"    print "### error norm exceeded maximum tolerance ###"
135    sys.exit(1)    sys.exit(1)
136  error=u_ex-u_i  error=u_ex-u_i
137  error_norm=error.Lsup()/norm_u_ex  error_norm=Lsup(error)/norm_u_ex
138  print "norm of the error for iterative solver is: ",error_norm  print "norm of the error for iterative solver is: ",error_norm
139  if error_norm >  error_tol:  if error_norm >  error_tol:
140    print "### error norm exceeded maximum tolerance ###"    print "### error norm exceeded maximum tolerance ###"
# Line 141  print "\n-----" Line 145  print "\n-----"
145  print "Done."  print "Done."
146  print "-----"  print "-----"
147    
148    stoptime = time.clock()
149    elapsed = stoptime - starttime
150    print "\nElapsed time: ", elapsed, "\n"
151    
152  sys.exit(0)  sys.exit(0)

Legend:
Removed from v.149  
changed lines
  Added in v.298

  ViewVC Help
Powered by ViewVC 1.1.26