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

Contents of /trunk/escript/test/python/test_pdetools.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 880 - (show annotations)
Wed Oct 25 23:58:16 2006 UTC (12 years, 9 months ago) by gross
File MIME type: text/x-python
File size: 13785 byte(s)
Locator accepts list of locations now
1 # $Id$
2
3 """
4 Test suite for the pdetools module
5
6 The tests must be linked with a Domain class object in the setUp method:
7
8 from esys.finley import Rectangle
9 class Test_LinearPDEOnFinley(Test_LinearPDE):
10 RES_TOL=1-8
11 def setUp(self):
12 self.domain = Rectangle(10,10,2)
13 def tearDown(self):
14 del self.domain
15 suite = unittest.TestSuite()
16 suite.addTest(unittest.makeSuite(Test_LinearPDEOnFinley))
17 unittest.TextTestRunner(verbosity=2).run(suite)
18
19 @var __author__: name of author
20 @var __copyright__: copyrights
21 @var __license__: licence agreement
22 @var __url__: url entry point on documentation
23 @var __version__: version
24 @var __date__: date of the version
25 """
26
27 __author__="Lutz Gross, l.gross@uq.edu.au"
28 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
29 http://www.access.edu.au
30 Primary Business: Queensland, Australia"""
31 __license__="""Licensed under the Open Software License version 3.0
32 http://www.opensource.org/licenses/osl-3.0.php"""
33 __url__="http://www.iservo.edu.au/esys/escript"
34 __version__="$Revision$"
35 __date__="$Date$"
36
37 import unittest
38 from esys.escript import *
39 from esys.escript.pdetools import Locator,Projector,TimeIntegrationManager,NoPDE
40
41 class Test_pdetools_noLumping(unittest.TestCase):
42 DEBUG=False
43 VERBOSE=False
44 def test_TimeIntegrationManager_scalar(self):
45 t=0.
46 dt=0.1
47 tm=TimeIntegrationManager(0.,p=1)
48 while t<1.:
49 t+=dt
50 tm.checkin(dt,t)
51 v_guess=tm.extrapolate(dt)
52 self.failUnless(abs(v_guess-(tm.getTime()+dt))<self.RES_TOL,"extrapolation is wrong")
53
54 def test_TimeIntegrationManager_vector(self):
55 t=0.
56 dt=0.3
57 tm=TimeIntegrationManager(0.,0.,p=1)
58 while t<1.:
59 t+=dt
60 tm.checkin(dt,t,3*t)
61 v_guess=tm.extrapolate(dt)
62 e=max(abs(v_guess[0]-(tm.getTime()+dt)),abs(v_guess[1]-(tm.getTime()+dt)*3.))
63 self.failUnless(e<self.RES_TOL,"extrapolation is wrong")
64
65 def test_Locator(self):
66 x=self.domain.getX()
67 l=Locator(self.domain,numarray.ones((self.domain.getDim(),)))
68 self.failUnless(ContinuousFunction(self.domain)==l.getFunctionSpace(),"wrong function space from domain")
69
70 l=Locator(ContinuousFunction(self.domain),numarray.ones((self.domain.getDim(),)))
71 self.failUnless(ContinuousFunction(self.domain)==l.getFunctionSpace(),"wrong function space")
72
73 xx=l.getX()
74 self.failUnless(isinstance(xx,numarray.NumArray),"wrong vector type")
75 self.failUnless(Lsup(xx-numarray.ones((self.domain.getDim(),)))<self.RES_TOL,"location wrong")
76 xx=l(x)
77 self.failUnless(isinstance(xx,numarray.NumArray),"wrong vector type")
78 self.failUnless(Lsup(xx-numarray.ones((self.domain.getDim(),)))<self.RES_TOL,"value wrong vector")
79 xx=l(x[0]+x[1])
80 self.failUnless(isinstance(xx,float),"wrong scalar type")
81 self.failUnless(abs(xx-2.)<self.RES_TOL,"value wrong scalar")
82
83 def test_Locator_withList(self):
84 x=self.domain.getX()
85 arg=[numarray.ones((self.domain.getDim(),)), numarray.zeros((self.domain.getDim(),))]
86 l=Locator(self.domain,arg)
87 self.failUnless(ContinuousFunction(self.domain)==l.getFunctionSpace(),"wrong function space from domain")
88
89 l=Locator(ContinuousFunction(self.domain),arg)
90 self.failUnless(ContinuousFunction(self.domain)==l.getFunctionSpace(),"wrong function space")
91
92 xx=l.getX()
93 self.failUnless(isinstance(xx,list),"list expected")
94 for i in range(len(xx)):
95 self.failUnless(isinstance(xx[i],numarray.NumArray),"vector expected for %s item"%i)
96 self.failUnless(Lsup(xx[i]-arg[i])<self.RES_TOL,"%s-th location is wrong"%i)
97 xx=l(x)
98 self.failUnless(isinstance(xx,list),"list expected (2)")
99 for i in range(len(xx)):
100 self.failUnless(isinstance(xx[i],numarray.NumArray),"vector expected for %s item (2)"%i)
101 self.failUnless(Lsup(xx[i]-arg[i])<self.RES_TOL,"%s-th location is wrong (2)"%i)
102 xx=l(x[0]+x[1])
103 self.failUnless(isinstance(xx,list),"list expected (3)")
104 for i in range(len(xx)):
105 self.failUnless(isinstance(xx[i],float),"wrong scalar type")
106 self.failUnless(abs(xx[i]-(arg[i][0]+arg[i][1]))<self.RES_TOL,"value wrong scalar")
107
108 def testProjector_rank0(self):
109 x=ContinuousFunction(self.domain).getX()
110 p=Projector(self.domain,reduce=False,fast=False)
111 td_ref=x[0]
112 td=p(td_ref.interpolate(Function(self.domain)))
113 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
114
115 def testProjector_rank1(self):
116 x=ContinuousFunction(self.domain).getX()
117 p=Projector(self.domain,reduce=False,fast=False)
118 td_ref=x
119 td=p(td_ref.interpolate(Function(self.domain)))
120 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
121
122 def testProjector_rank2(self):
123 x=ContinuousFunction(self.domain).getX()
124 p=Projector(self.domain,reduce=False,fast=False)
125 td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
126 td=p(td_ref.interpolate(Function(self.domain)))
127 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
128
129 def testProjector_rank3(self):
130 x=ContinuousFunction(self.domain).getX()
131 p=Projector(self.domain,reduce=False,fast=False)
132 td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
133 td=p(td_ref.interpolate(Function(self.domain)))
134 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
135
136 def testProjector_rank4(self):
137 x=ContinuousFunction(self.domain).getX()
138 p=Projector(self.domain,reduce=False,fast=False)
139 td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])
140 td=p(td_ref.interpolate(Function(self.domain)))
141 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
142
143
144 def testProjector_rank0_reduced(self):
145 x=ContinuousFunction(self.domain).getX()
146 p=Projector(self.domain,reduce=True,fast=False)
147 td_ref=x[0]
148 td=p(td_ref.interpolate(Function(self.domain)))
149 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
150
151 def testProjector_rank1_reduced(self):
152 x=ContinuousFunction(self.domain).getX()
153 p=Projector(self.domain,reduce=True,fast=False)
154 td_ref=x
155 td=p(td_ref.interpolate(Function(self.domain)))
156 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
157
158 def testProjector_rank2_reduced(self):
159 x=ContinuousFunction(self.domain).getX()
160 p=Projector(self.domain,reduce=True,fast=False)
161 td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
162 td=p(td_ref.interpolate(Function(self.domain)))
163 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
164
165 def testProjector_rank3_reduced(self):
166 x=ContinuousFunction(self.domain).getX()
167 p=Projector(self.domain,reduce=True,fast=False)
168 td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
169 td=p(td_ref.interpolate(Function(self.domain)))
170 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
171
172 def testProjector_rank4_reduced(self):
173 x=ContinuousFunction(self.domain).getX()
174 p=Projector(self.domain,reduce=True,fast=False)
175 td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])
176 td=p(td_ref.interpolate(Function(self.domain)))
177 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
178
179 def testProjector_rank0_fast_reduced(self):
180 x=ContinuousFunction(self.domain).getX()
181 h=Lsup(self.domain.getSize())
182 p=Projector(self.domain,reduce=True,fast=True)
183 td_ref=x[0]
184 td=p(td_ref.interpolate(Function(self.domain)))
185 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
186
187 def testProjector_rank1_fast_reduced(self):
188 x=ContinuousFunction(self.domain).getX()
189 h=Lsup(self.domain.getSize())
190 p=Projector(self.domain,reduce=True,fast=True)
191 td_ref=x
192 td=p(td_ref.interpolate(Function(self.domain)))
193 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
194
195 def testProjector_rank2_fast_reduced(self):
196 x=ContinuousFunction(self.domain).getX()
197 h=Lsup(self.domain.getSize())
198 p=Projector(self.domain,reduce=True,fast=True)
199 td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
200 td=p(td_ref.interpolate(Function(self.domain)))
201 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
202
203 def testProjector_rank3_fast_reduced(self):
204 x=ContinuousFunction(self.domain).getX()
205 h=Lsup(self.domain.getSize())
206 p=Projector(self.domain,reduce=True,fast=True)
207 td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
208 td=p(td_ref.interpolate(Function(self.domain)))
209 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
210
211 def testProjector_rank4_fast_reduced(self):
212 x=ContinuousFunction(self.domain).getX()
213 h=Lsup(self.domain.getSize())
214 p=Projector(self.domain,reduce=True,fast=True)
215 td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])
216 td=p(td_ref.interpolate(Function(self.domain)))
217 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
218
219 def test_NoPDE_scalar_missing_r(self):
220 p=NoPDE(self.domain)
221 x=self.domain.getX()
222 msk=whereZero(x[0])
223 p.setValue(D=1.,Y=1.,q=msk)
224 u=p.getSolution()
225 u_ex=(1.-msk)
226 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
227
228 def test_NoPDE_scalar_missing_Y(self):
229 p=NoPDE(self.domain)
230 x=self.domain.getX()
231 msk=whereZero(x[0])
232 p.setValue(D=1.,q=msk,r=2.)
233 u=p.getSolution()
234 u_ex=msk*2.
235 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
236
237 def test_NoPDE_scalar_constant(self):
238 p=NoPDE(self.domain)
239 x=self.domain.getX()
240 msk=whereZero(x[0])
241 p.setValue(D=1.,Y=1.,q=msk,r=2.)
242 u=p.getSolution()
243 u_ex=(1.-msk)+msk*2.
244 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
245
246 def test_NoPDE_scalar_variable(self):
247 p=NoPDE(self.domain)
248 x=self.domain.getX()
249 msk=whereZero(x[0])
250 p.setValue(D=x[0],Y=2*x[0],q=msk,r=2.)
251 u=p.getSolution()
252 u_ex=2.
253 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
254
255 def test_NoPDE_vector_missing_Y(self):
256 p=NoPDE(self.domain)
257 x=self.domain.getX()
258 msk=whereZero(x[0])*[1.,0.]
259 p.setValue(D=numarray.ones([2]),q=msk,r=2.)
260 u=p.getSolution()
261 u_ex=msk*2.
262 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
263
264 def test_NoPDE_vector_missing_r(self):
265 p=NoPDE(self.domain)
266 x=self.domain.getX()
267 msk=whereZero(x[0])*[1.,0.]
268 p.setValue(D=numarray.ones([2]),Y=numarray.ones([2]),q=msk)
269 u=p.getSolution()
270 u_ex=(1.-msk)
271 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
272
273 def test_NoPDE_vector_constant(self):
274 p=NoPDE(self.domain)
275 x=self.domain.getX()
276 msk=whereZero(x[0])*[1.,0.]
277 p.setValue(D=numarray.ones([2]),Y=numarray.ones([2]),q=msk,r=2.)
278 u=p.getSolution()
279 u_ex=(1.-msk)+msk*2.
280 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
281
282 def test_NoPDE_vector_variable(self):
283 p=NoPDE(self.domain)
284 x=self.domain.getX()
285 msk=whereZero(x[0])*[1.,0.]
286 p.setValue(D=x[:2],Y=2*x[:2],q=msk,r=2.)
287 u=p.getSolution()
288 u_ex=2.
289 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
290
291
292 class Test_pdetools(Test_pdetools_noLumping):
293 def testProjector_rank0_fast(self):
294 x=ContinuousFunction(self.domain).getX()
295 h=Lsup(self.domain.getSize())
296 p=Projector(self.domain,reduce=False,fast=True)
297 td_ref=x[0]
298 td=p(td_ref.interpolate(Function(self.domain)))
299 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
300
301 def testProjector_rank1_fast(self):
302 x=ContinuousFunction(self.domain).getX()
303 h=Lsup(self.domain.getSize())
304 p=Projector(self.domain,reduce=False,fast=True)
305 td_ref=x
306 td=p(td_ref.interpolate(Function(self.domain)))
307 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
308
309 def testProjector_rank2_fast(self):
310 x=ContinuousFunction(self.domain).getX()
311 h=Lsup(self.domain.getSize())
312 p=Projector(self.domain,reduce=False,fast=True)
313 td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
314 td=p(td_ref.interpolate(Function(self.domain)))
315 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
316
317 def testProjector_rank3_fast(self):
318 x=ContinuousFunction(self.domain).getX()
319 h=Lsup(self.domain.getSize())
320 p=Projector(self.domain,reduce=False,fast=True)
321 td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
322 td=p(td_ref.interpolate(Function(self.domain)))
323 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
324
325 def testProjector_rank4_fast(self):
326 x=ContinuousFunction(self.domain).getX()
327 h=Lsup(self.domain.getSize())
328 p=Projector(self.domain,reduce=False,fast=True)
329 td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])
330 td=p(td_ref.interpolate(Function(self.domain)))
331 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")

  ViewVC Help
Powered by ViewVC 1.1.26