/[escript]/trunk/ripley/test/python/run_simplesolve.py
ViewVC logotype

Contents of /trunk/ripley/test/python/run_simplesolve.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4984 - (show annotations)
Mon Jun 2 02:50:34 2014 UTC (4 years, 10 months ago) by sshaw
File MIME type: text/x-python
File size: 17336 byte(s)
revamping testrunners, now uses automated discovery and allows running specific tests without modifying files (see escriptcore/py_src/testing.py for more info/examples)

1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2014 by University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 __copyright__="""Copyright (c) 2003-2014 by University of Queensland
18 http://www.uq.edu.au
19 Primary Business: Queensland, Australia"""
20 __license__="""Licensed under the Open Software License version 3.0
21 http://www.opensource.org/licenses/osl-3.0.php"""
22 __url__="https://launchpad.net/escript-finley"
23
24 """
25 Test suite for the linearPDE and pdetools test on ripley
26
27 :remark:
28
29 :var __author__: name of author
30 :var __licence__: licence agreement
31 :var __url__: url entry point on documentation
32 :var __version__: version
33 :var __date__: date of the version
34 """
35
36 __author__="Lutz Gross, l.gross@uq.edu.au"
37
38 import esys.escriptcore.utestselect as unittest, sys
39 from esys.escriptcore.testing import *
40 from esys.escript import *
41 from esys.ripley import Rectangle,Brick
42 from esys.escript.linearPDEs import LinearPDE, SolverOptions
43 import numpy
44 SOLVER_VERBOSE=False
45
46 try:
47 RIPLEY_TEST_DATA=os.environ['RIPLEY_TEST_DATA']
48 except KeyError:
49 RIPLEY_TEST_DATA='.'
50
51 SOLVER_TOL=1.e-8
52 REL_TOL=1.e-6
53
54 FAC_DIAG=1.
55 FAC_OFFDIAG=-0.4
56
57 # number of elements in the spatial directions
58 NE0=12
59 NE1=12
60 NE2=8
61 mpiSize=getMPISizeWorld()
62 for x in [int(sqrt(mpiSize)),2,3,5,7,1]:
63 NX=x
64 NY=mpiSize//x
65 if NX*NY == mpiSize:
66 break
67
68 for x in [(int(mpiSize**(1/3.)),int(mpiSize**(1/3.))),(2,3),(2,2),(1,2),(1,1)]:
69 NXb=x[0]
70 NYb=x[1]
71 NZb=mpiSize//(x[0]*x[1])
72 if NXb*NYb*NZb == mpiSize:
73 break
74
75 class SimpleSolve_Rectangle_SinglePDE_Paso_BICGSTAB_Jacobi(unittest.TestCase):
76 def test_solve(self):
77 # Tell about how many MPI CPUs and OpenMP threads
78 domain=Rectangle(n0=NE0*NX-1, n1=NE1*NY-1, d0=NX, d1=NY)
79 x=Solution(domain).getX()
80 # --- set exact solution ----
81 u_ex=Scalar(0,Solution(domain))
82 u_ex=1.+2.*x[0]+3.*x[1]
83 # --- set exact gradient -----------
84 g_ex=Data(0.,(2,),Solution(domain))
85 g_ex[0]=2.
86 g_ex[1]=3.
87 # -------- test gradient --------------------------------
88 g=grad(u_ex)
89 self.assertTrue(Lsup(g_ex-g)<REL_TOL*Lsup(g_ex))
90 # -------- set-up PDE -----------------------------------
91 pde=LinearPDE(domain,numEquations=1)
92 mask=whereZero(x[0])
93 pde.setValue(r=u_ex,q=mask)
94 pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal()))
95 # -------- get the solution ---------------------------
96 pde.getSolverOptions().setTolerance(SOLVER_TOL)
97 pde.getSolverOptions().setSolverMethod(SolverOptions.BICGSTAB)
98 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
99 pde.getSolverOptions().setPackage(SolverOptions.PASO)
100 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
101 u=pde.getSolution()
102 # -------- test the solution ---------------------------
103 error=Lsup(u-u_ex)
104 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
105
106 class SimpleSolve_Rectangle_SinglePDE_Paso_PCG_Jacobi(unittest.TestCase):
107 def test_solve(self):
108 domain=Rectangle(n0=NE0*NX-1, n1=NE1*NY-1, d0=NX, d1=NY)
109 x=Solution(domain).getX()
110 # --- set exact solution ----
111 u_ex=Scalar(0,Solution(domain))
112 u_ex=1.+2.*x[0]+3.*x[1]
113 # --- set exact gradient -----------
114 g_ex=Data(0.,(2,),Solution(domain))
115 g_ex[0]=2.
116 g_ex[1]=3.
117 # -------- test gradient --------------------------------
118 g=grad(u_ex)
119 self.assertTrue(Lsup(g_ex-g)<REL_TOL*Lsup(g_ex))
120 # -------- set-up PDE -----------------------------------
121 pde=LinearPDE(domain,numEquations=1)
122 mask=whereZero(x[0])
123 pde.setValue(r=u_ex,q=mask)
124 pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal()))
125 # -------- get the solution ---------------------------
126 pde.getSolverOptions().setTolerance(SOLVER_TOL)
127 pde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
128 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
129 pde.getSolverOptions().setPackage(SolverOptions.PASO)
130 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
131 u=pde.getSolution()
132 # -------- test the solution ---------------------------
133 error=Lsup(u-u_ex)
134 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
135
136 class SimpleSolve_Rectangle_SystemPDE_Paso_PCG_Jacobi(unittest.TestCase):
137 def test_solve(self):
138 domain=Rectangle(n0=NE0*NX-1, n1=NE1*NY-1, d0=NX, d1=NY)
139 x=Solution(domain).getX()
140 # --- set exact solution ----
141 u_ex=Vector(0,Solution(domain))
142 u_ex[0]=1.+2.*x[0]+3.*x[1]
143 u_ex[1]=-1.+3.*x[0]+2.*x[1]
144 # --- set exact gradient -----------
145 g_ex=Data(0.,(2,2),Solution(domain))
146 g_ex[0,0]=2.
147 g_ex[0,1]=3.
148 g_ex[1,0]=3.
149 g_ex[1,1]=2.
150 # -------- test gradient --------------------------------
151 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
152 # -------- set-up PDE -----------------------------------
153 pde=LinearPDE(domain,numEquations=2)
154 mask=whereZero(x[0])
155 pde.setValue(r=u_ex,q=mask*numpy.ones(2,))
156 A=Tensor4(0,Function(domain))
157 A[0,:,0,:]=kronecker(2)
158 A[1,:,1,:]=kronecker(2)
159 Y=Vector(0.,Function(domain))
160 Y[0]=u_ex[0]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG
161 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG
162 pde.setValue(A=A,
163 D=kronecker(2)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((2,2))*FAC_OFFDIAG,
164 Y=Y,
165 y=matrixmult(g_ex,domain.getNormal()))
166 # -------- get the solution ---------------------------
167 pde.getSolverOptions().setTolerance(SOLVER_TOL)
168 pde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
169 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
170 pde.getSolverOptions().setPackage(SolverOptions.PASO)
171 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
172 u=pde.getSolution()
173 # -------- test the solution ---------------------------
174 error=Lsup(u-u_ex)
175 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
176
177 class SimpleSolve_Brick_SinglePDE_Paso_PCG_Jacobi(unittest.TestCase):
178 def test_solve(self):
179 domain=Brick(n0=NE0*NXb-1, n1=NE1*NYb-1, n2=NE2*NZb-1, d0=NXb, d1=NYb, d2=NZb)
180 x=Solution(domain).getX()
181 u_ex=1.+2.*x[0]+3.*x[1]+4.*x[2]
182 # --- set exact gradient -----------
183 g_ex=Data(0.,(3,),Solution(domain))
184 g_ex[0]=2.
185 g_ex[1]=3.
186 g_ex[2]=4.
187 # -------- test gradient --------------------------------
188 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
189 # -------- set-up PDE -----------------------------------
190 pde=LinearPDE(domain,numEquations=1)
191 mask=whereZero(x[0])
192 pde.setValue(r=u_ex,q=mask)
193 pde.setValue(A=kronecker(3),y=inner(g_ex,domain.getNormal()))
194 # -------- get the solution ---------------------------
195 pde.getSolverOptions().setTolerance(SOLVER_TOL)
196 pde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
197 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
198 pde.getSolverOptions().setPackage(SolverOptions.PASO)
199 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
200 u=pde.getSolution()
201 # -------- test the solution ---------------------------
202 error=Lsup(u-u_ex)
203 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
204
205 class SimpleSolve_Brick_SystemPDE_Paso_PCG_Jacobi(unittest.TestCase):
206 def test_solve(self):
207 domain=Brick(n0=NE0*NXb-1, n1=NE1*NYb-1, n2=NE2*NZb-1, d0=NXb, d1=NYb, d2=NZb)
208 x=Solution(domain).getX()
209 # --- set exact solution ----
210 u_ex=Vector(0,Solution(domain))
211 u_ex[0]=1.+2.*x[0]+3.*x[1]+4.*x[2]
212 u_ex[1]=-1.+4.*x[0]+1.*x[1]-2.*x[2]
213 u_ex[2]=5.+8.*x[0]+4.*x[1]+5.*x[2]
214 # --- set exact gradient -----------
215 g_ex=Data(0.,(3,3),Solution(domain))
216 g_ex[0,0]=2.
217 g_ex[0,1]=3.
218 g_ex[0,2]=4.
219 g_ex[1,0]=4.
220 g_ex[1,1]=1.
221 g_ex[1,2]=-2.
222 g_ex[2,0]=8.
223 g_ex[2,1]=4.
224 g_ex[2,2]=5.
225 # -------- test gradient --------------------------------
226 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
227 # -------- set-up PDE -----------------------------------
228 pde=LinearPDE(domain,numEquations=3)
229 mask=whereZero(x[0])
230 pde.setValue(r=u_ex,q=mask*numpy.ones(3,))
231 A=Tensor4(0,Function(domain))
232 A[0,:,0,:]=kronecker(3)
233 A[1,:,1,:]=kronecker(3)
234 A[2,:,2,:]=kronecker(3)
235 Y=Vector(0.,Function(domain))
236 Y[0]=u_ex[0]*FAC_DIAG+u_ex[2]*FAC_OFFDIAG+u_ex[1]*FAC_OFFDIAG
237 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG+u_ex[2]*FAC_OFFDIAG
238 Y[2]=u_ex[2]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG+u_ex[0]*FAC_OFFDIAG
239 pde.setValue(A=A,
240 D=kronecker(3)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((3,3))*FAC_OFFDIAG,
241 Y=Y,
242 y=matrixmult(g_ex,domain.getNormal()))
243 # -------- get the solution ---------------------------
244 pde.getSolverOptions().setTolerance(SOLVER_TOL)
245 pde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
246 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
247 pde.getSolverOptions().setPackage(SolverOptions.PASO)
248 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
249 u=pde.getSolution()
250 # -------- test the solution ---------------------------
251 error=Lsup(u-u_ex)
252 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
253
254 class SimpleSolve_Rectangle_SinglePDE_Paso_MINRES_Jacobi(unittest.TestCase):
255 def test_solve(self):
256 domain=Rectangle(n0=NE0*NX-1, n1=NE1*NY-1, d0=NX, d1=NY)
257 x=Solution(domain).getX()
258 # --- set exact solution ----
259 u_ex=Scalar(0,Solution(domain))
260 u_ex=1.+2.*x[0]+3.*x[1]
261 # --- set exact gradient -----------
262 g_ex=Data(0.,(2,),Solution(domain))
263 g_ex[0]=2.
264 g_ex[1]=3.
265 # -------- test gradient --------------------------------
266 g=grad(u_ex)
267 self.assertTrue(Lsup(g_ex-g)<REL_TOL*Lsup(g_ex))
268 # -------- set-up PDE -----------------------------------
269 pde=LinearPDE(domain,numEquations=1)
270 mask=whereZero(x[0])
271 pde.setValue(r=u_ex,q=mask)
272 pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal()))
273 # -------- get the solution ---------------------------
274 pde.getSolverOptions().setTolerance(SOLVER_TOL)
275 pde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
276 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
277 pde.getSolverOptions().setPackage(SolverOptions.PASO)
278
279 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
280 u=pde.getSolution()
281 # -------- test the solution ---------------------------
282 error=Lsup(u-u_ex)
283 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
284
285 class SimpleSolve_Rectangle_SystemPDE_Paso_MINRES_Jacobi(unittest.TestCase):
286 def test_solve(self):
287 domain=Rectangle(n0=NE0*NX-1, n1=NE1*NY-1, d0=NX, d1=NY)
288 x=Solution(domain).getX()
289 # --- set exact solution ----
290 u_ex=Vector(0,Solution(domain))
291 u_ex[0]=1.+2.*x[0]+3.*x[1]
292 u_ex[1]=-1.+3.*x[0]+2.*x[1]
293 # --- set exact gradient -----------
294 g_ex=Data(0.,(2,2),Solution(domain))
295 g_ex[0,0]=2.
296 g_ex[0,1]=3.
297 g_ex[1,0]=3.
298 g_ex[1,1]=2.
299 # -------- test gradient --------------------------------
300 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
301 # -------- set-up PDE -----------------------------------
302 pde=LinearPDE(domain,numEquations=2)
303 mask=whereZero(x[0])
304 pde.setValue(r=u_ex,q=mask*numpy.ones(2,))
305 A=Tensor4(0,Function(domain))
306 A[0,:,0,:]=kronecker(2)
307 A[1,:,1,:]=kronecker(2)
308 Y=Vector(0.,Function(domain))
309 Y[0]=u_ex[0]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG
310 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG
311 pde.setValue(A=A,
312 D=kronecker(2)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((2,2))*FAC_OFFDIAG,
313 Y=Y,
314 y=matrixmult(g_ex,domain.getNormal()))
315 # -------- get the solution ---------------------------
316 pde.getSolverOptions().setTolerance(SOLVER_TOL)
317 pde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
318 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
319 pde.getSolverOptions().setPackage(SolverOptions.PASO)
320 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
321 u=pde.getSolution()
322 # -------- test the solution ---------------------------
323 error=Lsup(u-u_ex)
324 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
325 class SimpleSolve_Brick_SinglePDE_Paso_MINRES_Jacobi(unittest.TestCase):
326 def test_solve(self):
327 domain=Brick(n0=NE0*NXb-1, n1=NE1*NYb-1, n2=NE2*NZb-1, d0=NXb, d1=NYb, d2=NZb)
328 x=Solution(domain).getX()
329 u_ex=1.+2.*x[0]+3.*x[1]+4.*x[2]
330 # --- set exact gradient -----------
331 g_ex=Data(0.,(3,),Solution(domain))
332 g_ex[0]=2.
333 g_ex[1]=3.
334 g_ex[2]=4.
335 # -------- test gradient --------------------------------
336 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
337 # -------- set-up PDE -----------------------------------
338 pde=LinearPDE(domain,numEquations=1)
339 mask=whereZero(x[0])
340 pde.setValue(r=u_ex,q=mask)
341 pde.setValue(A=kronecker(3),y=inner(g_ex,domain.getNormal()))
342 # -------- get the solution ---------------------------
343 pde.getSolverOptions().setTolerance(SOLVER_TOL)
344 pde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
345 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
346 pde.getSolverOptions().setPackage(SolverOptions.PASO)
347 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
348 u=pde.getSolution()
349 # -------- test the solution ---------------------------
350 error=Lsup(u-u_ex)
351 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
352
353 class SimpleSolve_Brick_SystemPDE_Paso_MINRES_Jacobi(unittest.TestCase):
354 def test_solve(self):
355 domain=Brick(n0=NE0*NXb-1, n1=NE1*NYb-1, n2=NE2*NZb-1, d0=NXb, d1=NYb, d2=NZb)
356 x=Solution(domain).getX()
357 # --- set exact solution ----
358 u_ex=Vector(0,Solution(domain))
359 u_ex[0]=1.+2.*x[0]+3.*x[1]+4.*x[2]
360 u_ex[1]=-1.+4.*x[0]+1.*x[1]-2.*x[2]
361 u_ex[2]=5.+8.*x[0]+4.*x[1]+5.*x[2]
362 # --- set exact gradient -----------
363 g_ex=Data(0.,(3,3),Solution(domain))
364 g_ex[0,0]=2.
365 g_ex[0,1]=3.
366 g_ex[0,2]=4.
367 g_ex[1,0]=4.
368 g_ex[1,1]=1.
369 g_ex[1,2]=-2.
370 g_ex[2,0]=8.
371 g_ex[2,1]=4.
372 g_ex[2,2]=5.
373 # -------- test gradient --------------------------------
374 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
375 # -------- set-up PDE -----------------------------------
376 pde=LinearPDE(domain,numEquations=3)
377 mask=whereZero(x[0])
378 pde.setValue(r=u_ex,q=mask*numpy.ones(3,))
379 A=Tensor4(0,Function(domain))
380 A[0,:,0,:]=kronecker(3)
381 A[1,:,1,:]=kronecker(3)
382 A[2,:,2,:]=kronecker(3)
383 Y=Vector(0.,Function(domain))
384 Y[0]=u_ex[0]*FAC_DIAG+u_ex[2]*FAC_OFFDIAG+u_ex[1]*FAC_OFFDIAG
385 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG+u_ex[2]*FAC_OFFDIAG
386 Y[2]=u_ex[2]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG+u_ex[0]*FAC_OFFDIAG
387 pde.setValue(A=A,
388 D=kronecker(3)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((3,3))*FAC_OFFDIAG,
389 Y=Y,
390 y=matrixmult(g_ex,domain.getNormal()))
391 # -------- get the solution ---------------------------
392 pde.getSolverOptions().setTolerance(SOLVER_TOL)
393 pde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
394 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
395 pde.getSolverOptions().setPackage(SolverOptions.PASO)
396 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
397 u=pde.getSolution()
398 # -------- test the solution ---------------------------
399 error=Lsup(u-u_ex)
400 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
401
402
403 if __name__ == '__main__':
404 run_tests(__name__, exit_on_failure=True)

  ViewVC Help
Powered by ViewVC 1.1.26