/[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 798 by gross, Fri Aug 4 01:05:36 2006 UTC revision 1072 by gross, Thu Mar 29 06:44:30 2007 UTC
# Line 38  import unittest Line 38  import unittest
38  from esys.escript import *  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_noLumping(unittest.TestCase):
42      DEBUG=False      DEBUG=False
43      VERBOSE=False      VERBOSE=False
44      def test_TimeIntegrationManager_scalar(self):      def test_TimeIntegrationManager_scalar(self):
# Line 79  class Test_pdetools(unittest.TestCase): Line 79  class Test_pdetools(unittest.TestCase):
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.RES_TOL,"value wrong scalar")          self.failUnless(abs(xx-2.)<self.RES_TOL,"value wrong scalar")
82    
83        def test_Locator_withList(self):
84            x=self.domain.getX()
85            arg=[numarray.ones((self.domain.getDim(),)), numarray.zeros((self.domain.getDim(),))]
86            l=Locator(self.domain,arg)
87            self.failUnless(ContinuousFunction(self.domain)==l.getFunctionSpace(),"wrong function space from domain")
88    
89            l=Locator(ContinuousFunction(self.domain),arg)
90            self.failUnless(ContinuousFunction(self.domain)==l.getFunctionSpace(),"wrong function space")
91    
92            xx=l.getX()
93            self.failUnless(isinstance(xx,list),"list expected")
94            for i in range(len(xx)):
95               self.failUnless(isinstance(xx[i],numarray.NumArray),"vector expected for %s item"%i)
96               self.failUnless(Lsup(xx[i]-arg[i])<self.RES_TOL,"%s-th location is wrong"%i)
97            xx=l(x)
98            self.failUnless(isinstance(xx,list),"list expected (2)")
99            for i in range(len(xx)):
100               self.failUnless(isinstance(xx[i],numarray.NumArray),"vector expected for %s item (2)"%i)
101               self.failUnless(Lsup(xx[i]-arg[i])<self.RES_TOL,"%s-th location is wrong (2)"%i)
102            xx=l(x[0]+x[1])
103            self.failUnless(isinstance(xx,list),"list expected (3)")
104            for i in range(len(xx)):
105               self.failUnless(isinstance(xx[i],float),"wrong scalar type")
106               self.failUnless(abs(xx[i]-(arg[i][0]+arg[i][1]))<self.RES_TOL,"value wrong scalar")
107                
108      def testProjector_rank0(self):      def testProjector_rank0(self):
109        x=ContinuousFunction(self.domain).getX()        x=ContinuousFunction(self.domain).getX()
# Line 115  class Test_pdetools(unittest.TestCase): Line 140  class Test_pdetools(unittest.TestCase):
140        td=p(td_ref.interpolate(Function(self.domain)))        td=p(td_ref.interpolate(Function(self.domain)))
141        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
142    
     def testProjector_rank0_fast(self):  
       x=ContinuousFunction(self.domain).getX()  
       h=Lsup(self.domain.getSize())  
       p=Projector(self.domain,reduce=False,fast=True)  
       td_ref=x[0]  
       td=p(td_ref.interpolate(Function(self.domain)))  
       self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")  
   
     def testProjector_rank1_fast(self):  
       x=ContinuousFunction(self.domain).getX()  
       h=Lsup(self.domain.getSize())  
       p=Projector(self.domain,reduce=False,fast=True)  
       td_ref=x  
       td=p(td_ref.interpolate(Function(self.domain)))  
       self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")  
   
     def testProjector_rank2_fast(self):  
       x=ContinuousFunction(self.domain).getX()  
       h=Lsup(self.domain.getSize())  
       p=Projector(self.domain,reduce=False,fast=True)  
       td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])  
       td=p(td_ref.interpolate(Function(self.domain)))  
       self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")  
   
     def testProjector_rank3_fast(self):  
       x=ContinuousFunction(self.domain).getX()  
       h=Lsup(self.domain.getSize())  
       p=Projector(self.domain,reduce=False,fast=True)  
       td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])  
       td=p(td_ref.interpolate(Function(self.domain)))  
       self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")  
   
     def testProjector_rank4_fast(self):  
       x=ContinuousFunction(self.domain).getX()  
       h=Lsup(self.domain.getSize())  
       p=Projector(self.domain,reduce=False,fast=True)  
       td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])  
       td=p(td_ref.interpolate(Function(self.domain)))  
       self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")  
