/[escript]/trunk/escript/test/python/test_linearPDEs.py
ViewVC logotype

Contents of /trunk/escript/test/python/test_linearPDEs.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 153 - (show annotations)
Tue Oct 25 01:51:20 2005 UTC (14 years ago) by jgs
Original Path: trunk/esys2/escript/py_src/test_linearPDEs.py
File MIME type: text/x-python
File size: 29754 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-10-25

1 # $Id$
2
3 """
4 Test suite for linearPDEs class
5
6 The tests must be linked with a Domain class object in the setUp method:
7
8 from esys.finley import Rectangle
9 class Test_LinearPDEOnFinley(Test_LinearPDE):
10 def setUp(self):
11 self.domain = Rectangle(10,10,2)
12 suite = unittest.TestSuite()
13 suite.addTest(unittest.makeSuite(Test_LinearPDEOnFinley))
14 unittest.TextTestRunner(verbosity=2).run(suite)
15
16 """
17
18 __author__="Lutz Gross, l.gross@uq.edu.au"
19 __licence__="contact: esys@access.uq.edu.au"
20 __url__="http://www.iservo.edu.au/esys/escript"
21 __version__="$Revision$"
22 __date__="$Date$"
23
24
25
26 from esys.escript.util import Lsup,kronecker,interpolate
27 from esys.escript import Function,FunctionOnBoundary,FunctionOnContactZero,Solution,ReducedSolution,Vector,ContinuousFunction,Scalar
28 from esys.escript.linearPDEs import LinearPDE,IllegalCoefficientValue,Poisson
29 import numarray
30 import unittest
31
32 class Test_linearPDEs(unittest.TestCase):
33 TOL=1.e-6
34 SOLVER_TOL=1.e-10
35 DEBUG=False
36 VERBOSE=False
37 def check(self,arg,ref_arg,tol=None):
38 """
39 checks if arg and ref_arg are nearly identical using the L{Lsup<esys.escript.util.Lsup>}
40 """
41 if tol==None: tol=self.TOL
42 return Lsup(arg-ref_arg)<=tol*Lsup(ref_arg)
43
44 class Test_Poisson(Test_linearPDEs):
45
46 def test_config(self):
47 mypde=Poisson(self.domain,debug=self.DEBUG)
48 self.failUnlessEqual((mypde.getNumEquations(),mypde.getNumSolutions(),mypde.isSymmetric()),(1,1,True),"set up incorrect")
49 def test_setCoefficient_q(self):
50 mypde=Poisson(self.domain,debug=self.DEBUG)
51 x=self.domain.getX()
52 q_ref=interpolate(x[0].whereZero(),Solution(self.domain))
53 A_ref=kronecker(self.domain)
54 mypde.setValue(q=x[0].whereZero())
55 self.failUnless(self.check(mypde.getCoefficientOfGeneralPDE("A"),A_ref),"A is not kronecker")
56 self.failUnless(mypde.getCoefficientOfGeneralPDE("B").isEmpty(),"B is not empty")
57 self.failUnless(mypde.getCoefficientOfGeneralPDE("C").isEmpty(),"C is not empty")
58 self.failUnless(mypde.getCoefficientOfGeneralPDE("D").isEmpty(),"D is not empty")
59 self.failUnless(mypde.getCoefficientOfGeneralPDE("X").isEmpty(),"X is not empty")
60 self.failUnless(mypde.getCoefficientOfGeneralPDE("Y").isEmpty(),"Y is not empty")
61 self.failUnless(mypde.getCoefficientOfGeneralPDE("y").isEmpty(),"y is not empty")
62 self.failUnless(mypde.getCoefficientOfGeneralPDE("d").isEmpty(),"d is not empty")
63 self.failUnless(mypde.getCoefficientOfGeneralPDE("d_contact").isEmpty(),"d_contact is not empty")
64 self.failUnless(mypde.getCoefficientOfGeneralPDE("y_contact").isEmpty(),"y_contact is not empty")
65 self.failUnless(self.check(mypde.getCoefficientOfGeneralPDE("q"),q_ref),"q is not empty")
66 self.failUnless(mypde.getCoefficientOfGeneralPDE("r").isEmpty(),"r is not empty")
67 def test_setCoefficient_f(self):
68 mypde=Poisson(self.domain,debug=self.DEBUG)
69 x=self.domain.getX()
70 Y_ref=interpolate(x[0],Function(self.domain))
71 A_ref=kronecker(self.domain)
72 mypde.setValue(f=x[0])
73 self.failUnless(self.check(mypde.getCoefficientOfGeneralPDE("A"),A_ref),"A is not kronecker")
74 self.failUnless(mypde.getCoefficientOfGeneralPDE("B").isEmpty(),"B is not empty")
75 self.failUnless(mypde.getCoefficientOfGeneralPDE("C").isEmpty(),"C is not empty")
76 self.failUnless(mypde.getCoefficientOfGeneralPDE("D").isEmpty(),"D is not empty")
77 self.failUnless(mypde.getCoefficientOfGeneralPDE("X").isEmpty(),"X is not empty")
78 self.failUnless(self.check(mypde.getCoefficientOfGeneralPDE("Y"),Y_ref),"Y is not x[0]")
79 self.failUnless(mypde.getCoefficientOfGeneralPDE("y").isEmpty(),"y is not empty")
80 self.failUnless(mypde.getCoefficientOfGeneralPDE("d").isEmpty(),"d is not empty")
81 self.failUnless(mypde.getCoefficientOfGeneralPDE("d_contact").isEmpty(),"d_contact is not empty")
82 self.failUnless(mypde.getCoefficientOfGeneralPDE("y_contact").isEmpty(),"y_contact is not empty")
83 self.failUnless(mypde.getCoefficientOfGeneralPDE("q").isEmpty(),"q is not empty")
84 self.failUnless(mypde.getCoefficientOfGeneralPDE("r").isEmpty(),"r is not empty")
85 def test_solve(self):
86 d=self.domain.getDim()
87 cf=ContinuousFunction(self.domain)
88 x=cf.getX()
89 #construct exact solution:
90 u_ex=Scalar(1.,cf)
91 for i in range(d):
92 u_ex*=x[i]*(2.-x[i])
93 #construct mask:
94 msk=Scalar(0.,cf)
95 for i in range(d):
96 msk+=x[i].whereZero()
97 #construct right hand side
98 f=Scalar(0,cf)
99 for i in range(d):
100 f_p=Scalar(1,cf)
101 for j in range(d):
102 if i==j:
103 f_p*=2.
104 else:
105 f_p*=x[j]*(2-x[j])
106 f+=f_p
107 mypde=Poisson(self.domain)
108 mypde.setValue(f=f,q=msk)
109 u=mypde.getSolution()
110 self.failUnless(self.check(u,u_ex,10*self.TOL),"incorrect solution")
111
112 class Test_LinearPDE(Test_linearPDEs):
113 N=4
114 def test_setCoefficient_WithIllegalFunctionSpace(self):
115 mypde=LinearPDE(self.domain,debug=self.DEBUG)
116 try:
117 success=True
118 mypde.setValue(C=Vector(0.,FunctionOnBoundary(self.domain)))
119 except IllegalCoefficientValue:
120 success=False
121 self.failUnless(not success,'inapropraite function space accepted')
122
123 def test_resetCoefficient_WithWrongShape(self):
124 mypde=LinearPDE(self.domain,numEquations=2,debug=self.DEBUG)
125 try:
126 success=True
127 mypde.setValue(C=0.)
128 except IllegalCoefficientValue:
129 success=False
130 self.failUnless(not success,'illegal shape accepted')
131 def test_reducedOn(self):
132 mypde=LinearPDE(self.domain,debug=self.DEBUG)
133 x=self.domain.getX()
134 mypde.setReducedOrderOn()
135 mypde.setValue(A=kronecker(self.domain),D=x[0],Y=x[0])
136 u=mypde.getSolution()
137 self.failUnless(self.check(u,1.),'solution is wrong.')
138
139 def test_attemptToChangeOrderAfterDefinedCoefficient(self):
140 mypde=LinearPDE(self.domain,debug=self.DEBUG)
141 mypde.setValue(D=1.)
142 try:
143 success=True
144 mypde.setReducedOrderOn()
145 except RuntimeError:
146 success=False
147 self.failUnless(not success,'alterion of order after coefficient is changed not detected.')
148
149 def test_reducedOnConfig(self):
150 mypde=LinearPDE(self.domain,debug=self.DEBUG)
151 mypde.setReducedOrderOn()
152 self.failUnlessEqual((mypde.getFunctionSpaceForSolution(),mypde.getFunctionSpaceForEquation()),(ReducedSolution(self.domain),ReducedSolution(self.domain)),"reduced function spaces expected.")
153 #
154 # set coefficients for scalars:
155 #
156 def test_setCoefficient_A_Scalar(self):
157 d=self.domain.getDim()
158 mypde=LinearPDE(self.domain,debug=self.DEBUG)
159 mypde.setValue(A=numarray.ones((d,d)))
160 coeff=mypde.getCoefficientOfGeneralPDE("A")
161 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((d,d),Function(self.domain),1,1))
162 def test_setCoefficient_B_Scalar(self):
163 d=self.domain.getDim()
164 mypde=LinearPDE(self.domain,debug=self.DEBUG)
165 mypde.setValue(B=numarray.ones((d,)))
166 coeff=mypde.getCoefficientOfGeneralPDE("B")
167 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((d,),Function(self.domain),1,1))
168 def test_setCoefficient_C_Scalar(self):
169 d=self.domain.getDim()
170 mypde=LinearPDE(self.domain,debug=self.DEBUG)
171 mypde.setValue(C=numarray.ones((d,)))
172 coeff=mypde.getCoefficientOfGeneralPDE("C")
173 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((d,),Function(self.domain),1,1))
174 def test_setCoefficient_D_Scalar(self):
175 d=self.domain.getDim()
176 mypde=LinearPDE(self.domain,debug=self.DEBUG)
177 mypde.setValue(D=1.)
178 coeff=mypde.getCoefficientOfGeneralPDE("D")
179 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((),Function(self.domain),1,1))
180 def test_setCoefficient_X_Scalar(self):
181 d=self.domain.getDim()
182 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
183 mypde.setValue(X=numarray.ones((d,)))
184 coeff=mypde.getCoefficientOfGeneralPDE("X")
185 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((d,),Function(self.domain),1))
186 def test_setCoefficient_Y_Scalar(self):
187 d=self.domain.getDim()
188 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
189 mypde.setValue(Y=1.)
190 coeff=mypde.getCoefficientOfGeneralPDE("Y")
191 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((),Function(self.domain),1))
192 def test_setCoefficient_y_Scalar(self):
193 d=self.domain.getDim()
194 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
195 mypde.setValue(y=1.)
196 coeff=mypde.getCoefficientOfGeneralPDE("y")
197 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((),FunctionOnBoundary(self.domain),1))
198 def test_setCoefficient_d_Scalar(self):
199 d=self.domain.getDim()
200 mypde=LinearPDE(self.domain,debug=self.DEBUG)
201 mypde.setValue(d=1.)
202 coeff=mypde.getCoefficientOfGeneralPDE("d")
203 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((),FunctionOnBoundary(self.domain),1,1))
204 def test_setCoefficient_d_contact_Scalar(self):
205 d=self.domain.getDim()
206 mypde=LinearPDE(self.domain,debug=self.DEBUG)
207 mypde.setValue(d_contact=1.)
208 coeff=mypde.getCoefficientOfGeneralPDE("d_contact")
209 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((),FunctionOnContactZero(self.domain),1,1))
210 def test_setCoefficient_y_contact_Scalar(self):
211 d=self.domain.getDim()
212 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
213 mypde.setValue(y_contact=1.)
214 coeff=mypde.getCoefficientOfGeneralPDE("y_contact")
215 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((),FunctionOnContactZero(self.domain),1))
216 def test_setCoefficient_r_Scalar(self):
217 d=self.domain.getDim()
218 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
219 mypde.setValue(r=1.)
220 coeff=mypde.getCoefficientOfGeneralPDE("r")
221 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions()),((),Solution(self.domain),1))
222 def test_setCoefficient_q_Scalar(self):
223 d=self.domain.getDim()
224 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
225 mypde.setValue(q=1.)
226 coeff=mypde.getCoefficientOfGeneralPDE("q")
227 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions()),((),Solution(self.domain),1))
228 def test_setCoefficient_r_Scalar_reducedOn(self):
229 d=self.domain.getDim()
230 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
231 mypde.setReducedOrderOn()
232 mypde.setValue(r=1.)
233 coeff=mypde.getCoefficientOfGeneralPDE("r")
234 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions()),((),ReducedSolution(self.domain),1))
235 def test_setCoefficient_q_Scalar_reducedOn(self):
236 d=self.domain.getDim()
237 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
238 mypde.setReducedOrderOn()
239 mypde.setValue(q=1.)
240 coeff=mypde.getCoefficientOfGeneralPDE("q")
241 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions()),((),ReducedSolution(self.domain),1))
242
243 #
244 # set coefficients for systems:
245 #
246 def test_setCoefficient_A_System(self):
247 d=self.domain.getDim()
248 mypde=LinearPDE(self.domain,debug=self.DEBUG)
249 mypde.setValue(A=numarray.ones((self.N,d,self.N,d)))
250 coeff=mypde.getCoefficientOfGeneralPDE("A")
251 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,d,self.N,d),Function(self.domain),self.N,self.N))
252 def test_setCoefficient_B_System(self):
253 d=self.domain.getDim()
254 mypde=LinearPDE(self.domain,debug=self.DEBUG)
255 mypde.setValue(B=numarray.ones((self.N,d,self.N)))
256 coeff=mypde.getCoefficientOfGeneralPDE("B")
257 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,d,self.N),Function(self.domain),self.N,self.N))
258 def test_setCoefficient_C_System(self):
259 d=self.domain.getDim()
260 mypde=LinearPDE(self.domain,debug=self.DEBUG)
261 mypde.setValue(C=numarray.ones((self.N,self.N,d)))
262 coeff=mypde.getCoefficientOfGeneralPDE("C")
263 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,self.N,d),Function(self.domain),self.N,self.N))
264 def test_setCoefficient_D_System(self):
265 d=self.domain.getDim()
266 mypde=LinearPDE(self.domain,debug=self.DEBUG)
267 mypde.setValue(D=numarray.ones((self.N,self.N)))
268 coeff=mypde.getCoefficientOfGeneralPDE("D")
269 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,self.N),Function(self.domain),self.N,self.N))
270 def test_setCoefficient_X_System(self):
271 d=self.domain.getDim()
272 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
273 mypde.setValue(X=numarray.ones((self.N,d)))
274 coeff=mypde.getCoefficientOfGeneralPDE("X")
275 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((self.N,d),Function(self.domain),self.N))
276 def test_setCoefficient_Y_System(self):
277 d=self.domain.getDim()
278 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
279 mypde.setValue(Y=numarray.ones((self.N,)))
280 coeff=mypde.getCoefficientOfGeneralPDE("Y")
281 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((self.N,),Function(self.domain),self.N))
282 def test_setCoefficient_y_System(self):
283 d=self.domain.getDim()
284 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
285 mypde.setValue(y=numarray.ones((self.N,)))
286 coeff=mypde.getCoefficientOfGeneralPDE("y")
287 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((self.N,),FunctionOnBoundary(self.domain),self.N))
288 def test_setCoefficient_d_System(self):
289 d=self.domain.getDim()
290 mypde=LinearPDE(self.domain,debug=self.DEBUG)
291 mypde.setValue(d=numarray.ones((self.N,self.N)))
292 coeff=mypde.getCoefficientOfGeneralPDE("d")
293 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,self.N),FunctionOnBoundary(self.domain),self.N,self.N))
294 def test_setCoefficient_d_contact_System(self):
295 d=self.domain.getDim()
296 mypde=LinearPDE(self.domain,debug=self.DEBUG)
297 mypde.setValue(d_contact=numarray.ones((self.N,self.N)))
298 coeff=mypde.getCoefficientOfGeneralPDE("d_contact")
299 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,self.N),FunctionOnContactZero(self.domain),self.N,self.N))
300 def test_setCoefficient_y_contact_System(self):
301 d=self.domain.getDim()
302 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
303 mypde.setValue(y_contact=numarray.ones((self.N,)))
304 coeff=mypde.getCoefficientOfGeneralPDE("y_contact")
305 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((self.N,),FunctionOnContactZero(self.domain),self.N))
306 def test_setCoefficient_r_System(self):
307 d=self.domain.getDim()
308 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
309 mypde.setValue(r=numarray.ones((self.N,)))
310 coeff=mypde.getCoefficientOfGeneralPDE("r")
311 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions()),((self.N,),Solution(self.domain),self.N))
312 def test_setCoefficient_q_System(self):
313 d=self.domain.getDim()
314 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
315 mypde.setValue(q=numarray.ones((self.N,)))
316 coeff=mypde.getCoefficientOfGeneralPDE("q")
317 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions()),((self.N,),Solution(self.domain),self.N))
318 def test_setCoefficient_r_System_reducedOn(self):
319 d=self.domain.getDim()
320 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
321 mypde.setReducedOrderOn()
322 mypde.setValue(r=numarray.ones((self.N,)))
323 coeff=mypde.getCoefficientOfGeneralPDE("r")
324 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions()),((self.N,),ReducedSolution(self.domain),self.N))
325 def test_setCoefficient_q_System_reducedOn(self):
326 d=self.domain.getDim()
327 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
328 mypde.setReducedOrderOn()
329 mypde.setValue(q=numarray.ones((self.N,)))
330 coeff=mypde.getCoefficientOfGeneralPDE("q")
331 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions()),((self.N,),ReducedSolution(self.domain),self.N))
332
333 def test_resetCoefficient_HomogeneousConstraint(self):
334 mypde=LinearPDE(self.domain,debug=self.DEBUG)
335 x=self.domain.getX()
336 mypde.setValue(A=kronecker(self.domain),Y=1.,q=x[0].whereZero())
337 u1=mypde.getSolution()
338 mypde.setValue(Y=2.)
339 u2=mypde.getSolution()
340 self.failUnless(self.check(u2,2*u1),'solution is wrong.')
341
342 def test_resetCoefficient_InHomogeneousConstraint(self):
343 mypde=LinearPDE(self.domain,debug=self.DEBUG)
344 x=self.domain.getX()
345 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.,r=1,q=x[0].whereZero())
346 u1=mypde.getSolution()
347 mypde.setValue(Y=2.,D=2)
348 u2=mypde.getSolution()
349 self.failUnless(self.check(u2,u1),'solution is wrong.')
350 mypde.setValue(r=2,Y=4.)
351 u2=mypde.getSolution()
352 self.failUnless(self.check(u2,2*u1),'solution is wrong.')
353
354 def test_symmetryCheckTrue_System(self):
355 d=self.domain.getDim()
356 mypde=LinearPDE(self.domain,debug=self.DEBUG)
357 A=numarray.ones((self.N,d,self.N,d))
358 C=2*numarray.ones((self.N,self.N,d))
359 B=2*numarray.ones((self.N,d,self.N))
360 D=3*numarray.ones((self.N,self.N))
361 d=4*numarray.ones((self.N,self.N))
362 d_contact=5*numarray.ones((self.N,self.N))
363 mypde.setValue(A=A,B=B,C=C,D=D,d=d,d_contact=d_contact)
364 self.failUnless(mypde.checkSymmetry(verbose=False),"symmetry detected")
365
366 def test_symmetryCheckFalse_A_System(self):
367 d=self.domain.getDim()
368 mypde=LinearPDE(self.domain,debug=self.DEBUG)
369 A=numarray.ones((self.N,d,self.N,d))
370 A[1,1,1,0]=0.
371 mypde.setValue(A=A)
372 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
373 def test_symmetryCheckFalse_BC_System(self):
374 d=self.domain.getDim()
375 mypde=LinearPDE(self.domain,debug=self.DEBUG)
376 C=2*numarray.ones((self.N,self.N,d))
377 B=2*numarray.ones((self.N,d,self.N))
378 B[0,0,1]=1.
379 mypde.setValue(B=B,C=C)
380 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
381
382 def test_symmetryCheckFalse_D_System(self):
383 mypde=LinearPDE(self.domain,debug=self.DEBUG)
384 D=3*numarray.ones((self.N,self.N))
385 D[0,1]=0.
386 mypde.setValue(D=D)
387 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
388
389 def test_symmetryCheckFalse_d_System(self):
390 mypde=LinearPDE(self.domain,debug=self.DEBUG)
391 d=4*numarray.ones((self.N,self.N))
392 d[0,1]=0.
393 mypde.setValue(d=d)
394 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
395
396 def test_symmetryCheckFalse_d_contact_System(self):
397 mypde=LinearPDE(self.domain,debug=self.DEBUG)
398 d_contact=5*numarray.ones((self.N,self.N))
399 d_contact[0,1]=0.
400 mypde.setValue(d_contact=d_contact)
401 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
402
403 def test_symmetryCheckTrue_Scalar(self):
404 d=self.domain.getDim()
405 mypde=LinearPDE(self.domain,debug=self.DEBUG)
406 A=numarray.ones((d,d))
407 C=2*numarray.ones((d,))
408 B=2*numarray.ones((d,))
409 D=3
410 d=4
411 d_contact=5
412 mypde.setValue(A=A,B=B,C=C,D=D,d=d,d_contact=d_contact)
413 self.failUnless(mypde.checkSymmetry(verbose=False),"symmetry detected")
414
415 def test_symmetryCheckFalse_A_Scalar(self):
416 d=self.domain.getDim()
417 mypde=LinearPDE(self.domain,debug=self.DEBUG)
418 A=numarray.ones((d,d))
419 A[1,0]=0.
420 mypde.setValue(A=A)
421 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
422 def test_symmetryCheckFalse_BC_Scalar(self):
423 d=self.domain.getDim()
424 mypde=LinearPDE(self.domain,debug=self.DEBUG)
425 C=2*numarray.ones((d,))
426 B=2*numarray.ones((d,))
427 B[0]=1.
428 mypde.setValue(B=B,C=C)
429 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
430 #
431 # solver checks:
432 #
433 def test_symmetryOnIterative(self):
434 mypde=LinearPDE(self.domain,debug=self.DEBUG)
435 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
436 u=mypde.getSolution(verbose=self.VERBOSE)
437 self.failUnless(self.check(u,1.),'solution is wrong.')
438 def test_symmetryOnDirect(self):
439 mypde=LinearPDE(self.domain,debug=self.DEBUG)
440 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
441 mypde.setSolverMethod(mypde.DIRECT)
442 u=mypde.getSolution(verbose=self.VERBOSE)
443 self.failUnless(self.check(u,1.),'solution is wrong.')
444 def test_PCG_JACOBI(self):
445 mypde=LinearPDE(self.domain,debug=self.DEBUG)
446 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
447 mypde.setSolverMethod(mypde.PCG)
448 u=mypde.getSolution(verbose=self.VERBOSE,preconditioner=mypde.JACOBI)
449 self.failUnless(self.check(u,1.),'solution is wrong.')
450 def test_PCG_ILU0(self):
451 mypde=LinearPDE(self.domain,debug=self.DEBUG)
452 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
453 mypde.setSolverMethod(mypde.PCG)
454 u=mypde.getSolution(verbose=self.VERBOSE,preconditioner=mypde.ILU0)
455 self.failUnless(self.check(u,1.),'solution is wrong.')
456 def test_DIRECT(self):
457 mypde=LinearPDE(self.domain,debug=self.DEBUG)
458 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
459 mypde.setSolverMethod(mypde.DIRECT)
460 u=mypde.getSolution(verbose=self.VERBOSE,preconditioner=mypde.ILU0)
461 self.failUnless(self.check(u,1.),'solution is wrong.')
462 def test_BICGSTAB_JACOBI(self):
463 mypde=LinearPDE(self.domain,debug=self.DEBUG)
464 mypde.setSolverMethod(mypde.BICGSTAB)
465 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
466 u=mypde.getSolution(verbose=self.VERBOSE,preconditioner=mypde.JACOBI)
467 self.failUnless(self.check(u,1.),'solution is wrong.')
468 def test_BICGSTAB_ILU0(self):
469 mypde=LinearPDE(self.domain,debug=self.DEBUG)
470 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
471 mypde.setSolverMethod(mypde.BICGSTAB)
472 u=mypde.getSolution(verbose=self.VERBOSE,preconditioner=mypde.ILU0)
473 self.failUnless(self.check(u,1.),'solution is wrong.')
474 def test_PRES20_JACOBI(self):
475 mypde=LinearPDE(self.domain,debug=self.DEBUG)
476 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
477 mypde.setSolverMethod(mypde.PRES20)
478 u=mypde.getSolution(verbose=self.VERBOSE,preconditioner=mypde.JACOBI)
479 self.failUnless(self.check(u,1.),'solution is wrong.')
480 def test_PRES20_ILU0(self):
481 mypde=LinearPDE(self.domain,debug=self.DEBUG)
482 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
483 mypde.setSolverMethod(mypde.PRES20)
484 u=mypde.getSolution(verbose=self.VERBOSE,preconditioner=mypde.ILU0)
485 self.failUnless(self.check(u,1.),'solution is wrong.')
486 def test_GMRESnoRestart_JACOBI(self):
487 mypde=LinearPDE(self.domain,debug=self.DEBUG)
488 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
489 mypde.setSolverMethod(mypde.GMRES)
490 u=mypde.getSolution(verbose=self.VERBOSE,preconditioner=mypde.JACOBI)
491 self.failUnless(self.check(u,1.),'solution is wrong.')
492 def test_GMRESnoRestart_ILU0(self):
493 mypde=LinearPDE(self.domain,debug=self.DEBUG)
494 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
495 mypde.setSolverMethod(mypde.GMRES)
496 u=mypde.getSolution(verbose=self.VERBOSE,preconditioner=mypde.ILU0)
497 self.failUnless(self.check(u,1.),'solution is wrong.')
498 def test_GMRES_JACOBI(self):
499 mypde=LinearPDE(self.domain,debug=self.DEBUG)
500 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
501 mypde.setSolverMethod(mypde.GMRES)
502 u=mypde.getSolution(verbose=self.VERBOSE,preconditioner=mypde.JACOBI)
503 self.failUnless(self.check(u,1.),'solution is wrong.')
504 def test_GMRES_ILU0(self):
505 mypde=LinearPDE(self.domain,debug=self.DEBUG)
506 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
507 mypde.setSolverMethod(mypde.GMRES)
508 u=mypde.getSolution(verbose=self.VERBOSE,preconditioner=mypde.ILU0)
509 self.failUnless(self.check(u,1.),'solution is wrong.')
510 def test_GMRES_truncation_restart_JACOBI(self):
511 mypde=LinearPDE(self.domain,debug=self.DEBUG)
512 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
513 mypde.setSolverMethod(mypde.GMRES)
514 u=mypde.getSolution(verbose=self.VERBOSE,preconditioner=mypde.JACOBI,truncation=10,restart=20)
515 self.failUnless(self.check(u,1.),'solution is wrong.')
516 def test_GMRES_truncation_restart_ILU0(self):
517 mypde=LinearPDE(self.domain,debug=self.DEBUG)
518 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
519 mypde.setSolverMethod(mypde.GMRES)
520 mypde.setTolerance(1.e-12)
521 u=mypde.getSolution(verbose=self.VERBOSE or True,preconditioner=mypde.ILU0,truncation=10,restart=20)
522 self.failUnless(self.check(u,1.),'solution is wrong.')
523 def test_Lumping_attemptToSetA(self):
524 mypde=LinearPDE(self.domain,debug=self.DEBUG)
525 try:
526 success=True
527 mypde.setSolverMethod(mypde.LUMPING)
528 mypde.setValue(A=kronecker(self.domain))
529 u=mypde.getSolution(verbose=self.VERBOSE)
530 except Warning:
531 success=False
532 self.failUnless(not success,'warning should be issued')
533 def test_Lumping_attemptToSetB(self):
534 mypde=LinearPDE(self.domain,debug=self.DEBUG)
535 try:
536 success=True
537 mypde.setSolverMethod(mypde.LUMPING)
538 mypde.setValue(B=kronecker(self.domain)[0])
539 u=mypde.getSolution(verbose=self.VERBOSE)
540 except Warning:
541 success=False
542 self.failUnless(not success,'warning should be issued')
543 def test_Lumping_attemptToSetC(self):
544 mypde=LinearPDE(self.domain,debug=self.DEBUG)
545 try:
546 success=True
547 mypde.setSolverMethod(mypde.LUMPING)
548 mypde.setValue(C=kronecker(self.domain)[0])
549 u=mypde.getSolution(verbose=self.VERBOSE)
550 except Warning:
551 success=False
552 self.failUnless(not success,'warning should be issued')
553
554 def test_Lumping(self):
555 mypde=LinearPDE(self.domain,debug=self.DEBUG)
556 mypde.setSolverMethod(mypde.LUMPING)
557 mypde.setValue(D=1.,Y=1.)
558 u=mypde.getSolution(verbose=self.VERBOSE,preconditioner=mypde.ILU0)
559 self.failUnless(self.check(u,1.),'solution is wrong.')
560 def test_Constrained_Lumping(self):
561 x=self.domain.getX()
562 mypde=LinearPDE(self.domain,debug=self.DEBUG)
563 mypde.setSolverMethod(mypde.LUMPING)
564 mypde.setValue(D=1.,Y=1.,q=x[0].whereZero(),r=1.)
565 u=mypde.getSolution(verbose=self.VERBOSE,preconditioner=mypde.ILU0)
566 self.failUnless(self.check(u,1.),'solution is wrong.')
567 def test_Lumping_updateRHS(self):
568 x=self.domain.getX()
569 mypde=LinearPDE(self.domain,debug=self.DEBUG)
570 mypde.setSolverMethod(mypde.LUMPING)
571 mypde.setValue(D=1.,Y=1.)
572 u=mypde.getSolution(verbose=self.VERBOSE,preconditioner=mypde.ILU0)
573 self.failUnless(self.check(u,1.),'first solution is wrong.')
574 mypde.setValue(Y=2.,q=x[0].whereZero(),r=2.)
575 u=mypde.getSolution(verbose=self.VERBOSE,preconditioner=mypde.ILU0)
576 self.failUnless(self.check(u,2.),'second solution is wrong.')
577 def test_Lumping_updateOperator(self):
578 x=self.domain.getX()
579 mypde=LinearPDE(self.domain,debug=self.DEBUG)
580 mypde.setSolverMethod(mypde.LUMPING)
581 mypde.setValue(D=1.,Y=1.)
582 u=mypde.getSolution(verbose=self.VERBOSE,preconditioner=mypde.ILU0)
583 mypde.setValue(D=2.)
584 u=mypde.getSolution(verbose=self.VERBOSE,preconditioner=mypde.ILU0)
585 self.failUnless(self.check(u,0.5),'second solution is wrong.')
586

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26