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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3103 - (show annotations)
Tue Aug 24 07:01:33 2010 UTC (9 years ago) by gross
Original Path: trunk/escript/test/python/test_linearPDEs.py
File MIME type: text/x-python
File size: 190278 byte(s)
test fix
1 # -*- coding: utf-8 -*-
2
3 ########################################################
4 #
5 # Copyright (c) 2003-2010 by University of Queensland
6 # Earth Systems Science Computational Center (ESSCC)
7 # http://www.uq.edu.au/esscc
8 #
9 # Primary Business: Queensland, Australia
10 # Licensed under the Open Software License version 3.0
11 # http://www.opensource.org/licenses/osl-3.0.php
12 #
13 ########################################################
14
15 __copyright__="""Copyright (c) 2003-2010 by University of Queensland
16 Earth Systems Science Computational Center (ESSCC)
17 http://www.uq.edu.au/esscc
18 Primary Business: Queensland, Australia"""
19 __license__="""Licensed under the Open Software License version 3.0
20 http://www.opensource.org/licenses/osl-3.0.php"""
21 __url__="https://launchpad.net/escript-finley"
22
23 """
24 Test suite for linearPDEs class
25
26 The tests must be linked with a Domain class object in the setUp method:
27
28 from esys.finley import Rectangle
29 class Test_LinearPDEOnFinley(Test_LinearPDE):
30 def setUp(self):
31 self.domain = Rectangle(10,10,2)
32 def tearDown(self):
33 del self.domain
34 suite = unittest.TestSuite()
35 suite.addTest(unittest.makeSuite(Test_LinearPDEOnFinley))
36 unittest.TextTestRunner(verbosity=2).run(suite)
37
38 :var __author__: name of author
39 :var __copyright__: copyrights
40 :var __license__: licence agreement
41 :var __url__: url entry point on documentation
42 :var __version__: version
43 :var __date__: date of the version
44 """
45
46 __author__="Lutz Gross, l.gross@uq.edu.au"
47
48 from esys.escript.util import Lsup,kronecker,interpolate,whereZero, outer, swap_axes
49 from esys.escript import Function,FunctionOnBoundary,FunctionOnContactZero,Solution,ReducedSolution,Vector,ContinuousFunction,Scalar, ReducedFunction,ReducedFunctionOnBoundary,ReducedFunctionOnContactZero,Data, Tensor4, Tensor
50 from esys.escript.linearPDEs import LinearPDE,IllegalCoefficientValue,Poisson, IllegalCoefficientFunctionSpace, TransportPDE, IllegalCoefficient, Helmholtz, LameEquation, SolverOptions
51 import numpy
52 import unittest
53
54 class Test_linearPDEs(unittest.TestCase):
55 TOL=1.e-6
56 SOLVER_TOL=1.e-10
57 DEBUG=False
58 VERBOSE=False
59 def check(self,arg,ref_arg,tol=None):
60 """
61 checks if arg and ref_arg are nearly identical using the `Lsup`
62 """
63 if tol==None: tol=self.TOL
64 return Lsup(arg-ref_arg)<=tol*Lsup(ref_arg)
65
66 class Test_LameEquation(Test_linearPDEs):
67
68 def test_config(self):
69 mypde=LameEquation(self.domain,debug=self.DEBUG)
70 d=self.domain.getDim()
71 self.failUnlessEqual((mypde.getNumEquations(), mypde.getNumSolutions(), mypde.getSolverOptions().isSymmetric()),(d,d,True),"set up incorrect")
72
73 def test_setCoefficient_q(self):
74 mypde=LameEquation(self.domain,debug=self.DEBUG)
75 x=self.domain.getX()
76 mypde.setValue(q=x)
77
78 q_ref=interpolate(x,Solution(self.domain))
79 self.failUnless(self.check(mypde.getCoefficient("A"),0),"A is not 0")
80 self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
81 self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
82 self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
83 self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
84 self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
85 self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
86 self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
87 self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
88 self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
89 self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
90 self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
91 self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
92 self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
93 self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
94 self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
95 self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
96 self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
97 self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
98 self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
99 self.failUnless(self.check(mypde.getCoefficient("q"),q_ref),"q is not empty")
100 self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
101
102 def test_setCoefficient_r(self):
103 mypde=LameEquation(self.domain,debug=self.DEBUG)
104 x=self.domain.getX()
105 mypde.setValue(r=x)
106
107 r_ref=interpolate(x,Solution(self.domain))
108 self.failUnless(self.check(mypde.getCoefficient("A"),0),"A is not 0")
109 self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
110 self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
111 self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
112 self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
113 self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
114 self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
115 self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
116 self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
117 self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
118 self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
119 self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
120 self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
121 self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
122 self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
123 self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
124 self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
125 self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
126 self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
127 self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
128 self.failUnless(self.check(mypde.getCoefficient("r"),r_ref),"r is nor x")
129 self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
130
131
132 def test_setCoefficient_F(self):
133 mypde=LameEquation(self.domain,debug=self.DEBUG)
134 x=self.domain.getX()
135 mypde.setValue(F=x)
136
137 Y_ref=interpolate(x,Function(self.domain))
138 self.failUnless(self.check(mypde.getCoefficient("A"),0),"A is not 0")
139 self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
140 self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
141 self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
142 self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
143 self.failUnless(self.check(mypde.getCoefficient("Y"),Y_ref),"Y is not x")
144 self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
145 self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
146 self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
147 self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
148 self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
149 self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
150 self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
151 self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
152 self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
153 self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
154 self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
155 self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
156 self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
157 self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
158 self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
159 self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
160
161 def test_setCoefficient_f(self):
162 mypde=LameEquation(self.domain,debug=self.DEBUG)
163 x=self.domain.getX()
164 mypde.setValue(f=x)
165
166 y_ref=interpolate(x,FunctionOnBoundary(self.domain))
167 self.failUnless(self.check(mypde.getCoefficient("A"),0),"A is not 0")
168 self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
169 self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
170 self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
171 self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
172 self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
173 self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
174 self.failUnless(self.check(mypde.getCoefficient("y"),y_ref),"d is not x[0]")
175 self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
176 self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
177 self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
178 self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
179 self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
180 self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
181 self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
182 self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"X_reduced is not empty")
183 self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
184 self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
185 self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
186 self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
187 self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
188 self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
189
190 def test_setCoefficient_sigma(self):
191 mypde=LameEquation(self.domain,debug=self.DEBUG)
192 x=self.domain.getX()
193 mypde.setValue(sigma=outer(x,x))
194
195 X_ref=interpolate(outer(x,x),Function(self.domain))
196 self.failUnless(self.check(mypde.getCoefficient("A"),0),"A is not 0")
197 self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
198 self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
199 self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
200 self.failUnless(self.check(mypde.getCoefficient("X"),X_ref),"X is not x X x")
201 self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
202 self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
203 self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
204 self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
205 self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
206 self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
207 self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
208 self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
209 self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
210 self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
211 self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"X_reduced is not empty")
212 self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
213 self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
214 self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
215 self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
216 self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
217 self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
218
219 def test_setCoefficient_lambda(self):
220 mypde=LameEquation(self.domain,debug=self.DEBUG)
221 x=self.domain.getX()
222 mypde.setValue(lame_lambda=x[0])
223
224
225 k3=kronecker(Function(self.domain))
226 k3Xk3=outer(k3,k3)
227 A_ref=x[0]*k3Xk3
228
229 self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
230 self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
231 self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
232 self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
233 self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
234 self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
235 self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
236 self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
237 self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
238 self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
239 self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
240 self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
241 self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
242 self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
243 self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
244 self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
245 self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
246 self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
247 self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
248 self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
249 self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
250 self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
251
252 def test_setCoefficient_mu(self):
253 mypde=LameEquation(self.domain,debug=self.DEBUG)
254 x=self.domain.getX()
255 mypde.setValue(lame_mu=x[0])
256
257
258 k3=kronecker(Function(self.domain))
259 k3Xk3=outer(k3,k3)
260 A_ref=x[0]*(swap_axes(k3Xk3,0,3)+swap_axes(k3Xk3,1,3))
261
262 self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
263 self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
264 self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
265 self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
266 self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
267 self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
268 self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
269 self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
270 self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
271 self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
272 self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
273 self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
274 self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
275 self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
276 self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
277 self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
278 self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
279 self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
280 self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
281 self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
282 self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
283 self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
284
285 def test_setCoefficient_lambdamu(self):
286 mypde=LameEquation(self.domain,debug=self.DEBUG)
287 x=self.domain.getX()
288 mypde.setValue(lame_lambda=x[0], lame_mu=x[1])
289
290 k3=kronecker(Function(self.domain))
291 k3Xk3=outer(k3,k3)
292 A_ref=x[0]*k3Xk3+x[1]*(swap_axes(k3Xk3,0,3)+swap_axes(k3Xk3,1,3))
293
294 self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
295 self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
296 self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
297 self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
298 self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
299 self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
300 self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
301 self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
302 self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
303 self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
304 self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
305 self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
306 self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
307 self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
308 self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
309 self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
310 self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
311 self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
312 self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
313 self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
314 self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
315 self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
316
317 def test_solve(self):
318 d=self.domain.getDim()
319 mypde=LameEquation(self.domain)
320 cf=ContinuousFunction(self.domain)
321 x=cf.getX()
322 u_ex=x
323 msk=Vector(0.,cf)
324 for i in range(d): msk[i]=whereZero(x[i])
325 mypde.setValue(q=msk,r=u_ex,lame_mu=3,lame_lambda=50,f=(2*3+50*d)*FunctionOnBoundary(self.domain).getNormal())
326
327 u=mypde.getSolution()
328 self.failUnless(self.check(u,u_ex,10*self.TOL),"incorrect solution")
329
330 class Test_Helmholtz(Test_linearPDEs):
331
332 def test_config(self):
333 mypde=Helmholtz(self.domain,debug=self.DEBUG)
334 self.failUnlessEqual((mypde.getNumEquations(), mypde.getNumSolutions(), mypde.getSolverOptions().isSymmetric()),(1,1,True),"set up incorrect")
335 def test_setCoefficient_q(self):
336 mypde=Helmholtz(self.domain,debug=self.DEBUG)
337 x=self.domain.getX()
338 mypde.setValue(q=whereZero(x[0]))
339
340 q_ref=interpolate(whereZero(x[0]),Solution(self.domain))
341 A_ref=kronecker(self.domain)
342
343 self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
344 self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
345 self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
346 self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
347 self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
348 self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
349 self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
350 self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
351 self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
352 self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
353 self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
354 self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
355 self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
356 self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
357 self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
358 self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
359 self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
360 self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
361 self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
362 self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
363 self.failUnless(self.check(mypde.getCoefficient("q"),q_ref),"q is not empty")
364 self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
365
366 def test_setCoefficient_r(self):
367 mypde=Helmholtz(self.domain,debug=self.DEBUG)
368 x=self.domain.getX()
369 mypde.setValue(r=x[0])
370
371 r_ref=interpolate(x[0],Solution(self.domain))
372 A_ref=kronecker(self.domain)
373 self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
374 self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
375 self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
376 self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
377 self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
378 self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
379 self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
380 self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
381 self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
382 self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
383 self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
384 self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
385 self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
386 self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
387 self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
388 self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
389 self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
390 self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
391 self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
392 self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
393 self.failUnless(self.check(mypde.getCoefficient("r"),r_ref),"r is nor x[0]")
394 self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
395
396
397 def test_setCoefficient_f(self):
398 mypde=Helmholtz(self.domain,debug=self.DEBUG)
399 x=self.domain.getX()
400 mypde.setValue(f=x[0])
401
402 Y_ref=interpolate(x[0],Function(self.domain))
403 A_ref=kronecker(self.domain)
404 self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
405 self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
406 self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
407 self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
408 self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
409 self.failUnless(self.check(mypde.getCoefficient("Y"),Y_ref),"Y is not x[0]")
410 self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
411 self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
412 self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
413 self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
414 self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
415 self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
416 self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
417 self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
418 self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
419 self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
420 self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
421 self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
422 self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
423 self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
424 self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
425 self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
426
427 def test_setCoefficient_alpha(self):
428 mypde=Helmholtz(self.domain,debug=self.DEBUG)
429 x=self.domain.getX()
430 mypde.setValue(alpha=x[0])
431
432 d_ref=interpolate(x[0],FunctionOnBoundary(self.domain))
433 A_ref=kronecker(self.domain)
434 self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
435 self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
436 self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
437 self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
438 self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
439 self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
440 self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
441 self.failUnless(self.check(mypde.getCoefficient("d"),d_ref),"d is not x[0]")
442 self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
443 self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
444 self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
445 self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
446 self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
447 self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
448 self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
449 self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"X_reduced is not empty")
450 self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
451 self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
452 self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
453 self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
454 self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
455 self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
456
457 def test_setCoefficient_g(self):
458 mypde=Helmholtz(self.domain,debug=self.DEBUG)
459 x=self.domain.getX()
460 mypde.setValue(g=x[0])
461
462 y_ref=interpolate(x[0],FunctionOnBoundary(self.domain))
463 A_ref=kronecker(self.domain)
464 self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
465 self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
466 self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
467 self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
468 self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
469 self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
470 self.failUnless(self.check(mypde.getCoefficient("y"),y_ref),"y is not x[0]")
471 self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
472 self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
473 self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
474 self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
475 self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
476 self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
477 self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
478 self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
479 self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
480 self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
481 self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
482 self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
483 self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
484 self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
485 self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
486
487 def test_setCoefficient_omega(self):
488 mypde=Helmholtz(self.domain,debug=self.DEBUG)
489 x=self.domain.getX()
490 mypde.setValue(omega=x[0])
491
492 D_ref=interpolate(x[0],Function(self.domain))
493 A_ref=kronecker(self.domain)
494 self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
495 self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
496 self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
497 self.failUnless(self.check(mypde.getCoefficient("D"),D_ref),"D is not x[0]")
498 self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
499 self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
500 self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
501 self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
502 self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
503 self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
504 self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
505 self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
506 self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
507 self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
508 self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
509 self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
510 self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
511 self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
512 self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
513 self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
514 self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
515 self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
516
517 def test_solve(self):
518 d=self.domain.getDim()
519 cf=ContinuousFunction(self.domain)
520 u_ex=Scalar(1.,cf)
521 mypde=Helmholtz(self.domain)
522 mypde.setValue(f=3,omega=3,alpha=2,g=2)
523 u=mypde.getSolution()
524 self.failUnless(self.check(u,u_ex,10*self.TOL),"incorrect solution")
525
526 class Test_Poisson(Test_linearPDEs):
527
528 def test_config(self):
529 mypde=Poisson(self.domain,debug=self.DEBUG)
530 self.failUnlessEqual((mypde.getNumEquations(), mypde.getNumSolutions(), mypde.getSolverOptions().isSymmetric()),(1,1,True),"set up incorrect")
531 def test_setCoefficient_q(self):
532 mypde=Poisson(self.domain,debug=self.DEBUG)
533 x=self.domain.getX()
534 q_ref=interpolate(whereZero(x[0]),Solution(self.domain))
535 A_ref=kronecker(self.domain)
536 mypde.setValue(q=whereZero(x[0]))
537 self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
538 self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
539 self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
540 self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
541 self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
542 self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
543 self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
544 self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
545 self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
546 self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
547 self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
548 self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
549 self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
550 self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
551 self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
552 self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
553 self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
554 self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
555 self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
556 self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
557 self.failUnless(self.check(mypde.getCoefficient("q"),q_ref),"q is not empty")
558 self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
559 def test_setCoefficient_f(self):
560 mypde=Poisson(self.domain,debug=self.DEBUG)
561 x=self.domain.getX()
562 Y_ref=interpolate(x[0],Function(self.domain))
563 A_ref=kronecker(self.domain)
564 mypde.setValue(f=x[0])
565 self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
566 self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
567 self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
568 self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
569 self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
570 self.failUnless(self.check(mypde.getCoefficient("Y"),Y_ref),"Y is not x[0]")
571 self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
572 self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
573 self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
574 self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
575 self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
576 self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
577 self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
578 self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
579 self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
580 self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
581 self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
582 self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
583 self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
584 self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
585 self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
586 self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
587 def test_setCoefficient_f_reduced(self):
588 mypde=Poisson(self.domain,debug=self.DEBUG)
589 x=self.domain.getX()
590 Y_ref=interpolate(x[0],ReducedFunction(self.domain))
591 A_ref=kronecker(self.domain)
592 mypde.setValue(f_reduced=x[0])
593 self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
594 self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
595 self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
596 self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
597 self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
598 self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
599 self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
600 self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
601 self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
602 self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
603 self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
604 self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
605 self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
606 self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
607 self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
608 self.failUnless(self.check(mypde.getCoefficient("Y_reduced"),Y_ref),"Y_reduced is not x[0]")
609 self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
610 self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
611 self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
612 self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
613 self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
614 self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
615 def test_solve(self):
616 d=self.domain.getDim()
617 cf=ContinuousFunction(self.domain)
618 x=cf.getX()
619 #construct exact solution:
620 u_ex=Scalar(1.,cf)
621 for i in range(d):
622 u_ex*=x[i]*(2.-x[i])
623 #construct mask:
624 msk=Scalar(0.,cf)
625 for i in range(d):
626 msk+=whereZero(x[i])
627 #construct right hand side
628 f=Scalar(0,cf)
629 for i in range(d):
630 f_p=Scalar(1,cf)
631 for j in range(d):
632 if i==j:
633 f_p*=2.
634 else:
635 f_p*=x[j]*(2-x[j])
636 f+=f_p
637 mypde=Poisson(self.domain)
638 mypde.setValue(f=f,q=msk)
639 u=mypde.getSolution()
640 self.failUnless(self.check(u,u_ex,10*self.TOL),"incorrect solution")
641
642 class Test_LinearPDE_noLumping(Test_linearPDEs):
643 N=4
644 def test_SolverOptions(self):
645 so=SolverOptions()
646
647 self.failUnless(so.getSmoother() == 28, "initial Smoother is wrong.")
648 self.failUnlessRaises(ValueError,so.setSmoother,-1)
649 so.setSmoother(so.GAUSS_SEIDEL)
650 self.failUnless(so.getSmoother() == 28, "Gauss-Seidel smoother is not set.")
651 so.setSmoother(so.JACOBI)
652 self.failUnless(so.getSmoother() == 10, "Jacobi smoother is not set.")
653
654 self.failUnless(so.getLevelMax() == 5, "initial LevelMax is wrong.")
655 self.failUnlessRaises(ValueError,so.setLevelMax,-1)
656 so.setLevelMax(20)
657 self.failUnless(so.getLevelMax() == 20, "LevelMax is wrong.")
658
659 self.failUnless(so.getCoarseningThreshold() == 0.25, "initial CoarseningThreshold is wrong.")
660 self.failUnlessRaises(ValueError,so.setCoarseningThreshold,-1)
661 so.setCoarseningThreshold(0.1)
662 self.failUnless(so.getCoarseningThreshold() == 0.1, "CoarseningThreshold is wrong.")
663
664 self.failUnless(so.getMinCoarseMatrixSize() == 500, "initial Minimum Coarse Matrix Size is wrong.")
665 self.failUnlessRaises(ValueError,so.setMinCoarseMatrixSize,-1)
666 so.setMinCoarseMatrixSize(1000)
667 self.failUnless(so.getMinCoarseMatrixSize() == 1000, "Minimum Coarse Matrix Size is wrong.")
668
669 self.failUnless(so.getNumSweeps() == 2, "initial Sweeps is wrong.")
670 self.failUnlessRaises(ValueError,so.setNumSweeps,-1)
671 so.setNumSweeps(3)
672 self.failUnless(so.getNumSweeps() == 3, "Sweeps is wrong.")
673
674 self.failUnless(so.getNumPreSweeps() == 2, "initial PreSweeps is wrong.")
675 self.failUnlessRaises(ValueError,so.setNumPreSweeps,-1)
676 so.setNumPreSweeps(4)
677 self.failUnless(so.getNumPreSweeps() == 4, "PreSweeps is wrong.")
678
679 self.failUnless(so.getNumPostSweeps() == 2, "initial PreSweeps is wrong.")
680 self.failUnlessRaises(ValueError,so.setNumPostSweeps,-1)
681 so.setNumPostSweeps(5)
682 self.failUnless(so.getNumPostSweeps() == 5, "PreSweeps is wrong.")
683
684 self.failUnless(so.getTolerance() == 1.e-8, "initial Tolerance is wrong.")
685 self.failUnlessRaises(ValueError,so.setTolerance,-1)
686 so.setTolerance(0.2)
687 self.failUnless(so.getTolerance() == 0.2, "Tolerance is wrong.")
688
689 self.failUnless(so.getAbsoluteTolerance() == 0., "initial AbsoluteTolerance is wrong.")
690 self.failUnlessRaises(ValueError,so.setAbsoluteTolerance,-1)
691 so.setAbsoluteTolerance(0.3)
692 self.failUnless(so.getAbsoluteTolerance() == 0.3, "AbsoluteTolerance is wrong.")
693
694 self.failUnless(so.getInnerTolerance() == 0.9, "initial InnerTolerance is wrong.")
695 self.failUnlessRaises(ValueError,so.setInnerTolerance,-1)
696 so.setInnerTolerance(0.4)
697 self.failUnless(so.getInnerTolerance() == 0.4, "InnerTolerance is wrong.")
698
699 self.failUnless(so.getDropTolerance() == 0.01, "initial DropTolerance is wrong.")
700 self.failUnlessRaises(ValueError,so.setDropTolerance,-1)
701 so.setDropTolerance(0.5)
702 self.failUnless(so.getDropTolerance() == 0.5, "DropDropTolerance is wrong.")
703
704 self.failUnless(so.getDropStorage() == 2., "initial DropStorage is wrong.")
705 self.failUnlessRaises(ValueError,so.setDropStorage,-1)
706 so.setDropStorage(10)
707 self.failUnless(so.getDropStorage() == 10, "DropStorage is wrong.")
708
709 self.failUnless(so.getRelaxationFactor() == 0.3, "initial RelaxationFactor is wrong.")
710 self.failUnlessRaises(ValueError,so.setRelaxationFactor,-1)
711 so.setRelaxationFactor(0.1)
712 self.failUnless(so.getRelaxationFactor() == 0.1, "Relaxation is wrong.")
713
714
715 self.failUnless(so.getIterMax() == 100000, "initial IterMax is wrong.")
716 self.failUnlessRaises(ValueError,so.setIterMax,0)
717 so.setIterMax(11)
718 self.failUnless(so.getIterMax() == 11, "IterMax is wrong.")
719
720 self.failUnless(so.getInnerIterMax() == 10, "initial InnerIterMax is wrong.")
721 self.failUnlessRaises(ValueError,so.setInnerIterMax,0)
722 so.setInnerIterMax(12)
723 self.failUnless(so.getInnerIterMax() == 12, "InnerIterMax is wrong.")
724
725 self.failUnless(so.getTruncation() == 20, "initial Truncation is wrong.")
726 self.failUnlessRaises(ValueError,so.setTruncation,0)
727 so.setTruncation(13)
728 self.failUnless(so.getTruncation() == 13, "Truncation is wrong.")
729
730 self.failUnless(so.getRestart() == None, "initial Truncation is wrong.")
731 self.failUnlessRaises(ValueError,so.setTruncation,0)
732 so.setRestart(14)
733 self.failUnless(so.getRestart() == 14, "Truncation is wrong.")
734 so.setRestart(None)
735 self.failUnless(so.getRestart() == None, "Truncation is wrong.")
736
737 self.failUnless(not so.isVerbose(), "initial verbosity flag is wrong.")
738 so.setVerbosityOn()
739 self.failUnless(so.isVerbose(), "verbosity (1) flag is wrong.")
740 so.setVerbosityOff()
741 self.failUnless(not so.isVerbose(), "verbosity (2) flag is wrong.")
742 so.setVerbosity(verbose=True)
743 self.failUnless(so.isVerbose(), "verbosity (3) flag is wrong.")
744 so.setVerbosity(verbose=False)
745 self.failUnless(not so.isVerbose(), "verbosity (4) flag is wrong.")
746
747 self.failUnless(not so.isSymmetric(), "initial symmetry flag is wrong.")
748 so.setSymmetryOn()
749 self.failUnless(so.isSymmetric(), "symmetry (1) flag is wrong.")
750 so.setSymmetryOff()
751 self.failUnless(not so.isSymmetric(), "symmetry (2) flag is wrong.")
752 so.setSymmetry(flag=True)
753 self.failUnless(so.isSymmetric(), "symmetry (3) flag is wrong.")
754 so.setSymmetry(flag=False)
755 self.failUnless(not so.isSymmetric(), "symmetry (4) flag is wrong.")
756
757 self.failUnless(so.adaptInnerTolerance(), "initial InnerToleranceAdaption flag is wrong.")
758 so.setInnerToleranceAdaptionOn()
759 self.failUnless(so.adaptInnerTolerance(), "InnerToleranceAdaption (1) flag is wrong.")
760 so.setInnerToleranceAdaptionOff()
761 self.failUnless(not so.adaptInnerTolerance(), "InnerToleranceAdaption (2) flag is wrong.")
762 so.setInnerToleranceAdaption(adapt=True)
763 self.failUnless(so.adaptInnerTolerance(), "InnerToleranceAdaption (3) flag is wrong.")
764 so.setInnerToleranceAdaption(adapt=False)
765 self.failUnless(not so.adaptInnerTolerance(), "InnerToleranceAdaption (4) flag is wrong.")
766
767 self.failUnless(not so.acceptConvergenceFailure(), "initial acceptConvergenceFailure flag is wrong.")
768 so.setAcceptanceConvergenceFailureOn()
769 self.failUnless(so.acceptConvergenceFailure(), "acceptConvergenceFailure (1) flag is wrong.")
770 so.setAcceptanceConvergenceFailureOff()
771 self.failUnless(not so.acceptConvergenceFailure(), "acceptConvergenceFailure (2) flag is wrong.")
772 so.setAcceptanceConvergenceFailure(accept=True)
773 self.failUnless(so.acceptConvergenceFailure(), "acceptConvergenceFailure (3) flag is wrong.")
774 so.setAcceptanceConvergenceFailure(accept=False)
775 self.failUnless(not so.acceptConvergenceFailure(), "acceptConvergenceFailure (4) flag is wrong.")
776
777 self.failUnless(so.getReordering() == 30, "initial Reordering is wrong.")
778 self.failUnlessRaises(ValueError,so.setReordering,-1)
779 so.setReordering(so.NO_REORDERING)
780 self.failUnless(so.getReordering() == 17, "NO_REORDERING is not set.")
781 so.setReordering(so.MINIMUM_FILL_IN)
782 self.failUnless(so.getReordering() == 18, "MINIMUM_FILL_IN is not set.")
783 so.setReordering(so.NESTED_DISSECTION)
784 self.failUnless(so.getReordering() == 19, "NESTED_DISSECTION is not set.")
785 so.setReordering(so.DEFAULT_REORDERING)
786 self.failUnless(so.getReordering() == 30, "DEFAULT_REORDERING is not set.")
787
788 self.failUnless(so.getPackage() == 0, "initial solver package is wrong.")
789 self.failUnlessRaises(ValueError,so.setPackage,-1)
790 so.setPackage(so.PASO)
791 self.failUnless(so.getPackage() == 21, "PASO is not set.")
792 so.setPackage(so.SUPER_LU)
793 self.failUnless(so.getPackage() == 31, "SUPER_LU is not set.")
794 so.setPackage(so.PASTIX)
795 self.failUnless(so.getPackage() == 32, "PASTIX is not set.")
796 so.setPackage(so.MKL)
797 self.failUnless(so.getPackage() == 15, "MKL is not set.")
798 so.setPackage(so.UMFPACK)
799 self.failUnless(so.getPackage() == 16, "UMFPACK is not set.")
800 so.setPackage(so.TRILINOS)
801 self.failUnless(so.getPackage() == 24, "TRILINOS is not set.")
802
803 self.failUnless(so.getSolverMethod() == 0, "initial SolverMethod is wrong.")
804 self.failUnlessRaises(ValueError,so.setSolverMethod,-1)
805 so.setSolverMethod(so.DIRECT)
806 self.failUnless(so.getSolverMethod() == 1, "DIRECT is not set.")
807 so.setSolverMethod(so.CHOLEVSKY)
808 self.failUnless(so.getSolverMethod() == 2, "CHOLEVSKY is not set.")
809 so.setSolverMethod(so.PCG)
810 self.failUnless(so.getSolverMethod() == 3, "PCG is not set.")
811 so.setSolverMethod(so.CR)
812 self.failUnless(so.getSolverMethod() == 4, "CR is not set.")
813 so.setSolverMethod(so.CGS)
814 self.failUnless(so.getSolverMethod() == 5, "CGS is not set.")
815 so.setSolverMethod(so.BICGSTAB)
816 self.failUnless(so.getSolverMethod() == 6, "BICGSTAB is not set.")
817 so.setSolverMethod(so.GMRES)
818 self.failUnless(so.getSolverMethod() == 11, "GMRES is not set.")
819 so.setSolverMethod(so.PRES20)
820 self.failUnless(so.getSolverMethod() == 12, "PRES20 is not set.")
821 so.setSolverMethod(so.LUMPING)
822 self.failUnless(so.getSolverMethod() == 13, "LUMPING is not set.")
823 so.setSolverMethod(so.ITERATIVE)
824 self.failUnless(so.getSolverMethod() == 20, "ITERATIVE is not set.")
825 so.setSolverMethod(so.NONLINEAR_GMRES)
826 self.failUnless(so.getSolverMethod() == 25, "NONLINEAR_GMRES is not set.")
827 so.setSolverMethod(so.TFQMR)
828 self.failUnless(so.getSolverMethod() == 26, "TFQMR is not set.")
829 so.setSolverMethod(so.MINRES)
830 self.failUnless(so.getSolverMethod() == 27, "MINRES is not set.")
831 so.setSolverMethod(so.DEFAULT)
832 self.failUnless(so.getSolverMethod() == 0, "DEFAULT is not set.")
833
834 self.failUnless(so.getPreconditioner() == 10, "initial Preconditioner is wrong.")
835 self.failUnlessRaises(ValueError,so.setPreconditioner,-1)
836 so.setPreconditioner(so.ILU0)
837 self.failUnless(so.getPreconditioner() == 8, "ILU0 is not set.")
838 so.setPreconditioner(so.ILUT)
839 self.failUnless(so.getPreconditioner() == 9, "ILUT is not set.")
840 so.setPreconditioner(so.JACOBI)
841 self.failUnless(so.getPreconditioner() == 10, "JACOBI is not set.")
842 so.setPreconditioner(so.AMG)
843 self.failUnless(so.getPreconditioner() == 22, "AMG is not set.")
844 so.setPreconditioner(so.REC_ILU)
845 self.failUnless(so.getPreconditioner() == 23, "REC_ILU is not set.")
846 so.setPreconditioner(so.GAUSS_SEIDEL)
847 self.failUnless(so.getPreconditioner() == 28, "GAUSS_SEIDEL is not set.")
848 so.setPreconditioner(so.RILU)
849 self.failUnless(so.getPreconditioner() == 29, "RILU is not set.")
850 so.setPreconditioner(so.AMLI)
851 self.failUnless(so.getPreconditioner() == 38, "AMLI is not set.")
852 so.setPreconditioner(so.NO_PRECONDITIONER)
853 self.failUnless(so.getPreconditioner() == 36, "NO_PRECONDITIONER is not set.")
854
855 self.failUnless(so.getCoarsening() == 0, "initial Coarseningr is wrong.")
856 self.failUnlessRaises(ValueError,so.setCoarsening,-1)
857 so.setCoarsening(so.YAIR_SHAPIRA_COARSENING)
858 self.failUnless(so.getCoarsening() == 33, "YAIR_SHAPIRA_COARSENING is not set.")
859 so.setCoarsening(so.RUGE_STUEBEN_COARSENING)
860 self.failUnless(so.getCoarsening() == 34, "RUGE_STUEBEN_COARSENING is not set.")
861 so.setCoarsening(so.AGGREGATION_COARSENING)
862 self.failUnless(so.getCoarsening() == 35, "AGREGATION_COARSENING is not set.")
863 so.setCoarsening(so.STANDARD_COARSENING)
864 self.failUnless(so.getCoarsening() == 39, "STANDARD_COARSENING is not set.")
865 so.setCoarsening(so.DEFAULT)
866 self.failUnless(so.getCoarsening() == 0, "DEFAULT is not set.")
867
868 self.failUnless(so.getDiagnostics("num_iter") == None, "initial num_iter is wrong.")
869 self.failUnless(so.getDiagnostics("num_inner_iter") == None, "initial num_inner_iter is wrong.")
870 self.failUnless(so.getDiagnostics("time") == None, "initial time is wrong.")
871 self.failUnless(so.getDiagnostics("set_up_time") == None, "initial set_up_time is wrong.")
872 self.failUnless(so.getDiagnostics("residual_norm") == None, "initial residual_norm is wrong.")
873 self.failUnless(so.getDiagnostics("converged") == None, "initial converged is wrong.")
874 self.failUnless(so.hasConverged() == None, "initial convergence flag is wrong.")
875 self.failUnless(so.getDiagnostics("cum_num_inner_iter") == 0, "initial cum_num_inner_iter is wrong.")
876 self.failUnless(so.getDiagnostics("cum_num_iter") == 0, "initial cum_num_iter is wrong.")
877 self.failUnless(so.getDiagnostics("cum_time") ==0, "initial cum_time is wrong.")
878 self.failUnless(so.getDiagnostics("cum_set_up_time") == 0, "initial cum_set_up_time is wrong.")
879
880 so._updateDiagnostics("num_iter",1)
881 so._updateDiagnostics("num_inner_iter",2)
882 so._updateDiagnostics("time",3)
883 so._updateDiagnostics("set_up_time",4)
884 so._updateDiagnostics("residual_norm",5)
885 so._updateDiagnostics("converged",True)
886
887 self.failUnless(so.getDiagnostics("num_iter") == 1, "num_iter is wrong.")
888 self.failUnless(so.getDiagnostics("num_inner_iter") == 2, "num_inner_iter is wrong.")
889 self.failUnless(so.getDiagnostics("time") == 3, "time is wrong.")
890 self.failUnless(so.getDiagnostics("set_up_time") == 4, "set_up_time is wrong.")
891 self.failUnless(so.getDiagnostics("residual_norm") == 5, "residual_norm is wrong.")
892 self.failUnless(so.getDiagnostics("converged"), "converged is wrong.")
893 self.failUnless(so.hasConverged(), "convergence flag is wrong.")
894 self.failUnless(so.getDiagnostics("cum_num_inner_iter") == 2, "cum_num_inner_iter is wrong.")
895 self.failUnless(so.getDiagnostics("cum_num_iter") == 1, "cum_num_iter is wrong.")
896 self.failUnless(so.getDiagnostics("cum_time") ==3, "cum_time is wrong.")
897 self.failUnless(so.getDiagnostics("cum_set_up_time") == 4, "cum_set_up_time is wrong.")
898
899 so.resetDiagnostics()
900 self.failUnless(so.getDiagnostics("num_iter") == None, "initial num_iter is wrong.")
901 self.failUnless(so.getDiagnostics("num_inner_iter") == None, "initial num_inner_iter is wrong.")
902 self.failUnless(so.getDiagnostics("time") == None, "initial time is wrong.")
903 self.failUnless(so.getDiagnostics("set_up_time") == None, "initial set_up_time is wrong.")
904 self.failUnless(so.getDiagnostics("residual_norm") == None, "initial residual_norm is wrong.")
905 self.failUnless(so.getDiagnostics("converged") == None, "initial converged is wrong.")
906 self.failUnless(so.hasConverged() == None, "initial convergence flag is wrong")
907 self.failUnless(so.getDiagnostics("cum_num_inner_iter") == 2, "cum_num_inner_iter is wrong.")
908 self.failUnless(so.getDiagnostics("cum_num_iter") == 1, "cum_num_iter is wrong.")
909 self.failUnless(so.getDiagnostics("cum_time") ==3, "cum_time is wrong.")
910 self.failUnless(so.getDiagnostics("cum_set_up_time") == 4, "cum_set_up_time is wrong.")
911
912 so._updateDiagnostics("num_iter",10)
913 so._updateDiagnostics("num_inner_iter",20)
914 so._updateDiagnostics("time",30)
915 so._updateDiagnostics("set_up_time",40)
916 so._updateDiagnostics("residual_norm",50)
917 so._updateDiagnostics("converged",False)
918
919 self.failUnless(so.getDiagnostics("num_iter") == 10, "num_iter is wrong.")
920 self.failUnless(so.getDiagnostics("num_inner_iter") == 20, "num_inner_iter is wrong.")
921 self.failUnless(so.getDiagnostics("time") == 30, "time is wrong.")
922 self.failUnless(so.getDiagnostics("set_up_time") == 40, "set_up_time is wrong.")
923 self.failUnless(so.getDiagnostics("residual_norm") == 50, "residual_norm is wrong.")
924 self.failUnless(not so.getDiagnostics("converged"), "converged is wrong.")
925 self.failUnless(not so.hasConverged(), "convergence flag is wrong.")
926 self.failUnless(so.getDiagnostics("cum_num_inner_iter") == 22, "cum_num_inner_iter is wrong.")
927 self.failUnless(so.getDiagnostics("cum_num_iter") == 11, "cum_num_iter is wrong.")
928 self.failUnless(so.getDiagnostics("cum_time") ==33, "cum_time is wrong.")
929 self.failUnless(so.getDiagnostics("cum_set_up_time") == 44, "cum_set_up_time is wrong.")
930
931 so.resetDiagnostics(all=True)
932 self.failUnless(so.getDiagnostics("num_iter") == None, "initial num_iter is wrong.")
933 self.failUnless(so.getDiagnostics("num_inner_iter") == None, "initial num_inner_iter is wrong.")
934 self.failUnless(so.getDiagnostics("time") == None, "initial time is wrong.")
935 self.failUnless(so.getDiagnostics("set_up_time") == None, "initial set_up_time is wrong.")
936 self.failUnless(so.getDiagnostics("residual_norm") == None, "initial residual_norm is wrong.")
937 self.failUnless(so.getDiagnostics("converged") == None, "initial converged is wrong.")
938 self.failUnless(so.hasConverged() == None, "initial convergence flag is wrong.")
939 self.failUnless(so.getDiagnostics("cum_num_inner_iter") == 0, "initial cum_num_inner_iter is wrong.")
940 self.failUnless(so.getDiagnostics("cum_num_iter") == 0, "initial cum_num_iter is wrong.")
941 self.failUnless(so.getDiagnostics("cum_time") ==0, "initial cum_time is wrong.")
942 self.failUnless(so.getDiagnostics("cum_set_up_time") == 0, "initial cum_set_up_time is wrong.")
943
944 def test_setCoefficient_WithIllegalFunctionSpace(self):
945 mypde=LinearPDE(self.domain,debug=self.DEBUG)
946 self.failUnlessRaises(IllegalCoefficientFunctionSpace, mypde.setValue, C=Vector(0.,FunctionOnBoundary(self.domain)))
947
948 def test_setCoefficient_WithWrongName(self):
949 mypde=LinearPDE(self.domain,debug=self.DEBUG)
950 self.failUnlessRaises(IllegalCoefficient, mypde.setValue, ROMA=0.)
951
952 def test_resetCoefficient_WithWrongShape(self):
953 mypde=LinearPDE(self.domain,numEquations=2,debug=self.DEBUG)
954 self.failUnlessRaises(IllegalCoefficientValue, mypde.setValue, C=0.)
955
956 def test_reducedOn(self):
957 mypde=LinearPDE(self.domain,debug=self.DEBUG)
958 x=self.domain.getX()
959 mypde.setReducedOrderOn()
960 mypde.setValue(A=kronecker(self.domain),D=x[0],Y=x[0])
961 u=mypde.getSolution()
962 self.failUnless(self.check(u,1.),'solution is wrong.')
963
964 def test_attemptToChangeOrderAfterDefinedCoefficient(self):
965 mypde=LinearPDE(self.domain,debug=self.DEBUG)
966 mypde.setValue(D=1.)
967 self.failUnlessRaises(RuntimeError, mypde.setReducedOrderOn)
968
969 def test_reducedOnConfig(self):
970 mypde=LinearPDE(self.domain,debug=self.DEBUG)
971 mypde.setReducedOrderOn()
972 self.failUnlessEqual((mypde.getFunctionSpaceForSolution(), mypde.getFunctionSpaceForEquation()),(ReducedSolution(self.domain),ReducedSolution(self.domain)),"reduced function spaces expected.")
973 #
974 # set coefficients for scalars:
975 #
976 def test_setCoefficient_A_Scalar(self):
977 d=self.domain.getDim()
978 mypde=LinearPDE(self.domain,debug=self.DEBUG)
979 mypde.setValue(A=numpy.ones((d,d)))
980 coeff=mypde.getCoefficient("A")
981 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((d,d),Function(self.domain),1,1))
982 def test_setCoefficient_B_Scalar(self):
983 d=self.domain.getDim()
984 mypde=LinearPDE(self.domain,debug=self.DEBUG)
985 mypde.setValue(B=numpy.ones((d,)))
986 coeff=mypde.getCoefficient("B")
987 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((d,),Function(self.domain),1,1))
988 def test_setCoefficient_C_Scalar(self):
989 d=self.domain.getDim()
990 mypde=LinearPDE(self.domain,debug=self.DEBUG)
991 mypde.setValue(C=numpy.ones((d,)))
992 coeff=mypde.getCoefficient("C")
993 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((d,),Function(self.domain),1,1))
994 def test_setCoefficient_D_Scalar(self):
995 d=self.domain.getDim()
996 mypde=LinearPDE(self.domain,debug=self.DEBUG)
997 mypde.setValue(D=1.)
998 coeff=mypde.getCoefficient("D")
999 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((),Function(self.domain),1,1))
1000 def test_setCoefficient_X_Scalar(self):
1001 d=self.domain.getDim()
1002 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1003 mypde.setValue(X=numpy.ones((d,)))
1004 coeff=mypde.getCoefficient("X")
1005 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((d,),Function(self.domain),1))
1006 def test_setCoefficient_Y_Scalar(self):
1007 d=self.domain.getDim()
1008 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1009 mypde.setValue(Y=1.)
1010 coeff=mypde.getCoefficient("Y")
1011 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((),Function(self.domain),1))
1012 def test_setCoefficient_y_Scalar(self):
1013 d=self.domain.getDim()
1014 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1015 mypde.setValue(y=1.)
1016 coeff=mypde.getCoefficient("y")
1017 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((),FunctionOnBoundary(self.domain),1))
1018 def test_setCoefficient_d_Scalar(self):
1019 d=self.domain.getDim()
1020 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1021 mypde.setValue(d=1.)
1022 coeff=mypde.getCoefficient("d")
1023 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((),FunctionOnBoundary(self.domain),1,1))
1024 def test_setCoefficient_d_contact_Scalar(self):
1025 d=self.domain.getDim()
1026 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1027 mypde.setValue(d_contact=1.)
1028 coeff=mypde.getCoefficient("d_contact")
1029 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((),FunctionOnContactZero(self.domain),1,1))
1030 def test_setCoefficient_y_contact_Scalar(self):
1031 d=self.domain.getDim()
1032 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1033 mypde.setValue(y_contact=1.)
1034 coeff=mypde.getCoefficient("y_contact")
1035 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((),FunctionOnContactZero(self.domain),1))
1036 def test_setCoefficient_A_reduced_Scalar(self):
1037 d=self.domain.getDim()
1038 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1039 mypde.setValue(A_reduced=numpy.ones((d,d)))
1040 coeff=mypde.getCoefficient("A_reduced")
1041 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((d,d),ReducedFunction(self.domain),1,1))
1042 def test_setCoefficient_B_reduced_Scalar(self):
1043 d=self.domain.getDim()
1044 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1045 mypde.setValue(B_reduced=numpy.ones((d,)))
1046 coeff=mypde.getCoefficient("B_reduced")
1047 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((d,),ReducedFunction(self.domain),1,1))
1048 def test_setCoefficient_C_reduced_Scalar(self):
1049 d=self.domain.getDim()
1050 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1051 mypde.setValue(C_reduced=numpy.ones((d,)))
1052 coeff=mypde.getCoefficient("C_reduced")
1053 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((d,),ReducedFunction(self.domain),1,1))
1054 def test_setCoefficient_D_reduced_Scalar(self):
1055 d=self.domain.getDim()
1056 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1057 mypde.setValue(D_reduced=1.)
1058 coeff=mypde.getCoefficient("D_reduced")
1059 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((),ReducedFunction(self.domain),1,1))
1060 def test_setCoefficient_X_reduced_Scalar(self):
1061 d=self.domain.getDim()
1062 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1063 mypde.setValue(X_reduced=numpy.ones((d,)))
1064 coeff=mypde.getCoefficient("X_reduced")
1065 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((d,),ReducedFunction(self.domain),1))
1066 def test_setCoefficient_Y_reduced_Scalar(self):
1067 d=self.domain.getDim()
1068 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1069 mypde.setValue(Y_reduced=1.)
1070 coeff=mypde.getCoefficient("Y_reduced")
1071 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((),ReducedFunction(self.domain),1))
1072 def test_setCoefficient_y_reduced_Scalar(self):
1073 d=self.domain.getDim()
1074 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1075 mypde.setValue(y_reduced=1.)
1076 coeff=mypde.getCoefficient("y_reduced")
1077 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((),ReducedFunctionOnBoundary(self.domain),1))
1078 def test_setCoefficient_d_reduced_Scalar(self):
1079 d=self.domain.getDim()
1080 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1081 mypde.setValue(d_reduced=1.)
1082 coeff=mypde.getCoefficient("d_reduced")
1083 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((),ReducedFunctionOnBoundary(self.domain),1,1))
1084 def test_setCoefficient_d_contact_reduced_Scalar(self):
1085 d=self.domain.getDim()
1086 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1087 mypde.setValue(d_contact_reduced=1.)
1088 coeff=mypde.getCoefficient("d_contact_reduced")
1089 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((),ReducedFunctionOnContactZero(self.domain),1,1))
1090 def test_setCoefficient_y_contact_reduced_Scalar(self):
1091 d=self.domain.getDim()
1092 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1093 mypde.setValue(y_contact_reduced=1.)
1094 coeff=mypde.getCoefficient("y_contact_reduced")
1095 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((),ReducedFunctionOnContactZero(self.domain),1))
1096 def test_setCoefficient_r_Scalar(self):
1097 d=self.domain.getDim()
1098 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
1099 mypde.setValue(r=1.)
1100 coeff=mypde.getCoefficient("r")
1101 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions()),((),Solution(self.domain),1))
1102 def test_setCoefficient_q_Scalar(self):
1103 d=self.domain.getDim()
1104 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
1105 mypde.setValue(q=1.)
1106 coeff=mypde.getCoefficient("q")
1107 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions()),((),Solution(self.domain),1))
1108 def test_setCoefficient_r_Scalar_reducedOn(self):
1109 d=self.domain.getDim()
1110 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
1111 mypde.setReducedOrderOn()
1112 mypde.setValue(r=1.)
1113 coeff=mypde.getCoefficient("r")
1114 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions()),((),ReducedSolution(self.domain),1))
1115 def test_setCoefficient_q_Scalar_reducedOn(self):
1116 d=self.domain.getDim()
1117 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
1118 mypde.setReducedOrderOn()
1119 mypde.setValue(q=1.)
1120 coeff=mypde.getCoefficient("q")
1121 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions()),((),ReducedSolution(self.domain),1))
1122
1123 def test_setCoefficient_A_reduced_Scalar_usingA(self):
1124 d=self.domain.getDim()
1125 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1126 mypde.setValue(A=Data(numpy.ones((d,d)),ReducedFunction(self.domain)))
1127 coeff=mypde.getCoefficient("A_reduced")
1128 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((d,d),ReducedFunction(self.domain),1,1))
1129 def test_setCoefficient_B_reduced_Scalar_usingB(self):
1130 d=self.domain.getDim()
1131 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1132 mypde.setValue(B=Data(numpy.ones((d,)),ReducedFunction(self.domain)))
1133 coeff=mypde.getCoefficient("B_reduced")
1134 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((d,),ReducedFunction(self.domain),1,1))
1135 def test_setCoefficient_C_reduced_Scalar_usingC(self):
1136 d=self.domain.getDim()
1137 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1138 mypde.setValue(C=Data(numpy.ones((d,)),ReducedFunction(self.domain)))
1139 coeff=mypde.getCoefficient("C_reduced")
1140 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((d,),ReducedFunction(self.domain),1,1))
1141 def test_setCoefficient_D_reduced_Scalar_usingD(self):
1142 d=self.domain.getDim()
1143 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1144 mypde.setValue(D=Scalar(1.,ReducedFunction(self.domain)))
1145 coeff=mypde.getCoefficient("D_reduced")
1146 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((),ReducedFunction(self.domain),1,1))
1147 def test_setCoefficient_X_reduced_Scalar_usingX(self):
1148 d=self.domain.getDim()
1149 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1150 mypde.setValue(X_reduced=Data(numpy.ones((d,)),ReducedFunction(self.domain)))
1151 coeff=mypde.getCoefficient("X_reduced")
1152 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((d,),ReducedFunction(self.domain),1))
1153 def test_setCoefficient_Y_reduced_Scalar_usingY(self):
1154 d=self.domain.getDim()
1155 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1156 mypde.setValue(Y=Scalar(1.,ReducedFunction(self.domain)))
1157 coeff=mypde.getCoefficient("Y_reduced")
1158 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((),ReducedFunction(self.domain),1))
1159 def test_setCoefficient_y_reduced_Scalar_using_y(self):
1160 d=self.domain.getDim()
1161 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1162 mypde.setValue(y=Scalar(1.,ReducedFunctionOnBoundary(self.domain)))
1163 coeff=mypde.getCoefficient("y_reduced")
1164 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((),ReducedFunctionOnBoundary(self.domain),1))
1165 def test_setCoefficient_d_reduced_Scalar_using_d(self):
1166 d=self.domain.getDim()
1167 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1168 mypde.setValue(d=Scalar(1.,ReducedFunctionOnBoundary(self.domain)))
1169 coeff=mypde.getCoefficient("d_reduced")
1170 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((),ReducedFunctionOnBoundary(self.domain),1,1))
1171 def test_setCoefficient_d_contact_reduced_Scalar_using_d_contact(self):
1172 d=self.domain.getDim()
1173 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1174 mypde.setValue(d_contact=Scalar(1.,ReducedFunctionOnContactZero(self.domain)))
1175 coeff=mypde.getCoefficient("d_contact_reduced")
1176 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((),ReducedFunctionOnContactZero(self.domain),1,1))
1177 def test_setCoefficient_y_contact_reduced_Scalar_using_y_contact(self):
1178 d=self.domain.getDim()
1179 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1180 mypde.setValue(y_contact=Scalar(1.,ReducedFunctionOnContactZero(self.domain)))
1181 coeff=mypde.getCoefficient("y_contact_reduced")
1182 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((),ReducedFunctionOnContactZero(self.domain),1))
1183 #
1184 # set coefficients for systems:
1185 #
1186 def test_setCoefficient_A_System(self):
1187 d=self.domain.getDim()
1188 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1189 mypde.setValue(A=numpy.ones((self.N,d,self.N,d)))
1190 coeff=mypde.getCoefficient("A")
1191 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,d,self.N,d),Function(self.domain),self.N,self.N))
1192 def test_setCoefficient_B_System(self):
1193 d=self.domain.getDim()
1194 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1195 mypde.setValue(B=numpy.ones((self.N,d,self.N)))
1196 coeff=mypde.getCoefficient("B")
1197 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,d,self.N),Function(self.domain),self.N,self.N))
1198 def test_setCoefficient_C_System(self):
1199 d=self.domain.getDim()
1200 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1201 mypde.setValue(C=numpy.ones((self.N,self.N,d)))
1202 coeff=mypde.getCoefficient("C")
1203 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N,d),Function(self.domain),self.N,self.N))
1204 def test_setCoefficient_D_System(self):
1205 d=self.domain.getDim()
1206 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1207 mypde.setValue(D=numpy.ones((self.N,self.N)))
1208 coeff=mypde.getCoefficient("D")
1209 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N),Function(self.domain),self.N,self.N))
1210 def test_setCoefficient_X_System(self):
1211 d=self.domain.getDim()
1212 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1213 mypde.setValue(X=numpy.ones((self.N,d)))
1214 coeff=mypde.getCoefficient("X")
1215 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,d),Function(self.domain),self.N))
1216 def test_setCoefficient_Y_System(self):
1217 d=self.domain.getDim()
1218 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1219 mypde.setValue(Y=numpy.ones((self.N,)))
1220 coeff=mypde.getCoefficient("Y")
1221 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,),Function(self.domain),self.N))
1222 def test_setCoefficient_y_System(self):
1223 d=self.domain.getDim()
1224 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1225 mypde.setValue(y=numpy.ones((self.N,)))
1226 coeff=mypde.getCoefficient("y")
1227 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,),FunctionOnBoundary(self.domain),self.N))
1228 def test_setCoefficient_d_System(self):
1229 d=self.domain.getDim()
1230 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1231 mypde.setValue(d=numpy.ones((self.N,self.N)))
1232 coeff=mypde.getCoefficient("d")
1233 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N),FunctionOnBoundary(self.domain),self.N,self.N))
1234 def test_setCoefficient_d_contact_System(self):
1235 d=self.domain.getDim()
1236 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1237 mypde.setValue(d_contact=numpy.ones((self.N,self.N)))
1238 coeff=mypde.getCoefficient("d_contact")
1239 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N),FunctionOnContactZero(self.domain),self.N,self.N))
1240 def test_setCoefficient_y_contact_System(self):
1241 d=self.domain.getDim()
1242 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1243 mypde.setValue(y_contact=numpy.ones((self.N,)))
1244 coeff=mypde.getCoefficient("y_contact")
1245 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,),FunctionOnContactZero(self.domain),self.N))
1246 def test_setCoefficient_A_reduced_System(self):
1247 d=self.domain.getDim()
1248 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1249 mypde.setValue(A_reduced=numpy.ones((self.N,d,self.N,d)))
1250 coeff=mypde.getCoefficient("A_reduced")
1251 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,d,self.N,d),ReducedFunction(self.domain),self.N,self.N))
1252 def test_setCoefficient_B_reduced_System(self):
1253 d=self.domain.getDim()
1254 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1255 mypde.setValue(B_reduced=numpy.ones((self.N,d,self.N)))
1256 coeff=mypde.getCoefficient("B_reduced")
1257 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,d,self.N),ReducedFunction(self.domain),self.N,self.N))
1258 def test_setCoefficient_C_reduced_System(self):
1259 d=self.domain.getDim()
1260 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1261 mypde.setValue(C_reduced=numpy.ones((self.N,self.N,d)))
1262 coeff=mypde.getCoefficient("C_reduced")
1263 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N,d),ReducedFunction(self.domain),self.N,self.N))
1264 def test_setCoefficient_D_System_reduced(self):
1265 d=self.domain.getDim()
1266 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1267 mypde.setValue(D_reduced=numpy.ones((self.N,self.N)))
1268 coeff=mypde.getCoefficient("D_reduced")
1269 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N),ReducedFunction(self.domain),self.N,self.N))
1270 def test_setCoefficient_X_System_reduced(self):
1271 d=self.domain.getDim()
1272 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1273 mypde.setValue(X_reduced=numpy.ones((self.N,d)))
1274 coeff=mypde.getCoefficient("X_reduced")
1275 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,d),ReducedFunction(self.domain),self.N))
1276 def test_setCoefficient_Y_System_reduced(self):
1277 d=self.domain.getDim()
1278 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1279 mypde.setValue(Y_reduced=numpy.ones((self.N,)))
1280 coeff=mypde.getCoefficient("Y_reduced")
1281 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,),ReducedFunction(self.domain),self.N))
1282 def test_setCoefficient_y_System_reduced(self):
1283 d=self.domain.getDim()
1284 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1285 mypde.setValue(y_reduced=numpy.ones((self.N,)))
1286 coeff=mypde.getCoefficient("y_reduced")
1287 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,),ReducedFunctionOnBoundary(self.domain),self.N))
1288 def test_setCoefficient_d_reduced_System(self):
1289 d=self.domain.getDim()
1290 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1291 mypde.setValue(d_reduced=numpy.ones((self.N,self.N)))
1292 coeff=mypde.getCoefficient("d_reduced")
1293 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N),ReducedFunctionOnBoundary(self.domain),self.N,self.N))
1294 def test_setCoefficient_d_contact_reduced_System(self):
1295 d=self.domain.getDim()
1296 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1297 mypde.setValue(d_contact_reduced=numpy.ones((self.N,self.N)))
1298 coeff=mypde.getCoefficient("d_contact_reduced")
1299 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N),ReducedFunctionOnContactZero(self.domain),self.N,self.N))
1300 def test_setCoefficient_y_contact_reduced_System(self):
1301 d=self.domain.getDim()
1302 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1303 mypde.setValue(y_contact_reduced=numpy.ones((self.N,)))
1304 coeff=mypde.getCoefficient("y_contact_reduced")
1305 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,),ReducedFunctionOnContactZero(self.domain),self.N))
1306 def test_setCoefficient_r_System(self):
1307 d=self.domain.getDim()
1308 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
1309 mypde.setValue(r=numpy.ones((self.N,)))
1310 coeff=mypde.getCoefficient("r")
1311 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions()),((self.N,),Solution(self.domain),self.N))
1312 def test_setCoefficient_q_System(self):
1313 d=self.domain.getDim()
1314 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
1315 mypde.setValue(q=numpy.ones((self.N,)))
1316 coeff=mypde.getCoefficient("q")
1317 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions()),((self.N,),Solution(self.domain),self.N))
1318 def test_setCoefficient_r_System_reducedOn(self):
1319 d=self.domain.getDim()
1320 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
1321 mypde.setReducedOrderOn()
1322 mypde.setValue(r=numpy.ones((self.N,)))
1323 coeff=mypde.getCoefficient("r")
1324 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions()),((self.N,),ReducedSolution(self.domain),self.N))
1325 def test_setCoefficient_q_System_reducedOn(self):
1326 d=self.domain.getDim()
1327 mypde=LinearPDE(self.domain,numEquations=3,debug=self.DEBUG)
1328 mypde.setReducedOrderOn()
1329 mypde.setValue(q=numpy.ones((self.N,)))
1330 coeff=mypde.getCoefficient("q")
1331 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions()),((self.N,),ReducedSolution(self.domain),self.N))
1332
1333 def test_setCoefficient_A_reduced_System_using_A(self):
1334 d=self.domain.getDim()
1335 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1336 mypde.setValue(A=Data(numpy.ones((self.N,d,self.N,d)),ReducedFunction(self.domain)))
1337 coeff=mypde.getCoefficient("A_reduced")
1338 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,d,self.N,d),ReducedFunction(self.domain),self.N,self.N))
1339 def test_setCoefficient_B_reduced_System_using_B(self):
1340 d=self.domain.getDim()
1341 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1342 mypde.setValue(B=Data(numpy.ones((self.N,d,self.N)),ReducedFunction(self.domain)))
1343 coeff=mypde.getCoefficient("B_reduced")
1344 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,d,self.N),ReducedFunction(self.domain),self.N,self.N))
1345 def test_setCoefficient_C_reduced_System_using_C(self):
1346 d=self.domain.getDim()
1347 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1348 mypde.setValue(C=Data(numpy.ones((self.N,self.N,d)),ReducedFunction(self.domain)))
1349 coeff=mypde.getCoefficient("C_reduced")
1350 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N,d),ReducedFunction(self.domain),self.N,self.N))
1351 def test_setCoefficient_D_System_reduced_using_D(self):
1352 d=self.domain.getDim()
1353 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1354 mypde.setValue(D=Data(numpy.ones((self.N,self.N)),ReducedFunction(self.domain)))
1355 coeff=mypde.getCoefficient("D_reduced")
1356 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N),ReducedFunction(self.domain),self.N,self.N))
1357 def test_setCoefficient_X_System_reduced_using_X(self):
1358 d=self.domain.getDim()
1359 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1360 mypde.setValue(X=Data(numpy.ones((self.N,d)),ReducedFunction(self.domain)))
1361 coeff=mypde.getCoefficient("X_reduced")
1362 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,d),ReducedFunction(self.domain),self.N))
1363 def test_setCoefficient_Y_System_reduced_using_Y(self):
1364 d=self.domain.getDim()
1365 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1366 mypde.setValue(Y=Data(numpy.ones((self.N,)),ReducedFunction(self.domain)))
1367 coeff=mypde.getCoefficient("Y_reduced")
1368 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,),ReducedFunction(self.domain),self.N))
1369 def test_setCoefficient_y_reduced_System_using_y(self):
1370 d=self.domain.getDim()
1371 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1372 mypde.setValue(y=Data(numpy.ones((self.N,)),ReducedFunctionOnBoundary(self.domain)))
1373 coeff=mypde.getCoefficient("y_reduced")
1374 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,),ReducedFunctionOnBoundary(self.domain),self.N))
1375 def test_setCoefficient_d_reduced_System_using_d(self):
1376 d=self.domain.getDim()
1377 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1378 mypde.setValue(d=Data(numpy.ones((self.N,self.N)),ReducedFunctionOnBoundary(self.domain)))
1379 coeff=mypde.getCoefficient("d_reduced")
1380 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N),ReducedFunctionOnBoundary(self.domain),self.N,self.N))
1381 def test_setCoefficient_d_contact_reduced_System_using_d_contact(self):
1382 d=self.domain.getDim()
1383 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1384 mypde.setValue(d_contact=Data(numpy.ones((self.N,self.N)),ReducedFunctionOnContactZero(self.domain)))
1385 coeff=mypde.getCoefficient("d_contact_reduced")
1386 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumSolutions(), mypde.getNumEquations()),((self.N,self.N),ReducedFunctionOnContactZero(self.domain),self.N,self.N))
1387 def test_setCoefficient_y_contact_reduced_System_using_y_contact(self):
1388 d=self.domain.getDim()
1389 mypde=LinearPDE(self.domain,numSolutions=3,debug=self.DEBUG)
1390 mypde.setValue(y_contact=Data(numpy.ones((self.N,)),ReducedFunctionOnContactZero(self.domain)))
1391 coeff=mypde.getCoefficient("y_contact_reduced")
1392 self.failUnlessEqual((coeff.getShape(),coeff.getFunctionSpace(), mypde.getNumEquations()),((self.N,),ReducedFunctionOnContactZero(self.domain),self.N))
1393 def test_resetCoefficient_HomogeneousConstraint(self):
1394 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1395 x=self.domain.getX()
1396 mypde.setValue(A=kronecker(self.domain),Y=1.,q=whereZero(x[0]))
1397 u1=mypde.getSolution()
1398 mypde.setValue(Y=2.)
1399 u2=mypde.getSolution()
1400 self.failUnless(self.check(u2,2*u1),'solution is wrong.')
1401
1402 def test_resetCoefficient_InHomogeneousConstraint(self):
1403 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1404 mypde.setSymmetryOn()
1405 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1406 x=self.domain.getX()
1407 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.,r=1,q=whereZero(x[0]))
1408 u1=mypde.getSolution()
1409 mypde.setValue(Y=2.,D=2)
1410 u2=mypde.getSolution()
1411 self.failUnless(self.check(u2,u1),'first solution is wrong.')
1412 u2=mypde.getSolution()
1413 self.failUnless(self.check(u2,u1),'first solution is wrong.')
1414 mypde.setValue(r=2,Y=4.)
1415 u2=mypde.getSolution()
1416 self.failUnless(self.check(u2,2*u1),'second solution is wrong.')
1417
1418 def test_Status(self):
1419 DIM=self.domain.getDim()
1420 x=self.domain.getX()
1421 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1422 mypde.getSolverOptions().setSymmetryOn()
1423 mypde.getSolverOptions().setTolerance(self.RES_TOL)
1424 mypde.setValue(A=kronecker(self.domain), q=whereZero(x[0])+whereZero(x[0]-1.), Y=2.)
1425 x1=self.domain.getX()
1426 u1_ref=x1[0]*(1.-x1[0])
1427 u1=mypde.getSolution()
1428 error1=Lsup(u1-u1_ref)/Lsup(u1_ref)
1429 self.failUnless(mypde.getDomainStatus() == mypde.getSystemStatus(), "status of first pde does not match domain status.")
1430
1431 self.domain.setX(x*5)
1432
1433 self.failUnless(mypde.getDomainStatus() != mypde.getSystemStatus(), "status of first pde matches updated domain status.")
1434 x2=self.domain.getX()
1435 u2_ref=x2[0]*(5.-x2[0])
1436 u2=mypde.getSolution()
1437 error2=Lsup(u2-u2_ref)/Lsup(u2_ref)
1438 self.failUnless(error2 <= max(error1,self.RES_TOL)*10., "solution of second PDE wrong.")
1439 self.failUnless(mypde.getDomainStatus() == mypde.getSystemStatus(), "status of second pde does not match domain status.")
1440
1441 def test_symmetryCheckTrue_System(self):
1442 d=self.domain.getDim()
1443 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1444 A=numpy.ones((self.N,d,self.N,d))
1445 C=2*numpy.ones((self.N,self.N,d))
1446 B=2*numpy.ones((self.N,d,self.N))
1447 D=3*numpy.ones((self.N,self.N))
1448 d=4*numpy.ones((self.N,self.N))
1449 d_contact=5*numpy.ones((self.N,self.N))
1450 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)
1451 self.failUnless(mypde.checkSymmetry(verbose=False),"symmetry detected")
1452
1453 def test_symmetryCheckFalse_A_System(self):
1454 d=self.domain.getDim()
1455 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1456 A=numpy.ones((self.N,d,self.N,d))
1457 A[1,1,1,0]=0.
1458 mypde.setValue(A=A)
1459 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1460 def test_symmetryCheckFalse_BC_System(self):
1461 d=self.domain.getDim()
1462 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1463 C=2*numpy.ones((self.N,self.N,d))
1464 B=2*numpy.ones((self.N,d,self.N))
1465 B[0,0,1]=1.
1466 mypde.setValue(B=B,C=C)
1467 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1468
1469 def test_symmetryCheckFalse_D_System(self):
1470 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1471 D=3*numpy.ones((self.N,self.N))
1472 D[0,1]=0.
1473 mypde.setValue(D=D)
1474 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1475
1476 def test_symmetryCheckFalse_d_System(self):
1477 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1478 d=4*numpy.ones((self.N,self.N))
1479 d[0,1]=0.
1480 mypde.setValue(d=d)
1481 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1482
1483 def test_symmetryCheckFalse_d_contact_System(self):
1484 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1485 d_contact=5*numpy.ones((self.N,self.N))
1486 d_contact[0,1]=0.
1487 mypde.setValue(d_contact=d_contact)
1488 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1489
1490 def test_symmetryCheckFalse_A_reduced_System(self):
1491 d=self.domain.getDim()
1492 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1493 A=numpy.ones((self.N,d,self.N,d))
1494 A[1,1,1,0]=0.
1495 mypde.setValue(A_reduced=A)
1496 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1497 def test_symmetryCheckFalse_BC_reduced_System(self):
1498 d=self.domain.getDim()
1499 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1500 C=2*numpy.ones((self.N,self.N,d))
1501 B=2*numpy.ones((self.N,d,self.N))
1502 B[0,0,1]=1.
1503 mypde.setValue(B_reduced=B,C_reduced=C)
1504 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1505
1506 def test_symmetryCheckFalse_D_reduced_System(self):
1507 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1508 D=3*numpy.ones((self.N,self.N))
1509 D[0,1]=0.
1510 mypde.setValue(D_reduced=D)
1511 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1512
1513 def test_symmetryCheckFalse_d_reduced_System(self):
1514 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1515 d=4*numpy.ones((self.N,self.N))
1516 d[0,1]=0.
1517 mypde.setValue(d_reduced=d)
1518 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1519
1520 def test_symmetryCheckFalse_d_contact_reduced_System(self):
1521 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1522 d_contact=5*numpy.ones((self.N,self.N))
1523 d_contact[0,1]=0.
1524 mypde.setValue(d_contact_reduced=d_contact)
1525 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1526
1527 def test_symmetryCheckTrue_Scalar(self):
1528 d=self.domain.getDim()
1529 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1530 A=numpy.ones((d,d))
1531 C=2*numpy.ones((d,))
1532 B=2*numpy.ones((d,))
1533 D=3
1534 d=4
1535 d_contact=5
1536 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)
1537 self.failUnless(mypde.checkSymmetry(verbose=False),"symmetry detected")
1538
1539 def test_symmetryCheckFalse_A_Scalar(self):
1540 d=self.domain.getDim()
1541 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1542 A=numpy.ones((d,d))
1543 A[1,0]=0.
1544 mypde.setValue(A=A)
1545 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1546 def test_symmetryCheckFalse_BC_Scalar(self):
1547 d=self.domain.getDim()
1548 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1549 C=2*numpy.ones((d,))
1550 B=2*numpy.ones((d,))
1551 B[0]=1.
1552 mypde.setValue(B=B,C=C)
1553 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1554 def test_symmetryCheckFalse_A_reduced_Scalar(self):
1555 d=self.domain.getDim()
1556 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1557 A=numpy.ones((d,d))
1558 A[1,0]=0.
1559 mypde.setValue(A_reduced=A)
1560 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1561 def test_symmetryCheckFalse_BC_reduced_Scalar(self):
1562 d=self.domain.getDim()
1563 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1564 C=2*numpy.ones((d,))
1565 B=2*numpy.ones((d,))
1566 B[0]=1.
1567 mypde.setValue(B_reduced=B,C_reduced=C)
1568 self.failUnless(not mypde.checkSymmetry(verbose=False),"symmetry detected")
1569 #
1570 # solver checks (single PDE)
1571 #
1572 def test_symmetryOnIterative(self):
1573 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1574 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1575 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1576 u=mypde.getSolution()
1577 self.failUnless(self.check(u,1.),'solution is wrong.')
1578 def test_symmetryOnDirect(self):
1579 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1580 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1581 mypde.getSolverOptions().setSolverMethod(SolverOptions.DIRECT)
1582 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1583 u=mypde.getSolution()
1584 self.failUnless(self.check(u,1.),'solution is wrong.')
1585 def test_PCG_JACOBI(self):
1586 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1587 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1588 mypde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
1589 mypde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
1590 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1591 u=mypde.getSolution()
1592 self.failUnless(self.check(u,1.),'solution is wrong.')
1593 def test_PCG_GAUSS_SEIDEL(self):
1594 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1595 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1596 mypde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
1597 mypde.getSolverOptions().setPreconditioner(SolverOptions.GAUSS_SEIDEL)
1598 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1599 u=mypde.getSolution()
1600 self.failUnless(self.check(u,1.),'solution is wrong.')
1601 def test_PCG_AMG(self):
1602 if self.order!=2:
1603 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1604 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1605 mypde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
1606 mypde.getSolverOptions().setPreconditioner(SolverOptions.AMG)
1607 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1608 u=mypde.getSolution()
1609 self.failUnless(self.check(u,1.),'solution is wrong.')
1610 def test_PCG_ILU0(self):
1611 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1612 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1613 mypde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
1614 mypde.getSolverOptions().setPreconditioner(SolverOptions.ILU0)
1615 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1616 u=mypde.getSolution()
1617 self.failUnless(self.check(u,1.),'solution is wrong.')
1618 def test_PCG_RILU(self):
1619 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1620 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1621 mypde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
1622 mypde.getSolverOptions().setPreconditioner(SolverOptions.RILU)
1623 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1624 u=mypde.getSolution()
1625 self.failUnless(self.check(u,1.),'solution is wrong.')
1626 def test_PCG_REC_ILU(self):
1627 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1628 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1629 mypde.getSolverOptions().setSolverMethod(SolverOptions.PCG)
1630 mypde.getSolverOptions().setPreconditioner(SolverOptions.REC_ILU)
1631 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1632 u=mypde.getSolution()
1633 self.failUnless(self.check(u,1.),'solution is wrong.')
1634 def test_DIRECT(self):
1635 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1636 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1637 mypde.getSolverOptions().setSolverMethod(SolverOptions.DIRECT)
1638 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1639 u=mypde.getSolution()
1640 self.failUnless(self.check(u,1.),'solution is wrong.')
1641 def test_BICGSTAB_JACOBI(self):
1642 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1643 mypde.getSolverOptions().setSolverMethod(SolverOptions.BICGSTAB)
1644 mypde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
1645 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1646 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1647 u=mypde.getSolution()
1648 self.failUnless(self.check(u,1.),'solution is wrong.')
1649 def test_BICGSTAB_GAUSS_SEIDEL(self):
1650 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1651 mypde.getSolverOptions().setSolverMethod(SolverOptions.BICGSTAB)
1652 mypde.getSolverOptions().setPreconditioner(SolverOptions.GAUSS_SEIDEL)
1653 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1654 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1655 u=mypde.getSolution()
1656 self.failUnless(self.check(u,1.),'solution is wrong.')
1657 def test_BICGSTAB_AMG(self):
1658 if self.order!=2:
1659 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1660 mypde.getSolverOptions().setSolverMethod(SolverOptions.BICGSTAB)
1661 mypde.getSolverOptions().setPreconditioner(SolverOptions.AMG)
1662 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1663 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1664 u=mypde.getSolution()
1665 self.failUnless(self.check(u,1.),'solution is wrong.')
1666 def test_BICGSTAB_ILU0(self):
1667 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1668 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1669 mypde.getSolverOptions().setSolverMethod(SolverOptions.BICGSTAB)
1670 mypde.getSolverOptions().setPreconditioner(SolverOptions.ILU0)
1671 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1672 u=mypde.getSolution()
1673 self.failUnless(self.check(u,1.),'solution is wrong.')
1674 def test_BICGSTAB_RILU(self):
1675 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1676 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1677 mypde.getSolverOptions().setSolverMethod(SolverOptions.BICGSTAB)
1678 mypde.getSolverOptions().setPreconditioner(SolverOptions.RILU)
1679 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1680 u=mypde.getSolution()
1681 self.failUnless(self.check(u,1.),'solution is wrong.')
1682 def test_BICGSTAB_REC_ILU(self):
1683 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1684 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1685 mypde.getSolverOptions().setSolverMethod(SolverOptions.BICGSTAB)
1686 mypde.getSolverOptions().setPreconditioner(SolverOptions.REC_ILU)
1687 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1688 u=mypde.getSolution()
1689 self.failUnless(self.check(u,1.),'solution is wrong.')
1690 def test_MINRES_JACOBI(self):
1691 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1692 mypde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
1693 mypde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
1694 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1695 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1696 u=mypde.getSolution()
1697 self.failUnless(self.check(u,1.),'solution is wrong.')
1698 def test_MINRES_GAUSS_SEIDEL(self):
1699 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1700 mypde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
1701 mypde.getSolverOptions().setPreconditioner(SolverOptions.GAUSS_SEIDEL)
1702 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1703 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1704 u=mypde.getSolution()
1705 self.failUnless(self.check(u,1.),'solution is wrong.')
1706 def test_MINRES_AMG(self):
1707 if self.order!=2:
1708 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1709 mypde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
1710 mypde.getSolverOptions().setPreconditioner(SolverOptions.AMG)
1711 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1712 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1713 u=mypde.getSolution()
1714 self.failUnless(self.check(u,1.),'solution is wrong.')
1715 def test_MINRES_ILU0(self):
1716 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1717 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1718 mypde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
1719 mypde.getSolverOptions().setPreconditioner(SolverOptions.ILU0)
1720 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1721 u=mypde.getSolution()
1722 self.failUnless(self.check(u,1.),'solution is wrong.')
1723 def test_MINRES_RILU(self):
1724 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1725 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1726 mypde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
1727 mypde.getSolverOptions().setPreconditioner(SolverOptions.RILU)
1728 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1729 u=mypde.getSolution()
1730 self.failUnless(self.check(u,1.),'solution is wrong.')
1731 def test_MINRES_REC_ILU(self):
1732 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1733 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1734 mypde.getSolverOptions().setSolverMethod(SolverOptions.MINRES)
1735 mypde.getSolverOptions().setPreconditioner(SolverOptions.REC_ILU)
1736 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1737 u=mypde.getSolution()
1738 self.failUnless(self.check(u,1.),'solution is wrong.')
1739 def test_TFQMR_JACOBI(self):
1740 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1741 mypde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)
1742 mypde.getSolverOptions().setPreconditioner(SolverOptions.JACOBI)
1743 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1744 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1745 u=mypde.getSolution()
1746 self.failUnless(self.check(u,1.),'solution is wrong.')
1747 def test_TFQMR_GAUSS_SEIDEL(self):
1748 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1749 mypde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)
1750 mypde.getSolverOptions().setPreconditioner(SolverOptions.GAUSS_SEIDEL)
1751 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1752 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1753 u=mypde.getSolution()
1754 self.failUnless(self.check(u,1.),'solution is wrong.')
1755 def test_TFQMR_AMG(self):
1756 if self.order!=2:
1757 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1758 mypde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)
1759 mypde.getSolverOptions().setPreconditioner(SolverOptions.AMG)
1760 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1761 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1762 u=mypde.getSolution()
1763 self.failUnless(self.check(u,1.),'solution is wrong.')
1764 def test_TFQMR_ILU0(self):
1765 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1766 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1767 mypde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)
1768 mypde.getSolverOptions().setPreconditioner(SolverOptions.ILU0)
1769 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1770 u=mypde.getSolution()
1771 self.failUnless(self.check(u,1.),'solution is wrong.')
1772 def test_TFQMR_RILU(self):
1773 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1774 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1775 mypde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)
1776 mypde.getSolverOptions().setPreconditioner(SolverOptions.RILU)
1777 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1778 u=mypde.getSolution()
1779 self.failUnless(self.check(u,1.),'solution is wrong.')
1780 def test_TFQMR_REC_ILU(self):
1781 mypde=LinearPDE(self.domain,debug=self.DEBUG)
1782 mypde.setValue(A=kronecker(self.domain),D=1.,Y=1.)
1783 mypde.getSolverOptions().setSolverMethod(SolverOptions.TFQMR)
1784 mypde.getSolverOptions().setPreconditioner(SolverOptions.REC_ILU)
1785 mypde.getSolverOptions().setVerbosity(self.VERBOSE)
1786 u=mypde.getSolution()
1787 self.failUnless(self.check(u,1.),'solution is wrong.'