/[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 700 - (show annotations)
Thu Apr 6 00:13:40 2006 UTC (13 years, 8 months ago) by gross
File MIME type: text/x-python
File size: 12134 byte(s)
A few changes in the build mechanism and the file structure so scons can build release tar files:

  * paso/src/Solver has been moved to paso/src 
  * all test_.py are now run_.py files and are assumed to be passing python tests. they can run by 
    scons py_tests and are part of the release test set
  * escript/py_src/test_ are moved to escript/test/python and are installed in to the build directory 
    (rather then the PYTHONPATH).
  * all py files in test/python which don't start with run_ or test_ are now 'local_py_tests'. they are installed i
    by not run automatically.
  * CppUnitTest is now treated as a escript module (against previous decisions).
  * scons realse builds nor tar/zip files with relvant source code (src and tests in seperate files)

the python tests don't pass yet due to path problems.


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

  ViewVC Help
Powered by ViewVC 1.1.26