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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 609 - (hide annotations)
Tue Mar 21 09:46:39 2006 UTC (13 years, 6 months ago) by elspeth
Original Path: trunk/escript/py_src/test_pdetools.py
File MIME type: text/x-python
File size: 11927 byte(s)
Updated copyright and licence notices.

1 gross 525 # $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     """
17    
18     __author__="Lutz Gross, l.gross@uq.edu.au"
19 elspeth 609 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
20     http://www.access.edu.au
21     Primary Business: Queensland, Australia"""
22     __licence__="""Licensed under the Open Software License version 3.0
23     http://www.opensource.org/licences/osl-3.0.php"""
24 gross 525 __url__="http://www.iservo.edu.au/esys/escript"
25     __version__="$Revision$"
26     __date__="$Date$"
27    
28     import unittest
29     from esys.escript import *
30     from esys.escript.pdetools import Locator,Projector,TimeIntegrationManager,NoPDE
31    
32     class Test_pdetools(unittest.TestCase):
33     TOL=1.e-6
34     DEBUG=False
35     VERBOSE=False
36     def test_TimeIntegrationManager_scalar(self):
37     t=0.
38     dt=0.1
39     tm=TimeIntegrationManager(0.,p=1)
40     while t<1.:
41     t+=dt
42     tm.checkin(dt,t)
43     v_guess=tm.extrapolate(dt)
44     self.failUnless(abs(v_guess-(tm.getTime()+dt))<self.TOL,"extrapolation is wrong")
45    
46     def test_TimeIntegrationManager_vector(self):
47     t=0.
48     dt=0.3
49     tm=TimeIntegrationManager(0.,0.,p=1)
50     while t<1.:
51     t+=dt
52     tm.checkin(dt,t,3*t)
53     v_guess=tm.extrapolate(dt)
54     e=max(abs(v_guess[0]-(tm.getTime()+dt)),abs(v_guess[1]-(tm.getTime()+dt)*3.))
55     self.failUnless(e<self.TOL,"extrapolation is wrong")
56    
57     def test_Locator(self):
58     x=self.domain.getX()
59     l=Locator(self.domain,numarray.ones((self.domain.getDim(),)))
60     self.failUnless(ContinuousFunction(self.domain)==l.getFunctionSpace(),"wrong function space from domain")
61    
62     l=Locator(ContinuousFunction(self.domain),numarray.ones((self.domain.getDim(),)))
63     self.failUnless(ContinuousFunction(self.domain)==l.getFunctionSpace(),"wrong function space")
64    
65     xx=l.getX()
66     self.failUnless(isinstance(xx,numarray.NumArray),"wrong vector type")
67     self.failUnless(Lsup(xx-numarray.ones((self.domain.getDim(),)))<self.TOL,"location wrong")
68     xx=l(x)
69     self.failUnless(isinstance(xx,numarray.NumArray),"wrong vector type")
70     self.failUnless(Lsup(xx-numarray.ones((self.domain.getDim(),)))<self.TOL,"value wrong vector")
71     xx=l(x[0]+x[1])
72     self.failUnless(isinstance(xx,float),"wrong scalar type")
73     self.failUnless(abs(xx-2.)<self.TOL,"value wrong scalar")
74    
75     def testProjector_rank0(self):
76     x=ContinuousFunction(self.domain).getX()
77     p=Projector(self.domain,reduce=False,fast=False)
78     td_ref=x[0]
79     td=p(td_ref.interpolate(Function(self.domain)))
80     self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
81    
82     def testProjector_rank1(self):
83     x=ContinuousFunction(self.domain).getX()
84     p=Projector(self.domain,reduce=False,fast=False)
85     td_ref=x
86     td=p(td_ref.interpolate(Function(self.domain)))
87     self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
88    
89     def testProjector_rank2(self):
90     x=ContinuousFunction(self.domain).getX()
91     p=Projector(self.domain,reduce=False,fast=False)
92     td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
93     td=p(td_ref.interpolate(Function(self.domain)))
94     self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
95    
96     def testProjector_rank3(self):
97     x=ContinuousFunction(self.domain).getX()
98     p=Projector(self.domain,reduce=False,fast=False)
99     td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
100     td=p(td_ref.interpolate(Function(self.domain)))
101     self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
102    
103     def testProjector_rank4(self):
104     x=ContinuousFunction(self.domain).getX()
105     p=Projector(self.domain,reduce=False,fast=False)
106     td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])
107     td=p(td_ref.interpolate(Function(self.domain)))
108     self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
109    
110     def testProjector_rank0_fast(self):
111     x=ContinuousFunction(self.domain).getX()
112     h=Lsup(self.domain.getSize())
113     p=Projector(self.domain,reduce=False,fast=True)
114     td_ref=x[0]
115     td=p(td_ref.interpolate(Function(self.domain)))
116     self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
117    
118     def testProjector_rank1_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
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_rank2_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=[[11.,12.],[21,22.]]*(x[0]+x[1])
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_rank3_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=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(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_rank4_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=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(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_rank0_reduced(self):
151     x=ContinuousFunction(self.domain).getX()
152     p=Projector(self.domain,reduce=True,fast=False)
153     td_ref=x[0]
154     td=p(td_ref.interpolate(Function(self.domain)))
155     self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
156    
157     def testProjector_rank1_reduced(self):
158     x=ContinuousFunction(self.domain).getX()
159     p=Projector(self.domain,reduce=True,fast=False)
160     td_ref=x
161     td=p(td_ref.interpolate(Function(self.domain)))
162     self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
163    
164     def testProjector_rank2_reduced(self):
165     x=ContinuousFunction(self.domain).getX()
166     p=Projector(self.domain,reduce=True,fast=False)
167     td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
168     td=p(td_ref.interpolate(Function(self.domain)))
169     self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
170    
171     def testProjector_rank3_reduced(self):
172     x=ContinuousFunction(self.domain).getX()
173     p=Projector(self.domain,reduce=True,fast=False)
174     td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
175     td=p(td_ref.interpolate(Function(self.domain)))
176     self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
177    
178     def testProjector_rank4_reduced(self):
179     x=ContinuousFunction(self.domain).getX()
180     p=Projector(self.domain,reduce=True,fast=False)
181     td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])
182     td=p(td_ref.interpolate(Function(self.domain)))
183     self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")
184    
185     def testProjector_rank0_fast_reduced(self):
186     x=ContinuousFunction(self.domain).getX()
187     h=Lsup(self.domain.getSize())
188     p=Projector(self.domain,reduce=True,fast=True)
189     td_ref=x[0]
190     td=p(td_ref.interpolate(Function(self.domain)))
191     self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
192    
193     def testProjector_rank1_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
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_rank2_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=[[11.,12.],[21,22.]]*(x[0]+x[1])
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_rank3_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=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(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_rank4_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=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(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 test_NoPDE_scalar_missing_r(self):
226     p=NoPDE(self.domain)
227     x=self.domain.getX()
228     msk=whereZero(x[0])
229     p.setValue(D=1.,Y=1.,q=msk)
230     u=p.getSolution()
231     u_ex=(1.-msk)
232     self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")
233    
234     def test_NoPDE_scalar_missing_Y(self):
235     p=NoPDE(self.domain)
236     x=self.domain.getX()
237     msk=whereZero(x[0])
238     p.setValue(D=1.,q=msk,r=2.)
239     u=p.getSolution()
240     u_ex=msk*2.
241     self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")
242    
243     def test_NoPDE_scalar_constant(self):
244     p=NoPDE(self.domain)
245     x=self.domain.getX()
246     msk=whereZero(x[0])
247     p.setValue(D=1.,Y=1.,q=msk,r=2.)
248     u=p.getSolution()
249     u_ex=(1.-msk)+msk*2.
250     self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")
251    
252     def test_NoPDE_scalar_variable(self):
253     p=NoPDE(self.domain)
254     x=self.domain.getX()
255     msk=whereZero(x[0])
256     p.setValue(D=x[0],Y=2*x[0],q=msk,r=2.)
257     u=p.getSolution()
258     u_ex=2.
259     self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")
260    
261     def test_NoPDE_vector_missing_Y(self):
262     p=NoPDE(self.domain)
263     x=self.domain.getX()
264     msk=whereZero(x[0])*[1.,0.]
265     p.setValue(D=1.,q=msk,r=2.)
266     u=p.getSolution()
267     u_ex=msk*2.
268     self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")
269    
270     def test_NoPDE_vector_missing_r(self):
271     p=NoPDE(self.domain)
272     x=self.domain.getX()
273     msk=whereZero(x[0])*[1.,0.]
274     p.setValue(D=1.,Y=1.,q=msk)
275     u=p.getSolution()
276     u_ex=(1.-msk)
277     self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")
278    
279     def test_NoPDE_vector_constant(self):
280     p=NoPDE(self.domain)
281     x=self.domain.getX()
282     msk=whereZero(x[0])*[1.,0.]
283     p.setValue(D=1.,Y=1.,q=msk,r=2.)
284     u=p.getSolution()
285     u_ex=(1.-msk)+msk*2.
286     self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")
287    
288     def test_NoPDE_vector_variable(self):
289     p=NoPDE(self.domain)
290     x=self.domain.getX()
291     msk=whereZero(x[0])*[1.,0.]
292     p.setValue(D=x[:2],Y=2*x[:2],q=msk,r=2.)
293     u=p.getSolution()
294     u_ex=2.
295     self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")

  ViewVC Help
Powered by ViewVC 1.1.26