/[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 854 - (show annotations)
Thu Sep 21 05:29:42 2006 UTC (13 years ago) by gross
File MIME type: text/x-python
File size: 12365 byte(s)
Some modifications to the binary operations +,-,*/, pow. 
The code is a bit simpler now and more efficient has there is
no reseising required now. the resizing method has been removed as
it is very, very inefficient. Even serial code should be faster now.
It is now forbidden to do an inplace update of scalar data object with an object 
of rank >0 as this is very slow (and does not make much sense). 


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(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 testProjector_rank0(self):
84 x=ContinuousFunction(self.domain).getX()
85 p=Projector(self.domain,reduce=False,fast=False)
86 td_ref=x[0]
87 td=p(td_ref.interpolate(Function(self.domain)))
88 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
89
90 def testProjector_rank1(self):
91 x=ContinuousFunction(self.domain).getX()
92 p=Projector(self.domain,reduce=False,fast=False)
93 td_ref=x
94 td=p(td_ref.interpolate(Function(self.domain)))
95 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
96
97 def testProjector_rank2(self):
98 x=ContinuousFunction(self.domain).getX()
99 p=Projector(self.domain,reduce=False,fast=False)
100 td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
101 td=p(td_ref.interpolate(Function(self.domain)))
102 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
103
104 def testProjector_rank3(self):
105 x=ContinuousFunction(self.domain).getX()
106 p=Projector(self.domain,reduce=False,fast=False)
107 td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
108 td=p(td_ref.interpolate(Function(self.domain)))
109 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
110
111 def testProjector_rank4(self):
112 x=ContinuousFunction(self.domain).getX()
113 p=Projector(self.domain,reduce=False,fast=False)
114 td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])
115 td=p(td_ref.interpolate(Function(self.domain)))
116 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
117
118 def testProjector_rank0_fast(self):
119 x=ContinuousFunction(self.domain).getX()
120 h=Lsup(self.domain.getSize())
121 p=Projector(self.domain,reduce=False,fast=True)
122 td_ref=x[0]
123 td=p(td_ref.interpolate(Function(self.domain)))
124 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
125
126 def testProjector_rank1_fast(self):
127 x=ContinuousFunction(self.domain).getX()
128 h=Lsup(self.domain.getSize())
129 p=Projector(self.domain,reduce=False,fast=True)
130 td_ref=x
131 td=p(td_ref.interpolate(Function(self.domain)))
132 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
133
134 def testProjector_rank2_fast(self):
135 x=ContinuousFunction(self.domain).getX()
136 h=Lsup(self.domain.getSize())
137 p=Projector(self.domain,reduce=False,fast=True)
138 td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
139 td=p(td_ref.interpolate(Function(self.domain)))
140 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
141
142 def testProjector_rank3_fast(self):
143 x=ContinuousFunction(self.domain).getX()
144 h=Lsup(self.domain.getSize())
145 p=Projector(self.domain,reduce=False,fast=True)
146 td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
147 td=p(td_ref.interpolate(Function(self.domain)))
148 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
149
150 def testProjector_rank4_fast(self):
151 x=ContinuousFunction(self.domain).getX()
152 h=Lsup(self.domain.getSize())
153 p=Projector(self.domain,reduce=False,fast=True)
154 td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])
155 td=p(td_ref.interpolate(Function(self.domain)))
156 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
157
158 def testProjector_rank0_reduced(self):
159 x=ContinuousFunction(self.domain).getX()
160 p=Projector(self.domain,reduce=True,fast=False)
161 td_ref=x[0]
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_rank1_reduced(self):
166 x=ContinuousFunction(self.domain).getX()
167 p=Projector(self.domain,reduce=True,fast=False)
168 td_ref=x
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_rank2_reduced(self):
173 x=ContinuousFunction(self.domain).getX()
174 p=Projector(self.domain,reduce=True,fast=False)
175 td_ref=[[11.,12.],[21,22.]]*(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_rank3_reduced(self):
180 x=ContinuousFunction(self.domain).getX()
181 p=Projector(self.domain,reduce=True,fast=False)
182 td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
183 td=p(td_ref.interpolate(Function(self.domain)))
184 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
185
186 def testProjector_rank4_reduced(self):
187 x=ContinuousFunction(self.domain).getX()
188 p=Projector(self.domain,reduce=True,fast=False)
189 td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])
190 td=p(td_ref.interpolate(Function(self.domain)))
191 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
192
193 def testProjector_rank0_fast_reduced(self):
194 x=ContinuousFunction(self.domain).getX()
195 h=Lsup(self.domain.getSize())
196 p=Projector(self.domain,reduce=True,fast=True)
197 td_ref=x[0]
198 td=p(td_ref.interpolate(Function(self.domain)))
199 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
200
201 def testProjector_rank1_fast_reduced(self):
202 x=ContinuousFunction(self.domain).getX()
203 h=Lsup(self.domain.getSize())
204 p=Projector(self.domain,reduce=True,fast=True)
205 td_ref=x
206 td=p(td_ref.interpolate(Function(self.domain)))
207 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
208
209 def testProjector_rank2_fast_reduced(self):
210 x=ContinuousFunction(self.domain).getX()
211 h=Lsup(self.domain.getSize())
212 p=Projector(self.domain,reduce=True,fast=True)
213 td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
214 td=p(td_ref.interpolate(Function(self.domain)))
215 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
216
217 def testProjector_rank3_fast_reduced(self):
218 x=ContinuousFunction(self.domain).getX()
219 h=Lsup(self.domain.getSize())
220 p=Projector(self.domain,reduce=True,fast=True)
221 td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
222 td=p(td_ref.interpolate(Function(self.domain)))
223 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
224
225 def testProjector_rank4_fast_reduced(self):
226 x=ContinuousFunction(self.domain).getX()
227 h=Lsup(self.domain.getSize())
228 p=Projector(self.domain,reduce=True,fast=True)
229 td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])
230 td=p(td_ref.interpolate(Function(self.domain)))
231 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
232
233 def test_NoPDE_scalar_missing_r(self):
234 p=NoPDE(self.domain)
235 x=self.domain.getX()
236 msk=whereZero(x[0])
237 p.setValue(D=1.,Y=1.,q=msk)
238 u=p.getSolution()
239 u_ex=(1.-msk)
240 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
241
242 def test_NoPDE_scalar_missing_Y(self):
243 p=NoPDE(self.domain)
244 x=self.domain.getX()
245 msk=whereZero(x[0])
246 p.setValue(D=1.,q=msk,r=2.)
247 u=p.getSolution()
248 u_ex=msk*2.
249 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
250
251 def test_NoPDE_scalar_constant(self):
252 p=NoPDE(self.domain)
253 x=self.domain.getX()
254 msk=whereZero(x[0])
255 p.setValue(D=1.,Y=1.,q=msk,r=2.)
256 u=p.getSolution()
257 u_ex=(1.-msk)+msk*2.
258 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
259
260 def test_NoPDE_scalar_variable(self):
261 p=NoPDE(self.domain)
262 x=self.domain.getX()
263 msk=whereZero(x[0])
264 p.setValue(D=x[0],Y=2*x[0],q=msk,r=2.)
265 u=p.getSolution()
266 u_ex=2.
267 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
268
269 def test_NoPDE_vector_missing_Y(self):
270 p=NoPDE(self.domain)
271 x=self.domain.getX()
272 msk=whereZero(x[0])*[1.,0.]
273 p.setValue(D=numarray.ones([2]),q=msk,r=2.)
274 u=p.getSolution()
275 u_ex=msk*2.
276 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
277
278 def test_NoPDE_vector_missing_r(self):
279 p=NoPDE(self.domain)
280 x=self.domain.getX()
281 msk=whereZero(x[0])*[1.,0.]
282 p.setValue(D=numarray.ones([2]),Y=numarray.ones([2]),q=msk)
283 u=p.getSolution()
284 u_ex=(1.-msk)
285 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
286
287 def test_NoPDE_vector_constant(self):
288 p=NoPDE(self.domain)
289 x=self.domain.getX()
290 msk=whereZero(x[0])*[1.,0.]
291 p.setValue(D=numarray.ones([2]),Y=numarray.ones([2]),q=msk,r=2.)
292 u=p.getSolution()
293 u_ex=(1.-msk)+msk*2.
294 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
295
296 def test_NoPDE_vector_variable(self):
297 p=NoPDE(self.domain)
298 x=self.domain.getX()
299 msk=whereZero(x[0])*[1.,0.]
300 p.setValue(D=x[:2],Y=2*x[:2],q=msk,r=2.)
301 u=p.getSolution()
302 u_ex=2.
303 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")

  ViewVC Help
Powered by ViewVC 1.1.26