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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4938 - (show annotations)
Wed May 14 01:13:23 2014 UTC (5 years, 3 months ago) by jfenwick
File MIME type: text/x-python
File size: 48141 byte(s)
Modify unit tests to read their classes from
esys.escriptcore.utestselect

Change the line in that file to switch between unittest and unittest2


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 dudley
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
40 from esys.escript import *
41 from esys.dudley import Rectangle,Brick
42 from esys.escript.linearPDEs import LinearPDE, SolverOptions
43 import numpy
44 OPTIMIZE=True
45 SOLVER_VERBOSE=False
46 # setNumberOfThreads(2)
47
48 try:
49 DUDLEY_TEST_DATA=os.environ['DUDLEY_TEST_DATA']
50 except KeyError:
51 DUDLEY_TEST_DATA='.'
52
53 DUDLEY_TEST_MESH_PATH=os.path.join(DUDLEY_TEST_DATA,"data_meshes")
54
55 # number of elements in the spatial directions
56 NE0=8
57 NE1=10
58 NE2=12
59
60 NE0=12
61 NE1=13
62 NE2=8
63
64 SOLVER_TOL=1.e-8
65 REL_TOL=1.e-6
66
67 FAC_DIAG=1.
68 FAC_OFFDIAG=-0.4
69
70
71 class SimpleSolve_Rectangle_Order1_SinglePDE_Paso_BICGSTAB_Jacobi(unittest.TestCase):
72 def test_solve(self):
73 # Tell about how many MPI CPUs and OpenMP threads
74 domain=Rectangle(NE0,NE1,1, optimize=OPTIMIZE)
75 x=Solution(domain).getX()
76 # --- set exact solution ----
77 u_ex=Scalar(0,Solution(domain))
78 u_ex=1.+2.*x[0]+3.*x[1]
79 # --- set exact gradient -----------
80 g_ex=Data(0.,(2,),Solution(domain))
81 g_ex[0]=2.
82 g_ex[1]=3.
83 # -------- test gradient --------------------------------
84 g=grad(u_ex)
85 self.assertTrue(Lsup(g_ex-g)<REL_TOL*Lsup(g_ex))
86 # -------- set-up PDE -----------------------------------
87 pde=LinearPDE(domain,numEquations=1)
88 mask=whereZero(x[0])
89 pde.setValue(r=u_ex,q=mask)
90 pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal()))
91 # -------- get the solution ---------------------------
92 pde.getSolverOptions().setTolerance(SOLVER_TOL)
93 pde.getSolverOptions().setSolverMethod(SolverOptions.BICGSTAB)
94 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
95 pde.getSolverOptions().setPackage(SolverOptions.PASO)
96 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
97 u=pde.getSolution()
98 # -------- test the solution ---------------------------
99 error=Lsup(u-u_ex)
100 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
101 class SimpleSolve_Rectangle_Order1_SinglePDE_Paso_PCG_Jacobi(unittest.TestCase):
102 def test_solve(self):
103 domain=Rectangle(NE0,NE1,1, optimize=OPTIMIZE)
104 x=Solution(domain).getX()
105 # --- set exact solution ----
106 u_ex=Scalar(0,Solution(domain))
107 u_ex=1.+2.*x[0]+3.*x[1]
108 # --- set exact gradient -----------
109 g_ex=Data(0.,(2,),Solution(domain))
110 g_ex[0]=2.
111 g_ex[1]=3.
112 # -------- test gradient --------------------------------
113 g=grad(u_ex)
114 self.assertTrue(Lsup(g_ex-g)<REL_TOL*Lsup(g_ex))
115 # -------- set-up PDE -----------------------------------
116 pde=LinearPDE(domain,numEquations=1)
117 mask=whereZero(x[0])
118 pde.setValue(r=u_ex,q=mask)
119 pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal()))
120 # -------- get the solution ---------------------------
121 pde.getSolverOptions().setTolerance(SOLVER_TOL)
122 pde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
123 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
124 pde.getSolverOptions().setPackage(SolverOptions.PASO)
125 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
126 u=pde.getSolution()
127 # -------- test the solution ---------------------------
128 error=Lsup(u-u_ex)
129 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
130 class SimpleSolve_Rectangle_Order1_SystemPDE_Paso_PCG_Jacobi(unittest.TestCase):
131 def test_solve(self):
132 domain=Rectangle(NE0,NE1,1,optimize=OPTIMIZE)
133 x=Solution(domain).getX()
134 # --- set exact solution ----
135 u_ex=Vector(0,Solution(domain))
136 u_ex[0]=1.+2.*x[0]+3.*x[1]
137 u_ex[1]=-1.+3.*x[0]+2.*x[1]
138 # --- set exact gradient -----------
139 g_ex=Data(0.,(2,2),Solution(domain))
140 g_ex[0,0]=2.
141 g_ex[0,1]=3.
142 g_ex[1,0]=3.
143 g_ex[1,1]=2.
144 # -------- test gradient --------------------------------
145 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
146 # -------- set-up PDE -----------------------------------
147 pde=LinearPDE(domain,numEquations=2)
148 mask=whereZero(x[0])
149 pde.setValue(r=u_ex,q=mask*numpy.ones(2,))
150 A=Tensor4(0,Function(domain))
151 A[0,:,0,:]=kronecker(2)
152 A[1,:,1,:]=kronecker(2)
153 Y=Vector(0.,Function(domain))
154 Y[0]=u_ex[0]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG
155 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG
156 pde.setValue(A=A,
157 D=kronecker(2)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((2,2))*FAC_OFFDIAG,
158 Y=Y,
159 y=matrixmult(g_ex,domain.getNormal()))
160 # -------- get the solution ---------------------------
161 pde.getSolverOptions().setTolerance(SOLVER_TOL)
162 pde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
163 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
164 pde.getSolverOptions().setPackage(SolverOptions.PASO)
165 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
166 u=pde.getSolution()
167 # -------- test the solution ---------------------------
168 error=Lsup(u-u_ex)
169 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
170 class SimpleSolve_Rectangle_Order2_SinglePDE_Paso_PCG_Jacobi(unittest.TestCase):
171 def test_solve(self):
172 domain=Rectangle(NE0,NE1,2,l0=1.,l1=1,optimize=OPTIMIZE)
173 x=Solution(domain).getX()
174 # --- set exact solution ----
175 u_ex=1.+2.*x[0]+3.*x[1]+4.*x[0]**2+5.*x[1]*x[0]+6.*x[1]**2
176 # --- set exact gradient -----------
177 g_ex=Data(0.,(2,),Solution(domain))
178 g_ex[0]=2.+8.*x[0]+5.*x[1]
179 g_ex[1]=3.+5.*x[0]+12.*x[1]
180 # -------- test gradient --------------------------------
181 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
182 # -------- set-up PDE -----------------------------------
183 pde=LinearPDE(domain,numEquations=1)
184 mask=whereZero(x[0])
185 pde.setValue(r=u_ex,q=mask)
186 pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal()),Y=-20.)
187 # -------- get the solution ---------------------------
188 pde.getSolverOptions().setTolerance(SOLVER_TOL)
189 pde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
190 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
191 pde.getSolverOptions().setPackage(SolverOptions.PASO)
192 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
193 u=pde.getSolution()
194 # -------- test the solution ---------------------------
195 error=Lsup(u-u_ex)
196 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
197 class SimpleSolve_Rectangle_Order2_SystemPDE_Paso_PCG_Jacobi(unittest.TestCase):
198 def test_solve(self):
199 domain=Rectangle(NE0,NE1,2,optimize=OPTIMIZE)
200 x=Solution(domain).getX()
201 # --- set exact solution ----
202 u_ex=Vector(0,Solution(domain))
203 u_ex[0]=1.+2.*x[0]+3.*x[1]+4.*x[0]**2+5.*x[1]*x[0]+6.*x[1]**2
204 u_ex[1]=-1.+4.*x[0]+2.*x[1]+1.*x[0]**2+6.*x[1]*x[0]+4.*x[1]**2
205 # --- set exact gradient -----------
206 g_ex=Data(0.,(2,2),Solution(domain))
207 g_ex[0,0]=2.+8.*x[0]+5.*x[1]
208 g_ex[0,1]=3.+5.*x[0]+12.*x[1]
209 g_ex[1,0]=4.+2.*x[0]+6.*x[1]
210 g_ex[1,1]=2.+6.*x[0]+8.*x[1]
211 # -------- test gradient --------------------------------
212 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
213 # -------- set-up PDE -----------------------------------
214 pde=LinearPDE(domain,numEquations=2)
215 mask=whereZero(x[0])
216 pde.setValue(r=u_ex,q=mask*numpy.ones(2,))
217 A=Tensor4(0,Function(domain))
218 A[0,:,0,:]=kronecker(2)
219 A[1,:,1,:]=kronecker(2)
220 Y=Vector(0.,Function(domain))
221 Y[0]=u_ex[0]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG
222 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG
223 pde.setValue(A=A,
224 D=kronecker(2)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((2,2))*FAC_OFFDIAG,
225 Y=Y-[20.,10.],
226 y=matrixmult(g_ex,domain.getNormal()))
227 # -------- get the solution ---------------------------
228 pde.getSolverOptions().setTolerance(SOLVER_TOL)
229 pde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
230 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
231 pde.getSolverOptions().setPackage(SolverOptions.PASO)
232 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
233 u=pde.getSolution()
234 # -------- test the solution ---------------------------
235 error=Lsup(u-u_ex)
236 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
237 class SimpleSolve_Brick_Order1_SinglePDE_Paso_PCG_Jacobi(unittest.TestCase):
238 def test_solve(self):
239 domain=Brick(NE0,NE1,NE2,1,optimize=OPTIMIZE)
240 x=Solution(domain).getX()
241 u_ex=1.+2.*x[0]+3.*x[1]+4.*x[2]
242 # --- set exact gradient -----------
243 g_ex=Data(0.,(3,),Solution(domain))
244 g_ex[0]=2.
245 g_ex[1]=3.
246 g_ex[2]=4.
247 # -------- test gradient --------------------------------
248 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
249 # -------- set-up PDE -----------------------------------
250 pde=LinearPDE(domain,numEquations=1)
251 mask=whereZero(x[0])
252 pde.setValue(r=u_ex,q=mask)
253 pde.setValue(A=kronecker(3),y=inner(g_ex,domain.getNormal()))
254 # -------- get the solution ---------------------------
255 pde.getSolverOptions().setTolerance(SOLVER_TOL)
256 pde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
257 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
258 pde.getSolverOptions().setPackage(SolverOptions.PASO)
259 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
260 u=pde.getSolution()
261 # -------- test the solution ---------------------------
262 error=Lsup(u-u_ex)
263 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
264 class SimpleSolve_Brick_Order1_SystemPDE_Paso_PCG_Jacobi(unittest.TestCase):
265 def test_solve(self):
266 domain=Brick(NE0,NE1,NE2,1,optimize=OPTIMIZE)
267 x=Solution(domain).getX()
268 # --- set exact solution ----
269 u_ex=Vector(0,Solution(domain))
270 u_ex[0]=1.+2.*x[0]+3.*x[1]+4.*x[2]
271 u_ex[1]=-1.+4.*x[0]+1.*x[1]-2.*x[2]
272 u_ex[2]=5.+8.*x[0]+4.*x[1]+5.*x[2]
273 # --- set exact gradient -----------
274 g_ex=Data(0.,(3,3),Solution(domain))
275 g_ex[0,0]=2.
276 g_ex[0,1]=3.
277 g_ex[0,2]=4.
278 g_ex[1,0]=4.
279 g_ex[1,1]=1.
280 g_ex[1,2]=-2.
281 g_ex[2,0]=8.
282 g_ex[2,1]=4.
283 g_ex[2,2]=5.
284 # -------- test gradient --------------------------------
285 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
286 # -------- set-up PDE -----------------------------------
287 pde=LinearPDE(domain,numEquations=3)
288 mask=whereZero(x[0])
289 pde.setValue(r=u_ex,q=mask*numpy.ones(3,))
290 A=Tensor4(0,Function(domain))
291 A[0,:,0,:]=kronecker(3)
292 A[1,:,1,:]=kronecker(3)
293 A[2,:,2,:]=kronecker(3)
294 Y=Vector(0.,Function(domain))
295 Y[0]=u_ex[0]*FAC_DIAG+u_ex[2]*FAC_OFFDIAG+u_ex[1]*FAC_OFFDIAG
296 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG+u_ex[2]*FAC_OFFDIAG
297 Y[2]=u_ex[2]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG+u_ex[0]*FAC_OFFDIAG
298 pde.setValue(A=A,
299 D=kronecker(3)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((3,3))*FAC_OFFDIAG,
300 Y=Y,
301 y=matrixmult(g_ex,domain.getNormal()))
302 # -------- get the solution ---------------------------
303 pde.getSolverOptions().setTolerance(SOLVER_TOL)
304 pde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
305 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
306 pde.getSolverOptions().setPackage(SolverOptions.PASO)
307 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
308 u=pde.getSolution()
309 # -------- test the solution ---------------------------
310 error=Lsup(u-u_ex)
311 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
312 class SimpleSolve_Brick_Order2_SinglePDE_Paso_PCG_Jacobi(unittest.TestCase):
313 def test_solve(self):
314 domain=Brick(NE0,NE1,NE2,2,optimize=OPTIMIZE)
315 x=Solution(domain).getX()
316 # --- set exact solution ----
317 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
318 # --- set exact gradient -----------
319 g_ex=Data(0.,(3,),Solution(domain))
320 g_ex[0]=2.+6.*x[1]+8.*x[2]+18.*x[0]
321 g_ex[1]=3.+6.*x[0]+7.*x[2]+20.*x[1]
322 g_ex[2]=4.+7.*x[1]+8.*x[0]+22.*x[2]
323 # -------- test gradient --------------------------------
324 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
325 # -------- set-up PDE -----------------------------------
326 pde=LinearPDE(domain,numEquations=1)
327 mask=whereZero(x[0])
328 pde.setValue(r=u_ex,q=mask)
329 pde.setValue(A=kronecker(3),y=inner(g_ex,domain.getNormal()),Y=-60.)
330 # -------- get the solution ---------------------------
331 pde.getSolverOptions().setTolerance(SOLVER_TOL)
332 pde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
333 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
334 pde.getSolverOptions().setPackage(SolverOptions.PASO)
335 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
336 u=pde.getSolution()
337 # -------- test the solution ---------------------------
338 error=Lsup(u-u_ex)
339 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
340 class SimpleSolve_Brick_Order2_SystemPDE_Paso_PCG_Jacobi(unittest.TestCase):
341 def test_solve(self):
342 domain=Brick(NE0,NE1,NE2,2,optimize=OPTIMIZE)
343 x=Solution(domain).getX()
344 # --- set exact solution ----
345 u_ex=Vector(0,Solution(domain))
346 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
347 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
348 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
349 # --- set exact gradient -----------
350 g_ex=Data(0.,(3,3),Solution(domain))
351 g_ex[0,0]=2.+6.*x[1]+8.*x[2]+18.*x[0]
352 g_ex[0,1]=3.+6.*x[0]+7.*x[2]+20.*x[1]
353 g_ex[0,2]=4.+7.*x[1]+8.*x[0]+22.*x[2]
354 g_ex[1,0]=4.+3.*x[1]-8.*x[2]-4.*x[0]
355 g_ex[1,1]=1+3.*x[0]+2.*x[2]+14.*x[1]
356 g_ex[1,2]=-6.+2.*x[1]-8.*x[0]+10.*x[2]
357 g_ex[2,0]=7.-6.*x[1]+2.*x[2]+4.*x[0]
358 g_ex[2,1]=9.-6.*x[0]+8.*x[2]+16.*x[1]
359 g_ex[2,2]=2+8.*x[1]+2.*x[0]+2.*x[2]
360 # -------- test gradient --------------------------------
361 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
362 # -------- set-up PDE -----------------------------------
363 pde=LinearPDE(domain,numEquations=3)
364 mask=whereZero(x[0])
365 pde.setValue(r=u_ex,q=mask*numpy.ones(3,))
366 Y=Vector(0.,Function(domain))
367 Y[0]=u_ex[0]*FAC_DIAG+u_ex[2]*FAC_OFFDIAG+u_ex[1]*FAC_OFFDIAG
368 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG+u_ex[2]*FAC_OFFDIAG
369 Y[2]=u_ex[2]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG+u_ex[0]*FAC_OFFDIAG
370 A=Tensor4(0,Function(domain))
371 A[0,:,0,:]=kronecker(3)
372 A[1,:,1,:]=kronecker(3)
373 A[2,:,2,:]=kronecker(3)
374 pde.setValue(A=A,
375 D=kronecker(3)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((3,3))*FAC_OFFDIAG,
376 Y=Y-numpy.array([60.,20.,22.]),
377 y=matrixmult(g_ex,domain.getNormal()))
378 # -------- get the solution ---------------------------
379 pde.getSolverOptions().setTolerance(SOLVER_TOL)
380 pde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
381 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
382 pde.getSolverOptions().setPackage(SolverOptions.PASO)
383 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
384 u=pde.getSolution()
385 # -------- test the solution ---------------------------
386 error=Lsup(u-u_ex)
387 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
388
389 class SimpleSolve_Rectangle_Order1_SinglePDE_Paso_TFQMR_Jacobi(unittest.TestCase):
390 def test_solve(self):
391 domain=Rectangle(NE0,NE1,1, optimize=OPTIMIZE)
392 x=Solution(domain).getX()
393 # --- set exact solution ----
394 u_ex=Scalar(0,Solution(domain))
395 u_ex=1.+2.*x[0]+3.*x[1]
396 # --- set exact gradient -----------
397 g_ex=Data(0.,(2,),Solution(domain))
398 g_ex[0]=2.
399 g_ex[1]=3.
400 # -------- test gradient --------------------------------
401 g=grad(u_ex)
402 self.assertTrue(Lsup(g_ex-g)<REL_TOL*Lsup(g_ex))
403 # -------- set-up PDE -----------------------------------
404 pde=LinearPDE(domain,numEquations=1)
405 mask=whereZero(x[0])
406 pde.setValue(r=u_ex,q=mask)
407 pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal()))
408 # -------- get the solution ---------------------------
409 pde.getSolverOptions().setTolerance(SOLVER_TOL)
410 pde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)
411 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
412 pde.getSolverOptions().setPackage(SolverOptions.PASO)
413 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
414 u=pde.getSolution()
415 # -------- test the solution ---------------------------
416 error=Lsup(u-u_ex)
417 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
418
419 class SimpleSolve_Rectangle_Order2_SinglePDE_Paso_TFQMR_Jacobi(unittest.TestCase):
420 def test_solve(self):
421 domain=Rectangle(NE0,NE1,2,l0=1.,l1=1,optimize=OPTIMIZE)
422 x=Solution(domain).getX()
423 # --- set exact solution ----
424 u_ex=1.+2.*x[0]+3.*x[1]+4.*x[0]**2+5.*x[1]*x[0]+6.*x[1]**2
425 # --- set exact gradient -----------
426 g_ex=Data(0.,(2,),Solution(domain))
427 g_ex[0]=2.+8.*x[0]+5.*x[1]
428 g_ex[1]=3.+5.*x[0]+12.*x[1]
429 # -------- test gradient --------------------------------
430 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
431 # -------- set-up PDE -----------------------------------
432 pde=LinearPDE(domain,numEquations=1)
433 mask=whereZero(x[0])
434 pde.setValue(r=u_ex,q=mask)
435 pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal()),Y=-20.)
436 # -------- get the solution ---------------------------
437 pde.getSolverOptions().setTolerance(SOLVER_TOL)
438 pde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)
439 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
440 pde.getSolverOptions().setPackage(SolverOptions.PASO)
441 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
442 u=pde.getSolution()
443 # -------- test the solution ---------------------------
444 error=Lsup(u-u_ex)
445 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
446
447 class SimpleSolve_Rectangle_Order1_SystemPDE_Paso_TFQMR_Jacobi(unittest.TestCase):
448 def test_solve(self):
449 domain=Rectangle(NE0,NE1,1,optimize=OPTIMIZE)
450 x=Solution(domain).getX()
451 # --- set exact solution ----
452 u_ex=Vector(0,Solution(domain))
453 u_ex[0]=1.+2.*x[0]+3.*x[1]
454 u_ex[1]=-1.+3.*x[0]+2.*x[1]
455 # --- set exact gradient -----------
456 g_ex=Data(0.,(2,2),Solution(domain))
457 g_ex[0,0]=2.
458 g_ex[0,1]=3.
459 g_ex[1,0]=3.
460 g_ex[1,1]=2.
461 # -------- test gradient --------------------------------
462 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
463 # -------- set-up PDE -----------------------------------
464 pde=LinearPDE(domain,numEquations=2)
465 mask=whereZero(x[0])
466 pde.setValue(r=u_ex,q=mask*numpy.ones(2,))
467 A=Tensor4(0,Function(domain))
468 A[0,:,0,:]=kronecker(2)
469 A[1,:,1,:]=kronecker(2)
470 Y=Vector(0.,Function(domain))
471 Y[0]=u_ex[0]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG
472 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG
473 pde.setValue(A=A,
474 D=kronecker(2)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((2,2))*FAC_OFFDIAG,
475 Y=Y,
476 y=matrixmult(g_ex,domain.getNormal()))
477 # -------- get the solution ---------------------------
478 pde.getSolverOptions().setTolerance(SOLVER_TOL)
479 pde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)
480 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
481 pde.getSolverOptions().setPackage(SolverOptions.PASO)
482 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
483 u=pde.getSolution()
484 # -------- test the solution ---------------------------
485 error=Lsup(u-u_ex)
486 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
487
488 class SimpleSolve_Rectangle_Order2_SystemPDE_Paso_TFQMR_Jacobi(unittest.TestCase):
489 def test_solve(self):
490 domain=Rectangle(NE0,NE1,2,optimize=OPTIMIZE)
491 x=Solution(domain).getX()
492 # --- set exact solution ----
493 u_ex=Vector(0,Solution(domain))
494 u_ex[0]=1.+2.*x[0]+3.*x[1]+4.*x[0]**2+5.*x[1]*x[0]+6.*x[1]**2
495 u_ex[1]=-1.+4.*x[0]+2.*x[1]+1.*x[0]**2+6.*x[1]*x[0]+4.*x[1]**2
496 # --- set exact gradient -----------
497 g_ex=Data(0.,(2,2),Solution(domain))
498 g_ex[0,0]=2.+8.*x[0]+5.*x[1]
499 g_ex[0,1]=3.+5.*x[0]+12.*x[1]
500 g_ex[1,0]=4.+2.*x[0]+6.*x[1]
501 g_ex[1,1]=2.+6.*x[0]+8.*x[1]
502 # -------- test gradient --------------------------------
503 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
504 # -------- set-up PDE -----------------------------------
505 pde=LinearPDE(domain,numEquations=2)
506 mask=whereZero(x[0])
507 pde.setValue(r=u_ex,q=mask*numpy.ones(2,))
508 A=Tensor4(0,Function(domain))
509 A[0,:,0,:]=kronecker(2)
510 A[1,:,1,:]=kronecker(2)
511 Y=Vector(0.,Function(domain))
512 Y[0]=u_ex[0]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG
513 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG
514 pde.setValue(A=A,
515 D=kronecker(2)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((2,2))*FAC_OFFDIAG,
516 Y=Y-[20.,10.],
517 y=matrixmult(g_ex,domain.getNormal()))
518 # -------- get the solution ---------------------------
519 pde.getSolverOptions().setTolerance(SOLVER_TOL)
520 pde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)
521 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
522 pde.getSolverOptions().setPackage(SolverOptions.PASO)
523 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
524 u=pde.getSolution()
525 # -------- test the solution ---------------------------
526 error=Lsup(u-u_ex)
527 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
528
529 class SimpleSolve_Brick_Order1_SinglePDE_Paso_TFQMR_Jacobi(unittest.TestCase):
530 def test_solve(self):
531 domain=Brick(NE0,NE1,NE2,1,optimize=OPTIMIZE)
532 x=Solution(domain).getX()
533 u_ex=1.+2.*x[0]+3.*x[1]+4.*x[2]
534 # --- set exact gradient -----------
535 g_ex=Data(0.,(3,),Solution(domain))
536 g_ex[0]=2.
537 g_ex[1]=3.
538 g_ex[2]=4.
539 # -------- test gradient --------------------------------
540 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
541 # -------- set-up PDE -----------------------------------
542 pde=LinearPDE(domain,numEquations=1)
543 mask=whereZero(x[0])
544 pde.setValue(r=u_ex,q=mask)
545 pde.setValue(A=kronecker(3),y=inner(g_ex,domain.getNormal()))
546 # -------- get the solution ---------------------------
547 pde.getSolverOptions().setTolerance(SOLVER_TOL)
548 pde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)
549 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
550 pde.getSolverOptions().setPackage(SolverOptions.PASO)
551 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
552 u=pde.getSolution()
553 # -------- test the solution ---------------------------
554 error=Lsup(u-u_ex)
555 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
556
557 class SimpleSolve_Brick_Order1_SystemPDE_Paso_TFQMR_Jacobi(unittest.TestCase):
558 def test_solve(self):
559 domain=Brick(NE0,NE1,NE2,1,optimize=OPTIMIZE)
560 x=Solution(domain).getX()
561 # --- set exact solution ----
562 u_ex=Vector(0,Solution(domain))
563 u_ex[0]=1.+2.*x[0]+3.*x[1]+4.*x[2]
564 u_ex[1]=-1.+4.*x[0]+1.*x[1]-2.*x[2]
565 u_ex[2]=5.+8.*x[0]+4.*x[1]+5.*x[2]
566 # --- set exact gradient -----------
567 g_ex=Data(0.,(3,3),Solution(domain))
568 g_ex[0,0]=2.
569 g_ex[0,1]=3.
570 g_ex[0,2]=4.
571 g_ex[1,0]=4.
572 g_ex[1,1]=1.
573 g_ex[1,2]=-2.
574 g_ex[2,0]=8.
575 g_ex[2,1]=4.
576 g_ex[2,2]=5.
577 # -------- test gradient --------------------------------
578 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
579 # -------- set-up PDE -----------------------------------
580 pde=LinearPDE(domain,numEquations=3)
581 mask=whereZero(x[0])
582 pde.setValue(r=u_ex,q=mask*numpy.ones(3,))
583 A=Tensor4(0,Function(domain))
584 A[0,:,0,:]=kronecker(3)
585 A[1,:,1,:]=kronecker(3)
586 A[2,:,2,:]=kronecker(3)
587 Y=Vector(0.,Function(domain))
588 Y[0]=u_ex[0]*FAC_DIAG+u_ex[2]*FAC_OFFDIAG+u_ex[1]*FAC_OFFDIAG
589 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG+u_ex[2]*FAC_OFFDIAG
590 Y[2]=u_ex[2]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG+u_ex[0]*FAC_OFFDIAG
591 pde.setValue(A=A,
592 D=kronecker(3)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((3,3))*FAC_OFFDIAG,
593 Y=Y,
594 y=matrixmult(g_ex,domain.getNormal()))
595 # -------- get the solution ---------------------------
596 pde.getSolverOptions().setTolerance(SOLVER_TOL)
597 pde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)
598 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
599 pde.getSolverOptions().setPackage(SolverOptions.PASO)
600 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
601 u=pde.getSolution()
602 # -------- test the solution ---------------------------
603 error=Lsup(u-u_ex)
604 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
605
606 class SimpleSolve_Brick_Order2_SinglePDE_Paso_TFQMR_Jacobi(unittest.TestCase):
607 def test_solve(self):
608 domain=Brick(NE0,NE1,NE2,2,optimize=OPTIMIZE)
609 x=Solution(domain).getX()
610 # --- set exact solution ----
611 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
612 # --- set exact gradient -----------
613 g_ex=Data(0.,(3,),Solution(domain))
614 g_ex[0]=2.+6.*x[1]+8.*x[2]+18.*x[0]
615 g_ex[1]=3.+6.*x[0]+7.*x[2]+20.*x[1]
616 g_ex[2]=4.+7.*x[1]+8.*x[0]+22.*x[2]
617 # -------- test gradient --------------------------------
618 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
619 # -------- set-up PDE -----------------------------------
620 pde=LinearPDE(domain,numEquations=1)
621 mask=whereZero(x[0])
622 pde.setValue(r=u_ex,q=mask)
623 pde.setValue(A=kronecker(3),y=inner(g_ex,domain.getNormal()),Y=-60.)
624 # -------- get the solution ---------------------------
625 pde.getSolverOptions().setTolerance(SOLVER_TOL)
626 pde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)
627 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
628 pde.getSolverOptions().setPackage(SolverOptions.PASO)
629 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
630 u=pde.getSolution()
631 # -------- test the solution ---------------------------
632 error=Lsup(u-u_ex)
633 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
634
635 class SimpleSolve_Brick_Order2_SystemPDE_Paso_TFQMR_Jacobi(unittest.TestCase):
636 def test_solve(self):
637 domain=Brick(NE0,NE1,NE2,2,optimize=OPTIMIZE)
638 x=Solution(domain).getX()
639 # --- set exact solution ----
640 u_ex=Vector(0,Solution(domain))
641 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
642 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
643 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
644 # --- set exact gradient -----------
645 g_ex=Data(0.,(3,3),Solution(domain))
646 g_ex[0,0]=2.+6.*x[1]+8.*x[2]+18.*x[0]
647 g_ex[0,1]=3.+6.*x[0]+7.*x[2]+20.*x[1]
648 g_ex[0,2]=4.+7.*x[1]+8.*x[0]+22.*x[2]
649 g_ex[1,0]=4.+3.*x[1]-8.*x[2]-4.*x[0]
650 g_ex[1,1]=1+3.*x[0]+2.*x[2]+14.*x[1]
651 g_ex[1,2]=-6.+2.*x[1]-8.*x[0]+10.*x[2]
652 g_ex[2,0]=7.-6.*x[1]+2.*x[2]+4.*x[0]
653 g_ex[2,1]=9.-6.*x[0]+8.*x[2]+16.*x[1]
654 g_ex[2,2]=2+8.*x[1]+2.*x[0]+2.*x[2]
655 # -------- test gradient --------------------------------
656 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
657 # -------- set-up PDE -----------------------------------
658 pde=LinearPDE(domain,numEquations=3)
659 mask=whereZero(x[0])
660 pde.setValue(r=u_ex,q=mask*numpy.ones(3,))
661 Y=Vector(0.,Function(domain))
662 Y[0]=u_ex[0]*FAC_DIAG+u_ex[2]*FAC_OFFDIAG+u_ex[1]*FAC_OFFDIAG
663 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG+u_ex[2]*FAC_OFFDIAG
664 Y[2]=u_ex[2]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG+u_ex[0]*FAC_OFFDIAG
665 A=Tensor4(0,Function(domain))
666 A[0,:,0,:]=kronecker(3)
667 A[1,:,1,:]=kronecker(3)
668 A[2,:,2,:]=kronecker(3)
669 pde.setValue(A=A,
670 D=kronecker(3)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((3,3))*FAC_OFFDIAG,
671 Y=Y-numpy.array([60.,20.,22.]),
672 y=matrixmult(g_ex,domain.getNormal()))
673 # -------- get the solution ---------------------------
674 pde.getSolverOptions().setTolerance(SOLVER_TOL)
675 pde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)
676 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
677 pde.getSolverOptions().setPackage(SolverOptions.PASO)
678 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
679 u=pde.getSolution()
680 # -------- test the solution ---------------------------
681 error=Lsup(u-u_ex)
682 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
683
684
685 class SimpleSolve_Rectangle_Order1_SinglePDE_Paso_MINRES_Jacobi(unittest.TestCase):
686 def test_solve(self):
687 domain=Rectangle(NE0,NE1,1, optimize=OPTIMIZE)
688 x=Solution(domain).getX()
689 # --- set exact solution ----
690 u_ex=Scalar(0,Solution(domain))
691 u_ex=1.+2.*x[0]+3.*x[1]
692 # --- set exact gradient -----------
693 g_ex=Data(0.,(2,),Solution(domain))
694 g_ex[0]=2.
695 g_ex[1]=3.
696 # -------- test gradient --------------------------------
697 g=grad(u_ex)
698 self.assertTrue(Lsup(g_ex-g)<REL_TOL*Lsup(g_ex))
699 # -------- set-up PDE -----------------------------------
700 pde=LinearPDE(domain,numEquations=1)
701 mask=whereZero(x[0])
702 pde.setValue(r=u_ex,q=mask)
703 pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal()))
704 # -------- get the solution ---------------------------
705 pde.getSolverOptions().setTolerance(SOLVER_TOL)
706 pde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
707 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
708 pde.getSolverOptions().setPackage(SolverOptions.PASO)
709
710 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
711 u=pde.getSolution()
712 # -------- test the solution ---------------------------
713 error=Lsup(u-u_ex)
714 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
715
716 class SimpleSolve_Rectangle_Order2_SinglePDE_Paso_MINRES_Jacobi(unittest.TestCase):
717 def test_solve(self):
718 domain=Rectangle(NE0,NE1,2,l0=1.,l1=1,optimize=OPTIMIZE)
719 x=Solution(domain).getX()
720 # --- set exact solution ----
721 u_ex=1.+2.*x[0]+3.*x[1]+4.*x[0]**2+5.*x[1]*x[0]+6.*x[1]**2
722 # --- set exact gradient -----------
723 g_ex=Data(0.,(2,),Solution(domain))
724 g_ex[0]=2.+8.*x[0]+5.*x[1]
725 g_ex[1]=3.+5.*x[0]+12.*x[1]
726 # -------- test gradient --------------------------------
727 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
728 # -------- set-up PDE -----------------------------------
729 pde=LinearPDE(domain,numEquations=1)
730 mask=whereZero(x[0])
731 pde.setValue(r=u_ex,q=mask)
732 pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal()),Y=-20.)
733 # -------- get the solution ---------------------------
734 pde.getSolverOptions().setTolerance(SOLVER_TOL)
735 pde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
736 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
737 pde.getSolverOptions().setPackage(SolverOptions.PASO)
738 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
739 u=pde.getSolution()
740 # -------- test the solution ---------------------------
741 error=Lsup(u-u_ex)
742 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
743
744 class SimpleSolve_Rectangle_Order1_SystemPDE_Paso_MINRES_Jacobi(unittest.TestCase):
745 def test_solve(self):
746 domain=Rectangle(NE0,NE1,1,optimize=OPTIMIZE)
747 x=Solution(domain).getX()
748 # --- set exact solution ----
749 u_ex=Vector(0,Solution(domain))
750 u_ex[0]=1.+2.*x[0]+3.*x[1]
751 u_ex[1]=-1.+3.*x[0]+2.*x[1]
752 # --- set exact gradient -----------
753 g_ex=Data(0.,(2,2),Solution(domain))
754 g_ex[0,0]=2.
755 g_ex[0,1]=3.
756 g_ex[1,0]=3.
757 g_ex[1,1]=2.
758 # -------- test gradient --------------------------------
759 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
760 # -------- set-up PDE -----------------------------------
761 pde=LinearPDE(domain,numEquations=2)
762 mask=whereZero(x[0])
763 pde.setValue(r=u_ex,q=mask*numpy.ones(2,))
764 A=Tensor4(0,Function(domain))
765 A[0,:,0,:]=kronecker(2)
766 A[1,:,1,:]=kronecker(2)
767 Y=Vector(0.,Function(domain))
768 Y[0]=u_ex[0]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG
769 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG
770 pde.setValue(A=A,
771 D=kronecker(2)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((2,2))*FAC_OFFDIAG,
772 Y=Y,
773 y=matrixmult(g_ex,domain.getNormal()))
774 # -------- get the solution ---------------------------
775 pde.getSolverOptions().setTolerance(SOLVER_TOL)
776 pde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
777 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
778 pde.getSolverOptions().setPackage(SolverOptions.PASO)
779 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
780 u=pde.getSolution()
781 # -------- test the solution ---------------------------
782 error=Lsup(u-u_ex)
783 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
784
785 class SimpleSolve_Rectangle_Order2_SystemPDE_Paso_MINRES_Jacobi(unittest.TestCase):
786 def test_solve(self):
787 domain=Rectangle(NE0,NE1,2,optimize=OPTIMIZE)
788 x=Solution(domain).getX()
789 # --- set exact solution ----
790 u_ex=Vector(0,Solution(domain))
791 u_ex[0]=1.+2.*x[0]+3.*x[1]+4.*x[0]**2+5.*x[1]*x[0]+6.*x[1]**2
792 u_ex[1]=-1.+4.*x[0]+2.*x[1]+1.*x[0]**2+6.*x[1]*x[0]+4.*x[1]**2
793 # --- set exact gradient -----------
794 g_ex=Data(0.,(2,2),Solution(domain))
795 g_ex[0,0]=2.+8.*x[0]+5.*x[1]
796 g_ex[0,1]=3.+5.*x[0]+12.*x[1]
797 g_ex[1,0]=4.+2.*x[0]+6.*x[1]
798 g_ex[1,1]=2.+6.*x[0]+8.*x[1]
799 # -------- test gradient --------------------------------
800 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
801 # -------- set-up PDE -----------------------------------
802 pde=LinearPDE(domain,numEquations=2)
803 mask=whereZero(x[0])
804 pde.setValue(r=u_ex,q=mask*numpy.ones(2,))
805 A=Tensor4(0,Function(domain))
806 A[0,:,0,:]=kronecker(2)
807 A[1,:,1,:]=kronecker(2)
808 Y=Vector(0.,Function(domain))
809 Y[0]=u_ex[0]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG
810 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG
811 pde.setValue(A=A,
812 D=kronecker(2)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((2,2))*FAC_OFFDIAG,
813 Y=Y-[20.,10.],
814 y=matrixmult(g_ex,domain.getNormal()))
815 # -------- get the solution ---------------------------
816 pde.getSolverOptions().setTolerance(SOLVER_TOL)
817 pde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
818 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
819 pde.getSolverOptions().setPackage(SolverOptions.PASO)
820 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
821 u=pde.getSolution()
822 # -------- test the solution ---------------------------
823 error=Lsup(u-u_ex)
824 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
825
826 class SimpleSolve_Brick_Order1_SinglePDE_Paso_MINRES_Jacobi(unittest.TestCase):
827 def test_solve(self):
828 domain=Brick(NE0,NE1,NE2,1,optimize=OPTIMIZE)
829 x=Solution(domain).getX()
830 u_ex=1.+2.*x[0]+3.*x[1]+4.*x[2]
831 # --- set exact gradient -----------
832 g_ex=Data(0.,(3,),Solution(domain))
833 g_ex[0]=2.
834 g_ex[1]=3.
835 g_ex[2]=4.
836 # -------- test gradient --------------------------------
837 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
838 # -------- set-up PDE -----------------------------------
839 pde=LinearPDE(domain,numEquations=1)
840 mask=whereZero(x[0])
841 pde.setValue(r=u_ex,q=mask)
842 pde.setValue(A=kronecker(3),y=inner(g_ex,domain.getNormal()))
843 # -------- get the solution ---------------------------
844 pde.getSolverOptions().setTolerance(SOLVER_TOL)
845 pde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
846 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
847 pde.getSolverOptions().setPackage(SolverOptions.PASO)
848 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
849 u=pde.getSolution()
850 # -------- test the solution ---------------------------
851 error=Lsup(u-u_ex)
852 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
853
854 class SimpleSolve_Brick_Order1_SystemPDE_Paso_MINRES_Jacobi(unittest.TestCase):
855 def test_solve(self):
856 domain=Brick(NE0,NE1,NE2,1,optimize=OPTIMIZE)
857 x=Solution(domain).getX()
858 # --- set exact solution ----
859 u_ex=Vector(0,Solution(domain))
860 u_ex[0]=1.+2.*x[0]+3.*x[1]+4.*x[2]
861 u_ex[1]=-1.+4.*x[0]+1.*x[1]-2.*x[2]
862 u_ex[2]=5.+8.*x[0]+4.*x[1]+5.*x[2]
863 # --- set exact gradient -----------
864 g_ex=Data(0.,(3,3),Solution(domain))
865 g_ex[0,0]=2.
866 g_ex[0,1]=3.
867 g_ex[0,2]=4.
868 g_ex[1,0]=4.
869 g_ex[1,1]=1.
870 g_ex[1,2]=-2.
871 g_ex[2,0]=8.
872 g_ex[2,1]=4.
873 g_ex[2,2]=5.
874 # -------- test gradient --------------------------------
875 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
876 # -------- set-up PDE -----------------------------------
877 pde=LinearPDE(domain,numEquations=3)
878 mask=whereZero(x[0])
879 pde.setValue(r=u_ex,q=mask*numpy.ones(3,))
880 A=Tensor4(0,Function(domain))
881 A[0,:,0,:]=kronecker(3)
882 A[1,:,1,:]=kronecker(3)
883 A[2,:,2,:]=kronecker(3)
884 Y=Vector(0.,Function(domain))
885 Y[0]=u_ex[0]*FAC_DIAG+u_ex[2]*FAC_OFFDIAG+u_ex[1]*FAC_OFFDIAG
886 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG+u_ex[2]*FAC_OFFDIAG
887 Y[2]=u_ex[2]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG+u_ex[0]*FAC_OFFDIAG
888 pde.setValue(A=A,
889 D=kronecker(3)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((3,3))*FAC_OFFDIAG,
890 Y=Y,
891 y=matrixmult(g_ex,domain.getNormal()))
892 # -------- get the solution ---------------------------
893 pde.getSolverOptions().setTolerance(SOLVER_TOL)
894 pde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
895 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
896 pde.getSolverOptions().setPackage(SolverOptions.PASO)
897 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
898 u=pde.getSolution()
899 # -------- test the solution ---------------------------
900 error=Lsup(u-u_ex)
901 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
902
903 class SimpleSolve_Brick_Order2_SinglePDE_Paso_MINRES_Jacobi(unittest.TestCase):
904 def test_solve(self):
905 domain=Brick(NE0,NE1,NE2,2,optimize=OPTIMIZE)
906 x=Solution(domain).getX()
907 # --- set exact solution ----
908 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
909 # --- set exact gradient -----------
910 g_ex=Data(0.,(3,),Solution(domain))
911 g_ex[0]=2.+6.*x[1]+8.*x[2]+18.*x[0]
912 g_ex[1]=3.+6.*x[0]+7.*x[2]+20.*x[1]
913 g_ex[2]=4.+7.*x[1]+8.*x[0]+22.*x[2]
914 # -------- test gradient --------------------------------
915 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
916 # -------- set-up PDE -----------------------------------
917 pde=LinearPDE(domain,numEquations=1)
918 mask=whereZero(x[0])
919 pde.setValue(r=u_ex,q=mask)
920 pde.setValue(A=kronecker(3),y=inner(g_ex,domain.getNormal()),Y=-60.)
921 # -------- get the solution ---------------------------
922 pde.getSolverOptions().setTolerance(SOLVER_TOL)
923 pde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
924 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
925 pde.getSolverOptions().setPackage(SolverOptions.PASO)
926 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
927 u=pde.getSolution()
928 # -------- test the solution ---------------------------
929 error=Lsup(u-u_ex)
930 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
931
932 class SimpleSolve_Brick_Order2_SystemPDE_Paso_MINRES_Jacobi(unittest.TestCase):
933 def test_solve(self):
934 domain=Brick(NE0,NE1,NE2,2,optimize=OPTIMIZE)
935 x=Solution(domain).getX()
936 # --- set exact solution ----
937 u_ex=Vector(0,Solution(domain))
938 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
939 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
940 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
941 # --- set exact gradient -----------
942 g_ex=Data(0.,(3,3),Solution(domain))
943 g_ex[0,0]=2.+6.*x[1]+8.*x[2]+18.*x[0]
944 g_ex[0,1]=3.+6.*x[0]+7.*x[2]+20.*x[1]
945 g_ex[0,2]=4.+7.*x[1]+8.*x[0]+22.*x[2]
946 g_ex[1,0]=4.+3.*x[1]-8.*x[2]-4.*x[0]
947 g_ex[1,1]=1+3.*x[0]+2.*x[2]+14.*x[1]
948 g_ex[1,2]=-6.+2.*x[1]-8.*x[0]+10.*x[2]
949 g_ex[2,0]=7.-6.*x[1]+2.*x[2]+4.*x[0]
950 g_ex[2,1]=9.-6.*x[0]+8.*x[2]+16.*x[1]
951 g_ex[2,2]=2+8.*x[1]+2.*x[0]+2.*x[2]
952 # -------- test gradient --------------------------------
953 self.assertTrue(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex))
954 # -------- set-up PDE -----------------------------------
955 pde=LinearPDE(domain,numEquations=3)
956 mask=whereZero(x[0])
957 pde.setValue(r=u_ex,q=mask*numpy.ones(3,))
958 Y=Vector(0.,Function(domain))
959 Y[0]=u_ex[0]*FAC_DIAG+u_ex[2]*FAC_OFFDIAG+u_ex[1]*FAC_OFFDIAG
960 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG+u_ex[2]*FAC_OFFDIAG
961 Y[2]=u_ex[2]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG+u_ex[0]*FAC_OFFDIAG
962 A=Tensor4(0,Function(domain))
963 A[0,:,0,:]=kronecker(3)
964 A[1,:,1,:]=kronecker(3)
965 A[2,:,2,:]=kronecker(3)
966 pde.setValue(A=A,
967 D=kronecker(3)*(FAC_DIAG-FAC_OFFDIAG)+numpy.ones((3,3))*FAC_OFFDIAG,
968 Y=Y-numpy.array([60.,20.,22.]),
969 y=matrixmult(g_ex,domain.getNormal()))
970 # -------- get the solution ---------------------------
971 pde.getSolverOptions().setTolerance(SOLVER_TOL)
972 pde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
973 pde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
974 pde.getSolverOptions().setPackage(SolverOptions.PASO)
975 pde.getSolverOptions().setVerbosity(SOLVER_VERBOSE)
976 u=pde.getSolution()
977 # -------- test the solution ---------------------------
978 error=Lsup(u-u_ex)
979 self.assertTrue(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error)
980
981 if __name__ == '__main__':
982 suite = unittest.TestSuite()
983 suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order1_SinglePDE_Paso_BICGSTAB_Jacobi))
984 suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order1_SinglePDE_Paso_PCG_Jacobi))
985 suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order1_SystemPDE_Paso_PCG_Jacobi))
986 suite.addTest(unittest.makeSuite(SimpleSolve_Brick_Order1_SinglePDE_Paso_PCG_Jacobi))
987 suite.addTest(unittest.makeSuite(SimpleSolve_Brick_Order1_SystemPDE_Paso_PCG_Jacobi))
988 suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order1_SinglePDE_Paso_TFQMR_Jacobi))
989 suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order1_SystemPDE_Paso_TFQMR_Jacobi))
990 suite.addTest(unittest.makeSuite(SimpleSolve_Brick_Order1_SinglePDE_Paso_TFQMR_Jacobi))
991 suite.addTest(unittest.makeSuite(SimpleSolve_Brick_Order1_SystemPDE_Paso_TFQMR_Jacobi))
992 suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order1_SinglePDE_Paso_MINRES_Jacobi))
993 suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order1_SinglePDE_Paso_MINRES_Jacobi))
994 suite.addTest(unittest.makeSuite(SimpleSolve_Brick_Order1_SinglePDE_Paso_MINRES_Jacobi))
995 suite.addTest(unittest.makeSuite(SimpleSolve_Brick_Order1_SystemPDE_Paso_MINRES_Jacobi))
996
997 s=unittest.TextTestRunner(verbosity=2).run(suite)
998 if not s.wasSuccessful(): sys.exit(1)

  ViewVC Help
Powered by ViewVC 1.1.26