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

Diff of /trunk/escript/test/python/test_linearPDEs.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1861 by gross, Wed Oct 8 04:20:07 2008 UTC revision 2344 by jfenwick, Mon Mar 30 02:13:58 2009 UTC
# Line 17  http://www.uq.edu.au/esscc Line 17  http://www.uq.edu.au/esscc
17  Primary Business: Queensland, Australia"""  Primary Business: Queensland, Australia"""
18  __license__="""Licensed under the Open Software License version 3.0  __license__="""Licensed under the Open Software License version 3.0
19  http://www.opensource.org/licenses/osl-3.0.php"""  http://www.opensource.org/licenses/osl-3.0.php"""
20  __url__="http://www.uq.edu.au/esscc/escript-finley"  __url__="https://launchpad.net/escript-finley"
21    
22  """  """
23  Test suite for linearPDEs class  Test suite for linearPDEs class
# Line 44  The tests must be linked with a Domain c Line 44  The tests must be linked with a Domain c
44    
45  __author__="Lutz Gross, l.gross@uq.edu.au"  __author__="Lutz Gross, l.gross@uq.edu.au"
46    
47  from esys.escript.util import Lsup,kronecker,interpolate,whereZero  from esys.escript.util import Lsup,kronecker,interpolate,whereZero, outer, swap_axes
48  from esys.escript import Function,FunctionOnBoundary,FunctionOnContactZero,Solution,ReducedSolution,Vector,ContinuousFunction,Scalar, ReducedFunction,ReducedFunctionOnBoundary,ReducedFunctionOnContactZero,Data, Tensor4, Tensor  from esys.escript import Function,FunctionOnBoundary,FunctionOnContactZero,Solution,ReducedSolution,Vector,ContinuousFunction,Scalar, ReducedFunction,ReducedFunctionOnBoundary,ReducedFunctionOnContactZero,Data, Tensor4, Tensor
49  from esys.escript.linearPDEs import LinearPDE,IllegalCoefficientValue,Poisson, IllegalCoefficientFunctionSpace, TransportPDE, IllegalCoefficient  from esys.escript.linearPDEs import LinearPDE,IllegalCoefficientValue,Poisson, IllegalCoefficientFunctionSpace, TransportPDE, IllegalCoefficient, Helmholtz, LameEquation
50  import numarray  import numarray
51  import unittest  import unittest
52    
# Line 62  class Test_linearPDEs(unittest.TestCase) Line 62  class Test_linearPDEs(unittest.TestCase)
62          if tol==None: tol=self.TOL          if tol==None: tol=self.TOL
63          return Lsup(arg-ref_arg)<=tol*Lsup(ref_arg)          return Lsup(arg-ref_arg)<=tol*Lsup(ref_arg)
64            
65    class Test_LameEquation(Test_linearPDEs):
66    
67        def test_config(self):
68            mypde=LameEquation(self.domain,debug=self.DEBUG)
69            d=self.domain.getDim()
70            self.failUnlessEqual((mypde.getNumEquations(),mypde.getNumSolutions(),mypde.isSymmetric()),(d,d,True),"set up incorrect")
71    
72        def test_setCoefficient_q(self):
73            mypde=LameEquation(self.domain,debug=self.DEBUG)
74            x=self.domain.getX()
75            mypde.setValue(q=x)
76    
77            q_ref=interpolate(x,Solution(self.domain))
78            self.failUnless(self.check(mypde.getCoefficient("A"),0),"A is not 0")
79            self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
80            self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
81            self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
82            self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
83            self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
84            self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
85            self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
86            self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
87            self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
88            self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
89            self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
90            self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
91            self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
92            self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
93            self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
94            self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
95            self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
96            self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
97            self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
98            self.failUnless(self.check(mypde.getCoefficient("q"),q_ref),"q is not empty")
99            self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
100    
101        def test_setCoefficient_r(self):
102            mypde=LameEquation(self.domain,debug=self.DEBUG)
103            x=self.domain.getX()
104            mypde.setValue(r=x)
105    
106            r_ref=interpolate(x,Solution(self.domain))
107            self.failUnless(self.check(mypde.getCoefficient("A"),0),"A is not 0")
108            self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
109            self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
110            self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
111            self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
112            self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
113            self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
114            self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
115            self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
116            self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
117            self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
118            self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
119            self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
120            self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
121            self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
122            self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
123            self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
124            self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
125            self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
126            self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
127            self.failUnless(self.check(mypde.getCoefficient("r"),r_ref),"r is nor x")
128            self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
129    
130    
131        def test_setCoefficient_F(self):
132            mypde=LameEquation(self.domain,debug=self.DEBUG)
133            x=self.domain.getX()
134            mypde.setValue(F=x)
135    
136            Y_ref=interpolate(x,Function(self.domain))
137            self.failUnless(self.check(mypde.getCoefficient("A"),0),"A is not 0")
138            self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
139            self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
140            self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
141            self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
142            self.failUnless(self.check(mypde.getCoefficient("Y"),Y_ref),"Y is not x")
143            self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
144            self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
145            self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
146            self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
147            self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
148            self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
149            self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
150            self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
151            self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
152            self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
153            self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
154            self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
155            self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
156            self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
157            self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
158            self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
159    
160        def test_setCoefficient_f(self):
161            mypde=LameEquation(self.domain,debug=self.DEBUG)
162            x=self.domain.getX()
163            mypde.setValue(f=x)
164    
165            y_ref=interpolate(x,FunctionOnBoundary(self.domain))
166            self.failUnless(self.check(mypde.getCoefficient("A"),0),"A is not 0")
167            self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
168            self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
169            self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
170            self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
171            self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
172            self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
173            self.failUnless(self.check(mypde.getCoefficient("y"),y_ref),"d is not x[0]")
174            self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
175            self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
176            self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
177            self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
178            self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
179            self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
180            self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
181            self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"X_reduced is not empty")
182            self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
183            self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
184            self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
185            self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
186            self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
187            self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
188    
189        def test_setCoefficient_sigma(self):
190            mypde=LameEquation(self.domain,debug=self.DEBUG)
191            x=self.domain.getX()
192            mypde.setValue(sigma=outer(x,x))
193    
194            X_ref=interpolate(outer(x,x),Function(self.domain))
195            self.failUnless(self.check(mypde.getCoefficient("A"),0),"A is not 0")
196            self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
197            self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
198            self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
199            self.failUnless(self.check(mypde.getCoefficient("X"),X_ref),"X is not x X x")
200            self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
201            self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
202            self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
203            self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
204            self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
205            self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
206            self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
207            self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
208            self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
209            self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
210            self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"X_reduced is not empty")
211            self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
212            self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
213            self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
214            self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
215            self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
216            self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
217    
218        def test_setCoefficient_lambda(self):
219            mypde=LameEquation(self.domain,debug=self.DEBUG)
220            x=self.domain.getX()
221            mypde.setValue(lame_lambda=x[0])
222    
223    
224            k3=kronecker(Function(self.domain))
225            k3Xk3=outer(k3,k3)
226            A_ref=x[0]*k3Xk3
227    
228            self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
229            self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
230            self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
231            self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
232            self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
233            self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
234            self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
235            self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
236            self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
237            self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
238            self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
239            self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
240            self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
241            self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
242            self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
243            self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
244            self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
245            self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
246            self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
247            self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
248            self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
249            self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
250    
251        def test_setCoefficient_mu(self):
252            mypde=LameEquation(self.domain,debug=self.DEBUG)
253            x=self.domain.getX()
254            mypde.setValue(lame_mu=x[0])
255    
256    
257            k3=kronecker(Function(self.domain))
258            k3Xk3=outer(k3,k3)
259            A_ref=x[0]*(swap_axes(k3Xk3,0,3)+swap_axes(k3Xk3,1,3))
260    
261            self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
262            self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
263            self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
264            self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
265            self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
266            self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
267            self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
268            self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
269            self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
270            self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
271            self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
272            self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
273            self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
274            self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
275            self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
276            self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
277            self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
278            self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
279            self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
280            self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
281            self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
282            self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
283    
284        def test_setCoefficient_lambdamu(self):
285            mypde=LameEquation(self.domain,debug=self.DEBUG)
286            x=self.domain.getX()
287            mypde.setValue(lame_lambda=x[0], lame_mu=x[1])
288    
289            k3=kronecker(Function(self.domain))
290            k3Xk3=outer(k3,k3)
291            A_ref=x[0]*k3Xk3+x[1]*(swap_axes(k3Xk3,0,3)+swap_axes(k3Xk3,1,3))
292    
293            self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
294            self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
295            self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
296            self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
297            self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
298            self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
299            self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
300            self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
301            self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
302            self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
303            self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
304            self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
305            self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
306            self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
307            self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
308            self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
309            self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
310            self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
311            self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
312            self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
313            self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
314            self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
315    
316        def test_solve(self):
317           d=self.domain.getDim()
318           mypde=LameEquation(self.domain)
319           cf=ContinuousFunction(self.domain)
320           x=cf.getX()
321           u_ex=x
322           msk=Vector(0.,cf)
323           for i in range(d): msk[i]=whereZero(x[i])
324           mypde.setValue(q=msk,r=u_ex,lame_mu=3,lame_lambda=50,f=(2*3+50*d)*FunctionOnBoundary(self.domain).getNormal())
325    
326           u=mypde.getSolution()
327           self.failUnless(self.check(u,u_ex,10*self.TOL),"incorrect solution")
328    
329    class Test_Helmholtz(Test_linearPDEs):
330    
331        def test_config(self):
332            mypde=Helmholtz(self.domain,debug=self.DEBUG)
333            self.failUnlessEqual((mypde.getNumEquations(),mypde.getNumSolutions(),mypde.isSymmetric()),(1,1,True),"set up incorrect")
334        def test_setCoefficient_q(self):
335            mypde=Helmholtz(self.domain,debug=self.DEBUG)
336            x=self.domain.getX()
337            mypde.setValue(q=whereZero(x[0]))
338    
339            q_ref=interpolate(whereZero(x[0]),Solution(self.domain))
340            A_ref=kronecker(self.domain)
341    
342            self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
343            self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
344            self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
345            self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
346            self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
347            self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
348            self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
349            self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
350            self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
351            self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
352            self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
353            self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
354            self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
355            self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
356            self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
357            self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
358            self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
359            self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
360            self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
361            self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
362            self.failUnless(self.check(mypde.getCoefficient("q"),q_ref),"q is not empty")
363            self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
364    
365        def test_setCoefficient_r(self):
366            mypde=Helmholtz(self.domain,debug=self.DEBUG)
367            x=self.domain.getX()
368            mypde.setValue(r=x[0])
369    
370            r_ref=interpolate(x[0],Solution(self.domain))
371            A_ref=kronecker(self.domain)
372            self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
373            self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
374            self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
375            self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
376            self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
377            self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
378            self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
379            self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
380            self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
381            self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
382            self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
383            self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
384            self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
385            self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
386            self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
387            self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
388            self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
389            self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
390            self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
391            self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
392            self.failUnless(self.check(mypde.getCoefficient("r"),r_ref),"r is nor x[0]")
393            self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
394    
395    
396        def test_setCoefficient_f(self):
397            mypde=Helmholtz(self.domain,debug=self.DEBUG)
398            x=self.domain.getX()
399            mypde.setValue(f=x[0])
400    
401            Y_ref=interpolate(x[0],Function(self.domain))
402            A_ref=kronecker(self.domain)
403            self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
404            self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
405            self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
406            self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
407            self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
408            self.failUnless(self.check(mypde.getCoefficient("Y"),Y_ref),"Y is not x[0]")
409            self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
410            self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
411            self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
412            self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
413            self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
414            self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
415            self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
416            self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
417            self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
418            self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
419            self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
420            self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
421            self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
422            self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
423            self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
424            self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
425    
426        def test_setCoefficient_alpha(self):
427            mypde=Helmholtz(self.domain,debug=self.DEBUG)
428            x=self.domain.getX()
429            mypde.setValue(alpha=x[0])
430    
431            d_ref=interpolate(x[0],FunctionOnBoundary(self.domain))
432            A_ref=kronecker(self.domain)
433            self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
434            self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
435            self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
436            self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
437            self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
438            self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
439            self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
440            self.failUnless(self.check(mypde.getCoefficient("d"),d_ref),"d is not x[0]")
441            self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
442            self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
443            self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
444            self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
445            self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
446            self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
447            self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
448            self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"X_reduced is not empty")
449            self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
450            self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
451            self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
452            self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
453            self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
454            self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
455    
456        def test_setCoefficient_g(self):
457            mypde=Helmholtz(self.domain,debug=self.DEBUG)
458            x=self.domain.getX()
459            mypde.setValue(g=x[0])
460    
461            y_ref=interpolate(x[0],FunctionOnBoundary(self.domain))
462            A_ref=kronecker(self.domain)
463            self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
464            self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
465            self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
466            self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty")
467            self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
468            self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
469            self.failUnless(self.check(mypde.getCoefficient("y"),y_ref),"y is not x[0]")
470            self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
471            self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
472            self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
473            self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
474            self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
475            self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
476            self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
477            self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
478            self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
479            self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
480            self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
481            self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
482            self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
483            self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
484            self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
485    
486        def test_setCoefficient_omega(self):
487            mypde=Helmholtz(self.domain,debug=self.DEBUG)
488            x=self.domain.getX()
489            mypde.setValue(omega=x[0])
490    
491            D_ref=interpolate(x[0],Function(self.domain))
492            A_ref=kronecker(self.domain)
493            self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker")
494            self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty")
495            self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty")
496            self.failUnless(self.check(mypde.getCoefficient("D"),D_ref),"D is not x[0]")
497            self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty")
498            self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty")
499            self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty")
500            self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty")
501            self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty")
502            self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty")
503            self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty")
504            self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty")
505            self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty")
506            self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty")
507            self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty")
508            self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty")
509            self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty")
510            self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty")
511            self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty")
512            self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty")
513            self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty")
514            self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty")
515    
516        def test_solve(self):
517           d=self.domain.getDim()
518           cf=ContinuousFunction(self.domain)
519           u_ex=Scalar(1.,cf)
520           mypde=Helmholtz(self.domain)
521           mypde.setValue(f=3,omega=3,alpha=2,g=2)
522           u=mypde.getSolution()
523           self.failUnless(self.check(u,u_ex,10*self.TOL),"incorrect solution")
524    
525  class Test_Poisson(Test_linearPDEs):  class Test_Poisson(Test_linearPDEs):
526    
527      def test_config(self):      def test_config(self):
# Line 1262  class Test_LinearPDE(Test_LinearPDE_noLu Line 1722  class Test_LinearPDE(Test_LinearPDE_noLu
1722    
1723  class Test_TransportPDE(Test_linearPDEs):  class Test_TransportPDE(Test_linearPDEs):
1724      N=4      N=4
1725      def test_init_theta(self):      def test_init_useBackwardEuler(self):
1726          mypde=TransportPDE(self.domain,debug=self.DEBUG, theta=1.)          mypde=TransportPDE(self.domain,debug=self.DEBUG, useBackwardEuler=True)
1727          self.failUnless(mypde.getTheta()==1.,'wrong theta')          self.failUnless(mypde.useBackwardEuler()==True,'backward Euler should be used')
1728      def test_init_invalid_theta(self):      def test_init_donntUseBackwardEuler(self):
1729          self.failUnlessRaises(ValueError,TransportPDE,self.domain,debug=self.DEBUG, theta=-1.)          mypde=TransportPDE(self.domain,debug=self.DEBUG, useBackwardEuler=False)
1730            self.failUnless(mypde.useBackwardEuler()==False,'backward Euler should not be used')
1731      def test_setCoefficient_WithWrongName(self):      def test_setCoefficient_WithWrongName(self):
1732          mypde=TransportPDE(self.domain,debug=self.DEBUG)          mypde=TransportPDE(self.domain,debug=self.DEBUG)
1733          self.failUnlessRaises(IllegalCoefficient,mypde.setValue, ROMA=Vector(0.,FunctionOnBoundary(self.domain)))          self.failUnlessRaises(IllegalCoefficient,mypde.setValue, ROMA=Vector(0.,FunctionOnBoundary(self.domain)))

Legend:
Removed from v.1861  
changed lines
  Added in v.2344

  ViewVC Help
Powered by ViewVC 1.1.26