143    
144      def testProjector_rank0_reduced(self):      def testProjector_rank0_reduced(self):
145        x=ContinuousFunction(self.domain).getX()        x=ContinuousFunction(self.domain).getX()
# Line 190  class Test_pdetools(unittest.TestCase): Line 176  class Test_pdetools(unittest.TestCase):
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.RES_TOL,"value wrong")        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
178    
179      def testProjector_rank0_fast_reduced(self):      def testProjector_rank0_with_reduced_input(self):
180        x=ContinuousFunction(self.domain).getX()        x=ContinuousFunction(self.domain).getX()
181        h=Lsup(self.domain.getSize())        p=Projector(self.domain,reduce=False,fast=False)
       p=Projector(self.domain,reduce=True,fast=True)  
182        td_ref=x[0]        td_ref=x[0]
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)*h,"value wrong")        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
185    
186      def testProjector_rank1_fast_reduced(self):      def testProjector_rank1_with_reduced_input(self):
187        x=ContinuousFunction(self.domain).getX()        x=ContinuousFunction(self.domain).getX()
188        h=Lsup(self.domain.getSize())        p=Projector(self.domain,reduce=False,fast=False)
       p=Projector(self.domain,reduce=True,fast=True)  
189        td_ref=x        td_ref=x
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)*h,"value wrong")        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
192    
193      def testProjector_rank2_fast_reduced(self):      def testProjector_rank2_with_reduced_input(self):
194        x=ContinuousFunction(self.domain).getX()        x=ContinuousFunction(self.domain).getX()
195        h=Lsup(self.domain.getSize())        p=Projector(self.domain,reduce=False,fast=False)
       p=Projector(self.domain,reduce=True,fast=True)  
196        td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])        td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
197        td=p(td_ref.interpolate(Function(self.domain)))        td=p(td_ref.interpolate(Function(self.domain)))
198        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
199    
200      def testProjector_rank3_fast_reduced(self):      def testProjector_rank3_with_reduced_input(self):
201        x=ContinuousFunction(self.domain).getX()        x=ContinuousFunction(self.domain).getX()
202        h=Lsup(self.domain.getSize())        p=Projector(self.domain,reduce=False,fast=False)
       p=Projector(self.domain,reduce=True,fast=True)  
203        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])
204        td=p(td_ref.interpolate(Function(self.domain)))        td=p(td_ref.interpolate(Function(self.domain)))
205        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
206    
207      def testProjector_rank4_fast_reduced(self):      def testProjector_rank4_with_reduced_input(self):
208        x=ContinuousFunction(self.domain).getX()        x=ContinuousFunction(self.domain).getX()
209        h=Lsup(self.domain.getSize())        p=Projector(self.domain,reduce=False,fast=False)
       p=Projector(self.domain,reduce=True,fast=True)  
