/[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 1809 - (show annotations)
Thu Sep 25 06:43:44 2008 UTC (11 years, 1 month ago) by ksteube
File MIME type: text/x-python
File size: 66707 byte(s)
Copyright updated in all python files

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2008 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2003-2008 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="http://www.uq.edu.au/esscc/escript-finley"
21
22 """
23 Test suite for linearPDEs class
24
25 The tests must be linked with a Domain class object in the setUp method:
26
27 from esys.finley import Rectangle
28 class Test_LinearPDEOnFinley(Test_LinearPDE):
29 def setUp(self):
30 self.domain = Rectangle(10,10,2)
31 def tearDown(self):
32 del self.domain
33 suite = unittest.TestSuite()
34 suite.addTest(unittest.makeSuite(Test_LinearPDEOnFinley))
35 unittest.TextTestRunner(verbosity=2).run(suite)
36
37 @var __author__: name of author
38 @var __copyright__: copyrights
39 @var __license__: licence agreement
40 @var __url__: url entry point on documentation
41 @var __version__: version
42 @var __date__: date of the version
43 """
44
45 __author__="Lutz Gross, l.gross@uq.edu.au"
46
47 from esys.escript.util import Lsup,kronecker,interpolate,whereZero
48 from esys.escript import Function,FunctionOnBoundary,FunctionOnContactZero,Solution,ReducedSolution,Vector,ContinuousFunction,Scalar, ReducedFunction,ReducedFunctionOnBoundary,ReducedFunctionOnContactZero,Data, Tensor4, Tensor
49 from esys.escript.linearPDEs import LinearPDE,IllegalCoefficientValue,Poisson, IllegalCoefficientFunctionSpace
50 import numarray
51 import unittest
52
53 class Test_linearPDEs(unittest.TestCase):
54 TOL=1.e-6
55 SOLVER_TOL=1.e-10
56 DEBUG=False
57 VERBOSE=False
58 def check(self,arg,ref_arg,tol=None):
59 """
60 checks if arg and ref_arg are nearly identical using the L{Lsup<esys.escript.util.Lsup>}
61 """
62 if tol==None: tol=self.TOL
63 return Lsup(arg-ref_arg)<=tol*Lsup(ref_arg)
64
65 class Test_Poisson(Test_linearPDEs):
66
67 def test_config(self):
68 mypde=Poisson(self.domain,debug=self.DEBUG)
69 self.failUnlessEqual((mypde.getNumEquations(),mypde.getNumSolutions(),mypde.isSymmetric()),(1,1,True),"set up incorrect")
70 def test_setCoefficient_q(self):
71 mypde=Poisson(self.domain,debug=self.DEBUG)
72 x=self.domain.getX()
73 q_ref=interpolate(whereZero(x[0]),Solution(self.domain))
74 A_ref=kronecker(self.domain)
75 mypde.setValue(q=whereZero(x[0]))
76 self.failUnless(self.check(mypde.getCoefficientOfGeneralPDE("A"),A_ref),"A is not kronecker")
77 self.failUnless(mypde.getCoefficientOfGeneralPDE("B").isEmpty(),"B is not empty")
78 self.failUnless(mypde.getCoefficientOfGeneralPDE("C").isEmpty(),"C is not empty")
79 self.failUnless(mypde.getCoefficientOfGeneralPDE("D").isEmpty(),"D is not empty")
80 self.failUnless(mypde.getCoefficientOfGeneralPDE("X").isEmpty(),"X is not empty")
81 self.failUnless(mypde.getCoefficientOfGeneralPDE("Y").isEmpty(),"Y is not empty")
82 self.failUnless(mypde.getCoefficientOfGeneralPDE("y").isEmpty(),"y is not empty")
83 self.failUnless(mypde.getCoefficientOfGeneralPDE("d").isEmpty(),"d is not empty")
84 self.failUnless(mypde.getCoefficientOfGeneralPDE("d_contact").isEmpty(),"d_contact is not empty")
85 self.failUnless(mypde.getCoefficientOfGeneralPDE("y_contact").isEmpty(),"y_contact is not empty")
86 self.failUnless(mypde.getCoefficientOfGeneralPDE("A_reduced").isEmpty(),"A_reduced is not empty")
87 self.failUnless(mypde.getCoefficientOfGeneralPDE("B_reduced").isEmpty(),"B_reduced is not empty")
88 self.failUnless(mypde.getCoefficientOfGeneralPDE("C_reduced").isEmpty(),"C_reduced is not empty")
89 self.failUnless(mypde.getCoefficientOfGeneralPDE("D_reduced").isEmpty(),"D_reduced is not empty")
90 self.failUnless(mypde.getCoefficientOfGeneralPDE("X_reduced").isEmpty(),"X_reduced is not empty")
91 self.failUnless(mypde.getCoefficientOfGeneralPDE("Y_reduced").isEmpty(),"Y_reduced is not empty")
92 self.failUnless(mypde.getCoefficientOfGeneralPDE("y_reduced").isEmpty(),"y_reduced is not empty")
93 self.failUnless(mypde.getCoefficientOfGeneralPDE("d_reduced").isEmpty(),"d_reduced is not empty")
94 self.failUnless(mypde.getCoefficientOfGeneralPDE("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
95 self.failUnless(mypde.getCoefficientOfGeneralPDE("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
96 self.failUnless(self.check(mypde.getCoefficientOfGeneralPDE("q"),q_ref),"q is not empty")
97 self.failUnless(mypde.getCoefficientOfGeneralPDE("r").isEmpty(),"r is not empty")
98 def test_setCoefficient_f(self):
99 mypde=Poisson(self.domain,debug=self.DEBUG)
100 x=self.domain.getX()
101 Y_ref=interpolate(x[0],Function(self.domain))
102 A_ref=kronecker(self.domain)
103 mypde.setValue(f=x[0])
104 self.failUnless(self.check(mypde.getCoefficientOfGeneralPDE("A"),A_ref),"A is not kronecker")
105 self.failUnless(mypde.getCoefficientOfGeneralPDE("B").isEmpty(),"B is not empty")
106 self.failUnless(mypde.getCoefficientOfGeneralPDE("C").isEmpty(),"C is not empty")
107 self.failUnless(mypde.getCoefficientOfGeneralPDE("D").isEmpty(),"D is not empty")
108 self.failUnless(mypde.getCoefficientOfGeneralPDE("X").isEmpty(),"X is not empty")
109 self.failUnless(self.check(mypde.getCoefficientOfGeneralPDE("Y"),Y_ref),"Y is not x[0]")
110 self.failUnless(mypde.getCoefficientOfGeneralPDE("y").isEmpty(),"y is not empty")
111 self.failUnless(mypde.getCoefficientOfGeneralPDE("d").isEmpty(),"d is not empty")
112 self.failUnless(mypde.getCoefficientOfGeneralPDE("d_contact").isEmpty(),"d_contact is not empty")
113 self.failUnless(mypde.getCoefficientOfGeneralPDE("y_contact").isEmpty(),"y_contact is not empty")
114 self.failUnless(mypde.getCoefficientOfGeneralPDE("A_reduced").isEmpty(),"A_reduced is not empty")
115 self.failUnless(mypde.getCoefficientOfGeneralPDE("B_reduced").isEmpty(),"B_reduced is not empty")
116 self.failUnless(mypde.getCoefficientOfGeneralPDE("C_reduced").isEmpty(),"C_reduced is not empty")
117 self.failUnless(mypde.getCoefficientOfGeneralPDE("D_reduced").isEmpty(),"D_reduced is not empty")
118 self.failUnless(mypde.getCoefficientOfGeneralPDE("X_reduced").isEmpty(),"X_reduced is not empty")
119 self.failUnless(mypde.getCoefficientOfGeneralPDE("Y_reduced").isEmpty(),"Y_reduced is not empty")
120 self.failUnless(mypde.getCoefficientOfGeneralPDE("y_reduced").isEmpty(),"y_reduced is not empty")
121 self.failUnless(mypde.getCoefficientOfGeneralPDE("d_reduced").isEmpty(),"d_reduced is not empty")
122 self.failUnless(mypde.getCoefficientOfGeneralPDE("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
123 self.failUnless(mypde.getCoefficientOfGeneralPDE("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
124 self.failUnless(mypde.getCoefficientOfGeneralPDE("q").isEmpty(),"q is not empty")
125 self.failUnless(mypde.getCoefficientOfGeneralPDE("r").isEmpty(),"r is not empty")
126 def test_setCoefficient_f_reduced(self):
127 mypde=Poisson(self.domain,debug=self.DEBUG)
128 x=self.domain.getX()
129 Y_ref=interpolate(x[0],ReducedFunction(self.domain))
130 A_ref=kronecker(self.domain)
131 mypde.setValue(f_reduced=x[0])
132 self.failUnless(self.check(mypde.getCoefficientOfGeneralPDE("A"),A_ref),"A is not kronecker")
133 self.failUnless(mypde.getCoefficientOfGeneralPDE("B").isEmpty(),"B is not empty")
134 self.failUnless(mypde.getCoefficientOfGeneralPDE("C").isEmpty(),"C is not empty")
135 self.failUnless(mypde.getCoefficientOfGeneralPDE("D").isEmpty(),"D is not empty")
136 self.failUnless(mypde.getCoefficientOfGeneralPDE("X").isEmpty(),"X is not empty")
137 self.failUnless(mypde.getCoefficientOfGeneralPDE("Y").isEmpty(),"Y is not empty")
138 self.failUnless(mypde.getCoefficientOfGeneralPDE("y").isEmpty(),"y is not empty")
139 self.failUnless(mypde.getCoefficientOfGeneralPDE("d").isEmpty(),"d is not empty")
140 self.failUnless(mypde.getCoefficientOfGeneralPDE("d_contact").isEmpty(),"d_contact is not empty")
141 self.failUnless(mypde.getCoefficientOfGeneralPDE("y_contact").isEmpty(),"y_contact is not empty")
142 self.failUnless(mypde.getCoefficientOfGeneralPDE("A_reduced").isEmpty(),"A_reduced is not empty")
143 self.failUnless(mypde.getCoefficientOfGeneralPDE("B_reduced").isEmpty(),"B_reduced is not empty")
144 self.failUnless(mypde.getCoefficientOfGeneralPDE("C_reduced").isEmpty(),"C_reduced is not empty")
145 self.failUnless(mypde.getCoefficientOfGeneralPDE("D_reduced").isEmpty(),"D_reduced is not empty")
146 self.failUnless(mypde.getCoefficientOfGeneralPDE("X_reduced").isEmpty(),"X_reduced is not empty")
147 self.failUnless(self.check(mypde.getCoefficientOfGeneralPDE("Y_reduced"),Y_ref),"Y_reduced is not x[0]")
148 self.failUnless(mypde.getCoefficientOfGeneralPDE("y_reduced").isEmpty(),"y_reduced is not empty")
149 self.failUnless(mypde.getCoefficientOfGeneralPDE("d_reduced").isEmpty(),"d_reduced is not empty")
150 self.failUnless(mypde.getCoefficientOfGeneralPDE("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
151 self.failUnless(mypde.getCoefficientOfGeneralPDE("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
152 self.failUnless(mypde.getCoefficientOfGeneralPDE("q").isEmpty(),"q is not empty")
153 self.failUnless(mypde.getCoefficientOfGeneralPDE("r").isEmpty(),"r is not empty")
154 def test_solve(self):
155 d=self.domain.getDim()
156 cf=ContinuousFunction(self.domain)
157 x=cf.getX()
158 #construct exact solution:
159 u_ex=Scalar(1.,cf)
160 for i in range(d):
161 u_ex*=x[i]*(2.-x[i])
162 #construct mask:
163 msk=Scalar(0.,cf)
164 for i in range(d):
165 msk+=whereZero(x[i])
166 #construct right hand side
167 f=Scalar(0,cf)
168 for i in range(d):
169 f_p=Scalar(1,cf)
170 for j in range(d):
171 if i==j:
172 f_p*=2.
173 else:
174 f_p*=x[j]*(2-x[j])
175 f+=f_p
176 mypde=Poisson(self.domain)
177 mypde.setValue(f=f,q=msk)
178 u=mypde.getSolution()
179 self.failUnless(self.check(u,u_ex,10*self.TOL),"incorrect solution")
180
181 class Test_LinearPDE_noLumping(Test_linearPDEs):
182 N=4
183 def test_setCoefficient_WithIllegalFunctionSpace(self):
184 mypde=LinearPDE(self.domain,debug=self.DEBUG)
185 try:
186 success=True
187 mypde.setValue(C=Vector(0.,FunctionOnBoundary(self.domain)))
188 except IllegalCoefficientFunctionSpace:
189 success=False
190 self.failUnless(not success,'inapropraite function space accepted')
191
192 def test_resetCoefficient_WithWrongShape(self):
193 mypde=LinearPDE(self.domain,numEquations=2,debug=self.DEBUG)
194 try:
195 success=True
196 mypde.setValue(C=0.)
197 except IllegalCoefficientValue:
198 success=False
199 self.failUnless(not success,'illegal shape accepted')
200 def test_reducedOn(self):
201 mypde=LinearPDE(self.domain,debug=self.DEBUG)
202 x=self.domain.getX()
203 mypde.setReducedOrderOn()
204 mypde.setValue(A=kronecker(self.domain),D=x[0],Y=x[0])
205 u=mypde.getSolution()
206 self.failUnless(self.check(u,1.),'solution is wrong.')
207
208 def test_attemptToChangeOrderAfterDefinedCoefficient(self):
209 mypde=LinearPDE(self.domain,debug=self.DEBUG)
210 mypde.setValue(D=1.)
211 try:
212 success=True
213 mypde.setReducedOrderOn()
214 except RuntimeError:
215 success=False
216 self.failUnless(not success,'alterion of order after coefficient is changed not detected.')
217
218 def test_reducedOnConfig(self):
219 mypde=LinearPDE(self.domain,debug=self.DEBUG)
220 mypde.setReducedOrderOn()
221 self.failUnlessEqual((mypde.getFunctionSpaceForSolution(),mypde.getFunctionSpaceForEquation()),(ReducedSolution(self.domain),ReducedSolution(self.domain)),"reduced function spaces expected.")
222 #
223 # set coefficients for scalars:
224 #
225 def test_setCoefficient_A_Scalar(self):
226 d=self.domain.getDim()
227 mypde=LinearPDE(self.domain,debug=self.DEBUG)
228 mypde.setValue(A=numarray.ones((d,d)))
229 coeff=mypde.getCoefficientOfGeneralPDE("A")
230 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((d,d),Function(self.domain),1,1))
231 def test_setCoefficient_B_Scalar(self):
232 d=self.domain.getDim()
233 mypde=LinearPDE(self.domain,debug=self.DEBUG)
234 mypde.setValue(B=numarray.ones((d,)))
235 coeff=mypde.getCoefficientOfGeneralPDE("B")
236 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((d,),Function(self.domain),1,1))
237 def test_setCoefficient_C_Scalar(self):
238 d=self.domain.getDim()
239 mypde=LinearPDE(self.domain,debug=self.DEBUG)
240 mypde.setValue(C=numarray.ones((d,)))
241 coeff=mypde.getCoefficientOfGeneralPDE("C")
242 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((d,),Function(self.domain),1,1))
243 def test_setCoefficient_D_Scalar(self):
244 d=self.domain.getDim()
245 mypde=LinearPDE(self.domain,debug=self.DEBUG)
246 mypde.setValue(D=1.)
247 coeff=mypde.getCoefficientOfGeneralPDE("D")
248 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((),Function(self.domain),1,1))
249 def test_setCoefficient_X_Scalar(self):
250 d=self.domain.getDim()
251 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
252 mypde.setValue(X=numarray.ones((d,)))
253 coeff=mypde.getCoefficientOfGeneralPDE("X")
254 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((d,),Function(self.domain),1))
255 def test_setCoefficient_Y_Scalar(self):
256 d=self.domain.getDim()
257 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
258 mypde.setValue(Y=1.)
259 coeff=mypde.getCoefficientOfGeneralPDE("Y")
260 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((),Function(self.domain),1))
261 def test_setCoefficient_y_Scalar(self):
262 d=self.domain.getDim()
263 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
264 mypde.setValue(y=1.)
265 coeff=mypde.getCoefficientOfGeneralPDE("y")
266 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((),FunctionOnBoundary(self.domain),1))
267 def test_setCoefficient_d_Scalar(self):
268 d=self.domain.getDim()
269 mypde=LinearPDE(self.domain,debug=self.DEBUG)
270 mypde.setValue(d=1.)
271 coeff=mypde.getCoefficientOfGeneralPDE("d")
272 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((),FunctionOnBoundary(self.domain),1,1))
273 def test_setCoefficient_d_contact_Scalar(self):
274 d=self.domain.getDim()
275 mypde=LinearPDE(self.domain,debug=self.DEBUG)
276 mypde.setValue(d_contact=1.)
277 coeff=mypde.getCoefficientOfGeneralPDE("d_contact")
278 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((),FunctionOnContactZero(self.domain),1,1))
279 def test_setCoefficient_y_contact_Scalar(self):
280 d=self.domain.getDim()
281 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
282 mypde.setValue(y_contact=1.)
283 coeff=mypde.getCoefficientOfGeneralPDE("y_contact")
284 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((),FunctionOnContactZero(self.domain),1))
285 def test_setCoefficient_A_reduced_Scalar(self):
286 d=self.domain.getDim()
287 mypde=LinearPDE(self.domain,debug=self.DEBUG)
288 mypde.setValue(A_reduced=numarray.ones((d,d)))
289 coeff=mypde.getCoefficientOfGeneralPDE("A_reduced")
290 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((d,d),ReducedFunction(self.domain),1,1))
291 def test_setCoefficient_B_reduced_Scalar(self):
292 d=self.domain.getDim()
293 mypde=LinearPDE(self.domain,debug=self.DEBUG)
294 mypde.setValue(B_reduced=numarray.ones((d,)))
295 coeff=mypde.getCoefficientOfGeneralPDE("B_reduced")
296 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((d,),ReducedFunction(self.domain),1,1))
297 def test_setCoefficient_C_reduced_Scalar(self):
298 d=self.domain.getDim()
299 mypde=LinearPDE(self.domain,debug=self.DEBUG)
300 mypde.setValue(C_reduced=numarray.ones((d,)))
301 coeff=mypde.getCoefficientOfGeneralPDE("C_reduced")
302 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((d,),ReducedFunction(self.domain),1,1))
303 def test_setCoefficient_D_reduced_Scalar(self):
304 d=self.domain.getDim()
305 mypde=LinearPDE(self.domain,debug=self.DEBUG)
306 mypde.setValue(D_reduced=1.)
307 coeff=mypde.getCoefficientOfGeneralPDE("D_reduced")
308 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((),ReducedFunction(self.domain),1,1))
309 def test_setCoefficient_X_reduced_Scalar(self):
310 d=self.domain.getDim()
311 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
312 mypde.setValue(X_reduced=numarray.ones((d,)))
313 coeff=mypde.getCoefficientOfGeneralPDE("X_reduced")
314 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((d,),ReducedFunction(self.domain),1))
315 def test_setCoefficient_Y_reduced_Scalar(self):
316 d=self.domain.getDim()
317 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
318 mypde.setValue(Y_reduced=1.)
319 coeff=mypde.getCoefficientOfGeneralPDE("Y_reduced")
320 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((),ReducedFunction(self.domain),1))
321 def test_setCoefficient_y_reduced_Scalar(self):
322 d=self.domain.getDim()
323 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
324 mypde.setValue(y_reduced=1.)
325 coeff=mypde.getCoefficientOfGeneralPDE("y_reduced")
326 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((),ReducedFunctionOnBoundary(self.domain),1))
327 def test_setCoefficient_d_reduced_Scalar(self):
328 d=self.domain.getDim()
329 mypde=LinearPDE(self.domain,debug=self.DEBUG)
330 mypde.setValue(d_reduced=1.)
331 coeff=mypde.getCoefficientOfGeneralPDE("d_reduced")
332 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((),ReducedFunctionOnBoundary(self.domain),1,1))
333 def test_setCoefficient_d_contact_reduced_Scalar(self):
334 d=self.domain.getDim()
335 mypde=LinearPDE(self.domain,debug=self.DEBUG)
336 mypde.setValue(d_contact_reduced=1.)
337 coeff=mypde.getCoefficientOfGeneralPDE("d_contact_reduced")
338 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((),ReducedFunctionOnContactZero(self.domain),1,1))
339 def test_setCoefficient_y_contact_reduced_Scalar(self):
340 d=self.domain.getDim()
341 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
342 mypde.setValue(y_contact_reduced=1.)
343 coeff=mypde.getCoefficientOfGeneralPDE("y_contact_reduced")
344 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((),ReducedFunctionOnContactZero(self.domain),1))
345 def test_setCoefficient_r_Scalar(self):
346 d=self.domain.getDim()
347 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
348 mypde.setValue(r=1.)
349 coeff=mypde.getCoefficientOfGeneralPDE("r")
350 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions()),((),Solution(self.domain),1))
351 def test_setCoefficient_q_Scalar(self):
352 d=self.domain.getDim()
353 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
354 mypde.setValue(q=1.)
355 coeff=mypde.getCoefficientOfGeneralPDE("q")
356 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions()),((),Solution(self.domain),1))
357 def test_setCoefficient_r_Scalar_reducedOn(self):
358 d=self.domain.getDim()
359 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
360 mypde.setReducedOrderOn()
361 mypde.setValue(r=1.)
362 coeff=mypde.getCoefficientOfGeneralPDE("r")
363 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions()),((),ReducedSolution(self.domain),1))
364 def test_setCoefficient_q_Scalar_reducedOn(self):
365 d=self.domain.getDim()
366 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
367 mypde.setReducedOrderOn()
368 mypde.setValue(q=1.)
369 coeff=mypde.getCoefficientOfGeneralPDE("q")
370 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions()),((),ReducedSolution(self.domain),1))
371
372 def test_setCoefficient_A_reduced_Scalar_usingA(self):
373 d=self.domain.getDim()
374 mypde=LinearPDE(self.domain,debug=self.DEBUG)
375 mypde.setValue(A=Data(numarray.ones((d,d)),ReducedFunction(self.domain)))
376 coeff=mypde.getCoefficientOfGeneralPDE("A_reduced")
377 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((d,d),ReducedFunction(self.domain),1,1))
378 def test_setCoefficient_B_reduced_Scalar_usingB(self):
379 d=self.domain.getDim()
380 mypde=LinearPDE(self.domain,debug=self.DEBUG)
381 mypde.setValue(B=Data(numarray.ones((d,)),ReducedFunction(self.domain)))
382 coeff=mypde.getCoefficientOfGeneralPDE("B_reduced")
383 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((d,),ReducedFunction(self.domain),1,1))
384 def test_setCoefficient_C_reduced_Scalar_usingC(self):
385 d=self.domain.getDim()
386 mypde=LinearPDE(self.domain,debug=self.DEBUG)
387 mypde.setValue(C=Data(numarray.ones((d,)),ReducedFunction(self.domain)))
388 coeff=mypde.getCoefficientOfGeneralPDE("C_reduced")
389 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((d,),ReducedFunction(self.domain),1,1))
390 def test_setCoefficient_D_reduced_Scalar_usingD(self):
391 d=self.domain.getDim()
392 mypde=LinearPDE(self.domain,debug=self.DEBUG)
393 mypde.setValue(D=Scalar(1.,ReducedFunction(self.domain)))
394 coeff=mypde.getCoefficientOfGeneralPDE("D_reduced")
395 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((),ReducedFunction(self.domain),1,1))
396 def test_setCoefficient_X_reduced_Scalar_usingX(self):
397 d=self.domain.getDim()
398 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
399 mypde.setValue(X_reduced=Data(numarray.ones((d,)),ReducedFunction(self.domain)))
400 coeff=mypde.getCoefficientOfGeneralPDE("X_reduced")
401 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((d,),ReducedFunction(self.domain),1))
402 def test_setCoefficient_Y_reduced_Scalar_usingY(self):
403 d=self.domain.getDim()
404 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
405 mypde.setValue(Y=Scalar(1.,ReducedFunction(self.domain)))
406 coeff=mypde.getCoefficientOfGeneralPDE("Y_reduced")
407 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((),ReducedFunction(self.domain),1))
408 def test_setCoefficient_y_reduced_Scalar_using_y(self):
409 d=self.domain.getDim()
410 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
411 mypde.setValue(y=Scalar(1.,ReducedFunctionOnBoundary(self.domain)))
412 coeff=mypde.getCoefficientOfGeneralPDE("y_reduced")
413 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((),ReducedFunctionOnBoundary(self.domain),1))
414 def test_setCoefficient_d_reduced_Scalar_using_d(self):
415 d=self.domain.getDim()
416 mypde=LinearPDE(self.domain,debug=self.DEBUG)
417 mypde.setValue(d=Scalar(1.,ReducedFunctionOnBoundary(self.domain)))
418 coeff=mypde.getCoefficientOfGeneralPDE("d_reduced")
419 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((),ReducedFunctionOnBoundary(self.domain),1,1))
420 def test_setCoefficient_d_contact_reduced_Scalar_using_d_contact(self):
421 d=self.domain.getDim()
422 mypde=LinearPDE(self.domain,debug=self.DEBUG)
423 mypde.setValue(d_contact=Scalar(1.,ReducedFunctionOnContactZero(self.domain)))
424 coeff=mypde.getCoefficientOfGeneralPDE("d_contact_reduced")
425 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((),ReducedFunctionOnContactZero(self.domain),1,1))
426 def test_setCoefficient_y_contact_reduced_Scalar_using_y_contact(self):
427 d=self.domain.getDim()
428 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
429 mypde.setValue(y_contact=Scalar(1.,ReducedFunctionOnContactZero(self.domain)))
430 coeff=mypde.getCoefficientOfGeneralPDE("y_contact_reduced")
431 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((),ReducedFunctionOnContactZero(self.domain),1))
432 #
433 # set coefficients for systems:
434 #
435 def test_setCoefficient_A_System(self):
436 d=self.domain.getDim()
437 mypde=LinearPDE(self.domain,debug=self.DEBUG)
438 mypde.setValue(A=numarray.ones((self.N,d,self.N,d)))
439 coeff=mypde.getCoefficientOfGeneralPDE("A")
440 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,d,self.N,d),Function(self.domain),self.N,self.N))
441 def test_setCoefficient_B_System(self):
442 d=self.domain.getDim()
443 mypde=LinearPDE(self.domain,debug=self.DEBUG)
444 mypde.setValue(B=numarray.ones((self.N,d,self.N)))
445 coeff=mypde.getCoefficientOfGeneralPDE("B")
446 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,d,self.N),Function(self.domain),self.N,self.N))
447 def test_setCoefficient_C_System(self):
448 d=self.domain.getDim()
449 mypde=LinearPDE(self.domain,debug=self.DEBUG)
450 mypde.setValue(C=numarray.ones((self.N,self.N,d)))
451 coeff=mypde.getCoefficientOfGeneralPDE("C")
452 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,self.N,d),Function(self.domain),self.N,self.N))
453 def test_setCoefficient_D_System(self):
454 d=self.domain.getDim()
455 mypde=LinearPDE(self.domain,debug=self.DEBUG)
456 mypde.setValue(D=numarray.ones((self.N,self.N)))
457 coeff=mypde.getCoefficientOfGeneralPDE("D")
458 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,self.N),Function(self.domain),self.N,self.N))
459 def test_setCoefficient_X_System(self):
460 d=self.domain.getDim()
461 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
462 mypde.setValue(X=numarray.ones((self.N,d)))
463 coeff=mypde.getCoefficientOfGeneralPDE("X")
464 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((self.N,d),Function(self.domain),self.N))
465 def test_setCoefficient_Y_System(self):
466 d=self.domain.getDim()
467 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
468 mypde.setValue(Y=numarray.ones((self.N,)))
469 coeff=mypde.getCoefficientOfGeneralPDE("Y")
470 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((self.N,),Function(self.domain),self.N))
471 def test_setCoefficient_y_System(self):
472 d=self.domain.getDim()
473 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
474 mypde.setValue(y=numarray.ones((self.N,)))
475 coeff=mypde.getCoefficientOfGeneralPDE("y")
476 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((self.N,),FunctionOnBoundary(self.domain),self.N))
477 def test_setCoefficient_d_System(self):
478 d=self.domain.getDim()
479 mypde=LinearPDE(self.domain,debug=self.DEBUG)
480 mypde.setValue(d=numarray.ones((self.N,self.N)))
481 coeff=mypde.getCoefficientOfGeneralPDE("d")
482 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,self.N),FunctionOnBoundary(self.domain),self.N,self.N))
483 def test_setCoefficient_d_contact_System(self):
484 d=self.domain.getDim()
485 mypde=LinearPDE(self.domain,debug=self.DEBUG)
486 mypde.setValue(d_contact=numarray.ones((self.N,self.N)))
487 coeff=mypde.getCoefficientOfGeneralPDE("d_contact")
488 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,self.N),FunctionOnContactZero(self.domain),self.N,self.N))
489 def test_setCoefficient_y_contact_System(self):
490 d=self.domain.getDim()
491 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
492 mypde.setValue(y_contact=numarray.ones((self.N,)))
493 coeff=mypde.getCoefficientOfGeneralPDE("y_contact")
494 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((self.N,),FunctionOnContactZero(self.domain),self.N))
495 def test_setCoefficient_A_reduced_System(self):
496 d=self.domain.getDim()
497 mypde=LinearPDE(self.domain,debug=self.DEBUG)
498 mypde.setValue(A_reduced=numarray.ones((self.N,d,self.N,d)))
499 coeff=mypde.getCoefficientOfGeneralPDE("A_reduced")
500 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,d,self.N,d),ReducedFunction(self.domain),self.N,self.N))
501 def test_setCoefficient_B_reduced_System(self):
502 d=self.domain.getDim()
503 mypde=LinearPDE(self.domain,debug=self.DEBUG)
504 mypde.setValue(B_reduced=numarray.ones((self.N,d,self.N)))
505 coeff=mypde.getCoefficientOfGeneralPDE("B_reduced")
506 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,d,self.N),ReducedFunction(self.domain),self.N,self.N))
507 def test_setCoefficient_C_reduced_System(self):
508 d=self.domain.getDim()
509 mypde=LinearPDE(self.domain,debug=self.DEBUG)
510 mypde.setValue(C_reduced=numarray.ones((self.N,self.N,d)))
511 coeff=mypde.getCoefficientOfGeneralPDE("C_reduced")
512 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,self.N,d),ReducedFunction(self.domain),self.N,self.N))
513 def test_setCoefficient_D_System_reduced(self):
514 d=self.domain.getDim()
515 mypde=LinearPDE(self.domain,debug=self.DEBUG)
516 mypde.setValue(D_reduced=numarray.ones((self.N,self.N)))
517 coeff=mypde.getCoefficientOfGeneralPDE("D_reduced")
518 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,self.N),ReducedFunction(self.domain),self.N,self.N))
519 def test_setCoefficient_X_System_reduced(self):
520 d=self.domain.getDim()
521 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
522 mypde.setValue(X_reduced=numarray.ones((self.N,d)))
523 coeff=mypde.getCoefficientOfGeneralPDE("X_reduced")
524 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((self.N,d),ReducedFunction(self.domain),self.N))
525 def test_setCoefficient_Y_System_reduced(self):
526 d=self.domain.getDim()
527 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
528 mypde.setValue(Y_reduced=numarray.ones((self.N,)))
529 coeff=mypde.getCoefficientOfGeneralPDE("Y_reduced")
530 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((self.N,),ReducedFunction(self.domain),self.N))
531 def test_setCoefficient_y_System_reduced(self):
532 d=self.domain.getDim()
533 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
534 mypde.setValue(y_reduced=numarray.ones((self.N,)))
535 coeff=mypde.getCoefficientOfGeneralPDE("y_reduced")
536 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((self.N,),ReducedFunctionOnBoundary(self.domain),self.N))
537 def test_setCoefficient_d_reduced_System(self):
538 d=self.domain.getDim()
539 mypde=LinearPDE(self.domain,debug=self.DEBUG)
540 mypde.setValue(d_reduced=numarray.ones((self.N,self.N)))
541 coeff=mypde.getCoefficientOfGeneralPDE("d_reduced")
542 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,self.N),ReducedFunctionOnBoundary(self.domain),self.N,self.N))
543 def test_setCoefficient_d_contact_reduced_System(self):
544 d=self.domain.getDim()
545 mypde=LinearPDE(self.domain,debug=self.DEBUG)
546 mypde.setValue(d_contact_reduced=numarray.ones((self.N,self.N)))
547 coeff=mypde.getCoefficientOfGeneralPDE("d_contact_reduced")
548 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,self.N),ReducedFunctionOnContactZero(self.domain),self.N,self.N))
549 def test_setCoefficient_y_contact_reduced_System(self):
550 d=self.domain.getDim()
551 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
552 mypde.setValue(y_contact_reduced=numarray.ones((self.N,)))
553 coeff=mypde.getCoefficientOfGeneralPDE("y_contact_reduced")
554 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((self.N,),ReducedFunctionOnContactZero(self.domain),self.N))
555 def test_setCoefficient_r_System(self):
556 d=self.domain.getDim()
557 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
558 mypde.setValue(r=numarray.ones((self.N,)))
559 coeff=mypde.getCoefficientOfGeneralPDE("r")
560 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions()),((self.N,),Solution(self.domain),self.N))
561 def test_setCoefficient_q_System(self):
562 d=self.domain.getDim()
563 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
564 mypde.setValue(q=numarray.ones((self.N,)))
565 coeff=mypde.getCoefficientOfGeneralPDE("q")
566 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions()),((self.N,),Solution(self.domain),self.N))
567 def test_setCoefficient_r_System_reducedOn(self):
568 d=self.domain.getDim()
569 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
570 mypde.setReducedOrderOn()
571 mypde.setValue(r=numarray.ones((self.N,)))
572 coeff=mypde.getCoefficientOfGeneralPDE("r")
573 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions()),((self.N,),ReducedSolution(self.domain),self.N))
574 def test_setCoefficient_q_System_reducedOn(self):
575 d=self.domain.getDim()
576 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
577 mypde.setReducedOrderOn()
578 mypde.setValue(q=numarray.ones((self.N,)))
579 coeff=mypde.getCoefficientOfGeneralPDE("q")
580 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions()),((self.N,),ReducedSolution(self.domain),self.N))
581
582 def test_setCoefficient_A_reduced_System_using_A(self):
583 d=self.domain.getDim()
584 mypde=LinearPDE(self.domain,debug=self.DEBUG)
585 mypde.setValue(A=Data(numarray.ones((self.N,d,self.N,d)),ReducedFunction(self.domain)))
586 coeff=mypde.getCoefficientOfGeneralPDE("A_reduced")
587 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,d,self.N,d),ReducedFunction(self.domain),self.N,self.N))
588 def test_setCoefficient_B_reduced_System_using_B(self):
589 d=self.domain.getDim()
590 mypde=LinearPDE(self.domain,debug=self.DEBUG)
591 mypde.setValue(B=Data(numarray.ones((self.N,d,self.N)),ReducedFunction(self.domain)))
592 coeff=mypde.getCoefficientOfGeneralPDE("B_reduced")
593 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,d,self.N),ReducedFunction(self.domain),self.N,self.N))
594 def test_setCoefficient_C_reduced_System_using_C(self):
595 d=self.domain.getDim()
596 mypde=LinearPDE(self.domain,debug=self.DEBUG)
597 mypde.setValue(C=Data(numarray.ones((self.N,self.N,d)),ReducedFunction(self.domain)))
598 coeff=mypde.getCoefficientOfGeneralPDE("C_reduced")
599 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,self.N,d),ReducedFunction(self.domain),self.N,self.N))
600 def test_setCoefficient_D_System_reduced_using_D(self):
601 d=self.domain.getDim()
602 mypde=LinearPDE(self.domain,debug=self.DEBUG)
603 mypde.setValue(D=Data(numarray.ones((self.N,self.N)),ReducedFunction(self.domain)))
604 coeff=mypde.getCoefficientOfGeneralPDE("D_reduced")
605 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,self.N),ReducedFunction(self.domain),self.N,self.N))
606 def test_setCoefficient_X_System_reduced_using_X(self):
607 d=self.domain.getDim()
608 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
609 mypde.setValue(X=Data(numarray.ones((self.N,d)),ReducedFunction(self.domain)))
610 coeff=mypde.getCoefficientOfGeneralPDE("X_reduced")
611 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((self.N,d),ReducedFunction(self.domain),self.N))
612 def test_setCoefficient_Y_System_reduced_using_Y(self):
613 d=self.domain.getDim()
614 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
615 mypde.setValue(Y=Data(numarray.ones((self.N,)),ReducedFunction(self.domain)))
616 coeff=mypde.getCoefficientOfGeneralPDE("Y_reduced")
617 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((self.N,),ReducedFunction(self.domain),self.N))
618 def test_setCoefficient_y_reduced_System_using_y(self):
619 d=self.domain.getDim()
620 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
621 mypde.setValue(y=Data(numarray.ones((self.N,)),ReducedFunctionOnBoundary(self.domain)))
622 coeff=mypde.getCoefficientOfGeneralPDE("y_reduced")
623 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((self.N,),ReducedFunctionOnBoundary(self.domain),self.N))
624 def test_setCoefficient_d_reduced_System_using_d(self):
625 d=self.domain.getDim()
626 mypde=LinearPDE(self.domain,debug=self.DEBUG)
627 mypde.setValue(d=Data(numarray.ones((self.N,self.N)),ReducedFunctionOnBoundary(self.domain)))
628 coeff=mypde.getCoefficientOfGeneralPDE("d_reduced")
629 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,self.N),ReducedFunctionOnBoundary(self.domain),self.N,self.N))
630 def test_setCoefficient_d_contact_reduced_System_using_d_contact(self):
631 d=self.domain.getDim()
632 mypde=LinearPDE(self.domain,debug=self.DEBUG)
633 mypde.setValue(d_contact=Data(numarray.ones((self.N,self.N)),ReducedFunctionOnContactZero(self.domain)))
634 coeff=mypde.getCoefficientOfGeneralPDE("d_contact_reduced")
635 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumSolutions(),mypde.getNumEquations()),((self.N,self.N),ReducedFunctionOnContactZero(self.domain),self.N,self.N))
636 def test_setCoefficient_y_contact_reduced_System_using_y_contact(self):
637 d=self.domain.getDim()
638 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
639 mypde.setValue(y_contact=Data(numarray.ones((self.N,)),ReducedFunctionOnContactZero(self.domain)))
640 coeff=mypde.getCoefficientOfGeneralPDE("y_contact_reduced")
641 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(),mypde.getNumEquations()),((self.N,),ReducedFunctionOnContactZero(self.domain),self.N))
642 def test_resetCoefficient_HomogeneousConstraint(self):
643 mypde=LinearPDE(self.domain,debug=self.DEBUG)
644 x=self.domain.getX()
645 mypde.setValue(A=kronecker(self.domain),Y=1.,q=whereZero(x[0]))
646 u1=mypde.getSolution()
647 mypde.setValue(Y=2.)
648 u2=mypde.getSolution()
649 self.failUnless(self.check(u2,2*u1),'solution is wrong.')
650
651 def test_resetCoefficient_InHomogeneousConstraint(self):
652 mypde=LinearPDE(self.domain,debug=self.DEBUG)
653 mypde.setSymmetryOn()
654 x=self.domain.getX()
655 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.,r=1,q=whereZero(x[0]))
656 u1=mypde.getSolution(verbose=self.VERBOSE)
657 mypde.setValue(Y=2.,D=2)
658 u2=mypde.getSolution(verbose=self.VERBOSE)
659 self.failUnless(self.check(u2,u1),'first solution is wrong.')
660 u2=mypde.getSolution(verbose=self.VERBOSE)
661 self.failUnless(self.check(u2,u1),'first solution is wrong.')
662 mypde.setValue(r=2,Y=4.)
663 u2=mypde.getSolution(verbose=self.VERBOSE)
664 self.failUnless(self.check(u2,2*u1),'second solution is wrong.')
665
666 def test_symmetryCheckTrue_System(self):
667 d=self.domain.getDim()
668 mypde=LinearPDE(self.domain,debug=self.DEBUG)
669 A=numarray.ones((self.N,d,self.N,d))
670 C=2*numarray.ones((self.N,self.N,d))
671 B=2*numarray.ones((self.N,d,self.N))
672 D=3*numarray.ones((self.N,self.N))
673 d=4*numarray.ones((self.N,self.N))
674 d_contact=5*numarray.ones((self.N,self.N))
675 mypde.setValue(A=A,B=B,C=C,D=D,d=d,d_contact=d_contact,A_reduced=-A,B_reduced=-B,C_reduced=-C,D_reduced=-D,d_reduced=-d,d_contact_reduced=-d_contact)
676 self.failUnless(mypde.checkSymmetry(verbose=False),"symmetry detected")
677
678 def test_symmetryCheckFalse_A_System(self):
679 d=self.domain.getDim()
680 mypde=LinearPDE(self.domain,debug=self.DEBUG)
681 A=numarray.ones((self.N,d,self.N,d))
682 A[1,1,1,0]=0.
683 mypde.setValue(A=A)
684 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
685 def test_symmetryCheckFalse_BC_System(self):
686 d=self.domain.getDim()
687 mypde=LinearPDE(self.domain,debug=self.DEBUG)
688 C=2*numarray.ones((self.N,self.N,d))
689 B=2*numarray.ones((self.N,d,self.N))
690 B[0,0,1]=1.
691 mypde.setValue(B=B,C=C)
692 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
693
694 def test_symmetryCheckFalse_D_System(self):
695 mypde=LinearPDE(self.domain,debug=self.DEBUG)
696 D=3*numarray.ones((self.N,self.N))
697 D[0,1]=0.
698 mypde.setValue(D=D)
699 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
700
701 def test_symmetryCheckFalse_d_System(self):
702 mypde=LinearPDE(self.domain,debug=self.DEBUG)
703 d=4*numarray.ones((self.N,self.N))
704 d[0,1]=0.
705 mypde.setValue(d=d)
706 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
707
708 def test_symmetryCheckFalse_d_contact_System(self):
709 mypde=LinearPDE(self.domain,debug=self.DEBUG)
710 d_contact=5*numarray.ones((self.N,self.N))
711 d_contact[0,1]=0.
712 mypde.setValue(d_contact=d_contact)
713 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
714
715 def test_symmetryCheckFalse_A_reduced_System(self):
716 d=self.domain.getDim()
717 mypde=LinearPDE(self.domain,debug=self.DEBUG)
718 A=numarray.ones((self.N,d,self.N,d))
719 A[1,1,1,0]=0.
720 mypde.setValue(A_reduced=A)
721 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
722 def test_symmetryCheckFalse_BC_reduced_System(self):
723 d=self.domain.getDim()
724 mypde=LinearPDE(self.domain,debug=self.DEBUG)
725 C=2*numarray.ones((self.N,self.N,d))
726 B=2*numarray.ones((self.N,d,self.N))
727 B[0,0,1]=1.
728 mypde.setValue(B_reduced=B,C_reduced=C)
729 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
730
731 def test_symmetryCheckFalse_D_reduced_System(self):
732 mypde=LinearPDE(self.domain,debug=self.DEBUG)
733 D=3*numarray.ones((self.N,self.N))
734 D[0,1]=0.
735 mypde.setValue(D_reduced=D)
736 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
737
738 def test_symmetryCheckFalse_d_reduced_System(self):
739 mypde=LinearPDE(self.domain,debug=self.DEBUG)
740 d=4*numarray.ones((self.N,self.N))
741 d[0,1]=0.
742 mypde.setValue(d_reduced=d)
743 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
744
745 def test_symmetryCheckFalse_d_contact_reduced_System(self):
746 mypde=LinearPDE(self.domain,debug=self.DEBUG)
747 d_contact=5*numarray.ones((self.N,self.N))
748 d_contact[0,1]=0.
749 mypde.setValue(d_contact_reduced=d_contact)
750 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
751
752 def test_symmetryCheckTrue_Scalar(self):
753 d=self.domain.getDim()
754 mypde=LinearPDE(self.domain,debug=self.DEBUG)
755 A=numarray.ones((d,d))
756 C=2*numarray.ones((d,))
757 B=2*numarray.ones((d,))
758 D=3
759 d=4
760 d_contact=5
761 mypde.setValue(A=A,B=B,C=C,D=D,d=d,d_contact=d_contact,A_reduced=-A,B_reduced=-B,C_reduced=-C,D_reduced=-D,d_reduced=-d,d_contact_reduced=-d_contact)
762 self.failUnless(mypde.checkSymmetry(verbose=False),"symmetry detected")
763
764 def test_symmetryCheckFalse_A_Scalar(self):
765 d=self.domain.getDim()
766 mypde=LinearPDE(self.domain,debug=self.DEBUG)
767 A=numarray.ones((d,d))
768 A[1,0]=0.
769 mypde.setValue(A=A)
770 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
771 def test_symmetryCheckFalse_BC_Scalar(self):
772 d=self.domain.getDim()
773 mypde=LinearPDE(self.domain,debug=self.DEBUG)
774 C=2*numarray.ones((d,))
775 B=2*numarray.ones((d,))
776 B[0]=1.
777 mypde.setValue(B=B,C=C)
778 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
779 def test_symmetryCheckFalse_A_reduced_Scalar(self):
780 d=self.domain.getDim()
781 mypde=LinearPDE(self.domain,debug=self.DEBUG)
782 A=numarray.ones((d,d))
783 A[1,0]=0.
784 mypde.setValue(A_reduced=A)
785 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
786 def test_symmetryCheckFalse_BC_reduced_Scalar(self):
787 d=self.domain.getDim()
788 mypde=LinearPDE(self.domain,debug=self.DEBUG)
789 C=2*numarray.ones((d,))
790 B=2*numarray.ones((d,))
791 B[0]=1.
792 mypde.setValue(B_reduced=B,C_reduced=C)
793 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
794 #
795 # solver checks (single PDE)
796 #
797 def test_symmetryOnIterative(self):
798 mypde=LinearPDE(self.domain,debug=self.DEBUG)
799 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
800 u=mypde.getSolution(verbose=self.VERBOSE)
801 self.failUnless(self.check(u,1.),'solution is wrong.')
802 def test_symmetryOnDirect(self):
803 mypde=LinearPDE(self.domain,debug=self.DEBUG)
804 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
805 mypde.setSolverMethod(mypde.DIRECT)
806 u=mypde.getSolution(verbose=self.VERBOSE)
807 self.failUnless(self.check(u,1.),'solution is wrong.')
808 def test_PCG_JACOBI(self):
809 mypde=LinearPDE(self.domain,debug=self.DEBUG)
810 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
811 mypde.setSolverMethod(mypde.PCG,mypde.JACOBI)
812 u=mypde.getSolution(verbose=self.VERBOSE)
813 self.failUnless(self.check(u,1.),'solution is wrong.')
814 def test_PCG_ILU0(self):
815 mypde=LinearPDE(self.domain,debug=self.DEBUG)
816 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
817 mypde.setSolverMethod(mypde.PCG,mypde.ILU0)
818 u=mypde.getSolution(verbose=self.VERBOSE)
819 self.failUnless(self.check(u,1.),'solution is wrong.')
820 def test_DIRECT(self):
821 mypde=LinearPDE(self.domain,debug=self.DEBUG)
822 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
823 mypde.setSolverMethod(mypde.DIRECT)
824 u=mypde.getSolution(verbose=self.VERBOSE)
825 self.failUnless(self.check(u,1.),'solution is wrong.')
826 def test_BICGSTAB_JACOBI(self):
827 mypde=LinearPDE(self.domain,debug=self.DEBUG)
828 mypde.setSolverMethod(mypde.BICGSTAB,mypde.JACOBI)
829 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
830 u=mypde.getSolution(verbose=self.VERBOSE)
831 self.failUnless(self.check(u,1.),'solution is wrong.')
832 def test_BICGSTAB_ILU0(self):
833 mypde=LinearPDE(self.domain,debug=self.DEBUG)
834 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
835 mypde.setSolverMethod(mypde.BICGSTAB,mypde.ILU0)
836 u=mypde.getSolution(verbose=self.VERBOSE)
837 self.failUnless(self.check(u,1.),'solution is wrong.')
838 def test_PRES20_JACOBI(self):
839 mypde=LinearPDE(self.domain,debug=self.DEBUG)
840 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
841 mypde.setSolverMethod(mypde.PRES20,mypde.JACOBI)
842 u=mypde.getSolution(verbose=self.VERBOSE)
843 self.failUnless(self.check(u,1.),'solution is wrong.')
844 def test_PRES20_ILU0(self):
845 mypde=LinearPDE(self.domain,debug=self.DEBUG)
846 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
847 mypde.setSolverMethod(mypde.PRES20,mypde.ILU0)
848 u=mypde.getSolution(verbose=self.VERBOSE)
849 self.failUnless(self.check(u,1.),'solution is wrong.')
850 def test_GMRESnoRestart_JACOBI(self):
851 mypde=LinearPDE(self.domain,debug=self.DEBUG)
852 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
853 mypde.setSolverMethod(mypde.GMRES,mypde.JACOBI)
854 # u=mypde.getSolution(verbose=self.VERBOSE,truncation=5)
855 u=mypde.getSolution(verbose=self.VERBOSE)
856 self.failUnless(self.check(u,1.),'solution is wrong.')
857 def test_GMRESnoRestart_ILU0(self):
858 mypde=LinearPDE(self.domain,debug=self.DEBUG)
859 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
860 mypde.setSolverMethod(mypde.GMRES,mypde.ILU0)
861 # u=mypde.getSolution(verbose=self.VERBOSE,truncation=5)
862 u=mypde.getSolution(verbose=self.VERBOSE)
863 self.failUnless(self.check(u,1.),'solution is wrong.')
864 def test_GMRES_JACOBI(self):
865 mypde=LinearPDE(self.domain,debug=self.DEBUG)
866 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
867 mypde.setSolverMethod(mypde.GMRES,mypde.JACOBI)
868 u=mypde.getSolution(verbose=self.VERBOSE)
869 self.failUnless(self.check(u,1.),'solution is wrong.')
870 def test_GMRES_ILU0(self):
871 mypde=LinearPDE(self.domain,debug=self.DEBUG)
872 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
873 mypde.setSolverMethod(mypde.GMRES,mypde.ILU0)
874 u=mypde.getSolution(verbose=self.VERBOSE)
875 self.failUnless(self.check(u,1.),'solution is wrong.')
876 def test_GMRES_truncation_restart_JACOBI(self):
877 mypde=LinearPDE(self.domain,debug=self.DEBUG)
878 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
879 mypde.setSolverMethod(mypde.GMRES,mypde.JACOBI)
880 u=mypde.getSolution(verbose=self.VERBOSE,truncation=10,restart=20)
881 self.failUnless(self.check(u,1.),'solution is wrong.')
882 def test_GMRES_truncation_restart_ILU0(self):
883 mypde=LinearPDE(self.domain,debug=self.DEBUG)
884 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
885 mypde.setSolverMethod(mypde.GMRES,mypde.ILU0)
886 u=mypde.getSolution(verbose=self.VERBOSE,truncation=10,restart=20)
887 self.failUnless(self.check(u,1.),'solution is wrong.')
888 #
889 # solver checks (PDE system)
890 #
891 def test_symmetryOnIterative_System(self):
892 A=Tensor4(0.,Function(self.domain))
893 D=Tensor(1.,Function(self.domain))
894 Y=Vector(self.domain.getDim(),Function(self.domain))
895 for i in range(self.domain.getDim()):
896 A[i,:,i,:]=kronecker(self.domain)
897 D[i,i]+=i
898 Y[i]+=i
899 mypde=LinearPDE(self.domain,debug=self.DEBUG)
900 mypde.setValue(A=A,D=D,Y=Y)
901 u=mypde.getSolution(verbose=self.VERBOSE)
902 self.failUnless(self.check(u,1.),'solution is wrong.')
903 def test_symmetryOnDirect_System(self):
904 A=Tensor4(0.,Function(self.domain))
905 D=Tensor(1.,Function(self.domain))
906 Y=Vector(self.domain.getDim(),Function(self.domain))
907 for i in range(self.domain.getDim()):
908 A[i,:,i,:]=kronecker(self.domain)
909 D[i,i]+=i
910 Y[i]+=i
911 mypde=LinearPDE(self.domain,debug=self.DEBUG)
912 mypde.setValue(A=A,D=D,Y=Y)
913 mypde.setSolverMethod(mypde.DIRECT)
914 u=mypde.getSolution(verbose=self.VERBOSE)
915 self.failUnless(self.check(u,1.),'solution is wrong.')
916 def test_PCG_JACOBI_System(self):
917 A=Tensor4(0.,Function(self.domain))
918 D=Tensor(1.,Function(self.domain))
919 Y=Vector(self.domain.getDim(),Function(self.domain))
920 for i in range(self.domain.getDim()):
921 A[i,:,i,:]=kronecker(self.domain)
922 D[i,i]+=i
923 Y[i]+=i
924 mypde=LinearPDE(self.domain,debug=self.DEBUG)
925 mypde.setValue(A=A,D=D,Y=Y)
926 mypde.setSolverMethod(mypde.PCG,mypde.JACOBI)
927 u=mypde.getSolution(verbose=self.VERBOSE)
928 self.failUnless(self.check(u,1.),'solution is wrong.')
929 def test_PCG_ILU0_System(self):
930 A=Tensor4(0.,Function(self.domain))
931 D=Tensor(1.,Function(self.domain))
932 Y=Vector(self.domain.getDim(),Function(self.domain))
933 for i in range(self.domain.getDim()):
934 A[i,:,i,:]=kronecker(self.domain)
935 D[i,i]+=i
936 Y[i]+=i
937 mypde=LinearPDE(self.domain,debug=self.DEBUG)
938 mypde.setValue(A=A,D=D,Y=Y)
939 mypde.setSolverMethod(mypde.PCG,mypde.ILU0)
940 u=mypde.getSolution(verbose=self.VERBOSE)
941 self.failUnless(self.check(u,1.),'solution is wrong.')
942 def test_DIRECT_System(self):
943 A=Tensor4(0.,Function(self.domain))
944 D=Tensor(1.,Function(self.domain))
945 Y=Vector(self.domain.getDim(),Function(self.domain))
946 for i in range(self.domain.getDim()):
947 A[i,:,i,:]=kronecker(self.domain)
948 D[i,i]+=i
949 Y[i]+=i
950 mypde=LinearPDE(self.domain,debug=self.DEBUG)
951 mypde.setValue(A=A,D=D,Y=Y)
952 mypde.setSolverMethod(mypde.DIRECT)
953 u=mypde.getSolution(verbose=self.VERBOSE)
954 self.failUnless(self.check(u,1.),'solution is wrong.')
955 def test_BICGSTAB_JACOBI_System(self):
956 A=Tensor4(0.,Function(self.domain))
957 D=Tensor(1.,Function(self.domain))
958 Y=Vector(self.domain.getDim(),Function(self.domain))
959 for i in range(self.domain.getDim()):
960 A[i,:,i,:]=kronecker(self.domain)
961 D[i,i]+=i
962 Y[i]+=i
963 mypde=LinearPDE(self.domain,debug=self.DEBUG)
964 mypde.setValue(A=A,D=D,Y=Y)
965 mypde.setSolverMethod(mypde.BICGSTAB,mypde.JACOBI)
966 u=mypde.getSolution(verbose=self.VERBOSE)
967 self.failUnless(self.check(u,1.),'solution is wrong.')
968 def test_BICGSTAB_ILU0_System(self):
969 A=Tensor4(0.,Function(self.domain))
970 D=Tensor(1.,Function(self.domain))
971 Y=Vector(self.domain.getDim(),Function(self.domain))
972 for i in range(self.domain.getDim()):
973 A[i,:,i,:]=kronecker(self.domain)
974 D[i,i]+=i
975 Y[i]+=i
976 mypde=LinearPDE(self.domain,debug=self.DEBUG)
977 mypde.setValue(A=A,D=D,Y=Y)
978 mypde.setSolverMethod(mypde.BICGSTAB,mypde.ILU0)
979 u=mypde.getSolution(verbose=self.VERBOSE)
980 self.failUnless(self.check(u,1.),'solution is wrong.')
981 def test_PRES20_JACOBI_System(self):
982 A=Tensor4(0.,Function(self.domain))
983 D=Tensor(1.,Function(self.domain))
984 Y=Vector(self.domain.getDim(),Function(self.domain))
985 for i in range(self.domain.getDim()):
986 A[i,:,i,:]=kronecker(self.domain)
987 D[i,i]+=i
988 Y[i]+=i
989 mypde=LinearPDE(self.domain,debug=self.DEBUG)
990 mypde.setValue(A=A,D=D,Y=Y)
991 mypde.setSolverMethod(mypde.PRES20,mypde.JACOBI)
992 u=mypde.getSolution(verbose=self.VERBOSE)
993 self.failUnless(self.check(u,1.),'solution is wrong.')
994 def test_PRES20_ILU0_System(self):
995 A=Tensor4(0.,Function(self.domain))
996 D=Tensor(1.,Function(self.domain))
997 Y=Vector(self.domain.getDim(),Function(self.domain))
998 for i in range(self.domain.getDim()):
999 A[i,:,i,:]=kronecker(self.domain)
1000 D[i,i]+=i
1001 Y[i]+=i
1002 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1003 mypde.setValue(A=A,D=D,Y=Y)
1004 mypde.setSolverMethod(mypde.PRES20,mypde.ILU0)
1005 u=mypde.getSolution(verbose=self.VERBOSE)
1006 self.failUnless(self.check(u,1.),'solution is wrong.')
1007 def test_GMRESnoRestart_JACOBI_System(self):
1008 A=Tensor4(0.,Function(self.domain))
1009 D=Tensor(1.,Function(self.domain))
1010 Y=Vector(self.domain.getDim(),Function(self.domain))
1011 for i in range(self.domain.getDim()):
1012 A[i,:,i,:]=kronecker(self.domain)
1013 D[i,i]+=i
1014 Y[i]+=i
1015 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1016 mypde.setValue(A=A,D=D,Y=Y)
1017 mypde.setSolverMethod(mypde.GMRES,mypde.JACOBI)
1018 # u=mypde.getSolution(verbose=self.VERBOSE,truncation=5)
1019 u=mypde.getSolution(verbose=self.VERBOSE)
1020 self.failUnless(self.check(u,1.),'solution is wrong.')
1021 def test_GMRESnoRestart_ILU0_System(self):
1022 A=Tensor4(0.,Function(self.domain))
1023 D=Tensor(1.,Function(self.domain))
1024 Y=Vector(self.domain.getDim(),Function(self.domain))
1025 for i in range(self.domain.getDim()):
1026 A[i,:,i,:]=kronecker(self.domain)
1027 D[i,i]+=i
1028 Y[i]+=i
1029 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1030 mypde.setValue(A=A,D=D,Y=Y)
1031 mypde.setSolverMethod(mypde.GMRES,mypde.ILU0)
1032 # u=mypde.getSolution(verbose=self.VERBOSE,truncation=5)
1033 u=mypde.getSolution(verbose=self.VERBOSE)
1034 self.failUnless(self.check(u,1.),'solution is wrong.')
1035 def test_GMRES_JACOBI_System(self):
1036 A=Tensor4(0.,Function(self.domain))
1037 D=Tensor(1.,Function(self.domain))
1038 Y=Vector(self.domain.getDim(),Function(self.domain))
1039 for i in range(self.domain.getDim()):
1040 A[i,:,i,:]=kronecker(self.domain)
1041 D[i,i]+=i
1042 Y[i]+=i
1043 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1044 mypde.setValue(A=A,D=D,Y=Y)
1045 mypde.setSolverMethod(mypde.GMRES,mypde.JACOBI)
1046 u=mypde.getSolution(verbose=self.VERBOSE)
1047 self.failUnless(self.check(u,1.),'solution is wrong.')
1048 def test_GMRES_ILU0_System(self):
1049 A=Tensor4(0.,Function(self.domain))
1050 D=Tensor(1.,Function(self.domain))
1051 Y=Vector(self.domain.getDim(),Function(self.domain))
1052 for i in range(self.domain.getDim()):
1053 A[i,:,i,:]=kronecker(self.domain)
1054 D[i,i]+=i
1055 Y[i]+=i
1056 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1057 mypde.setValue(A=A,D=D,Y=Y)
1058 mypde.setSolverMethod(mypde.GMRES,mypde.ILU0)
1059 u=mypde.getSolution(verbose=self.VERBOSE)
1060 self.failUnless(self.check(u,1.),'solution is wrong.')
1061 def test_GMRES_truncation_restart_JACOBI_System(self):
1062 A=Tensor4(0.,Function(self.domain))
1063 D=Tensor(1.,Function(self.domain))
1064 Y=Vector(self.domain.getDim(),Function(self.domain))
1065 for i in range(self.domain.getDim()):
1066 A[i,:,i,:]=kronecker(self.domain)
1067 D[i,i]+=i
1068 Y[i]+=i
1069 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1070 mypde.setValue(A=A,D=D,Y=Y)
1071 mypde.setSolverMethod(mypde.GMRES,mypde.JACOBI)
1072 u=mypde.getSolution(verbose=self.VERBOSE,truncation=10,restart=20)
1073 self.failUnless(self.check(u,1.),'solution is wrong.')
1074 def test_GMRES_truncation_restart_ILU0_System(self):
1075 A=Tensor4(0.,Function(self.domain))
1076 D=Tensor(1.,Function(self.domain))
1077 Y=Vector(self.domain.getDim(),Function(self.domain))
1078 for i in range(self.domain.getDim()):
1079 A[i,:,i,:]=kronecker(self.domain)
1080 D[i,i]+=i
1081 Y[i]+=i
1082 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1083 mypde.setValue(A=A,D=D,Y=Y)
1084 mypde.setSolverMethod(mypde.GMRES,mypde.ILU0)
1085 u=mypde.getSolution(verbose=self.VERBOSE,truncation=10,restart=20)
1086 self.failUnless(self.check(u,1.),'solution is wrong.')
1087
1088 class Test_LinearPDE(Test_LinearPDE_noLumping):
1089 def test_Lumping_attemptToSetA(self):
1090 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1091 try:
1092 success=True
1093 mypde.setSolverMethod(mypde.LUMPING)
1094 mypde.setValue(A=kronecker(self.domain))
1095 u=mypde.getSolution(verbose=self.VERBOSE)
1096 except ValueError:
1097 success=False
1098 self.failUnless(not success,'error should be issued')
1099 def test_Lumping_attemptToSetB(self):
1100 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1101 try:
1102 success=True
1103 mypde.setSolverMethod(mypde.LUMPING)
1104 mypde.setValue(B=kronecker(self.domain)[0])
1105 u=mypde.getSolution(verbose=self.VERBOSE)
1106 except ValueError:
1107 success=False
1108 self.failUnless(not success,'error should be issued')
1109 def test_Lumping_attemptToSetC(self):
1110 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1111 try:
1112 success=True
1113 mypde.setSolverMethod(mypde.LUMPING)
1114 mypde.setValue(C=kronecker(self.domain)[0])
1115 u=mypde.getSolution(verbose=self.VERBOSE)
1116 except ValueError:
1117 success=False
1118 self.failUnless(not success,'error should be issued')
1119
1120 def test_Lumping_attemptToSetA_reduced(self):
1121 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1122 try:
1123 success=True
1124 mypde.setSolverMethod(mypde.LUMPING)
1125 mypde.setValue(A_reduced=kronecker(self.domain))
1126 u=mypde.getSolution(verbose=self.VERBOSE)
1127 except ValueError:
1128 success=False
1129 self.failUnless(not success,'error should be issued')
1130 def test_Lumping_attemptToSetB_reduced(self):
1131 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1132 try:
1133 success=True
1134 mypde.setSolverMethod(mypde.LUMPING)
1135 mypde.setValue(B_reduced=kronecker(self.domain)[0])
1136 u=mypde.getSolution(verbose=self.VERBOSE)
1137 except ValueError:
1138 success=False
1139 self.failUnless(not success,'error should be issued')
1140 def test_Lumping_attemptToSetC_reduced(self):
1141 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1142 try:
1143 success=True
1144 mypde.setSolverMethod(mypde.LUMPING)
1145 mypde.setValue(C_reduced=kronecker(self.domain)[0])
1146 u=mypde.getSolution(verbose=self.VERBOSE)
1147 except ValueError:
1148 success=False
1149 self.failUnless(not success,'error should be issued')
1150
1151 def test_Lumping(self):
1152 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1153 mypde.setSolverMethod(mypde.LUMPING)
1154 mypde.setValue(D=1.,Y=1.)
1155 u=mypde.getSolution(verbose=self.VERBOSE)
1156 self.failUnless(self.check(u,1.),'solution is wrong.')
1157 def test_Constrained_Lumping(self):
1158 x=self.domain.getX()
1159 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1160 mypde.setSolverMethod(mypde.LUMPING)
1161 mypde.setValue(D=1.,Y=1.,q=whereZero(x[0]),r=1.)
1162 u=mypde.getSolution(verbose=self.VERBOSE)
1163 self.failUnless(self.check(u,1.),'solution is wrong.')
1164
1165 def test_Lumping_System(self):
1166 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1167 mypde.setSolverMethod(mypde.LUMPING)
1168 mypde.setValue(D=numarray.array([[1.,0.],[0.,2.]]),Y=numarray.array([1.,2.]))
1169 u=mypde.getSolution(verbose=self.VERBOSE)
1170 self.failUnless(self.check(u,numarray.ones((2,))),'solution is wrong.')
1171 def test_Constrained_Lumping_System(self):
1172 x=self.domain.getX()
1173 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1174 mypde.setSolverMethod(mypde.LUMPING)
1175 mypde.setValue(D=numarray.array([[1.,0.],[0.,2.]]),Y=numarray.array([1.,2.]), \
1176 q=whereZero(x[0])*[0.,1],r=[0.,1.])
1177 u=mypde.getSolution(verbose=self.VERBOSE)
1178 self.failUnless(self.check(u,numarray.ones((2,))),'solution is wrong.')
1179
1180 def test_Lumping_updateRHS(self):
1181 x=self.domain.getX()
1182 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1183 mypde.setSolverMethod(mypde.LUMPING)
1184 mypde.setValue(D=1.,Y=1.)
1185 u=mypde.getSolution(verbose=self.VERBOSE)
1186 self.failUnless(self.check(u,1.),'first solution is wrong.')
1187 mypde.setValue(Y=2.,q=whereZero(x[0]),r=2.)
1188 u=mypde.getSolution(verbose=self.VERBOSE)
1189 self.failUnless(self.check(u,2.),'second solution is wrong.')
1190 def test_Lumping_updateOperator(self):
1191 x=self.domain.getX()
1192 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1193 mypde.setSolverMethod(mypde.LUMPING)
1194 mypde.setValue(D=1.,Y=1.)
1195 u=mypde.getSolution(verbose=self.VERBOSE)
1196 mypde.setValue(D=2.)
1197 u=mypde.getSolution(verbose=self.VERBOSE)
1198 self.failUnless(self.check(u,0.5),'second solution is wrong.')
1199

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26