1 |
# |
2 |
# $Id$ |
3 |
# |
4 |
####################################################### |
5 |
# |
6 |
# Copyright 2003-2007 by ACceSS MNRF |
7 |
# Copyright 2007 by University of Queensland |
8 |
# |
9 |
# http://esscc.uq.edu.au |
10 |
# Primary Business: Queensland, Australia |
11 |
# Licensed under the Open Software License version 3.0 |
12 |
# http://www.opensource.org/licenses/osl-3.0.php |
13 |
# |
14 |
####################################################### |
15 |
# |
16 |
|
17 |
""" |
18 |
Test suite for the linearPDE and pdetools test on finley |
19 |
|
20 |
@remark: |
21 |
|
22 |
@var __author__: name of author |
23 |
@var __licence__: licence agreement |
24 |
@var __url__: url entry point on documentation |
25 |
@var __version__: version |
26 |
@var __date__: date of the version |
27 |
""" |
28 |
|
29 |
__copyright__=""" Copyright (c) 2006 by ACcESS MNRF |
30 |
http://www.access.edu.au |
31 |
Primary Business: Queensland, Australia""" |
32 |
__license__="""Licensed under the Open Software License version 3.0 |
33 |
http://www.opensource.org/licenses/osl-3.0.php""" |
34 |
__author__="Lutz Gross, l.gross@uq.edu.au" |
35 |
__url__="http://www.iservo.edu.au/esys/escript" |
36 |
__version__="$Revision: 859 $" |
37 |
__date__="$Date: 2006-09-26 12:19:18 +1000 (Tue, 26 Sep 2006) $" |
38 |
|
39 |
import unittest, sys |
40 |
|
41 |
from esys.escript import * |
42 |
from esys.finley import Rectangle,Brick |
43 |
from esys.escript.linearPDEs import LinearPDE |
44 |
OPTIMIZE=False |
45 |
SOLVER_VERBOSE=False |
46 |
# setNumberOfThreads(2) |
47 |
|
48 |
try: |
49 |
FINLEY_TEST_DATA=os.environ['FINLEY_TEST_DATA'] |
50 |
except KeyError: |
51 |
FINLEY_TEST_DATA='.' |
52 |
|
53 |
FINLEY_TEST_MESH_PATH=FINLEY_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=12 |
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 |
printParallelThreadCounts() |
75 |
domain=Rectangle(NE0,NE1,1, optimize=OPTIMIZE) |
76 |
x=Solution(domain).getX() |
77 |
# --- set exact solution ---- |
78 |
u_ex=Scalar(0,Solution(domain)) |
79 |
u_ex=1.+2.*x[0]+3.*x[1] |
80 |
# --- set exact gradient ----------- |
81 |
g_ex=Data(0.,(2,),Solution(domain)) |
82 |
g_ex[0]=2. |
83 |
g_ex[1]=3. |
84 |
# -------- test gradient -------------------------------- |
85 |
g=grad(u_ex) |
86 |
self.failUnless(Lsup(g_ex-g)<REL_TOL*Lsup(g_ex)) |
87 |
# -------- set-up PDE ----------------------------------- |
88 |
pde=LinearPDE(domain,numEquations=1) |
89 |
mask=whereZero(x[0]) |
90 |
pde.setValue(r=u_ex,q=mask) |
91 |
pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal())) |
92 |
# -------- get the solution --------------------------- |
93 |
pde.setTolerance(SOLVER_TOL) |
94 |
pde.setSolverMethod(pde.BICGSTAB,pde.JACOBI) |
95 |
pde.setSolverPackage(pde.PASO) |
96 |
u=pde.getSolution(verbose=SOLVER_VERBOSE) |
97 |
# -------- test the solution --------------------------- |
98 |
error=Lsup(u-u_ex)/Lsup(u_ex) |
99 |
self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error) |
100 |
class SimpleSolve_Rectangle_Order1_SinglePDE_Paso_PCG_Jacobi(unittest.TestCase): |
101 |
def test_solve(self): |
102 |
domain=Rectangle(NE0,NE1,1, optimize=OPTIMIZE) |
103 |
x=Solution(domain).getX() |
104 |
# --- set exact solution ---- |
105 |
u_ex=Scalar(0,Solution(domain)) |
106 |
u_ex=1.+2.*x[0]+3.*x[1] |
107 |
# --- set exact gradient ----------- |
108 |
g_ex=Data(0.,(2,),Solution(domain)) |
109 |
g_ex[0]=2. |
110 |
g_ex[1]=3. |
111 |
# -------- test gradient -------------------------------- |
112 |
g=grad(u_ex) |
113 |
self.failUnless(Lsup(g_ex-g)<REL_TOL*Lsup(g_ex)) |
114 |
# -------- set-up PDE ----------------------------------- |
115 |
pde=LinearPDE(domain,numEquations=1) |
116 |
mask=whereZero(x[0]) |
117 |
pde.setValue(r=u_ex,q=mask) |
118 |
pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal())) |
119 |
# -------- get the solution --------------------------- |
120 |
pde.setTolerance(SOLVER_TOL) |
121 |
pde.setSolverMethod(pde.PCG,pde.JACOBI) |
122 |
pde.setSolverPackage(pde.PASO) |
123 |
u=pde.getSolution(verbose=SOLVER_VERBOSE) |
124 |
# -------- test the solution --------------------------- |
125 |
error=Lsup(u-u_ex)/Lsup(u_ex) |
126 |
self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error) |
127 |
class SimpleSolve_Rectangle_Order1_SystemPDE_Paso_PCG_Jacobi(unittest.TestCase): |
128 |
def test_solve(self): |
129 |
domain=Rectangle(NE0,NE1,1,optimize=OPTIMIZE) |
130 |
x=Solution(domain).getX() |
131 |
# --- set exact solution ---- |
132 |
u_ex=Vector(0,Solution(domain)) |
133 |
u_ex[0]=1.+2.*x[0]+3.*x[1] |
134 |
u_ex[1]=-1.+3.*x[0]+2.*x[1] |
135 |
# --- set exact gradient ----------- |
136 |
g_ex=Data(0.,(2,2),Solution(domain)) |
137 |
g_ex[0,0]=2. |
138 |
g_ex[0,1]=3. |
139 |
g_ex[1,0]=3. |
140 |
g_ex[1,1]=2. |
141 |
# -------- test gradient -------------------------------- |
142 |
self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex)) |
143 |
# -------- set-up PDE ----------------------------------- |
144 |
pde=LinearPDE(domain,numEquations=2) |
145 |
mask=whereZero(x[0]) |
146 |
pde.setValue(r=u_ex,q=mask*numarray.ones(2,)) |
147 |
A=Tensor4(0,Function(domain)) |
148 |
A[0,:,0,:]=kronecker(2) |
149 |
A[1,:,1,:]=kronecker(2) |
150 |
Y=Vector(0.,Function(domain)) |
151 |
Y[0]=u_ex[0]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG |
152 |
Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG |
153 |
pde.setValue(A=A, |
154 |
D=kronecker(2)*(FAC_DIAG-FAC_OFFDIAG)+numarray.ones((2,2))*FAC_OFFDIAG, |
155 |
Y=Y, |
156 |
y=matrixmult(g_ex,domain.getNormal())) |
157 |
# -------- get the solution --------------------------- |
158 |
pde.setTolerance(SOLVER_TOL) |
159 |
pde.setSolverMethod(pde.PCG,pde.JACOBI) |
160 |
pde.setSolverPackage(pde.PASO) |
161 |
u=pde.getSolution(verbose=SOLVER_VERBOSE) |
162 |
# -------- test the solution --------------------------- |
163 |
error=Lsup(u-u_ex)/Lsup(u_ex) |
164 |
self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error) |
165 |
class SimpleSolve_Rectangle_Order2_SinglePDE_Paso_PCG_Jacobi(unittest.TestCase): |
166 |
def test_solve(self): |
167 |
domain=Rectangle(NE0,NE1,2,l0=1.,l1=1,optimize=OPTIMIZE) |
168 |
x=Solution(domain).getX() |
169 |
# --- set exact solution ---- |
170 |
u_ex=1.+2.*x[0]+3.*x[1]+4.*x[0]**2+5.*x[1]*x[0]+6.*x[1]**2 |
171 |
# --- set exact gradient ----------- |
172 |
g_ex=Data(0.,(2,),Solution(domain)) |
173 |
g_ex[0]=2.+8.*x[0]+5.*x[1] |
174 |
g_ex[1]=3.+5.*x[0]+12.*x[1] |
175 |
# -------- test gradient -------------------------------- |
176 |
self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex)) |
177 |
# -------- set-up PDE ----------------------------------- |
178 |
pde=LinearPDE(domain,numEquations=1) |
179 |
mask=whereZero(x[0]) |
180 |
pde.setValue(r=u_ex,q=mask) |
181 |
pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal()),Y=-20.) |
182 |
# -------- get the solution --------------------------- |
183 |
pde.setTolerance(SOLVER_TOL) |
184 |
pde.setSolverMethod(pde.PCG,pde.JACOBI) |
185 |
pde.setSolverPackage(pde.PASO) |
186 |
u=pde.getSolution(verbose=SOLVER_VERBOSE) |
187 |
# -------- test the solution --------------------------- |
188 |
error=Lsup(u-u_ex)/Lsup(u_ex) |
189 |
self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error) |
190 |
class SimpleSolve_Rectangle_Order2_SystemPDE_Paso_PCG_Jacobi(unittest.TestCase): |
191 |
def test_solve(self): |
192 |
domain=Rectangle(NE0,NE1,2,optimize=OPTIMIZE) |
193 |
x=Solution(domain).getX() |
194 |
# --- set exact solution ---- |
195 |
u_ex=Vector(0,Solution(domain)) |
196 |
u_ex[0]=1.+2.*x[0]+3.*x[1]+4.*x[0]**2+5.*x[1]*x[0]+6.*x[1]**2 |
197 |
u_ex[1]=-1.+4.*x[0]+2.*x[1]+1.*x[0]**2+6.*x[1]*x[0]+4.*x[1]**2 |
198 |
# --- set exact gradient ----------- |
199 |
g_ex=Data(0.,(2,2),Solution(domain)) |
200 |
g_ex[0,0]=2.+8.*x[0]+5.*x[1] |
201 |
g_ex[0,1]=3.+5.*x[0]+12.*x[1] |
202 |
g_ex[1,0]=4.+2.*x[0]+6.*x[1] |
203 |
g_ex[1,1]=2.+6.*x[0]+8.*x[1] |
204 |
# -------- test gradient -------------------------------- |
205 |
self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex)) |
206 |
# -------- set-up PDE ----------------------------------- |
207 |
pde=LinearPDE(domain,numEquations=2) |
208 |
mask=whereZero(x[0]) |
209 |
pde.setValue(r=u_ex,q=mask*numarray.ones(2,)) |
210 |
A=Tensor4(0,Function(domain)) |
211 |
A[0,:,0,:]=kronecker(2) |
212 |
A[1,:,1,:]=kronecker(2) |
213 |
Y=Vector(0.,Function(domain)) |
214 |
Y[0]=u_ex[0]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG |
215 |
Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG |
216 |
pde.setValue(A=A, |
217 |
D=kronecker(2)*(FAC_DIAG-FAC_OFFDIAG)+numarray.ones((2,2))*FAC_OFFDIAG, |
218 |
Y=Y-[20.,10.], |
219 |
y=matrixmult(g_ex,domain.getNormal())) |
220 |
# -------- get the solution --------------------------- |
221 |
pde.setTolerance(SOLVER_TOL) |
222 |
pde.setSolverMethod(pde.PCG,pde.JACOBI) |
223 |
pde.setSolverPackage(pde.PASO) |
224 |
u=pde.getSolution(verbose=SOLVER_VERBOSE) |
225 |
# -------- test the solution --------------------------- |
226 |
error=Lsup(u-u_ex)/Lsup(u_ex) |
227 |
self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error) |
228 |
class SimpleSolve_Brick_Order1_SinglePDE_Paso_PCG_Jacobi(unittest.TestCase): |
229 |
def test_solve(self): |
230 |
domain=Brick(NE0,NE1,NE2,1,optimize=OPTIMIZE) |
231 |
x=Solution(domain).getX() |
232 |
u_ex=1.+2.*x[0]+3.*x[1]+4.*x[2] |
233 |
# --- set exact gradient ----------- |
234 |
g_ex=Data(0.,(3,),Solution(domain)) |
235 |
g_ex[0]=2. |
236 |
g_ex[1]=3. |
237 |
g_ex[2]=4. |
238 |
# -------- test gradient -------------------------------- |
239 |
self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex)) |
240 |
# -------- set-up PDE ----------------------------------- |
241 |
pde=LinearPDE(domain,numEquations=1) |
242 |
mask=whereZero(x[0]) |
243 |
pde.setValue(r=u_ex,q=mask) |
244 |
pde.setValue(A=kronecker(3),y=inner(g_ex,domain.getNormal())) |
245 |
# -------- get the solution --------------------------- |
246 |
pde.setTolerance(SOLVER_TOL) |
247 |
pde.setSolverMethod(pde.PCG,pde.JACOBI) |
248 |
pde.setSolverPackage(pde.PASO) |
249 |
u=pde.getSolution(verbose=SOLVER_VERBOSE) |
250 |
# -------- test the solution --------------------------- |
251 |
error=Lsup(u-u_ex)/Lsup(u_ex) |
252 |
self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error) |
253 |
class SimpleSolve_Brick_Order1_SystemPDE_Paso_PCG_Jacobi(unittest.TestCase): |
254 |
def test_solve(self): |
255 |
domain=Brick(NE0,NE1,NE2,1,optimize=OPTIMIZE) |
256 |
x=Solution(domain).getX() |
257 |
# --- set exact solution ---- |
258 |
u_ex=Vector(0,Solution(domain)) |
259 |
u_ex[0]=1.+2.*x[0]+3.*x[1]+4.*x[2] |
260 |
u_ex[1]=-1.+4.*x[0]+1.*x[1]-2.*x[2] |
261 |
u_ex[2]=5.+8.*x[0]+4.*x[1]+5.*x[2] |
262 |
# --- set exact gradient ----------- |
263 |
g_ex=Data(0.,(3,3),Solution(domain)) |
264 |
g_ex[0,0]=2. |
265 |
g_ex[0,1]=3. |
266 |
g_ex[0,2]=4. |
267 |
g_ex[1,0]=4. |
268 |
g_ex[1,1]=1. |
269 |
g_ex[1,2]=-2. |
270 |
g_ex[2,0]=8. |
271 |
g_ex[2,1]=4. |
272 |
g_ex[2,2]=5. |
273 |
# -------- test gradient -------------------------------- |
274 |
self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex)) |
275 |
# -------- set-up PDE ----------------------------------- |
276 |
pde=LinearPDE(domain,numEquations=3) |
277 |
mask=whereZero(x[0]) |
278 |
pde.setValue(r=u_ex,q=mask*numarray.ones(3,)) |
279 |
A=Tensor4(0,Function(domain)) |
280 |
A[0,:,0,:]=kronecker(3) |
281 |
A[1,:,1,:]=kronecker(3) |
282 |
A[2,:,2,:]=kronecker(3) |
283 |
Y=Vector(0.,Function(domain)) |
284 |
Y[0]=u_ex[0]*FAC_DIAG+u_ex[2]*FAC_OFFDIAG+u_ex[1]*FAC_OFFDIAG |
285 |
Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG+u_ex[2]*FAC_OFFDIAG |
286 |
Y[2]=u_ex[2]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG+u_ex[0]*FAC_OFFDIAG |
287 |
pde.setValue(A=A, |
288 |
D=kronecker(3)*(FAC_DIAG-FAC_OFFDIAG)+numarray.ones((3,3))*FAC_OFFDIAG, |
289 |
Y=Y, |
290 |
y=matrixmult(g_ex,domain.getNormal())) |
291 |
# -------- get the solution --------------------------- |
292 |
pde.setTolerance(SOLVER_TOL) |
293 |
pde.setSolverMethod(pde.PCG,pde.JACOBI) |
294 |
pde.setSolverPackage(pde.PASO) |
295 |
u=pde.getSolution(verbose=SOLVER_VERBOSE) |
296 |
# -------- test the solution --------------------------- |
297 |
error=Lsup(u-u_ex)/Lsup(u_ex) |
298 |
self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error) |
299 |
class SimpleSolve_Brick_Order2_SinglePDE_Paso_PCG_Jacobi(unittest.TestCase): |
300 |
def test_solve(self): |
301 |
domain=Brick(NE0,NE1,NE2,2,optimize=OPTIMIZE) |
302 |
x=Solution(domain).getX() |
303 |
# --- set exact solution ---- |
304 |
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 |
305 |
# --- set exact gradient ----------- |
306 |
g_ex=Data(0.,(3,),Solution(domain)) |
307 |
g_ex[0]=2.+6.*x[1]+8.*x[2]+18.*x[0] |
308 |
g_ex[1]=3.+6.*x[0]+7.*x[2]+20.*x[1] |
309 |
g_ex[2]=4.+7.*x[1]+8.*x[0]+22.*x[2] |
310 |
# -------- test gradient -------------------------------- |
311 |
self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex)) |
312 |
# -------- set-up PDE ----------------------------------- |
313 |
pde=LinearPDE(domain,numEquations=1) |
314 |
mask=whereZero(x[0]) |
315 |
pde.setValue(r=u_ex,q=mask) |
316 |
pde.setValue(A=kronecker(3),y=inner(g_ex,domain.getNormal()),Y=-60.) |
317 |
# -------- get the solution --------------------------- |
318 |
pde.setTolerance(SOLVER_TOL) |
319 |
pde.setSolverMethod(pde.PCG,pde.JACOBI) |
320 |
pde.setSolverPackage(pde.PASO) |
321 |
u=pde.getSolution(verbose=SOLVER_VERBOSE) |
322 |
# -------- test the solution --------------------------- |
323 |
error=Lsup(u-u_ex)/Lsup(u_ex) |
324 |
self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error) |
325 |
class SimpleSolve_Brick_Order2_SystemPDE_Paso_PCG_Jacobi(unittest.TestCase): |
326 |
def test_solve(self): |
327 |
domain=Brick(NE0,NE1,NE2,2,optimize=OPTIMIZE) |
328 |
x=Solution(domain).getX() |
329 |
# --- set exact solution ---- |
330 |
u_ex=Vector(0,Solution(domain)) |
331 |
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 |
332 |
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 |
333 |
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 |
334 |
# --- set exact gradient ----------- |
335 |
g_ex=Data(0.,(3,3),Solution(domain)) |
336 |
g_ex[0,0]=2.+6.*x[1]+8.*x[2]+18.*x[0] |
337 |
g_ex[0,1]=3.+6.*x[0]+7.*x[2]+20.*x[1] |
338 |
g_ex[0,2]=4.+7.*x[1]+8.*x[0]+22.*x[2] |
339 |
g_ex[1,0]=4.+3.*x[1]-8.*x[2]-4.*x[0] |
340 |
g_ex[1,1]=1+3.*x[0]+2.*x[2]+14.*x[1] |
341 |
g_ex[1,2]=-6.+2.*x[1]-8.*x[0]+10.*x[2] |
342 |
g_ex[2,0]=7.-6.*x[1]+2.*x[2]+4.*x[0] |
343 |
g_ex[2,1]=9.-6.*x[0]+8.*x[2]+16.*x[1] |
344 |
g_ex[2,2]=2+8.*x[1]+2.*x[0]+2.*x[2] |
345 |
# -------- test gradient -------------------------------- |
346 |
self.failUnless(Lsup(g_ex-grad(u_ex))<REL_TOL*Lsup(g_ex)) |
347 |
# -------- set-up PDE ----------------------------------- |
348 |
pde=LinearPDE(domain,numEquations=3) |
349 |
mask=whereZero(x[0]) |
350 |
pde.setValue(r=u_ex,q=mask*numarray.ones(3,)) |
351 |
Y=Vector(0.,Function(domain)) |
352 |
Y[0]=u_ex[0]*FAC_DIAG+u_ex[2]*FAC_OFFDIAG+u_ex[1]*FAC_OFFDIAG |
353 |
Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG+u_ex[2]*FAC_OFFDIAG |
354 |
Y[2]=u_ex[2]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG+u_ex[0]*FAC_OFFDIAG |
355 |
A=Tensor4(0,Function(domain)) |
356 |
A[0,:,0,:]=kronecker(3) |
357 |
A[1,:,1,:]=kronecker(3) |
358 |
A[2,:,2,:]=kronecker(3) |
359 |
pde.setValue(A=A, |
360 |
D=kronecker(3)*(FAC_DIAG-FAC_OFFDIAG)+numarray.ones((3,3))*FAC_OFFDIAG, |
361 |
Y=Y-numarray.array([60.,20.,22.]), |
362 |
y=matrixmult(g_ex,domain.getNormal())) |
363 |
# -------- get the solution --------------------------- |
364 |
pde.setTolerance(SOLVER_TOL) |
365 |
pde.setSolverMethod(pde.PCG,pde.JACOBI) |
366 |
pde.setSolverPackage(pde.PASO) |
367 |
u=pde.getSolution(verbose=SOLVER_VERBOSE) |
368 |
# -------- test the solution --------------------------- |
369 |
error=Lsup(u-u_ex)/Lsup(u_ex) |
370 |
self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error) |
371 |
|
372 |
class SimpleSolve_Rectangle_Order1_SinglePDE_Paso_TFQMR_Jacobi(unittest.TestCase): |
373 |
def test_solve(self): |
374 |
domain=Rectangle(NE0,NE1,1, optimize=OPTIMIZE) |
375 |
x=Solution(domain).getX() |
376 |
# --- set exact solution ---- |
377 |
u_ex=Scalar(0,Solution(domain)) |
378 |
u_ex=1.+2.*x[0]+3.*x[1] |
379 |
# --- set exact gradient ----------- |
380 |
g_ex=Data(0.,(2,),Solution(domain)) |
381 |
g_ex[0]=2. |
382 |
g_ex[1]=3. |
383 |
# -------- test gradient -------------------------------- |
384 |
g=grad(u_ex) |
385 |
self.failUnless(Lsup(g_ex-g)<REL_TOL*Lsup(g_ex)) |
386 |
# -------- set-up PDE ----------------------------------- |
387 |
pde=LinearPDE(domain,numEquations=1) |
388 |
mask=whereZero(x[0]) |
389 |
pde.setValue(r=u_ex,q=mask) |
390 |
pde.setValue(A=kronecker(2),y=inner(g_ex,domain.getNormal())) |
391 |
# -------- get the solution --------------------------- |
392 |
pde.setTolerance(SOLVER_TOL) |
393 |
pde.setSolverMethod(pde.TFQMR,pde.JACOBI) |
394 |
pde.setSolverPackage(pde.PASO) |
395 |
u=pde.getSolution(verbose=SOLVER_VERBOSE) |
396 |
# -------- test the solution --------------------------- |
397 |
error=Lsup(u-u_ex)/Lsup(u_ex) |
398 |
self.failUnless(error<REL_TOL*Lsup(u_ex), "solution error %s is too big."%error) |
399 |
|
400 |
if __name__ == '__main__': |
401 |
suite = unittest.TestSuite() |
402 |
suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order1_SinglePDE_Paso_BICGSTAB_Jacobi)) |
403 |
suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order1_SinglePDE_Paso_PCG_Jacobi)) |
404 |
suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order1_SystemPDE_Paso_PCG_Jacobi)) |
405 |
suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order2_SinglePDE_Paso_PCG_Jacobi)) |
406 |
suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order2_SystemPDE_Paso_PCG_Jacobi)) |
407 |
suite.addTest(unittest.makeSuite(SimpleSolve_Brick_Order1_SinglePDE_Paso_PCG_Jacobi)) |
408 |
suite.addTest(unittest.makeSuite(SimpleSolve_Brick_Order1_SystemPDE_Paso_PCG_Jacobi)) |
409 |
suite.addTest(unittest.makeSuite(SimpleSolve_Brick_Order2_SinglePDE_Paso_PCG_Jacobi)) |
410 |
suite.addTest(unittest.makeSuite(SimpleSolve_Brick_Order2_SystemPDE_Paso_PCG_Jacobi)) |
411 |
suite.addTest(unittest.makeSuite(SimpleSolve_Rectangle_Order1_SinglePDE_Paso_TFQMR_Jacobi)) |
412 |
|
413 |
s=unittest.TextTestRunner(verbosity=2).run(suite) |
414 |
if not s.wasSuccessful(): sys.exit(1) |