/[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 855 - (show annotations)
Fri Sep 22 09:30:06 2006 UTC (13 years ago) by gross
File MIME type: text/x-python
File size: 12423 byte(s)
some tests for triangle meshes added
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 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
119 def testProjector_rank0_reduced(self):
120 x=ContinuousFunction(self.domain).getX()
121 p=Projector(self.domain,reduce=True,fast=False)
122 td_ref=x[0]
123 td=p(td_ref.interpolate(Function(self.domain)))
124 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
125
126 def testProjector_rank1_reduced(self):
127 x=ContinuousFunction(self.domain).getX()
128 p=Projector(self.domain,reduce=True,fast=False)
129 td_ref=x
130 td=p(td_ref.interpolate(Function(self.domain)))
131 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
132
133 def testProjector_rank2_reduced(self):
134 x=ContinuousFunction(self.domain).getX()
135 p=Projector(self.domain,reduce=True,fast=False)
136 td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
137 td=p(td_ref.interpolate(Function(self.domain)))
138 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
139
140 def testProjector_rank3_reduced(self):
141 x=ContinuousFunction(self.domain).getX()
142 p=Projector(self.domain,reduce=True,fast=False)
143 td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
144 td=p(td_ref.interpolate(Function(self.domain)))
145 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
146
147 def testProjector_rank4_reduced(self):
148 x=ContinuousFunction(self.domain).getX()
149 p=Projector(self.domain,reduce=True,fast=False)
150 td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])
151 td=p(td_ref.interpolate(Function(self.domain)))
152 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
153
154 def testProjector_rank0_fast_reduced(self):
155 x=ContinuousFunction(self.domain).getX()
156 h=Lsup(self.domain.getSize())
157 p=Projector(self.domain,reduce=True,fast=True)
158 td_ref=x[0]
159 td=p(td_ref.interpolate(Function(self.domain)))
160 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
161
162 def testProjector_rank1_fast_reduced(self):
163 x=ContinuousFunction(self.domain).getX()
164 h=Lsup(self.domain.getSize())
165 p=Projector(self.domain,reduce=True,fast=True)
166 td_ref=x
167 td=p(td_ref.interpolate(Function(self.domain)))
168 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
169
170 def testProjector_rank2_fast_reduced(self):
171 x=ContinuousFunction(self.domain).getX()
172 h=Lsup(self.domain.getSize())
173 p=Projector(self.domain,reduce=True,fast=True)
174 td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
175 td=p(td_ref.interpolate(Function(self.domain)))
176 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
177
178 def testProjector_rank3_fast_reduced(self):
179 x=ContinuousFunction(self.domain).getX()
180 h=Lsup(self.domain.getSize())
181 p=Projector(self.domain,reduce=True,fast=True)
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)*h,"value wrong")
185
186 def testProjector_rank4_fast_reduced(self):
187 x=ContinuousFunction(self.domain).getX()
188 h=Lsup(self.domain.getSize())
189 p=Projector(self.domain,reduce=True,fast=True)
190 td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])
191 td=p(td_ref.interpolate(Function(self.domain)))
192 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
193
194 def test_NoPDE_scalar_missing_r(self):
195 p=NoPDE(self.domain)
196 x=self.domain.getX()
197 msk=whereZero(x[0])
198 p.setValue(D=1.,Y=1.,q=msk)
199 u=p.getSolution()
200 u_ex=(1.-msk)
201 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
202
203 def test_NoPDE_scalar_missing_Y(self):
204 p=NoPDE(self.domain)
205 x=self.domain.getX()
206 msk=whereZero(x[0])
207 p.setValue(D=1.,q=msk,r=2.)
208 u=p.getSolution()
209 u_ex=msk*2.
210 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
211
212 def test_NoPDE_scalar_constant(self):
213 p=NoPDE(self.domain)
214 x=self.domain.getX()
215 msk=whereZero(x[0])
216 p.setValue(D=1.,Y=1.,q=msk,r=2.)
217 u=p.getSolution()
218 u_ex=(1.-msk)+msk*2.
219 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
220
221 def test_NoPDE_scalar_variable(self):
222 p=NoPDE(self.domain)
223 x=self.domain.getX()
224 msk=whereZero(x[0])
225 p.setValue(D=x[0],Y=2*x[0],q=msk,r=2.)
226 u=p.getSolution()
227 u_ex=2.
228 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
229
230 def test_NoPDE_vector_missing_Y(self):
231 p=NoPDE(self.domain)
232 x=self.domain.getX()
233 msk=whereZero(x[0])*[1.,0.]
234 p.setValue(D=numarray.ones([2]),q=msk,r=2.)
235 u=p.getSolution()
236 u_ex=msk*2.
237 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
238
239 def test_NoPDE_vector_missing_r(self):
240 p=NoPDE(self.domain)
241 x=self.domain.getX()
242 msk=whereZero(x[0])*[1.,0.]
243 p.setValue(D=numarray.ones([2]),Y=numarray.ones([2]),q=msk)
244 u=p.getSolution()
245 u_ex=(1.-msk)
246 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
247
248 def test_NoPDE_vector_constant(self):
249 p=NoPDE(self.domain)
250 x=self.domain.getX()
251 msk=whereZero(x[0])*[1.,0.]
252 p.setValue(D=numarray.ones([2]),Y=numarray.ones([2]),q=msk,r=2.)
253 u=p.getSolution()
254 u_ex=(1.-msk)+msk*2.
255 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
256
257 def test_NoPDE_vector_variable(self):
258 p=NoPDE(self.domain)
259 x=self.domain.getX()
260 msk=whereZero(x[0])*[1.,0.]
261 p.setValue(D=x[:2],Y=2*x[:2],q=msk,r=2.)
262 u=p.getSolution()
263 u_ex=2.
264 self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
265
266
267 class Test_pdetools(Test_pdetools_noLumping):
268 def testProjector_rank0_fast(self):
269 x=ContinuousFunction(self.domain).getX()
270 h=Lsup(self.domain.getSize())
271 p=Projector(self.domain,reduce=False,fast=True)
272 td_ref=x[0]
273 td=p(td_ref.interpolate(Function(self.domain)))
274 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
275
276 def testProjector_rank1_fast(self):
277 x=ContinuousFunction(self.domain).getX()
278 h=Lsup(self.domain.getSize())
279 p=Projector(self.domain,reduce=False,fast=True)
280 td_ref=x
281 td=p(td_ref.interpolate(Function(self.domain)))
282 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
283
284 def testProjector_rank2_fast(self):
285 x=ContinuousFunction(self.domain).getX()
286 h=Lsup(self.domain.getSize())
287 p=Projector(self.domain,reduce=False,fast=True)
288 td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
289 td=p(td_ref.interpolate(Function(self.domain)))
290 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
291
292 def testProjector_rank3_fast(self):
293 x=ContinuousFunction(self.domain).getX()
294 h=Lsup(self.domain.getSize())
295 p=Projector(self.domain,reduce=False,fast=True)
296 td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
297 td=p(td_ref.interpolate(Function(self.domain)))
298 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
299
300 def testProjector_rank4_fast(self):
301 x=ContinuousFunction(self.domain).getX()
302 h=Lsup(self.domain.getSize())
303 p=Projector(self.domain,reduce=False,fast=True)
304 td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])
305 td=p(td_ref.interpolate(Function(self.domain)))
306 self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")

  ViewVC Help
Powered by ViewVC 1.1.26