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

  ViewVC Help
Powered by ViewVC 1.1.26