/[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 798 - (show annotations)
Fri Aug 4 01:05:36 2006 UTC (13 years, 2 months ago) by gross
File MIME type: text/x-python
File size: 31003 byte(s)
Reimplementation of the assemblage with persistent jacobeans.
There are also a few changes to the tests which has now
dramatically reduced the memory demand.


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26