/[escript]/trunk/escript/py_src/test_linearPDEs.py
ViewVC logotype

Contents of /trunk/escript/py_src/test_linearPDEs.py

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26