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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 797 by gross, Thu Apr 6 00:13:40 2006 UTC revision 798 by gross, Fri Aug 4 01:05:36 2006 UTC
# Line 7  The tests must be linked with a Domain c Line 7  The tests must be linked with a Domain c
7    
8     from esys.finley import Rectangle     from esys.finley import Rectangle
9     class Test_LinearPDEOnFinley(Test_LinearPDE):     class Test_LinearPDEOnFinley(Test_LinearPDE):
10           RES_TOL=1-8
11         def setUp(self):         def setUp(self):
12             self.domain = Rectangle(10,10,2)             self.domain = Rectangle(10,10,2)
13           def tearDown(self):
14               del self.domain
15     suite = unittest.TestSuite()     suite = unittest.TestSuite()
16     suite.addTest(unittest.makeSuite(Test_LinearPDEOnFinley))     suite.addTest(unittest.makeSuite(Test_LinearPDEOnFinley))
17     unittest.TextTestRunner(verbosity=2).run(suite)     unittest.TextTestRunner(verbosity=2).run(suite)
# Line 36  from esys.escript import * Line 39  from esys.escript import *
39  from esys.escript.pdetools import Locator,Projector,TimeIntegrationManager,NoPDE  from esys.escript.pdetools import Locator,Projector,TimeIntegrationManager,NoPDE
40    
41  class Test_pdetools(unittest.TestCase):  class Test_pdetools(unittest.TestCase):
     TOL=1.e-6  
