/[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 3891 by caltinay, Wed Feb 1 06:16:25 2012 UTC revision 3892 by jfenwick, Tue Apr 10 08:57:23 2012 UTC
# Line 59  except KeyError: Line 59  except KeyError:
59       ESCRIPT_WORKDIR='.'       ESCRIPT_WORKDIR='.'
60    
61  class Test_TableInterpolation(unittest.TestCase):  class Test_TableInterpolation(unittest.TestCase):
62      RES_TOL=1.e-7 # RES_TOLerance to compare results          RES_TOL=1.e-7 # RES_TOLerance to compare results    
63                
64                
65      def test_NullFunctionSpace(self):      def test_NullFunctionSpace(self):
66      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]]          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]]
67      arn=numpy.array(arL)          arn=numpy.array(arL)
68      ars=[arL,arn]          ars=[arL,arn]
69      d0=Data(0)          d0=Data(0)
70      d1=Data(1)          d1=Data(1)
71      d2=Data(2)          d2=Data(2)
72      d35=Data(3.5)          d35=Data(3.5)
73      d4=Data(4)          d4=Data(4)
74      dm05=Data(-0.5)          dm05=Data(-0.5)
75      d175=Data(1.75)          d175=Data(1.75)
76      d225=Data(2.25)          d225=Data(2.25)
77      for arr in ars:          for arr in ars:
78          self.assertTrue(Lsup(d2.interpolateTable(arL,0, 1, d1, 0, 1, 100)+2)<self.RES_TOL)              self.assertTrue(Lsup(d2.interpolateTable(arL,0, 1, d1, 0, 1, 100)+2)<self.RES_TOL)
79          self.assertTrue(Lsup(d35.interpolateTable(arL,0, 1, d1, 0, 1, 100)+3.5)<self.RES_TOL)              self.assertTrue(Lsup(d35.interpolateTable(arL,0, 1, d1, 0, 1, 100)+3.5)<self.RES_TOL)
80          self.assertTrue(Lsup(d2.interpolateTable(arL,0,1, d35, 0, 1, 100)-3.5)<self.RES_TOL)              self.assertTrue(Lsup(d2.interpolateTable(arL,0,1, d35, 0, 1, 100)-3.5)<self.RES_TOL)
81          self.assertTrue(Lsup(d225.interpolateTable(arL,0,1,d175,0,1, 100)-0)<self.RES_TOL)              self.assertTrue(Lsup(d225.interpolateTable(arL,0,1,d175,0,1, 100)-0)<self.RES_TOL)
82             # Point out of bounds                 # Point out of bounds
83          self.assertRaises(RuntimeError, d1.interpolateTable,arL,0, 1, d4, 0, 0.5, 100, check_boundaries=True )              self.assertRaises(RuntimeError, d1.interpolateTable,arL,0, 1, d4, 0, 0.5, 100, check_boundaries=True )
84          self.assertRaises(RuntimeError, d4.interpolateTable, arL,0, 0.5, d1, 0, 1, 100, check_boundaries=True  )              self.assertRaises(RuntimeError, d4.interpolateTable, arL,0, 0.5, d1, 0, 1, 100, check_boundaries=True  )
85          self.assertRaises(RuntimeError, dm05.interpolateTable, arL,0,1, d1 , 0,1, 100, check_boundaries=True  )              self.assertRaises(RuntimeError, dm05.interpolateTable, arL,0,1, d1 , 0,1, 100, check_boundaries=True  )
86          self.assertRaises(RuntimeError, d1.interpolateTable, arL,0,1, dm05 , 0,1, 100,check_boundaries=True  )              self.assertRaises(RuntimeError, d1.interpolateTable, arL,0,1, dm05 , 0,1, 100,check_boundaries=True  )
87             #Test to ensure not check_boundaries does not throw in the above cases                 #Test to ensure not check_boundaries does not throw in the above cases
88          d1.interpolateTable(arL,0, 1, d4, 0, 0.5, 100, check_boundaries=False)              d1.interpolateTable(arL,0, 1, d4, 0, 0.5, 100, check_boundaries=False)
89          d4.interpolateTable( arL,0, 0.5, d1, 0, 1, 100, check_boundaries=False  )              d4.interpolateTable( arL,0, 0.5, d1, 0, 1, 100, check_boundaries=False  )
90          dm05.interpolateTable( arL,0,1, d1 , 0,1, 100, check_boundaries=False  )              dm05.interpolateTable( arL,0,1, d1 , 0,1, 100, check_boundaries=False  )
91          d1.interpolateTable( arL,0,1, dm05 , 0,1, 100,check_boundaries=False  )              d1.interpolateTable( arL,0,1, dm05 , 0,1, 100,check_boundaries=False  )
92                            
93             # interpolated value too large                 # interpolated value too large
94          self.assertRaises(RuntimeError, d2.interpolateTable, arL, 0, 1, d2, 0, 1, 1 )              self.assertRaises(RuntimeError, d2.interpolateTable, arL, 0, 1, d2, 0, 1, 1 )
95    
96    
97      def test_FunctionSpace3D(self):      def test_FunctionSpace3D(self):
98      vs=[(1,3,5,7,11,13,17,19), (-1,1,-1,1,-1,1,-1,1), (0.5, 17, 0.25, 42, 0.125, 35, 0.625, 49)]   #There is no particular significance to these numbers          vs=[(1,3,5,7,11,13,17,19), (-1,1,-1,1,-1,1,-1,1), (0.5, 17, 0.25, 42, 0.125, 35, 0.625, 49)]   #There is no particular significance to these numbers
99      for fs in self.functionspaces:          for fs in self.functionspaces:
100          points=fs.getX()              points=fs.getX()
101          for t in vs:              for t in vs:
102          v0, v1, v2, v3, v4, v5, v6, v7 =t                  v0, v1, v2, v3, v4, v5, v6, v7 =t
103          x=points[0]                  x=points[0]
104          y=points[1]                  y=points[1]
105          z=points[2]                  z=points[2]
106          xmax=sup(x)                  xmax=sup(x)
107          xmin=inf(x)                  xmin=inf(x)
108          ymax=sup(y)                  ymax=sup(y)
109          ymin=inf(y)                  ymin=inf(y)
110          zmax=sup(z)                  zmax=sup(z)
111          zmin=inf(z)                  zmin=inf(z)
112          xwidth=(xmax-xmin)/(self.xn-1)                  xwidth=(xmax-xmin)/(self.xn-1)
113          ywidth=(ymax-ymin)/(self.yn-1)                  ywidth=(ymax-ymin)/(self.yn-1)
114          zwidth=(zmax-zmin)/(self.zn-1)                        zwidth=(zmax-zmin)/(self.zn-1)          
115          table=[]                  table=[]
116          for k in range(self.zn):                  for k in range(self.zn):
117              face=[]                      face=[]
118              for j in range(self.yn):                      for j in range(self.yn):
119              row=[]                          row=[]
120              for i in range(self.xn):                          for i in range(self.xn):
121                  row.append(v0+v1*xwidth*i+v2*ywidth*j+v3*i*j*xwidth*ywidth)                                  row.append(v0+v1*xwidth*i+v2*ywidth*j+v3*i*j*xwidth*ywidth)
122              face.append(row)                          face.append(row)
123              table.append(face)                      table.append(face)
124              ref=v0+v1*(x-xmin)+v2*(y-ymin)+v3*(x-xmin)*(y-ymin)                  ref=v0+v1*(x-xmin)+v2*(y-ymin)+v3*(x-xmin)*(y-ymin)
125          lsupref=Lsup(ref)                  lsupref=Lsup(ref)
126          if lsupref!=0 and xwidth>0:     #This will happen in cases where there are no samples on this rank                  if lsupref!=0 and xwidth>0:             #This will happen in cases where there are no samples on this rank
127              res=interpolateTable(table, points, (xmin, ymin, zmin), (xwidth, ywidth, zwidth),900)                      res=interpolateTable(table, points, (xmin, ymin, zmin), (xwidth, ywidth, zwidth),900)
128                  self.assertTrue(Lsup(res-ref)/Lsup(ref)<self.RES_TOL,"Failed for %s"%str(fs))                      self.assertTrue(Lsup(res-ref)/Lsup(ref)<self.RES_TOL,"Failed for %s"%str(fs))
129              # Test undef                      # Test undef
130              self.assertRaises(RuntimeError, interpolateTable, table, points, (xmin, ymin, zmin), (xwidth, ywidth, zwidth), -1)                      self.assertRaises(RuntimeError, interpolateTable, table, points, (xmin, ymin, zmin), (xwidth, ywidth, zwidth), -1)
131              # Test bounds checking                      # Test bounds checking
132              self.assertRaises(RuntimeError, interpolateTable, table, points, (xmin, ymin, zmin), (xwidth/3, ywidth, zwidth), 900,True)                      self.assertRaises(RuntimeError, interpolateTable, table, points, (xmin, ymin, zmin), (xwidth/3, ywidth, zwidth), 900,True)
133              self.assertRaises(RuntimeError, interpolateTable, table, points, (xmin, ymin, zmin), (xwidth, ywidth/3, zwidth), 900, True)                      self.assertRaises(RuntimeError, interpolateTable, table, points, (xmin, ymin, zmin), (xwidth, ywidth/3, zwidth), 900, True)
134              self.assertRaises(RuntimeError, interpolateTable, table, points, (xmin, ymin, zmin), (xwidth, ywidth, zwidth/3), 900, True)                      self.assertRaises(RuntimeError, interpolateTable, table, points, (xmin, ymin, zmin), (xwidth, ywidth, zwidth/3), 900, True)
135    
136      def test_FunctionSpace2D(self):      def test_FunctionSpace2D(self):
137      vs=[(1,3,5,7), (-1,1,-1,1), (0.5, 17, 0.25, 42)]   #There is no particular significance to these numbers          vs=[(1,3,5,7), (-1,1,-1,1), (0.5, 17, 0.25, 42)]   #There is no particular significance to these numbers
138      for fs in self.functionspaces:          for fs in self.functionspaces:
139          points=fs.getX()              points=fs.getX()
140          for t in vs:              for t in vs:
141          v0, v1, v2, v3 =t                  v0, v1, v2, v3 =t
142          x=points[0]                  x=points[0]
143          y=points[1]                  y=points[1]
144          xmax=sup(x)                  xmax=sup(x)
145          xmin=inf(x)                  xmin=inf(x)
146          ymax=sup(y)                  ymax=sup(y)
147          ymin=inf(y)                  ymin=inf(y)
148          xwidth=(xmax-xmin)/(self.xn-1)                  xwidth=(xmax-xmin)/(self.xn-1)
149          ywidth=(ymax-ymin)/(self.yn-1)                  ywidth=(ymax-ymin)/(self.yn-1)
150          table=[]                  table=[]
151          for j in range(self.yn):                  for j in range(self.yn):
152                row=[]                        row=[]
153                for i in range(self.xn):                        for i in range(self.xn):
154              row.append(v0+v1*xwidth*i+v2*ywidth*j+v3*i*j*xwidth*ywidth)                          row.append(v0+v1*xwidth*i+v2*ywidth*j+v3*i*j*xwidth*ywidth)
155                    table.append(row)                        table.append(row)
156              ref=v0+v1*(x-xmin)+v2*(y-ymin)+v3*(x-xmin)*(y-ymin)                  ref=v0+v1*(x-xmin)+v2*(y-ymin)+v3*(x-xmin)*(y-ymin)
157          lsupref=Lsup(ref)                  lsupref=Lsup(ref)
158          if lsupref!=0 and xwidth>0:     #This will happen in cases where there are no samples on this rank                  if lsupref!=0 and xwidth>0:             #This will happen in cases where there are no samples on this rank
159                  res=x.interpolateTable(table,xmin,xwidth,y, ymin, ywidth,500)                      res=x.interpolateTable(table,xmin,xwidth,y, ymin, ywidth,500)
160                  self.assertTrue(Lsup(res-ref)/Lsup(ref)<self.RES_TOL,"Failed for %s"%str(fs))                      self.assertTrue(Lsup(res-ref)/Lsup(ref)<self.RES_TOL,"Failed for %s"%str(fs))
161              #Now we try for the new interface                      #Now we try for the new interface
162              res=interpolateTable(table,points[0:2], (xmin, ymin), (xwidth, ywidth),500)                      res=interpolateTable(table,points[0:2], (xmin, ymin), (xwidth, ywidth),500)
163              self.assertTrue(Lsup(res-ref)/Lsup(ref)<self.RES_TOL,"Failed for %s under unified call."%str(fs))                      self.assertTrue(Lsup(res-ref)/Lsup(ref)<self.RES_TOL,"Failed for %s under unified call."%str(fs))
164                                    
165                        
166    
167      def test_FunctionSpace1D(self):      def test_FunctionSpace1D(self):
168      vs=[(1,3), (-1,1), (0.5, 17)]     #There is no particular significance to these numbers          vs=[(1,3), (-1,1), (0.5, 17)]     #There is no particular significance to these numbers
169      for fs in self.functionspaces:          for fs in self.functionspaces:
170          points=fs.getX()              points=fs.getX()
171          for t in vs:              for t in vs:
172          v0, v1 =t                  v0, v1 =t
173          x=points[0]                  x=points[0]
174          xmax=sup(x)                  xmax=sup(x)
175          xmin=inf(x)                  xmin=inf(x)
176          xwidth=(xmax-xmin)/(self.xn-1)                  xwidth=(xmax-xmin)/(self.xn-1)
177          table=[]                  table=[]
178          for i in range(self.xn):                  for i in range(self.xn):
179             table.append(v0+v1*xwidth*i)                     table.append(v0+v1*xwidth*i)
180              ref=v0+v1*(x-xmin)                  ref=v0+v1*(x-xmin)
181          lsupref=Lsup(ref)                  lsupref=Lsup(ref)
182          if lsupref!=0 and xwidth>0:     #This will happen in cases where there are no samples on this rank                  if lsupref!=0 and xwidth>0:             #This will happen in cases where there are no samples on this rank
183             res=x.interpolateTable(table, xmin, xwidth,500)                     res=x.interpolateTable(table, xmin, xwidth,500)
184             self.assertTrue(Lsup(res-ref)/lsupref<self.RES_TOL,"Failed for %s"%str(fs))                     self.assertTrue(Lsup(res-ref)/lsupref<self.RES_TOL,"Failed for %s"%str(fs))
185             #Now we try for the new interface                     #Now we try for the new interface
186             res=interpolateTable(table,points[0:1], (xmin,), (xwidth, ),500)                     res=interpolateTable(table,points[0:1], (xmin,), (xwidth, ),500)
187             self.assertTrue(Lsup(res-ref)/Lsup(ref)<self.RES_TOL,"Failed for %s under unified call."%str(fs))                     self.assertTrue(Lsup(res-ref)/Lsup(ref)<self.RES_TOL,"Failed for %s under unified call."%str(fs))
188             res=interpolateTable(table,points[0:1], xmin, xwidth,500)                     res=interpolateTable(table,points[0:1], xmin, xwidth,500)
189             self.assertTrue(Lsup(res-ref)/Lsup(ref)<self.RES_TOL,"Failed for %s under unified call (no tuple)."%str(fs))                     self.assertTrue(Lsup(res-ref)/Lsup(ref)<self.RES_TOL,"Failed for %s under unified call (no tuple)."%str(fs))
190    
191  class Test_saveCSV(unittest.TestCase):  class Test_saveCSV(unittest.TestCase):
192    
193     def test_save1(self):     def test_save1(self):
194      X=self.domain.getX()          X=self.domain.getX()
195      X0=X[0]          X0=X[0]
196      fname=os.path.join(ESCRIPT_WORKDIR, "test_save1.csv")          fname=os.path.join(ESCRIPT_WORKDIR, "test_save1.csv")
197      saveDataCSV(fname,C=X, D=X0)          saveDataCSV(fname,C=X, D=X0)
198      saveDataCSV(fname,append=True, J=X0, H=X)          saveDataCSV(fname,append=True, J=X0, H=X)
199      self.assertTrue(os.path.exists(fname), "test file not created")          self.assertTrue(os.path.exists(fname), "test file not created")
200      f=open(fname,'r')          f=open(fname,'r')
201      line=f.readline()          line=f.readline()
202      self.assertEquals(line,"C_0, C_1, D\n")    #This tests both separator strings          self.assertEquals(line,"C_0, C_1, D\n")    #This tests both separator strings
203      #Now we find out how many rows it has          #Now we find out how many rows it has
204      linecount=0          linecount=0
205      while line != '':          while line != '':
206          linecount+=1                  linecount+=1
207          line=f.readline()                  line=f.readline()
208      self.assertEquals(linecount,self.linecount1*2)          self.assertEquals(linecount,self.linecount1*2)
209      f.close()          f.close()
210      #Now to other output          #Now to other output
211      T2=Tensor(7,X.getFunctionSpace())          T2=Tensor(7,X.getFunctionSpace())
212      T3=Tensor3(8,X.getFunctionSpace())          T3=Tensor3(8,X.getFunctionSpace())
213      T4=Tensor4(9,X.getFunctionSpace())          T4=Tensor4(9,X.getFunctionSpace())
214      saveDataCSV(fname,A=T2,B=T3,C=T4)          saveDataCSV(fname,A=T2,B=T3,C=T4)
215      f=open(fname,'r')          f=open(fname,'r')
216      line=f.readline()          line=f.readline()
217      self.assertEquals(line, 'A_0_0, A_1_0, A_0_1, A_1_1, B_0_0_0, B_0_0_1, B_1_0_0, B_1_0_1, B_0_1_0, B_0_1_1, B_1_1_0, B_1_1_1, C_0_0_0_0, C_0_0_0_1, C_0_0_1_0, C_0_0_1_1, C_1_0_0_0, C_1_0_0_1, C_1_0_1_0, C_1_0_1_1, C_0_1_0_0, C_0_1_0_1, C_0_1_1_0, C_0_1_1_1, C_1_1_0_0, C_1_1_0_1, C_1_1_1_0, C_1_1_1_1\n')          self.assertEquals(line, 'A_0_0, A_1_0, A_0_1, A_1_1, B_0_0_0, B_0_0_1, B_1_0_0, B_1_0_1, B_0_1_0, B_0_1_1, B_1_1_0, B_1_1_1, C_0_0_0_0, C_0_0_0_1, C_0_0_1_0, C_0_0_1_1, C_1_0_0_0, C_1_0_0_1, C_1_0_1_0, C_1_0_1_1, C_0_1_0_0, C_0_1_0_1, C_0_1_1_0, C_0_1_1_1, C_1_1_0_0, C_1_1_0_1, C_1_1_1_0, C_1_1_1_1\n')
218      line=f.readline()          line=f.readline()
219      line_expected=[7.]*4+[8.]*8+[9.]*16          line_expected=[7.]*4+[8.]*8+[9.]*16
220      line_got=[float(elt) for elt in line.split(',')]          line_got=[float(elt) for elt in line.split(',')]
221      self.assertEquals(line_got,line_expected)          self.assertEquals(line_got,line_expected)
222      linecount=1          linecount=1
223      while line != '':          while line != '':
224          linecount+=1                  linecount+=1
225          line=f.readline()                  line=f.readline()
226      self.assertEquals(linecount, self.linecount1)          self.assertEquals(linecount, self.linecount1)
227      f.close()            f.close()      
228      #Now to test separators and mask          #Now to test separators and mask
229      saveDataCSV(fname, sep="|",csep="/", U=X, V=X0, mask=X0)          saveDataCSV(fname, sep="|",csep="/", U=X, V=X0, mask=X0)
230      f=open(fname,'r')          f=open(fname,'r')
231      line=f.readline()          line=f.readline()
232      self.assertEquals(line, 'U/0|U/1|V\n')          self.assertEquals(line, 'U/0|U/1|V\n')
233      line=f.readline()          line=f.readline()
234      line_got=[float(elt) for elt in line.split('|')]          line_got=[float(elt) for elt in line.split('|')]
235      self.assertEquals(len(self.line_expected),len(line_got))          self.assertEquals(len(self.line_expected),len(line_got))
236      for i in range(len(self.line_expected)):          for i in range(len(self.line_expected)):
237          self.assertAlmostEquals(self.line_expected[i],line_got[i])                  self.assertAlmostEquals(self.line_expected[i],line_got[i])
238      linecount=1          linecount=1
239      while line!='':          while line!='':
240          linecount+=1                  linecount+=1
241          line=f.readline()                  line=f.readline()
242      self.assertEquals(linecount,self.linecount2)          self.assertEquals(linecount,self.linecount2)
243                
244                
245  class Test_Domain(unittest.TestCase):  class Test_Domain(unittest.TestCase):
246    
247     def test_getListOfTags(self): # requires self.boundary_tag_list     def test_getListOfTags(self): # requires self.boundary_tag_list
# Line 251  class Test_Domain(unittest.TestCase): Line 251  class Test_Domain(unittest.TestCase):
251             self.assertTrue(i in tags, "tag %s is missing."%i)             self.assertTrue(i in tags, "tag %s is missing."%i)
252    
253     def test_RandomData(self):     def test_RandomData(self):
254          fs=Function(self.domain)    # The choice of functionspace is arbitrary          fs=Function(self.domain)        # The choice of functionspace is arbitrary
255      dat=RandomData((2,2,2,2),fs,8)  # Choice of seed is arbitrary          dat=RandomData((2,2,2,2),fs,8)  # Choice of seed is arbitrary
256      self.assertTrue(Lsup(dat-1)<1.0001)          self.assertTrue(Lsup(dat-1)<1.0001)
257    
258     def test_Factories(self):     def test_Factories(self):
259      fs=Function(self.domain)    # The choice of functionspace is arbitrary          fs=Function(self.domain)        # The choice of functionspace is arbitrary
260      dime=self.domain.getDim()          dime=self.domain.getDim()
261      if dime>0:          if dime>0:
262         z=[]             z=[]
263         bad=[]             bad=[]
264         for i in range(dime):             for i in range(dime):
265          z+=[i]                  z+=[i]
266          bad+=[i]                  bad+=[i]
267         bad+=[i]             bad+=[i]
268         d=Vector(z,fs)             d=Vector(z,fs)
269         self.assertTrue(d.getShape()==(dime,))             self.assertTrue(d.getShape()==(dime,))
270         self.assertRaises(RuntimeError, Vector, bad,fs)  #test wrong shape             self.assertRaises(RuntimeError, Vector, bad,fs)      #test wrong shape
271         y=[]             y=[]
272         bad=[]             bad=[]
273         for i in range(dime):             for i in range(dime):
274          y+=[z]                  y+=[z]
275          bad+=[z]                  bad+=[z]
276         bad+=[z]             bad+=[z]
277         z=y             z=y
278         d=Tensor(z,fs)             d=Tensor(z,fs)
279         self.assertTrue(d.getShape()==(dime,dime))             self.assertTrue(d.getShape()==(dime,dime))
280         try:             try:
281          Tensor(bad,fs)                  Tensor(bad,fs)
282         except RuntimeError:             except RuntimeError:
283          pass                  pass
284         else:             else:
285          self.fail("Tensor should have rejected bad shape")                  self.fail("Tensor should have rejected bad shape")
286         y=[]             y=[]
287         bad=[]             bad=[]
288         for i in range(dime):             for i in range(dime):
289          y+=[z]                  y+=[z]
290          bad+=[z]                  bad+=[z]
291         bad+=[z]             bad+=[z]
292         z=y             z=y
293         d=Tensor3(z,fs)             d=Tensor3(z,fs)
294         self.assertTrue(d.getShape()==(dime,dime,dime))             self.assertTrue(d.getShape()==(dime,dime,dime))
295         try:             try:
296          Tensor3(bad,fs)                  Tensor3(bad,fs)
297         except RuntimeError:             except RuntimeError:
298          pass                  pass
299         else:             else:
300          self.fail("Tensor3 should have rejected bad shape")                  self.fail("Tensor3 should have rejected bad shape")
301         y=[]             y=[]
302         bad=[]             bad=[]
303         for i in range(dime):             for i in range(dime):
304          y+=[z]                  y+=[z]
305          bad+=[z]                  bad+=[z]
306         bad+=[z]             bad+=[z]
307         z=y             z=y
308         d=Tensor4(z,fs)             d=Tensor4(z,fs)
309         self.assertTrue(d.getShape()==(dime,dime,dime,dime))             self.assertTrue(d.getShape()==(dime,dime,dime,dime))
310         try:             try:
311          Tensor4(bad,fs)                  Tensor4(bad,fs)
312         except RuntimeError:             except RuntimeError:
313          pass                  pass
314         else:             else:
315          self.fail("Tensor4 should have rejected bad shape")                  self.fail("Tensor4 should have rejected bad shape")
316    
317    
318     def test_addTags(self):     def test_addTags(self):
# Line 337  class Test_Domain(unittest.TestCase): Line 337  class Test_Domain(unittest.TestCase):
337          r.setTaggedValue(1,1.)          r.setTaggedValue(1,1.)
338          s.setTaggedValue(tag2,2.)          s.setTaggedValue(tag2,2.)
339          r.setTaggedValue(2,2.)          r.setTaggedValue(2,2.)
340          self.assertRaises(RuntimeError,s.setTaggedValue,tag3,3.)    #tag3 does not exist          self.assertRaises(RuntimeError,s.setTaggedValue,tag3,3.)        #tag3 does not exist
341          self.assertTrue(Lsup(s-r)<=0.)          self.assertTrue(Lsup(s-r)<=0.)
342          # get tag:          # get tag:
343          names=getTagNames(self.domain)          names=getTagNames(self.domain)
# Line 449  class Test_Domain(unittest.TestCase): Line 449  class Test_Domain(unittest.TestCase):
449    
450  class Test_GlobalMinMax(unittest.TestCase):  class Test_GlobalMinMax(unittest.TestCase):
451     def test_GlobalMinMax(self):     def test_GlobalMinMax(self):
452      myrank=getMPIRankWorld()          myrank=getMPIRankWorld()
453      d=Data(myrank,Function(self.domain))          d=Data(myrank,Function(self.domain))
454      minproc=inf(d)          minproc=inf(d)
455      maxproc=sup(d)      #This tells us where to expect values to be          maxproc=sup(d)          #This tells us where to expect values to be
456      if d.getNumberOfDataPoints()>0:          if d.getNumberOfDataPoints()>0:
457          d.setValueOfDataPoint(0,myrank-0.001);                  d.setValueOfDataPoint(0,myrank-0.001);
458      p,n=d.minGlobalDataPoint()          p,n=d.minGlobalDataPoint()
459      self.assertTrue(p==minproc,"Incorrect process indentified as holding min")          self.assertTrue(p==minproc,"Incorrect process indentified as holding min")
460      self.assertTrue(n==0,"Incorrect position for min")          self.assertTrue(n==0,"Incorrect position for min")
461      if d.getNumberOfDataPoints()>0:          if d.getNumberOfDataPoints()>0:
462          d.setValueOfDataPoint(0,myrank+0.001)                  d.setValueOfDataPoint(0,myrank+0.001)
463      p,n=d.maxGlobalDataPoint()            p,n=d.maxGlobalDataPoint()      
464      self.assertTrue(p==maxproc,"Incorrect process indentified as holding min")          self.assertTrue(p==maxproc,"Incorrect process indentified as holding min")
465      self.assertTrue(n==0,"Incorrect position for min")          self.assertTrue(n==0,"Incorrect position for min")
466    
467                
468    
469  class Test_SetDataPointValue(unittest.TestCase):  class Test_SetDataPointValue(unittest.TestCase):
470     arg0=9.81     arg0=9.81
# Line 1577  class Test_Dump(unittest.TestCase): Line 1577  class Test_Dump(unittest.TestCase):
1577    
1578  class Test_Lazy(unittest.TestCase):  class Test_Lazy(unittest.TestCase):
1579    def makeLazyObj(self):    def makeLazyObj(self):
1580      d=delay(Data(1,self.mainfs,True))          d=delay(Data(1,self.mainfs,True))
1581      e=delay(Data(2,self.mainfs,True))          e=delay(Data(2,self.mainfs,True))
1582      p=(d+e*d)/e          p=(d+e*d)/e
1583      q=p/(3*d)          q=p/(3*d)
1584      r1=q*q          r1=q*q
1585      r2=q+q          r2=q+q
1586      r3=q/4          r3=q/4
1587      f=delay(Data(4,self.otherfs,True))          f=delay(Data(4,self.otherfs,True))
1588      t=Data(4,self.mainfs)          t=Data(4,self.mainfs)
1589      t.tag()          t.tag()
1590      t=delay(t)          t=delay(t)
1591      t=t*2          t=t*2
1592      return r1,r2,r3,f,t          return r1,r2,r3,f,t
1593        
1594    def test_GroupRes(self):    def test_GroupRes(self):
1595      rr1,rr2,rr3,rf,rt=self.makeLazyObj()          rr1,rr2,rr3,rf,rt=self.makeLazyObj()
1596      rr1=resolve(rr1)          rr1=resolve(rr1)
1597      rr2=resolve(rr2)          rr2=resolve(rr2)
1598      rr3=resolve(rr3)          rr3=resolve(rr3)
1599      rf=resolve(rf)          rf=resolve(rf)
1600      rt=resolve(rt)          rt=resolve(rt)
1601      r1,r2,r3,f,t=self.makeLazyObj()          r1,r2,r3,f,t=self.makeLazyObj()
1602      resolveGroup((r1,r2,r3))          resolveGroup((r1,r2,r3))
1603      err=Lsup(rr1-r1)+Lsup(rr2-r2)+Lsup(rr3-r3)          err=Lsup(rr1-r1)+Lsup(rr2-r2)+Lsup(rr3-r3)
1604      self.assertTrue(err<0.001, "Same functionspace group resolve")          self.assertTrue(err<0.001, "Same functionspace group resolve")
1605      r1,r2,r3,f,t=self.makeLazyObj()          r1,r2,r3,f,t=self.makeLazyObj()
1606      resolveGroup((r1,r2,r3,rt))          resolveGroup((r1,r2,r3,rt))
1607      err=Lsup(rr1-r1)+Lsup(rr2-r2)+Lsup(rr3-r3)+Lsup(rt-t)          err=Lsup(rr1-r1)+Lsup(rr2-r2)+Lsup(rr3-r3)+Lsup(rt-t)
1608      self.assertTrue(err<0.001, "Same functionspace group resolve with early collapse")          self.assertTrue(err<0.001, "Same functionspace group resolve with early collapse")
1609      r1,r2,r3,f,t=self.makeLazyObj()          r1,r2,r3,f,t=self.makeLazyObj()
1610      err=Lsup(rr1-r1)+Lsup(rr2-r2)+Lsup(rr3-r3)+Lsup(rt-t)+Lsup(rf-f)          err=Lsup(rr1-r1)+Lsup(rr2-r2)+Lsup(rr3-r3)+Lsup(rt-t)+Lsup(rf-f)
1611      self.assertTrue(err<0.001, "Same functionspace group resolve with mixed functionspaces")          self.assertTrue(err<0.001, "Same functionspace group resolve with mixed functionspaces")
1612                
1613                

Legend:
Removed from v.3891  
changed lines
  Added in v.3892

  ViewVC Help
Powered by ViewVC 1.1.26