/[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 149 - (hide annotations)
Thu Sep 1 03:31:39 2005 UTC (14 years, 1 month ago) by jgs
Original Path: trunk/esys2/finley/test/python/SimpleSolve.py
File MIME type: text/x-python
File size: 3718 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-09-01

1 jgs 82 # $Id$
2    
3     import sys
4     import os
5     import unittest
6    
7 jgs 149 from esys.escript import *
8     from esys.escript.linearPDEs import *
9     from esys import finley
10 jgs 82
11     print "\nSimpleSolve.py"
12     print "--------------"
13    
14 jgs 148 alpha=0.07
15     error_tol=1.e-5
16 jgs 82
17     # generate mesh
18    
19 jgs 102 # print "\nGenerate mesh: finley.Rectangle(9,12,1)=>"
20 jgs 115 # mydomain=finley.Rectangle(140,140)
21 jgs 82
22 jgs 102 # print "\nGenerate mesh: finley.Rectangle(4,4,1)=>"
23 jgs 149 # mydomain=finley.Rectangle(10,10,1)
24 jgs 148 mydomain=finley.Rectangle(190,190,1)
25 jgs 82
26     print "\nGenerate mesh: finley.Rectangle(151,151,1)=>"
27 jgs 148 # mydomain=finley.Rectangle(151,151,1)
28 jgs 115 # mydomain=finley.Rectangle(128,128,1)
29 jgs 82
30     print "\nSetup domain and functions"
31     print "--------------------------"
32    
33     print "e=Function(mydomain):"
34     e=Function(mydomain)
35    
36     print "n=ContinuousFunction(mydomain):"
37     n=ContinuousFunction(mydomain)
38    
39     # get handles to nodes and elements 1
40    
41     print "\nGet handles to nodes and elements(1)=>"
42     print "--------------------------------------"
43    
44     print "u_ex=Scalar(1,n,True):"
45     u_ex=Scalar(1,n,True)
46    
47     print "x=e.getX():"
48     x=e.getX()
49    
50     print "norm_u_ex=u_ex.Lsup():"
51     norm_u_ex=u_ex.Lsup()
52    
53 jgs 108 print "\nGenerate a test solution (1)"
54     print "----------------------------"
55    
56 jgs 102 print "mypde=LinearPDE( A=[[1.,0.8],[0.4,1.]], D=alpha, Y=alpha, domain=mydomain)"
57 jgs 104 mypde=LinearPDE(mydomain)
58 jgs 102 mypde.setDebugOn()
59 jgs 104 mypde.setValue(A=[[1.,0.8],[0.4,1.]],D=alpha,Y=alpha)
60 jgs 82
61 jgs 108 print "mypde.checkSymmetry()"
62     print mypde.checkSymmetry()
63 jgs 82
64 jgs 102 print "\nIterative Solver (1)=>"
65 jgs 149 u_i=mypde.getSolution(verbose=True,iter_max=3000,preconditioner=mypde.ILU0)
66 jgs 102
67 jgs 100 print "\nDirect Solver (1)=>"
68 jgs 148 mypde.setSolverMethod(mypde.DIRECT)
69 jgs 149 u_d=mypde.getSolution(verbose=True)
70 jgs 97
71 jgs 82 print "\n***************************************************************"
72     error=u_ex-u_d
73 jgs 147 error_norm=error.Lsup()/norm_u_ex
74     print "norm of the error for direct solver is : ",error_norm
75     if error_norm > error_tol:
76     print "### error norm exceeded maximum tolerance ###"
77     sys.exit(1)
78 jgs 82 error=u_ex-u_i
79 jgs 147 error_norm=error.Lsup()/norm_u_ex
80     print "norm of the error for iterative solver is: ",error_norm
81     if error_norm > error_tol:
82     print "### error norm exceeded maximum tolerance ###"
83     sys.exit(1)
84 jgs 82 print "***************************************************************"
85    
86     # get handles to nodes and elements 2
87    
88     print "\nGet handles to nodes and elements(2)=>"
89     print "--------------------------------------"
90    
91     print "x=n.getX():"
92     x=n.getX()
93    
94     print "msk=x[0].whereZero()+(x[0]-1.).whereZero()"
95     msk=x[0].whereZero()+(x[0]-1.).whereZero()
96    
97 jgs 102 print "mypde=LinearPDE(A=[[1.,0.],[0.,1.]],q=msk,r=u_ex)"
98 jgs 104 mypde=LinearPDE(mydomain)
99 jgs 108 mypde.setDebugOn()
100 jgs 104 mypde.setValue(A=[[1.,0.],[0.,1.]],q=msk,r=u_ex)
101 jgs 82
102 jgs 108 print "mypde.checkSymmetry()"
103     print mypde.checkSymmetry()
104    
105 jgs 82 # generate a test solution 2
106    
107     print "\nGenerate a test solution (2)"
108     print "----------------------------"
109    
110     print "\nDirect Solver (2)=>"
111    
112 jgs 123 #mypde.setSymmetryOn()
113     mypde.setTolerance(1.e-13)
114 jgs 115
115 jgs 102 # mypde.setSymmetryOn() : is not woking yet!
116 jgs 104 mypde.setSolverMethod(mypde.DIRECT)
117 jgs 149 u_d=mypde.getSolution(verbose=True)
118 jgs 82
119     print "\nIterative Solver (2)=>"
120    
121 jgs 108 mypde.setSymmetryOn()
122 jgs 123 mypde.setSolverMethod(mypde.DEFAULT_METHOD)
123 jgs 149 u_i=mypde.getSolution(verbose=True,iter_max=3000)
124 jgs 82
125     print "\n******************************************************************"
126     error=u_ex-u_d
127 jgs 147 error_norm=error.Lsup()/norm_u_ex
128     print "norm of the error for direct solver is : ",error_norm
129     if error_norm > error_tol:
130     print "### error norm exceeded maximum tolerance ###"
131     sys.exit(1)
132 jgs 82 error=u_ex-u_i
133 jgs 147 error_norm=error.Lsup()/norm_u_ex
134     print "norm of the error for iterative solver is: ",error_norm
135 jgs 148 if error_norm > error_tol:
136 jgs 147 print "### error norm exceeded maximum tolerance ###"
137     sys.exit(1)
138 jgs 82 print "******************************************************************"
139    
140     print "\n-----"
141     print "Done."
142     print "-----"
143 jgs 147
144     sys.exit(0)

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26