42      DEBUG=False      DEBUG=False
43      VERBOSE=False      VERBOSE=False
44      def test_TimeIntegrationManager_scalar(self):      def test_TimeIntegrationManager_scalar(self):
# Line 47  class Test_pdetools(unittest.TestCase): Line 49  class Test_pdetools(unittest.TestCase):
49             t+=dt             t+=dt
50             tm.checkin(dt,t)             tm.checkin(dt,t)
51          v_guess=tm.extrapolate(dt)          v_guess=tm.extrapolate(dt)
52          self.failUnless(abs(v_guess-(tm.getTime()+dt))<self.TOL,"extrapolation is wrong")          self.failUnless(abs(v_guess-(tm.getTime()+dt))<self.RES_TOL,"extrapolation is wrong")
53    
54      def test_TimeIntegrationManager_vector(self):      def test_TimeIntegrationManager_vector(self):
55          t=0.          t=0.
# Line 58  class Test_pdetools(unittest.TestCase): Line 60  class Test_pdetools(unittest.TestCase):
60             tm.checkin(dt,t,3*t)             tm.checkin(dt,t,3*t)
61          v_guess=tm.extrapolate(dt)          v_guess=tm.extrapolate(dt)
62          e=max(abs(v_guess[0]-(tm.getTime()+dt)),abs(v_guess[1]-(tm.getTime()+dt)*3.))          e=max(abs(v_guess[0]-(tm.getTime()+dt)),abs(v_guess[1]-(tm.getTime()+dt)*3.))
63          self.failUnless(e<self.TOL,"extrapolation is wrong")          self.failUnless(e<self.RES_TOL,"extrapolation is wrong")
64    
65      def test_Locator(self):      def test_Locator(self):
66          x=self.domain.getX()          x=self.domain.getX()
# Line 70  class Test_pdetools(unittest.TestCase): Line 72  class Test_pdetools(unittest.TestCase):
72    
73          xx=l.getX()          xx=l.getX()
74          self.failUnless(isinstance(xx,numarray.NumArray),"wrong vector type")          self.failUnless(isinstance(xx,numarray.NumArray),"wrong vector type")
75          self.failUnless(Lsup(xx-numarray.ones((self.domain.getDim(),)))<self.TOL,"location wrong")          self.failUnless(Lsup(xx-numarray.ones((self.domain.getDim(),)))<self.RES_TOL,"location wrong")
76          xx=l(x)          xx=l(x)
77          self.failUnless(isinstance(xx,numarray.NumArray),"wrong vector type")          self.failUnless(isinstance(xx,numarray.NumArray),"wrong vector type")
78          self.failUnless(Lsup(xx-numarray.ones((self.domain.getDim(),)))<self.TOL,"value wrong vector")          self.failUnless(Lsup(xx-numarray.ones((self.domain.getDim(),)))<self.RES_TOL,"value wrong vector")
79          xx=l(x[0]+x[1])          xx=l(x[0]+x[1])
80          self.failUnless(isinstance(xx,float),"wrong scalar type")          self.failUnless(isinstance(xx,float),"wrong scalar type")
81          self.failUnless(abs(xx-2.)<self.TOL,"value wrong scalar")          self.failUnless(abs(xx-2.)<self.RES_TOL,"value wrong scalar")
82                
83      def testProjector_rank0(self):      def testProjector_rank0(self):
84        x=ContinuousFunction(self.domain).getX()        x=ContinuousFunction(self.domain).getX()
85        p=Projector(self.domain,reduce=False,fast=False)        p=Projector(self.domain,reduce=False,fast=False)
86        td_ref=x[0]        td_ref=x[0]
87        td=p(td_ref.interpolate(Function(self.domain)))        td=p(td_ref.interpolate(Function(self.domain)))
88        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
89    
90      def testProjector_rank1(self):      def testProjector_rank1(self):
91        x=ContinuousFunction(self.domain).getX()        x=ContinuousFunction(self.domain).getX()
92        p=Projector(self.domain,reduce=False,fast=False)        p=Projector(self.domain,reduce=False,fast=False)
93        td_ref=x        td_ref=x
94        td=p(td_ref.interpolate(Function(self.domain)))        td=p(td_ref.interpolate(Function(self.domain)))
95        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
96    
97      def testProjector_rank2(self):      def testProjector_rank2(self):
98        x=ContinuousFunction(self.domain).getX()        x=ContinuousFunction(self.domain).getX()
99        p=Projector(self.domain,reduce=False,fast=False)        p=Projector(self.domain,reduce=False,fast=False)
100        td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])        td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
101        td=p(td_ref.interpolate(Function(self.domain)))        td=p(td_ref.interpolate(Function(self.domain)))
102        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
103    
104      def testProjector_rank3(self):      def testProjector_rank3(self):
105        x=ContinuousFunction(self.domain).getX()        x=ContinuousFunction(self.domain).getX()
106        p=Projector(self.domain,reduce=False,fast=False)        p=Projector(self.domain,reduce=False,fast=False)
107        td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])        td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
108        td=p(td_ref.interpolate(Function(self.domain)))        td=p(td_ref.interpolate(Function(self.domain)))
109        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
110    
111      def testProjector_rank4(self):      def testProjector_rank4(self):
112        x=ContinuousFunction(self.domain).getX()        x=ContinuousFunction(self.domain).getX()
113        p=Projector(self.domain,reduce=False,fast=False)        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])        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)))        td=p(td_ref.interpolate(Function(self.domain)))
116        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
117    
118      def testProjector_rank0_fast(self):      def testProjector_rank0_fast(self):
119        x=ContinuousFunction(self.domain).getX()        x=ContinuousFunction(self.domain).getX()
# Line 158  class Test_pdetools(unittest.TestCase): Line 160  class Test_pdetools(unittest.TestCase):
160        p=Projector(self.domain,reduce=True,fast=False)        p=Projector(self.domain,reduce=True,fast=False)
161        td_ref=x[0]        td_ref=x[0]
162        td=p(td_ref.interpolate(Function(self.domain)))        td=p(td_ref.interpolate(Function(self.domain)))
163        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
164    
165      def testProjector_rank1_reduced(self):      def testProjector_rank1_reduced(self):
166        x=ContinuousFunction(self.domain).getX()        x=ContinuousFunction(self.domain).getX()
167        p=Projector(self.domain,reduce=True,fast=False)        p=Projector(self.domain,reduce=True,fast=False)
168        td_ref=x        td_ref=x
169        td=p(td_ref.interpolate(Function(self.domain)))        td=p(td_ref.interpolate(Function(self.domain)))
170        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
171    
172      def testProjector_rank2_reduced(self):      def testProjector_rank2_reduced(self):
173        x=ContinuousFunction(self.domain).getX()        x=ContinuousFunction(self.domain).getX()
174        p=Projector(self.domain,reduce=True,fast=False)        p=Projector(self.domain,reduce=True,fast=False)
175        td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])        td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
176        td=p(td_ref.interpolate(Function(self.domain)))        td=p(td_ref.interpolate(Function(self.domain)))
177        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
178    
179      def testProjector_rank3_reduced(self):      def testProjector_rank3_reduced(self):
180        x=ContinuousFunction(self.domain).getX()        x=ContinuousFunction(self.domain).getX()
181        p=Projector(self.domain,reduce=True,fast=False)        p=Projector(self.domain,reduce=True,fast=False)
182        td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])        td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
183        td=p(td_ref.interpolate(Function(self.domain)))        td=p(td_ref.interpolate(Function(self.domain)))
184        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
185    
186      def testProjector_rank4_reduced(self):      def testProjector_rank4_reduced(self):
187        x=ContinuousFunction(self.domain).getX()        x=ContinuousFunction(self.domain).getX()
188        p=Projector(self.domain,reduce=True,fast=False)        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])        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)))        td=p(td_ref.interpolate(Function(self.domain)))
191        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.TOL,"value wrong")        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
192    
193      def testProjector_rank0_fast_reduced(self):      def testProjector_rank0_fast_reduced(self):
194        x=ContinuousFunction(self.domain).getX()        x=ContinuousFunction(self.domain).getX()
# Line 235  class Test_pdetools(unittest.TestCase): Line 237  class Test_pdetools(unittest.TestCase):
237        p.setValue(D=1.,Y=1.,q=msk)        p.setValue(D=1.,Y=1.,q=msk)
238        u=p.getSolution()        u=p.getSolution()
239        u_ex=(1.-msk)        u_ex=(1.-msk)
240        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
241    
242      def test_NoPDE_scalar_missing_Y(self):      def test_NoPDE_scalar_missing_Y(self):
243        p=NoPDE(self.domain)        p=NoPDE(self.domain)
# Line 244  class Test_pdetools(unittest.TestCase): Line 246  class Test_pdetools(unittest.TestCase):
246        p.setValue(D=1.,q=msk,r=2.)        p.setValue(D=1.,q=msk,r=2.)
247        u=p.getSolution()        u=p.getSolution()
248        u_ex=msk*2.        u_ex=msk*2.
249        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
250    
251      def test_NoPDE_scalar_constant(self):      def test_NoPDE_scalar_constant(self):
252        p=NoPDE(self.domain)        p=NoPDE(self.domain)
# Line 253  class Test_pdetools(unittest.TestCase): Line 255  class Test_pdetools(unittest.TestCase):
255        p.setValue(D=1.,Y=1.,q=msk,r=2.)        p.setValue(D=1.,Y=1.,q=msk,r=2.)
256        u=p.getSolution()        u=p.getSolution()
257        u_ex=(1.-msk)+msk*2.        u_ex=(1.-msk)+msk*2.
258        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
259    
260      def test_NoPDE_scalar_variable(self):      def test_NoPDE_scalar_variable(self):
261        p=NoPDE(self.domain)        p=NoPDE(self.domain)
# Line 262  class Test_pdetools(unittest.TestCase): Line 264  class Test_pdetools(unittest.TestCase):
264        p.setValue(D=x[0],Y=2*x[0],q=msk,r=2.)        p.setValue(D=x[0],Y=2*x[0],q=msk,r=2.)
265        u=p.getSolution()        u=p.getSolution()
266        u_ex=2.        u_ex=2.
267        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
268    
269      def test_NoPDE_vector_missing_Y(self):      def test_NoPDE_vector_missing_Y(self):
270        p=NoPDE(self.domain)        p=NoPDE(self.domain)
# Line 271  class Test_pdetools(unittest.TestCase): Line 273  class Test_pdetools(unittest.TestCase):
273        p.setValue(D=1.,q=msk,r=2.)        p.setValue(D=1.,q=msk,r=2.)
274        u=p.getSolution()        u=p.getSolution()
275        u_ex=msk*2.        u_ex=msk*2.
276        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
277    
278      def test_NoPDE_vector_missing_r(self):      def test_NoPDE_vector_missing_r(self):
279        p=NoPDE(self.domain)        p=NoPDE(self.domain)
# Line 280  class Test_pdetools(unittest.TestCase): Line 282  class Test_pdetools(unittest.TestCase):
282        p.setValue(D=1.,Y=1.,q=msk)        p.setValue(D=1.,Y=1.,q=msk)
283        u=p.getSolution()        u=p.getSolution()
284        u_ex=(1.-msk)        u_ex=(1.-msk)
285        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
286    
287      def test_NoPDE_vector_constant(self):      def test_NoPDE_vector_constant(self):
288        p=NoPDE(self.domain)        p=NoPDE(self.domain)
# Line 289  class Test_pdetools(unittest.TestCase): Line 291  class Test_pdetools(unittest.TestCase):
291        p.setValue(D=1.,Y=1.,q=msk,r=2.)        p.setValue(D=1.,Y=1.,q=msk,r=2.)
292        u=p.getSolution()        u=p.getSolution()
293        u_ex=(1.-msk)+msk*2.        u_ex=(1.-msk)+msk*2.
294        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
295    
296      def test_NoPDE_vector_variable(self):      def test_NoPDE_vector_variable(self):
297        p=NoPDE(self.domain)        p=NoPDE(self.domain)
# Line 298  class Test_pdetools(unittest.TestCase): Line 300  class Test_pdetools(unittest.TestCase):
300        p.setValue(D=x[:2],Y=2*x[:2],q=msk,r=2.)        p.setValue(D=x[:2],Y=2*x[:2],q=msk,r=2.)
301        u=p.getSolution()        u=p.getSolution()
302        u_ex=2.        u_ex=2.
303        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.TOL,"value wrong")        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")

Legend:
Removed from v.797  
changed lines
  Added in v.798

  ViewVC Help
Powered by ViewVC 1.1.26