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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 614 - (show annotations)
Wed Mar 22 01:37:07 2006 UTC (13 years, 6 months ago) by elspeth
Original Path: trunk/escript/py_src/test_linearPDEs.py
File MIME type: text/x-python
File size: 30742 byte(s)
Corrected spelling of 'license' in url so that the link actually points to the license.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26