210        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])
211        td=p(td_ref.interpolate(Function(self.domain)))        td=p(td_ref.interpolate(Function(self.domain)))
212        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")        self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
213    
214    
215        def testProjector_rank0_reduced_with_reduced_input(self):
216          x=ContinuousFunction(self.domain).getX()
217          p=Projector(self.domain,reduce=True,fast=False)
218          td_ref=1.
219          td=p(Data(td_ref,ReducedFunction(self.domain)))
220          self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
221    
222        def testProjector_rank1_reduced_with_reduced_input(self):
223          x=ContinuousFunction(self.domain).getX()
224          p=Projector(self.domain,reduce=True,fast=False)
225          td_ref=numarray.array([1.,2.,3.])
226          td=p(Data(td_ref,ReducedFunction(self.domain)))
227          self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
228    
229        def testProjector_rank2_reduced_with_reduced_input(self):
230          x=ContinuousFunction(self.domain).getX()
231          p=Projector(self.domain,reduce=True,fast=False)
232          td_ref=numarray.array([[11.,12.],[21,22.]])
233          td=p(Data(td_ref,ReducedFunction(self.domain)))
234          self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
235    
236        def testProjector_rank3_reduced_with_reduced_input(self):
237          x=ContinuousFunction(self.domain).getX()
238          p=Projector(self.domain,reduce=True,fast=False)
239          td_ref=numarray.array([[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]])
240          td=p(Data(td_ref,ReducedFunction(self.domain)))
241          self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
242    
243        def testProjector_rank4_reduced_with_reduced_input(self):
244          x=ContinuousFunction(self.domain).getX()
245          p=Projector(self.domain,reduce=True,fast=False)
246          td_ref=numarray.array([[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]])
247          td=p(Data(td_ref,ReducedFunction(self.domain)))
248          self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*self.RES_TOL,"value wrong")
249    
250    
251      def test_NoPDE_scalar_missing_r(self):      def test_NoPDE_scalar_missing_r(self):
252        p=NoPDE(self.domain)        p=NoPDE(self.domain)
# Line 270  class Test_pdetools(unittest.TestCase): Line 288  class Test_pdetools(unittest.TestCase):
288        p=NoPDE(self.domain)        p=NoPDE(self.domain)
289        x=self.domain.getX()        x=self.domain.getX()
290        msk=whereZero(x[0])*[1.,0.]        msk=whereZero(x[0])*[1.,0.]
291        p.setValue(D=1.,q=msk,r=2.)        p.setValue(D=numarray.ones([2]),q=msk,r=2.)
292        u=p.getSolution()        u=p.getSolution()
293        u_ex=msk*2.        u_ex=msk*2.
294        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
# Line 279  class Test_pdetools(unittest.TestCase): Line 297  class Test_pdetools(unittest.TestCase):
297        p=NoPDE(self.domain)        p=NoPDE(self.domain)
298        x=self.domain.getX()        x=self.domain.getX()
299        msk=whereZero(x[0])*[1.,0.]        msk=whereZero(x[0])*[1.,0.]
300        p.setValue(D=1.,Y=1.,q=msk)        p.setValue(D=numarray.ones([2]),Y=numarray.ones([2]),q=msk)
301        u=p.getSolution()        u=p.getSolution()
302        u_ex=(1.-msk)        u_ex=(1.-msk)
303        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
# Line 288  class Test_pdetools(unittest.TestCase): Line 306  class Test_pdetools(unittest.TestCase):
306        p=NoPDE(self.domain)        p=NoPDE(self.domain)
307        x=self.domain.getX()        x=self.domain.getX()
308        msk=whereZero(x[0])*[1.,0.]        msk=whereZero(x[0])*[1.,0.]
309        p.setValue(D=1.,Y=1.,q=msk,r=2.)        p.setValue(D=numarray.ones([2]),Y=numarray.ones([2]),q=msk,r=2.)
310        u=p.getSolution()        u=p.getSolution()
311        u_ex=(1.-msk)+msk*2.        u_ex=(1.-msk)+msk*2.
312        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
# Line 301  class Test_pdetools(unittest.TestCase): Line 319  class Test_pdetools(unittest.TestCase):
319        u=p.getSolution()        u=p.getSolution()
320        u_ex=2.        u_ex=2.
321        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")        self.failUnless(Lsup(u_ex-u)<Lsup(u_ex)*self.RES_TOL,"value wrong")
322    
323    
324    class Test_pdetools(Test_pdetools_noLumping):
325        def testProjector_rank0_fast_reduced(self):
326          x=ContinuousFunction(self.domain).getX()
327          h=Lsup(self.domain.getSize())
328          p=Projector(self.domain,reduce=True,fast=True)
329          td_ref=x[0]
330          td=p(td_ref.interpolate(Function(self.domain)))
331          self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
332    
333        def testProjector_rank1_fast_reduced(self):
334          x=ContinuousFunction(self.domain).getX()
335          h=Lsup(self.domain.getSize())
336          p=Projector(self.domain,reduce=True,fast=True)
337          td_ref=x
338          td=p(td_ref.interpolate(Function(self.domain)))
339          self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
340    
341        def testProjector_rank2_fast_reduced(self):
342          x=ContinuousFunction(self.domain).getX()
343          h=Lsup(self.domain.getSize())
344          p=Projector(self.domain,reduce=True,fast=True)
345          td_ref=[[11.,12.],[21,22.]]*(x[0]+x[1])
346          td=p(td_ref.interpolate(Function(self.domain)))
347          self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
348    
349        def testProjector_rank3_fast_reduced(self):
350          x=ContinuousFunction(self.domain).getX()
351          h=Lsup(self.domain.getSize())
352          p=Projector(self.domain,reduce=True,fast=True)
353          td_ref=[[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]]*(x[0]+x[1])
354          td=p(td_ref.interpolate(Function(self.domain)))
355          self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
356    
357        def testProjector_rank4_fast_reduced(self):
358          x=ContinuousFunction(self.domain).getX()
359          h=Lsup(self.domain.getSize())
360          p=Projector(self.domain,reduce=True,fast=True)
361          td_ref=[[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]]*(x[0]+x[1])
362          td=p(td_ref.interpolate(Function(self.domain)))
363          self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
364    
365        def testProjector_rank0_fast_reduced_with_reduced_input(self):
366          x=ContinuousFunction(self.domain).getX()
367          h=Lsup(self.domain.getSize())
368          p=Projector(self.domain,reduce=True,fast=True)
369          td_ref=1.
370          td=p(Data(td_ref,ReducedFunction(self.domain)))
371          self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
372    
373        def testProjector_rank1_fast_reduced_with_reduced_input(self):
374          x=ContinuousFunction(self.domain).getX()
375          h=Lsup(self.domain.getSize())
376          p=Projector(self.domain,reduce=True,fast=True)
377          td_ref=numarray.array([1.,2.,3.])
378          td=p(Data(td_ref,ReducedFunction(self.domain)))
379          self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
380    
381        def testProjector_rank2_fast_reduced_with_reduced_input(self):
382          x=ContinuousFunction(self.domain).getX()
383          h=Lsup(self.domain.getSize())
384          p=Projector(self.domain,reduce=True,fast=True)
385          td_ref=numarray.array([[11.,12.],[21,22.]])
386          td=p(Data(td_ref,ReducedFunction(self.domain)))
387          self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
388    
389        def testProjector_rank3_fast_reduced_with_reduced_input(self):
390          x=ContinuousFunction(self.domain).getX()
391          h=Lsup(self.domain.getSize())
392          p=Projector(self.domain,reduce=True,fast=True)
393          td_ref=numarray.array([[[111.,112.],[121,122.]],[[211.,212.],[221,222.]]])
394          td=p(Data(td_ref,ReducedFunction(self.domain)))
395          self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
396    
397        def testProjector_rank4_fast_reduced_with_reduced_input(self):
398          x=ContinuousFunction(self.domain).getX()
399          h=Lsup(self.domain.getSize())
400          p=Projector(self.domain,reduce=True,fast=True)
401          td_ref=numarray.array([[[[1111.,1112.],[1121,1122.]],[[1211.,1212.],[1221,1222.]]],[[[2111.,2112.],[2121,2122.]],[[2211.,2212.],[2221,2222.]]]])
402          td=p(Data(td_ref,ReducedFunction(self.domain)))
403          self.failUnless(Lsup(td-td_ref)<Lsup(td_ref)*h,"value wrong")
404    

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

  ViewVC Help
Powered by ViewVC 1.1.26