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

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

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

revision 2645 by jfenwick, Wed Sep 2 04:14:03 2009 UTC revision 2646 by jfenwick, Fri Sep 4 00:13:00 2009 UTC
# Line 54  import numpy Line 54  import numpy
54  from esys.escript import *  from esys.escript import *
55    
56    
57    class Test_TableInterpolation(unittest.TestCase):
58        RES_TOL=1.e-7 # RES_TOLerance to compare results    
59        
60        
61        def test_NullFunctionSpace(self):
62        arL=[[0, -1, -2, -3, -4], [1, 1, -2, -3, -4], [2, 2, 2, -3, -4], [3, 3, 3, 3, -4], [4, 4, 4, 4, 4]]
63        arn=numpy.array(arL)
64        ars=[arL,arn]
65        d0=Data(0)
66        d1=Data(1)
67        d2=Data(2)
68        d35=Data(3.5)
69        d4=Data(4)
70        dm05=Data(-0.5)
71        d175=Data(1.75)
72        d225=Data(2.25)
73        for arr in ars:
74            self.failUnless(Lsup(d1.interpolateTable(arL,0, 1, d2, 0, 1, 100)+2)<self.RES_TOL)
75            self.failUnless(Lsup(d1.interpolateTable(arL,0, 1, d35, 0, 1, 100)+3.5)<self.RES_TOL)
76            self.failUnless(Lsup(d35.interpolateTable(arL,0,1, d2, 0, 1, 100)-3.5)<self.RES_TOL)
77            self.failUnless(Lsup(d175.interpolateTable(arL,0,1,d225,0,1, 100)-0)<self.RES_TOL)
78            self.failUnless(Lsup(d2.interpolateTable(arL, 1, 4, d2, -1, 4, 100)-0.25)<self.RES_TOL)
79               # Point out of bounds
80            self.failUnlessRaises(RuntimeError, d1.interpolateTable,arL,0, 1, d4, 0, 1, 100 )
81            self.failUnlessRaises(RuntimeError, d4.interpolateTable, arL,0, 1, d1, 0, 1, 100 )
82            self.failUnlessRaises(RuntimeError, dm05.interpolateTable, arL,0,1, d1 , 0,1, 100 )
83            self.failUnlessRaises(RuntimeError, d1.interpolateTable, arL,0,1, dm05 , 0,1, 100 )
84               # interpolated value too large
85            self.failUnlessRaises(RuntimeError, d2.interpolateTable, arL, 0, 1, d2, 0, 1, 1 )
86    
87    
88        def test_FunctionSpace2D(self):
89        vs=[(1,3,5,7), (-1,1,-1,1), (0.5, 17, 0.25, 42)]   #There is no particular significance to these numbers
90        for fs in self.functionspaces:
91            print fs
92            points=fs.getX()
93            if not points.hasNoSamples():
94              for t in vs:
95            v0, v1, v2, v3 =t
96            x=points[0]
97            y=points[1]
98            xmax=sup(x)
99            xmin=inf(x)
100            ymax=sup(y)
101            ymin=inf(y)
102            xwidth=(xmax-xmin)/(self.xn-1)
103            ywidth=(ymax-ymin)/(self.yn-1)
104            table=[]
105            for j in xrange(self.yn+1):
106                  row=[]
107                  for i in xrange(self.xn+1):
108                row.append(v0+v1*xwidth*i+v2*ywidth*j+v3*i*j*xwidth*ywidth)
109                      table.append(row)
110                res=y.interpolateTable(table,ymin,ywidth,x, xmin, xwidth,500)
111                ref=v0+v1*x+v2*y+v3*x*y
112                self.failUnless(Lsup(res-ref)/Lsup(ref)<self.RES_TOL,"Failed for %s"%str(fs))
113            
114    
115        def test_FunctionSpace1D(self):
116        vs=[(1,3), (-1,1), (0.5, 17)]     #There is no particular significance to these numbers
117        for fs in self.functionspaces:
118            print fs
119            points=fs.getX()
120            if not points.hasNoSamples():
121              for t in vs:
122            v0, v1 =t
123            x=points[0]
124            xmax=sup(x)
125            xmin=inf(x)
126            xwidth=(xmax-xmin)/(self.xn-1)
127            table=[]
128            for i in xrange(self.xn+1):
129               table.append(v0+v1*xwidth*i)
130                res=x.interpolateTable(table, xmin, xwidth,500)
131                ref=v0+v1*x
132                self.failUnless(Lsup(res-ref)/Lsup(ref)<self.RES_TOL,"Failed for %s"%str(fs))
133            
134    
135    
136  class Test_saveCSV(unittest.TestCase):  class Test_saveCSV(unittest.TestCase):
137    
138     def test_save1(self):     def test_save1(self):

Legend:
Removed from v.2645  
changed lines
  Added in v.2646

  ViewVC Help
Powered by ViewVC 1.1.26