/[escript]/trunk-mpi-branch/finley/test/python/run_simplesolve.py
ViewVC logotype

Contents of /trunk-mpi-branch/finley/test/python/run_simplesolve.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1223 - (show annotations)
Fri Aug 3 02:40:39 2007 UTC (11 years, 8 months ago) by gross
File MIME type: text/x-python
File size: 14970 byte(s)
first attemt towards an improved MPI version.  

1 # $Id:$
2
3 """
4 Test suite for the linearPDE and pdetools test on finley
5
6 @remark:
7
8 @var __author__: name of author
9 @var __licence__: licence agreement
10 @var __url__: url entry point on documentation
11 @var __version__: version
12 @var __date__: date of the version
13 """
14
15 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
16 http://www.access.edu.au
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __author__="Lutz Gross, l.gross@uq.edu.au"
21 __url__="http://www.iservo.edu.au/esys/escript"
22 __version__="$Revision: 859 $"
23 __date__="$Date: 2006-09-26 12:19:18 +1000 (Tue, 26 Sep 2006) $"
24
25
26 import unittest
27
28 from esys.escript import *
29 from esys.finley import Rectangle,Brick
30 from esys.escript.linearPDEs import LinearPDE
31
32 try:
33 FINLEY_TEST_DATA=os.environ['FINLEY_TEST_DATA']
34 except KeyError:
35 FINLEY_TEST_DATA='.'
36
37 FINLEY_TEST_MESH_PATH=FINLEY_TEST_DATA+"/data_meshes/"
38
39 # number of elements in the spatial directions
40 NE0=12
41 NE1=12
42 NE2=8
43
44 SOLVER_TOL=1.e-8
45 REL_TOL=1.e-6
46
47 FAC_DIAG=1.
48 FAC_OFFDIAG=-0.4
49
50 class SimpleSolve_Rectangle_Order1_SinglePDE_Paso_PCG_Jacobi(unittest.TestCase):
51 def test_solve(self):
52 domain=Rectangle(NE0,NE1,2)
53 print "PY"*20
54 del domain
55 print "PY"*20
56 return
57
58 x=Solution(domain).getX()
59 # --- set exact solution ----
60 u_ex=Scalar(0,Solution(domain))
61 u_ex=1.+2.*x[0]+3.*x[1]
62 # --- set exact gradient -----------
63 g_ex=Data(0.,(2,),Solution(domain))
64 g_ex[0]=2.
65 g_ex[1]=3.
66 # -------- test gradient --------------------------------
67 self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
68 # -------- set-up PDE -----------------------------------
69 pde=LinearPDE(domain,numEquations=1)
70 mask=whereZero(x[0])
71 pde.setValue(r=u_ex,q=mask)
72 pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal()))
73 # -------- get the solution ---------------------------
74 pde.setTolerance(SOLVER_TOL)
75 pde.setSolverMethod(pde.PCG,pde.JACOBI)
76 pde.setSolverPackage(pde.PASO)
77 u=pde.getSolution()
78 # -------- test the solution ---------------------------
79 error=Lsup(u-u_ex)/Lsup(u_ex)
80 self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
81 class SimpleSolve_Rectangle_Order1_SystemPDE_Paso_PCG_Jacobi(unittest.TestCase):
82 def test_solve(self):
83 domain=Rectangle(NE0,NE1,1)
84 x=Solution(domain).getX()
85 # --- set exact solution ----
86 u_ex=Vector(0,Solution(domain))
87 u_ex[0]=1.+2.*x[0]+3.*x[1]
88 u_ex[1]=-1.+3.*x[0]+2.*x[1]
89 # --- set exact gradient -----------
90 g_ex=Data(0.,(2,2),Solution(domain))
91 g_ex[0,0]=2.
92 g_ex[0,1]=3.
93 g_ex[1,0]=3.
94 g_ex[1,1]=2.
95 # -------- test gradient --------------------------------
96 self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
97 # -------- set-up PDE -----------------------------------
98 pde=LinearPDE(domain,numEquations=2)
99 mask=whereZero(x[0])
100 pde.setValue(r=u_ex,q=mask*numarray.ones(2,))
101 A=Tensor4(0,Function(domain))
102 A[0,:,0,:]=kronecker(2)
103 A[1,:,1,:]=kronecker(2)
104 Y=Vector(0.,Function(domain))
105 Y[0]=u_ex[0]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG
106 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG
107 pde.setValue(A=A,
108 D=kronecker(2)*(FAC_DIAG-FAC_OFFDIAG)+numarray.ones((2,2))*FAC_OFFDIAG,
109 Y=Y,
110 y=matrixmult(g_ex,domain.getNormal()))
111 # -------- get the solution ---------------------------
112 pde.setTolerance(SOLVER_TOL)
113 pde.setSolverMethod(pde.PCG,pde.JACOBI)
114 pde.setSolverPackage(pde.PASO)
115 u=pde.getSolution()
116 # -------- test the solution ---------------------------
117 error=Lsup(u-u_ex)/Lsup(u_ex)
118 self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
119 class SimpleSolve_Rectangle_Order2_SinglePDE_Paso_PCG_Jacobi(unittest.TestCase):
120 def test_solve(self):
121 domain=Rectangle(NE0,NE1,2)
122 x=Solution(domain).getX()
123 # --- set exact solution ----
124 u_ex=1.+2.*x[0]+3.*x[1]+4.*x[0]**2+5.*x[1]*x[0]+6.*x[1]**2
125 # --- set exact gradient -----------
126 g_ex=Data(0.,(2,),Solution(domain))
127 g_ex[0]=2.+8.*x[0]+5.*x[1]
128 g_ex[1]=3.+5.*x[0]+12.*x[1]
129 # -------- test gradient --------------------------------
130 self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
131 # -------- set-up PDE -----------------------------------
132 pde=LinearPDE(domain,numEquations=1)
133 mask=whereZero(x[0])
134 pde.setValue(r=u_ex,q=mask)
135 pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal()),Y=-20.)
136 # -------- get the solution ---------------------------
137 pde.setTolerance(SOLVER_TOL)
138 pde.setSolverMethod(pde.PCG,pde.JACOBI)
139 pde.setSolverPackage(pde.PASO)
140 u=pde.getSolution()
141 # -------- test the solution ---------------------------
142 error=Lsup(u-u_ex)/Lsup(u_ex)
143 self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
144 class SimpleSolve_Rectangle_Order2_SystemPDE_Paso_PCG_Jacobi(unittest.TestCase):
145 def test_solve(self):
146 domain=Rectangle(NE0,NE1,2)
147 x=Solution(domain).getX()
148 # --- set exact solution ----
149 u_ex=Vector(0,Solution(domain))
150 u_ex[0]=1.+2.*x[0]+3.*x[1]+4.*x[0]**2+5.*x[1]*x[0]+6.*x[1]**2
151 u_ex[1]=-1.+4.*x[0]+2.*x[1]+1.*x[0]**2+6.*x[1]*x[0]+4.*x[1]**2
152 # --- set exact gradient -----------
153 g_ex=Data(0.,(2,2),Solution(domain))
154 g_ex[0,0]=2.+8.*x[0]+5.*x[1]
155 g_ex[0,1]=3.+5.*x[0]+12.*x[1]
156 g_ex[1,0]=4.+2.*x[0]+6.*x[1]
157 g_ex[1,1]=2.+6.*x[0]+8.*x[1]
158 # -------- test gradient --------------------------------
159 self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
160 # -------- set-up PDE -----------------------------------
161 pde=LinearPDE(domain,numEquations=2)
162 mask=whereZero(x[0])
163 pde.setValue(r=u_ex,q=mask*numarray.ones(2,))
164 A=Tensor4(0,Function(domain))
165 A[0,:,0,:]=kronecker(2)
166 A[1,:,1,:]=kronecker(2)
167 Y=Vector(0.,Function(domain))
168 Y[0]=u_ex[0]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG
169 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG
170 pde.setValue(A=A,
171 D=kronecker(2)*(FAC_DIAG-FAC_OFFDIAG)+numarray.ones((2,2))*FAC_OFFDIAG,
172 Y=Y-[20.,10.],
173 y=matrixmult(g_ex,domain.getNormal()))
174 # -------- get the solution ---------------------------
175 pde.setTolerance(SOLVER_TOL)
176 pde.setSolverMethod(pde.PCG,pde.JACOBI)
177 pde.setSolverPackage(pde.PASO)
178 u=pde.getSolution()
179 # -------- test the solution ---------------------------
180 error=Lsup(u-u_ex)/Lsup(u_ex)
181 self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
182 class SimpleSolve_Brick_Order1_SinglePDE_Paso_PCG_Jacobi(unittest.TestCase):
183 def test_solve(self):
184 domain=Brick(NE0,NE1,NE2,1)
185 x=Solution(domain).getX()
186 u_ex=1.+2.*x[0]+3.*x[1]+4.*x[2]
187 # --- set exact gradient -----------
188 g_ex=Data(0.,(3,),Solution(domain))
189 g_ex[0]=2.
190 g_ex[1]=3.
191 g_ex[2]=4.
192 # -------- test gradient --------------------------------
193 self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
194 # -------- set-up PDE -----------------------------------
195 pde=LinearPDE(domain,numEquations=1)
196 mask=whereZero(x[0])
197 pde.setValue(r=u_ex,q=mask)
198 pde.setValue(A=kronecker(3),y=inner(g_ex,domain.getNormal()))
199 # -------- get the solution ---------------------------
200 pde.setTolerance(SOLVER_TOL)
201 pde.setSolverMethod(pde.PCG,pde.JACOBI)
202 pde.setSolverPackage(pde.PASO)
203 u=pde.getSolution()
204 # -------- test the solution ---------------------------
205 error=Lsup(u-u_ex)/Lsup(u_ex)
206 self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
207 class SimpleSolve_Brick_Order1_SystemPDE_Paso_PCG_Jacobi(unittest.TestCase):
208 def test_solve(self):
209 domain=Brick(NE0,NE1,NE2,1)
210 x=Solution(domain).getX()
211 # --- set exact solution ----
212 u_ex=Vector(0,Solution(domain))
213 u_ex[0]=1.+2.*x[0]+3.*x[1]+4.*x[2]
214 u_ex[1]=-1.+4.*x[0]+1.*x[1]-2.*x[2]
215 u_ex[2]=5.+8.*x[0]+4.*x[1]+5.*x[2]
216 # --- set exact gradient -----------
217 g_ex=Data(0.,(3,3),Solution(domain))
218 g_ex[0,0]=2.
219 g_ex[0,1]=3.
220 g_ex[0,2]=4.
221 g_ex[1,0]=4.
222 g_ex[1,1]=1.
223 g_ex[1,2]=-2.
224 g_ex[2,0]=8.
225 g_ex[2,1]=4.
226 g_ex[2,2]=5.
227 # -------- test gradient --------------------------------
228 self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
229 # -------- set-up PDE -----------------------------------
230 pde=LinearPDE(domain,numEquations=3)
231 mask=whereZero(x[0])
232 pde.setValue(r=u_ex,q=mask*numarray.ones(3,))
233 A=Tensor4(0,Function(domain))
234 A[0,:,0,:]=kronecker(3)
235 A[1,:,1,:]=kronecker(3)
236 A[2,:,2,:]=kronecker(3)
237 Y=Vector(0.,Function(domain))
238 Y[0]=u_ex[0]*FAC_DIAG+u_ex[2]*FAC_OFFDIAG+u_ex[1]*FAC_OFFDIAG
239 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG+u_ex[2]*FAC_OFFDIAG
240 Y[2]=u_ex[2]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG+u_ex[0]*FAC_OFFDIAG
241 pde.setValue(A=A,
242 D=kronecker(3)*(FAC_DIAG-FAC_OFFDIAG)+numarray.ones((3,3))*FAC_OFFDIAG,
243 Y=Y,
244 y=matrixmult(g_ex,domain.getNormal()))
245 # -------- get the solution ---------------------------
246 pde.setTolerance(SOLVER_TOL)
247 pde.setSolverMethod(pde.PCG,pde.JACOBI)
248 pde.setSolverPackage(pde.PASO)
249 u=pde.getSolution()
250 # -------- test the solution ---------------------------
251 error=Lsup(u-u_ex)/Lsup(u_ex)
252 self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
253 class SimpleSolve_Brick_Order2_SinglePDE_Paso_PCG_Jacobi(unittest.TestCase):
254 def test_solve(self):
255 domain=Brick(NE0,NE1,NE2,2)
256 x=Solution(domain).getX()
257 # --- set exact solution ----
258 u_ex=1.+2.*x[0]+3.*x[1]+4.*x[2]+6.*x[0]*x[1]+7.*x[1]*x[2]+8.*x[2]*x[0]+9.*x[0]**2+10.*x[1]**2+11.*x[2]**2
259 # --- set exact gradient -----------
260 g_ex=Data(0.,(3,),Solution(domain))
261 g_ex[0]=2.+6.*x[1]+8.*x[2]+18.*x[0]
262 g_ex[1]=3.+6.*x[0]+7.*x[2]+20.*x[1]
263 g_ex[2]=4.+7.*x[1]+8.*x[0]+22.*x[2]
264 # -------- test gradient --------------------------------
265 self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
266 # -------- set-up PDE -----------------------------------
267 pde=LinearPDE(domain,numEquations=1)
268 mask=whereZero(x[0])
269 pde.setValue(r=u_ex,q=mask)
270 pde.setValue(A=kronecker(3),y=inner(g_ex,domain.getNormal()),Y=-60.)
271 # -------- get the solution ---------------------------
272 pde.setTolerance(SOLVER_TOL)
273 pde.setSolverMethod(pde.PCG,pde.JACOBI)
274 pde.setSolverPackage(pde.PASO)
275 u=pde.getSolution()
276 # -------- test the solution ---------------------------
277 error=Lsup(u-u_ex)/Lsup(u_ex)
278 self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
279 class SimpleSolve_Brick_Order2_SystemPDE_Paso_PCG_Jacobi(unittest.TestCase):
280 def test_solve(self):
281 domain=Brick(NE0,NE1,NE2,2)
282 x=Solution(domain).getX()
283 # --- set exact solution ----
284 u_ex=Vector(0,Solution(domain))
285 u_ex[0]=1.+2.*x[0]+3.*x[1]+4.*x[2]+6.*x[0]*x[1]+7.*x[1]*x[2]+8.*x[2]*x[0]+9.*x[0]**2+10.*x[1]**2+11.*x[2]**2
286 u_ex[1]=2.+4.*x[0]+1.*x[1]-6.*x[2]+3.*x[0]*x[1]+2.*x[1]*x[2]-8.*x[2]*x[0]-2.*x[0]**2+7.*x[1]**2+5.*x[2]**2
287 u_ex[2]=-2.+7.*x[0]+9.*x[1]+2*x[2]-6.*x[0]*x[1]+8.*x[1]*x[2]+2.*x[2]*x[0]+2.*x[0]**2+8.*x[1]**2+1.*x[2]**2
288 # --- set exact gradient -----------
289 g_ex=Data(0.,(3,3),Solution(domain))
290 g_ex[0,0]=2.+6.*x[1]+8.*x[2]+18.*x[0]
291 g_ex[0,1]=3.+6.*x[0]+7.*x[2]+20.*x[1]
292 g_ex[0,2]=4.+7.*x[1]+8.*x[0]+22.*x[2]
293 g_ex[1,0]=4.+3.*x[1]-8.*x[2]-4.*x[0]
294 g_ex[1,1]=1+3.*x[0]+2.*x[2]+14.*x[1]
295 g_ex[1,2]=-6.+2.*x[1]-8.*x[0]+10.*x[2]
296 g_ex[2,0]=7.-6.*x[1]+2.*x[2]+4.*x[0]
297 g_ex[2,1]=9.-6.*x[0]+8.*x[2]+16.*x[1]
298 g_ex[2,2]=2+8.*x[1]+2.*x[0]+2.*x[2]
299 # -------- test gradient --------------------------------
300 self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
301 # -------- set-up PDE -----------------------------------
302 pde=LinearPDE(domain,numEquations=3)
303 mask=whereZero(x[0])
304 pde.setValue(r=u_ex,q=mask*numarray.ones(3,))
305 Y=Vector(0.,Function(domain))
306 Y[0]=u_ex[0]*FAC_DIAG+u_ex[2]*FAC_OFFDIAG+u_ex[1]*FAC_OFFDIAG
307 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG+u_ex[2]*FAC_OFFDIAG
308 Y[2]=u_ex[2]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG+u_ex[0]*FAC_OFFDIAG
309 A=Tensor4(0,Function(domain))
310 A[0,:,0,:]=kronecker(3)
311 A[1,:,1,:]=kronecker(3)
312 A[2,:,2,:]=kronecker(3)
313 pde.setValue(A=A,
314 D=kronecker(3)*(FAC_DIAG-FAC_OFFDIAG)+numarray.ones((3,3))*FAC_OFFDIAG,
315 Y=Y-numarray.array([60.,20.,22.]),
316 y=matrixmult(g_ex,domain.getNormal()))
317 # -------- get the solution ---------------------------
318 pde.setTolerance(SOLVER_TOL)
319 pde.setSolverMethod(pde.PCG,pde.JACOBI)
320 pde.setSolverPackage(pde.PASO)
321 u=pde.getSolution()
322 # -------- test the solution ---------------------------
323 error=Lsup(u-u_ex)/Lsup(u_ex)
324 self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
325
326 if __name__ == '__main__':
327 suite = unittest.TestSuite()
328 suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order1_SinglePDE_Paso_PCG_Jacobi))
329 # suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order1_SystemPDE_Paso_PCG_Jacobi))
330 # suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order2_SinglePDE_Paso_PCG_Jacobi))
331 # suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order2_SystemPDE_Paso_PCG_Jacobi))
332 # suite.addTest(unittest.makeSuite(SimpleSolve_Brick_Order1_SinglePDE_Paso_PCG_Jacobi))
333 # suite.addTest(unittest.makeSuite(SimpleSolve_Brick_Order1_SystemPDE_Paso_PCG_Jacobi))
334 # suite.addTest(unittest.makeSuite(SimpleSolve_Brick_Order2_SinglePDE_Paso_PCG_Jacobi))
335 # suite.addTest(unittest.makeSuite(SimpleSolve_Brick_Order2_SystemPDE_Paso_PCG_Jacobi))
336 s=unittest.TextTestRunner(verbosity=2).run(suite)

  ViewVC Help
Powered by ViewVC 1.1.26