/[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 387 - (show annotations)
Tue Dec 20 00:37:20 2005 UTC (13 years, 9 months ago) by gross
File MIME type: text/x-python
File size: 29706 byte(s)
scale allows now to switch on and off certain problems
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,whereZero
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(whereZero(x[0]),Solution(self.domain))
53 A_ref=kronecker(self.domain)
54 mypde.setValue(q=whereZero(x[0]))
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+=whereZero(x[i])
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=whereZero(x[0]))
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 mypde.setSymmetryOn()
345 x=self.domain.getX()
346 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.,r=1,q=whereZero(x[0]))
347 u1=mypde.getSolution(verbose=self.VERBOSE)
348 mypde.setValue(Y=2.,D=2)
349 u2=mypde.getSolution(verbose=self.VERBOSE)
350 self.failUnless(self.check(u2,u1),'first solution is wrong.')
351 u2=mypde.getSolution(verbose=self.VERBOSE)
352 self.failUnless(self.check(u2,u1),'first solution is wrong.')
353 mypde.setValue(r=2,Y=4.)
354 u2=mypde.getSolution(verbose=self.VERBOSE)
355 self.failUnless(self.check(u2,2*u1),'second solution is wrong.')
356
357 def test_symmetryCheckTrue_System(self):
358 d=self.domain.getDim()
359 mypde=LinearPDE(self.domain,debug=self.DEBUG)
360 A=numarray.ones((self.N,d,self.N,d))
361 C=2*numarray.ones((self.N,self.N,d))
362 B=2*numarray.ones((self.N,d,self.N))
363 D=3*numarray.ones((self.N,self.N))
364 d=4*numarray.ones((self.N,self.N))
365 d_contact=5*numarray.ones((self.N,self.N))
366 mypde.setValue(A=A,B=B,C=C,D=D,d=d,d_contact=d_contact)
367 self.failUnless(mypde.checkSymmetry(verbose=False),"symmetry detected")
368
369 def test_symmetryCheckFalse_A_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 A[1,1,1,0]=0.
374 mypde.setValue(A=A)
375 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
376 def test_symmetryCheckFalse_BC_System(self):
377 d=self.domain.getDim()
378 mypde=LinearPDE(self.domain,debug=self.DEBUG)
379 C=2*numarray.ones((self.N,self.N,d))
380 B=2*numarray.ones((self.N,d,self.N))
381 B[0,0,1]=1.
382 mypde.setValue(B=B,C=C)
383 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
384
385 def test_symmetryCheckFalse_D_System(self):
386 mypde=LinearPDE(self.domain,debug=self.DEBUG)
387 D=3*numarray.ones((self.N,self.N))
388 D[0,1]=0.
389 mypde.setValue(D=D)
390 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
391
392 def test_symmetryCheckFalse_d_System(self):
393 mypde=LinearPDE(self.domain,debug=self.DEBUG)
394 d=4*numarray.ones((self.N,self.N))
395 d[0,1]=0.
396 mypde.setValue(d=d)
397 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
398
399 def test_symmetryCheckFalse_d_contact_System(self):
400 mypde=LinearPDE(self.domain,debug=self.DEBUG)
401 d_contact=5*numarray.ones((self.N,self.N))
402 d_contact[0,1]=0.
403 mypde.setValue(d_contact=d_contact)
404 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
405
406 def test_symmetryCheckTrue_Scalar(self):
407 d=self.domain.getDim()
408 mypde=LinearPDE(self.domain,debug=self.DEBUG)
409 A=numarray.ones((d,d))
410 C=2*numarray.ones((d,))
411 B=2*numarray.ones((d,))
412 D=3
413 d=4
414 d_contact=5
415 mypde.setValue(A=A,B=B,C=C,D=D,d=d,d_contact=d_contact)
416 self.failUnless(mypde.checkSymmetry(verbose=False),"symmetry detected")
417
418 def test_symmetryCheckFalse_A_Scalar(self):
419 d=self.domain.getDim()
420 mypde=LinearPDE(self.domain,debug=self.DEBUG)
421 A=numarray.ones((d,d))
422 A[1,0]=0.
423 mypde.setValue(A=A)
424 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
425 def test_symmetryCheckFalse_BC_Scalar(self):
426 d=self.domain.getDim()
427 mypde=LinearPDE(self.domain,debug=self.DEBUG)
428 C=2*numarray.ones((d,))
429 B=2*numarray.ones((d,))
430 B[0]=1.
431 mypde.setValue(B=B,C=C)
432 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
433 #
434 # solver checks:
435 #
436 def test_symmetryOnIterative(self):
437 mypde=LinearPDE(self.domain,debug=self.DEBUG)
438 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
439 u=mypde.getSolution(verbose=self.VERBOSE)
440 self.failUnless(self.check(u,1.),'solution is wrong.')
441 def test_symmetryOnDirect(self):
442 mypde=LinearPDE(self.domain,debug=self.DEBUG)
443 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
444 mypde.setSolverMethod(mypde.DIRECT)
445 u=mypde.getSolution(verbose=self.VERBOSE)
446 self.failUnless(self.check(u,1.),'solution is wrong.')
447 def test_PCG_JACOBI(self):
448 mypde=LinearPDE(self.domain,debug=self.DEBUG)
449 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
450 mypde.setSolverMethod(mypde.PCG,mypde.JACOBI)
451 u=mypde.getSolution(verbose=self.VERBOSE)
452 self.failUnless(self.check(u,1.),'solution is wrong.')
453 def test_PCG_ILU0(self):
454 mypde=LinearPDE(self.domain,debug=self.DEBUG)
455 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
456 mypde.setSolverMethod(mypde.PCG,mypde.ILU0)
457 u=mypde.getSolution(verbose=self.VERBOSE)
458 self.failUnless(self.check(u,1.),'solution is wrong.')
459 def test_DIRECT(self):
460 mypde=LinearPDE(self.domain,debug=self.DEBUG)
461 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
462 mypde.setSolverMethod(mypde.DIRECT)
463 u=mypde.getSolution(verbose=self.VERBOSE)
464 self.failUnless(self.check(u,1.),'solution is wrong.')
465 def test_BICGSTAB_JACOBI(self):
466 mypde=LinearPDE(self.domain,debug=self.DEBUG)
467 mypde.setSolverMethod(mypde.BICGSTAB,mypde.JACOBI)
468 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
469 u=mypde.getSolution(verbose=self.VERBOSE)
470 self.failUnless(self.check(u,1.),'solution is wrong.')
471 def test_BICGSTAB_ILU0(self):
472 mypde=LinearPDE(self.domain,debug=self.DEBUG)
473 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
474 mypde.setSolverMethod(mypde.BICGSTAB,mypde.ILU0)
475 u=mypde.getSolution(verbose=self.VERBOSE)
476 self.failUnless(self.check(u,1.),'solution is wrong.')
477 def test_PRES20_JACOBI(self):
478 mypde=LinearPDE(self.domain,debug=self.DEBUG)
479 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
480 mypde.setSolverMethod(mypde.PRES20,mypde.JACOBI)
481 u=mypde.getSolution(verbose=self.VERBOSE)
482 self.failUnless(self.check(u,1.),'solution is wrong.')
483 def test_PRES20_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.PRES20,mypde.ILU0)
487 u=mypde.getSolution(verbose=self.VERBOSE)
488 self.failUnless(self.check(u,1.),'solution is wrong.')
489 def test_GMRESnoRestart_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.GMRES,mypde.JACOBI)
493 # u=mypde.getSolution(verbose=self.VERBOSE,truncation=5)
494 u=mypde.getSolution(verbose=self.VERBOSE)
495 self.failUnless(self.check(u,1.),'solution is wrong.')
496 def test_GMRESnoRestart_ILU0(self):
497 mypde=LinearPDE(self.domain,debug=self.DEBUG)
498 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
499 mypde.setSolverMethod(mypde.GMRES,mypde.ILU0)
500 # u=mypde.getSolution(verbose=self.VERBOSE,truncation=5)
501 u=mypde.getSolution(verbose=self.VERBOSE)
502 self.failUnless(self.check(u,1.),'solution is wrong.')
503 def test_GMRES_JACOBI(self):
504 mypde=LinearPDE(self.domain,debug=self.DEBUG)
505 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
506 mypde.setSolverMethod(mypde.GMRES,mypde.JACOBI)
507 u=mypde.getSolution(verbose=self.VERBOSE)
508 self.failUnless(self.check(u,1.),'solution is wrong.')
509 def test_GMRES_ILU0(self):
510 mypde=LinearPDE(self.domain,debug=self.DEBUG)
511 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
512 mypde.setSolverMethod(mypde.GMRES,mypde.ILU0)
513 u=mypde.getSolution(verbose=self.VERBOSE)
514 self.failUnless(self.check(u,1.),'solution is wrong.')
515 def test_GMRES_truncation_restart_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,truncation=10,restart=20)
520 self.failUnless(self.check(u,1.),'solution is wrong.')
521 def test_GMRES_truncation_restart_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,truncation=10,restart=20)
526 self.failUnless(self.check(u,1.),'solution is wrong.')
527 def test_Lumping_attemptToSetA(self):
528 mypde=LinearPDE(self.domain,debug=self.DEBUG)
529 try:
530 success=True
531 mypde.setSolverMethod(mypde.LUMPING)
532 mypde.setValue(A=kronecker(self.domain))
533 u=mypde.getSolution(verbose=self.VERBOSE)
534 except Warning:
535 success=False
536 self.failUnless(not success,'warning should be issued')
537 def test_Lumping_attemptToSetB(self):
538 mypde=LinearPDE(self.domain,debug=self.DEBUG)
539 try:
540 success=True
541 mypde.setSolverMethod(mypde.LUMPING)
542 mypde.setValue(B=kronecker(self.domain)[0])
543 u=mypde.getSolution(verbose=self.VERBOSE)
544 except Warning:
545 success=False
546 self.failUnless(not success,'warning should be issued')
547 def test_Lumping_attemptToSetC(self):
548 mypde=LinearPDE(self.domain,debug=self.DEBUG)
549 try:
550 success=True
551 mypde.setSolverMethod(mypde.LUMPING)
552 mypde.setValue(C=kronecker(self.domain)[0])
553 u=mypde.getSolution(verbose=self.VERBOSE)
554 except Warning:
555 success=False
556 self.failUnless(not success,'warning should be issued')
557
558 def test_Lumping(self):
559 mypde=LinearPDE(self.domain,debug=self.DEBUG)
560 mypde.setSolverMethod(mypde.LUMPING)
561 mypde.setValue(D=1.,Y=1.)
562 u=mypde.getSolution(verbose=self.VERBOSE)
563 self.failUnless(self.check(u,1.),'solution is wrong.')
564 def test_Constrained_Lumping(self):
565 x=self.domain.getX()
566 mypde=LinearPDE(self.domain,debug=self.DEBUG)
567 mypde.setSolverMethod(mypde.LUMPING)
568 mypde.setValue(D=1.,Y=1.,q=whereZero(x[0]),r=1.)
569 u=mypde.getSolution(verbose=self.VERBOSE)
570 self.failUnless(self.check(u,1.),'solution is wrong.')
571 def test_Lumping_updateRHS(self):
572 x=self.domain.getX()
573 mypde=LinearPDE(self.domain,debug=self.DEBUG)
574 mypde.setSolverMethod(mypde.LUMPING)
575 mypde.setValue(D=1.,Y=1.)
576 u=mypde.getSolution(verbose=self.VERBOSE)
577 self.failUnless(self.check(u,1.),'first solution is wrong.')
578 mypde.setValue(Y=2.,q=whereZero(x[0]),r=2.)
579 u=mypde.getSolution(verbose=self.VERBOSE)
580 self.failUnless(self.check(u,2.),'second solution is wrong.')
581 def test_Lumping_updateOperator(self):
582 x=self.domain.getX()
583 mypde=LinearPDE(self.domain,debug=self.DEBUG)
584 mypde.setSolverMethod(mypde.LUMPING)
585 mypde.setValue(D=1.,Y=1.)
586 u=mypde.getSolution(verbose=self.VERBOSE)
587 mypde.setValue(D=2.)
588 u=mypde.getSolution(verbose=self.VERBOSE)
589 self.failUnless(self.check(u,0.5),'second solution is wrong.')
590

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26