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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 100 - (hide annotations)
Wed Dec 15 03:48:48 2004 UTC (14 years, 11 months ago) by jgs
Original Path: trunk/esys2/finley/test/python/SimpleSolve.py
File MIME type: text/x-python
File size: 3332 byte(s)
*** empty log message ***

1 jgs 82 # $Id$
2    
3     import sys
4     import os
5     import unittest
6    
7 jgs 100 esys_root=os.getenv('ESYS_ROOT')
8     sys.path.append(esys_root+'/finley/lib')
9     sys.path.append(esys_root+'/escript/lib')
10     sys.path.append(esys_root+'/escript/py_src')
11 jgs 82
12 jgs 100 from escript import *
13     from util import *
14     from linearPDE import *
15     import finley
16    
17 jgs 82 print "\nSimpleSolve.py"
18     print "--------------"
19    
20 jgs 100 my_options = {
21     "verbose" : True,
22     "reordering" : NO_REORDERING,
23     "tolerance" : 1.E-8,
24     "final_residual" : 0.,
25     "iterative_method" : PCG,
26     "preconditioner" : JACOBI,
27     "iter_max" : 5000,
28     "iter" : 0,
29     "drop_tolerance" : 1.10,
30     "drop_storage" : 2.
31     }
32    
33 jgs 82 alpha=0.01
34    
35 jgs 100 print "\nOptions: ", my_options
36    
37 jgs 82 # generate mesh
38    
39 jgs 100 print "\nGenerate mesh: finley.Rectangle(9,12,1)=>"
40     mydomain=finley.Rectangle(9,12,1)
41 jgs 82
42 jgs 100 print "\nGenerate mesh: finley.Rectangle(4,4,1)=>"
43     mydomain=finley.Rectangle(4,4,1)
44 jgs 82
45     print "\nGenerate mesh: finley.Rectangle(151,151,1)=>"
46     mydomain=finley.Rectangle(151,151,1)
47    
48     print "\nSetup domain and functions"
49     print "--------------------------"
50    
51     print "e=Function(mydomain):"
52     e=Function(mydomain)
53    
54     print "n=ContinuousFunction(mydomain):"
55     n=ContinuousFunction(mydomain)
56    
57     # get handles to nodes and elements 1
58    
59     print "\nGet handles to nodes and elements(1)=>"
60     print "--------------------------------------"
61    
62     print "u_ex=Scalar(1,n,True):"
63     u_ex=Scalar(1,n,True)
64    
65     print "x=e.getX():"
66     x=e.getX()
67    
68     print "norm_u_ex=u_ex.Lsup():"
69     norm_u_ex=u_ex.Lsup()
70    
71 jgs 100 print "mypde=linearPDE( A=[[1.,0.7],[0.7,1.]], D=alpha, Y=alpha, domain=mydomain)"
72     mypde=linearPDE(A=[[1.,0.7],[0.7,1.]],D=alpha,Y=alpha,domain=mydomain)
73     #mypde=linearPDE(A=[[1.,0.],[0.,1.]],D=alpha,Y=alpha,domain=mydomain)
74 jgs 82
75     # generate a test solution 1
76    
77     print "\nGenerate a test solution (1)"
78     print "----------------------------"
79    
80 jgs 100 print "\nDirect Solver (1)=>"
81 jgs 97
82 jgs 100 u_d=mypde.getSolution(iterative=False,**my_options)
83 jgs 97
84 jgs 100 print "\nIterative Solver (1)=>"
85 jgs 82
86 jgs 100 u_i=mypde.getSolution(iterative=True,**my_options)
87 jgs 82
88     print "\n***************************************************************"
89     error=u_ex-u_d
90     print "norm of the error for direct solver is : ",error.Lsup()/norm_u_ex
91     error=u_ex-u_i
92     print "norm of the error for iterative solver is: ",error.Lsup()/norm_u_ex
93     print "***************************************************************"
94    
95     # get handles to nodes and elements 2
96    
97     print "\nGet handles to nodes and elements(2)=>"
98     print "--------------------------------------"
99    
100     print "x=n.getX():"
101     x=n.getX()
102    
103     print "msk=x[0].whereZero()+(x[0]-1.).whereZero()"
104     msk=x[0].whereZero()+(x[0]-1.).whereZero()
105    
106 jgs 100 print "mypde=linearPDE(A=[[1.,0.],[0.,1.]],q=msk,r=u_ex)"
107     mypde=linearPDE(A=[[1.,0.],[0.,1.]],q=msk,r=u_ex)
108 jgs 82
109     # generate a test solution 2
110    
111     print "\nGenerate a test solution (2)"
112     print "----------------------------"
113    
114     print "\nDirect Solver (2)=>"
115    
116 jgs 100 u_d=mypde.getSolution(iterative=False,**my_options)
117 jgs 82
118     print "\nIterative Solver (2)=>"
119    
120 jgs 100 u_i=mypde.getSolution(iterative=True,**my_options)
121 jgs 82
122     print "\n******************************************************************"
123     error=u_ex-u_d
124     print "norm of the error for direct solver is : ",error.Lsup()/norm_u_ex
125     error=u_ex-u_i
126     print "norm of the error for iterative solver is: ",error.Lsup()/norm_u_ex
127     print "******************************************************************"
128    
129     print "\n-----"
130     print "Done."
131     print "-----"

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26