/[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 1226 - (show annotations)
Fri Aug 3 08:00:07 2007 UTC (11 years, 8 months ago) by gross
File MIME type: text/x-python
File size: 14922 byte(s)
hook for ParaMetis added. still needs some work
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, optimize=True)
53 return
54
55 x=Solution(domain).getX()
56 # --- set exact solution ----
57 u_ex=Scalar(0,Solution(domain))
58 u_ex=1.+2.*x[0]+3.*x[1]
59 # --- set exact gradient -----------
60 g_ex=Data(0.,(2,),Solution(domain))
61 g_ex[0]=2.
62 g_ex[1]=3.
63 # -------- test gradient --------------------------------
64 self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
65 # -------- set-up PDE -----------------------------------
66 pde=LinearPDE(domain,numEquations=1)
67 mask=whereZero(x[0])
68 pde.setValue(r=u_ex,q=mask)
69 pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal()))
70 # -------- get the solution ---------------------------
71 pde.setTolerance(SOLVER_TOL)
72 pde.setSolverMethod(pde.PCG,pde.JACOBI)
73 pde.setSolverPackage(pde.PASO)
74 u=pde.getSolution()
75 # -------- test the solution ---------------------------
76 error=Lsup(u-u_ex)/Lsup(u_ex)
77 self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
78 class SimpleSolve_Rectangle_Order1_SystemPDE_Paso_PCG_Jacobi(unittest.TestCase):
79 def test_solve(self):
80 domain=Rectangle(NE0,NE1,1)
81 x=Solution(domain).getX()
82 # --- set exact solution ----
83 u_ex=Vector(0,Solution(domain))
84 u_ex[0]=1.+2.*x[0]+3.*x[1]
85 u_ex[1]=-1.+3.*x[0]+2.*x[1]
86 # --- set exact gradient -----------
87 g_ex=Data(0.,(2,2),Solution(domain))
88 g_ex[0,0]=2.
89 g_ex[0,1]=3.
90 g_ex[1,0]=3.
91 g_ex[1,1]=2.
92 # -------- test gradient --------------------------------
93 self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
94 # -------- set-up PDE -----------------------------------
95 pde=LinearPDE(domain,numEquations=2)
96 mask=whereZero(x[0])
97 pde.setValue(r=u_ex,q=mask*numarray.ones(2,))
98 A=Tensor4(0,Function(domain))
99 A[0,:,0,:]=kronecker(2)
100 A[1,:,1,:]=kronecker(2)
101 Y=Vector(0.,Function(domain))
102 Y[0]=u_ex[0]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG
103 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG
104 pde.setValue(A=A,
105 D=kronecker(2)*(FAC_DIAG-FAC_OFFDIAG)+numarray.ones((2,2))*FAC_OFFDIAG,
106 Y=Y,
107 y=matrixmult(g_ex,domain.getNormal()))
108 # -------- get the solution ---------------------------
109 pde.setTolerance(SOLVER_TOL)
110 pde.setSolverMethod(pde.PCG,pde.JACOBI)
111 pde.setSolverPackage(pde.PASO)
112 u=pde.getSolution()
113 # -------- test the solution ---------------------------
114 error=Lsup(u-u_ex)/Lsup(u_ex)
115 self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
116 class SimpleSolve_Rectangle_Order2_SinglePDE_Paso_PCG_Jacobi(unittest.TestCase):
117 def test_solve(self):
118 domain=Rectangle(NE0,NE1,2)
119 x=Solution(domain).getX()
120 # --- set exact solution ----
121 u_ex=1.+2.*x[0]+3.*x[1]+4.*x[0]**2+5.*x[1]*x[0]+6.*x[1]**2
122 # --- set exact gradient -----------
123 g_ex=Data(0.,(2,),Solution(domain))
124 g_ex[0]=2.+8.*x[0]+5.*x[1]
125 g_ex[1]=3.+5.*x[0]+12.*x[1]
126 # -------- test gradient --------------------------------
127 self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
128 # -------- set-up PDE -----------------------------------
129 pde=LinearPDE(domain,numEquations=1)
130 mask=whereZero(x[0])
131 pde.setValue(r=u_ex,q=mask)
132 pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal()),Y=-20.)
133 # -------- get the solution ---------------------------
134 pde.setTolerance(SOLVER_TOL)
135 pde.setSolverMethod(pde.PCG,pde.JACOBI)
136 pde.setSolverPackage(pde.PASO)
137 u=pde.getSolution()
138 # -------- test the solution ---------------------------
139 error=Lsup(u-u_ex)/Lsup(u_ex)
140 self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
141 class SimpleSolve_Rectangle_Order2_SystemPDE_Paso_PCG_Jacobi(unittest.TestCase):
142 def test_solve(self):
143 domain=Rectangle(NE0,NE1,2)
144 x=Solution(domain).getX()
145 # --- set exact solution ----
146 u_ex=Vector(0,Solution(domain))
147 u_ex[0]=1.+2.*x[0]+3.*x[1]+4.*x[0]**2+5.*x[1]*x[0]+6.*x[1]**2
148 u_ex[1]=-1.+4.*x[0]+2.*x[1]+1.*x[0]**2+6.*x[1]*x[0]+4.*x[1]**2
149 # --- set exact gradient -----------
150 g_ex=Data(0.,(2,2),Solution(domain))
151 g_ex[0,0]=2.+8.*x[0]+5.*x[1]
152 g_ex[0,1]=3.+5.*x[0]+12.*x[1]
153 g_ex[1,0]=4.+2.*x[0]+6.*x[1]
154 g_ex[1,1]=2.+6.*x[0]+8.*x[1]
155 # -------- test gradient --------------------------------
156 self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
157 # -------- set-up PDE -----------------------------------
158 pde=LinearPDE(domain,numEquations=2)
159 mask=whereZero(x[0])
160 pde.setValue(r=u_ex,q=mask*numarray.ones(2,))
161 A=Tensor4(0,Function(domain))
162 A[0,:,0,:]=kronecker(2)
163 A[1,:,1,:]=kronecker(2)
164 Y=Vector(0.,Function(domain))
165 Y[0]=u_ex[0]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG
166 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG
167 pde.setValue(A=A,
168 D=kronecker(2)*(FAC_DIAG-FAC_OFFDIAG)+numarray.ones((2,2))*FAC_OFFDIAG,
169 Y=Y-[20.,10.],
170 y=matrixmult(g_ex,domain.getNormal()))
171 # -------- get the solution ---------------------------
172 pde.setTolerance(SOLVER_TOL)
173 pde.setSolverMethod(pde.PCG,pde.JACOBI)
174 pde.setSolverPackage(pde.PASO)
175 u=pde.getSolution()
176 # -------- test the solution ---------------------------
177 error=Lsup(u-u_ex)/Lsup(u_ex)
178 self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
179 class SimpleSolve_Brick_Order1_SinglePDE_Paso_PCG_Jacobi(unittest.TestCase):
180 def test_solve(self):
181 domain=Brick(NE0,NE1,NE2,1)
182 x=Solution(domain).getX()
183 u_ex=1.+2.*x[0]+3.*x[1]+4.*x[2]
184 # --- set exact gradient -----------
185 g_ex=Data(0.,(3,),Solution(domain))
186 g_ex[0]=2.
187 g_ex[1]=3.
188 g_ex[2]=4.
189 # -------- test gradient --------------------------------
190 self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
191 # -------- set-up PDE -----------------------------------
192 pde=LinearPDE(domain,numEquations=1)
193 mask=whereZero(x[0])
194 pde.setValue(r=u_ex,q=mask)
195 pde.setValue(A=kronecker(3),y=inner(g_ex,domain.getNormal()))
196 # -------- get the solution ---------------------------
197 pde.setTolerance(SOLVER_TOL)
198 pde.setSolverMethod(pde.PCG,pde.JACOBI)
199 pde.setSolverPackage(pde.PASO)
200 u=pde.getSolution()
201 # -------- test the solution ---------------------------
202 error=Lsup(u-u_ex)/Lsup(u_ex)
203 self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
204 class SimpleSolve_Brick_Order1_SystemPDE_Paso_PCG_Jacobi(unittest.TestCase):
205 def test_solve(self):
206 domain=Brick(NE0,NE1,NE2,1)
207 x=Solution(domain).getX()
208 # --- set exact solution ----
209 u_ex=Vector(0,Solution(domain))
210 u_ex[0]=1.+2.*x[0]+3.*x[1]+4.*x[2]
211 u_ex[1]=-1.+4.*x[0]+1.*x[1]-2.*x[2]
212 u_ex[2]=5.+8.*x[0]+4.*x[1]+5.*x[2]
213 # --- set exact gradient -----------
214 g_ex=Data(0.,(3,3),Solution(domain))
215 g_ex[0,0]=2.
216 g_ex[0,1]=3.
217 g_ex[0,2]=4.
218 g_ex[1,0]=4.
219 g_ex[1,1]=1.
220 g_ex[1,2]=-2.
221 g_ex[2,0]=8.
222 g_ex[2,1]=4.
223 g_ex[2,2]=5.
224 # -------- test gradient --------------------------------
225 self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
226 # -------- set-up PDE -----------------------------------
227 pde=LinearPDE(domain,numEquations=3)
228 mask=whereZero(x[0])
229 pde.setValue(r=u_ex,q=mask*numarray.ones(3,))
230 A=Tensor4(0,Function(domain))
231 A[0,:,0,:]=kronecker(3)
232 A[1,:,1,:]=kronecker(3)
233 A[2,:,2,:]=kronecker(3)
234 Y=Vector(0.,Function(domain))
235 Y[0]=u_ex[0]*FAC_DIAG+u_ex[2]*FAC_OFFDIAG+u_ex[1]*FAC_OFFDIAG
236 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG+u_ex[2]*FAC_OFFDIAG
237 Y[2]=u_ex[2]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG+u_ex[0]*FAC_OFFDIAG
238 pde.setValue(A=A,
239 D=kronecker(3)*(FAC_DIAG-FAC_OFFDIAG)+numarray.ones((3,3))*FAC_OFFDIAG,
240 Y=Y,
241 y=matrixmult(g_ex,domain.getNormal()))
242 # -------- get the solution ---------------------------
243 pde.setTolerance(SOLVER_TOL)
244 pde.setSolverMethod(pde.PCG,pde.JACOBI)
245 pde.setSolverPackage(pde.PASO)
246 u=pde.getSolution()
247 # -------- test the solution ---------------------------
248 error=Lsup(u-u_ex)/Lsup(u_ex)
249 self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
250 class SimpleSolve_Brick_Order2_SinglePDE_Paso_PCG_Jacobi(unittest.TestCase):
251 def test_solve(self):
252 domain=Brick(NE0,NE1,NE2,2)
253 x=Solution(domain).getX()
254 # --- set exact solution ----
255 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
256 # --- set exact gradient -----------
257 g_ex=Data(0.,(3,),Solution(domain))
258 g_ex[0]=2.+6.*x[1]+8.*x[2]+18.*x[0]
259 g_ex[1]=3.+6.*x[0]+7.*x[2]+20.*x[1]
260 g_ex[2]=4.+7.*x[1]+8.*x[0]+22.*x[2]
261 # -------- test gradient --------------------------------
262 self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
263 # -------- set-up PDE -----------------------------------
264 pde=LinearPDE(domain,numEquations=1)
265 mask=whereZero(x[0])
266 pde.setValue(r=u_ex,q=mask)
267 pde.setValue(A=kronecker(3),y=inner(g_ex,domain.getNormal()),Y=-60.)
268 # -------- get the solution ---------------------------
269 pde.setTolerance(SOLVER_TOL)
270 pde.setSolverMethod(pde.PCG,pde.JACOBI)
271 pde.setSolverPackage(pde.PASO)
272 u=pde.getSolution()
273 # -------- test the solution ---------------------------
274 error=Lsup(u-u_ex)/Lsup(u_ex)
275 self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
276 class SimpleSolve_Brick_Order2_SystemPDE_Paso_PCG_Jacobi(unittest.TestCase):
277 def test_solve(self):
278 domain=Brick(NE0,NE1,NE2,2)
279 x=Solution(domain).getX()
280 # --- set exact solution ----
281 u_ex=Vector(0,Solution(domain))
282 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
283 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
284 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
285 # --- set exact gradient -----------
286 g_ex=Data(0.,(3,3),Solution(domain))
287 g_ex[0,0]=2.+6.*x[1]+8.*x[2]+18.*x[0]
288 g_ex[0,1]=3.+6.*x[0]+7.*x[2]+20.*x[1]
289 g_ex[0,2]=4.+7.*x[1]+8.*x[0]+22.*x[2]
290 g_ex[1,0]=4.+3.*x[1]-8.*x[2]-4.*x[0]
291 g_ex[1,1]=1+3.*x[0]+2.*x[2]+14.*x[1]
292 g_ex[1,2]=-6.+2.*x[1]-8.*x[0]+10.*x[2]
293 g_ex[2,0]=7.-6.*x[1]+2.*x[2]+4.*x[0]
294 g_ex[2,1]=9.-6.*x[0]+8.*x[2]+16.*x[1]
295 g_ex[2,2]=2+8.*x[1]+2.*x[0]+2.*x[2]
296 # -------- test gradient --------------------------------
297 self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
298 # -------- set-up PDE -----------------------------------
299 pde=LinearPDE(domain,numEquations=3)
300 mask=whereZero(x[0])
301 pde.setValue(r=u_ex,q=mask*numarray.ones(3,))
302 Y=Vector(0.,Function(domain))
303 Y[0]=u_ex[0]*FAC_DIAG+u_ex[2]*FAC_OFFDIAG+u_ex[1]*FAC_OFFDIAG
304 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG+u_ex[2]*FAC_OFFDIAG
305 Y[2]=u_ex[2]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG+u_ex[0]*FAC_OFFDIAG
306 A=Tensor4(0,Function(domain))
307 A[0,:,0,:]=kronecker(3)
308 A[1,:,1,:]=kronecker(3)
309 A[2,:,2,:]=kronecker(3)
310 pde.setValue(A=A,
311 D=kronecker(3)*(FAC_DIAG-FAC_OFFDIAG)+numarray.ones((3,3))*FAC_OFFDIAG,
312 Y=Y-numarray.array([60.,20.,22.]),
313 y=matrixmult(g_ex,domain.getNormal()))
314 # -------- get the solution ---------------------------
315 pde.setTolerance(SOLVER_TOL)
316 pde.setSolverMethod(pde.PCG,pde.JACOBI)
317 pde.setSolverPackage(pde.PASO)
318 u=pde.getSolution()
319 # -------- test the solution ---------------------------
320 error=Lsup(u-u_ex)/Lsup(u_ex)
321 self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
322
323 if __name__ == '__main__':
324 suite = unittest.TestSuite()
325 suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order1_SinglePDE_Paso_PCG_Jacobi))
326 # suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order1_SystemPDE_Paso_PCG_Jacobi))
327 # suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order2_SinglePDE_Paso_PCG_Jacobi))
328 # suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order2_SystemPDE_Paso_PCG_Jacobi))
329 # suite.addTest(unittest.makeSuite(SimpleSolve_Brick_Order1_SinglePDE_Paso_PCG_Jacobi))
330 # suite.addTest(unittest.makeSuite(SimpleSolve_Brick_Order1_SystemPDE_Paso_PCG_Jacobi))
331 # suite.addTest(unittest.makeSuite(SimpleSolve_Brick_Order2_SinglePDE_Paso_PCG_Jacobi))
332 # suite.addTest(unittest.makeSuite(SimpleSolve_Brick_Order2_SystemPDE_Paso_PCG_Jacobi))
333 s=unittest.TextTestRunner(verbosity=2).run(suite)

  ViewVC Help
Powered by ViewVC 1.1.26