/[escript]/trunk/finley/test/python/run_visualization_interface.py
ViewVC logotype

Diff of /trunk/finley/test/python/run_visualization_interface.py

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

revision 2256 by jfenwick, Mon Feb 9 06:20:32 2009 UTC revision 2257 by gross, Mon Feb 9 07:06:00 2009 UTC
# Line 56  class Test_VisualizationInterface(unitte Line 56  class Test_VisualizationInterface(unitte
56             c+=1             c+=1
57    
58     # Compare two lists of numbers (stored as space-separated strings) using the L2 norm     # Compare two lists of numbers (stored as space-separated strings) using the L2 norm
59     def numericCompareL2(self, s1, s2):     def numericCompareL2(self, vector1, vector2):
60       if s2 == None: return False       if vector2 == None: return False
61       TOL = 1.0e-6       TOL = 1.0e-6
      vector1 = s1.split()  
      vector2 = s2.split()  
62       if len(vector1) != len(vector2): return False       if len(vector1) != len(vector2): return False
63       diff = 0.0       diff = 0.0
64       for i in range(0, len(vector1)):       for i in range(0, len(vector1)):
65         tmp = float(vector1[i]) - float(vector2[i])         tmp = vector1[i] - vector2[i]
66         diff += tmp * tmp         diff += tmp * tmp
67       if math.sqrt(diff) > TOL: return False       if math.sqrt(diff) > TOL: return False
68       return True       return True
69    
70     # Compare two elements (stored as space-separated strings of integers) after mapping node labels     # Compare two elements (stored as space-separated strings of integers) after mapping node labels
71     def elementCompareWithMap(self, e1, e2, mappy):     def elementCompareWithMap(self, e1, e2, value_map):
72       if e2 == None: return False       if e2 == None: return False
73       vector1 = e1.split()       vector1 = e1.split()
74       vector2 = e2.split()       vector2 = e2.split()
75       if len(vector1) != len(vector2): return False       if len(vector1) != len(vector2): return False
76       for i in range(0, len(vector1)):       for i in range(0, len(vector1)):
77         if int(vector1[i]) < 0: return False         if int(vector1[i]) < 0: return False
78         if int(vector1[i]) >= len(mappy): return False         if int(vector1[i]) >= len(value_map): return False
79         if mappy[int(vector1[i])] != int(vector2[i]): return False         if value_map[int(vector1[i])] != int(vector2[i]): return False
80       return True       return True
81    
82     def compareDataSetWithMap(self, d1, d2, mappy):     def compareDataSetWithMap(self, d1, d2, value_map):
83       if len(d1) != len(d2): return False       if len(d1) != len(d2): return False
84       for i in range(0, len(d1)):       for i in range(0, len(d1)):
85         if mappy[i] < 0: return False         if value_map.has_key(i):
86         if mappy[i] >= len(d1): return False            if not min( [ self.numericCompareL2(d1[i], d2[k] ) for k in value_map[i] ] ): return False
87         if not self.numericCompareL2(d1[i], d2[mappy[i]]): return False         else:
88              return False
89       return True       return True
90    
91     # Compare two VTK files which were generated by Finley method saveVTK     # Compare two VTK files which were generated by Finley method saveVTK
# Line 122  class Test_VisualizationInterface(unitte Line 121  class Test_VisualizationInterface(unitte
121         if lineList1[i].startswith('<DataArray Name="types"'):   doStringComparison = 1         if lineList1[i].startswith('<DataArray Name="types"'):   doStringComparison = 1
122    
123       # Find the list of nodes       # Find the list of nodes
124       nodeList1 = []       nodeMap1 = {}  
      nodeList2 = []  
      nodeDict1 = {} # These dictionaries are used to detect duplicate nodes, as with contact elements  
      nodeDict2 = {}  
125       withinTheNodeList = False       withinTheNodeList = False
126         cc=0
127       for i in range(0, len(lineList1)):       for i in range(0, len(lineList1)):
128         if withinTheNodeList and lineList1[i].startswith('</DataArray'): break   # Finished reading nodes         if withinTheNodeList and lineList1[i].startswith('</DataArray'): break   # Finished reading nodes
129         if withinTheNodeList:         if withinTheNodeList:
130           nodeList1.append(lineList1[i]) # The two files are guaranteed to have the nodes on           nodeMap1[cc]=[ float(x) for x in lineList1[i].split() ]
131           nodeList2.append(lineList2[i]) # the same lines at this point           cc+=1
          nodeDict1[lineList1[i]] = 1  
          nodeDict2[lineList2[i]] = 1  
132         if lineList1[i].startswith('<DataArray'): withinTheNodeList = True         if lineList1[i].startswith('<DataArray'): withinTheNodeList = True
133    
134       # Check for contact elements       nodeMap2 = {}  
135       if len(nodeList1) != len(nodeDict1):       withinTheNodeList = False
136         print "\n\nContact elements present, cannot compare nodes/elements due to duplicate nodes in %s\n" % file1       cc=0
137         return True, "Contact elements present, cannot compare nodes/elements due to duplicate nodes in %s" % file1       for i in range(0, len(lineList1)):
138       if len(nodeList2) != len(nodeDict2):         if withinTheNodeList and lineList2[i].startswith('</DataArray'): break   # Finished reading nodes
139         print "\n\nContact elements present, cannot compare nodes/elements due to duplicate nodes in %s\n" % file2         if withinTheNodeList:
140         return True, "Contact elements present, cannot compare nodes/elements due to duplicate nodes in %s" % file2           nodeMap2[cc]=[ float(x) for x in lineList2[i].split() ]
141             cc+=1
142           if lineList2[i].startswith('<DataArray'): withinTheNodeList = True
143    
144       if len(nodeList1) != len(nodeList2):       if len(nodeMap1) != len(nodeMap2):
145         return False, "Error: The two files have different numbers of nodes"         return False, "Error: The two files have different numbers of nodes"
146    
147       # Compute the node mapping from file1 to file2       nodeMap1to2 = {}
148       nodeMap1to2 = []       for n1 in nodeMap1.keys():
149       for i in range(0, len(nodeList1)):             v=[]
150         nodeMap1to2.append(-1)             for n2 in nodeMap2.keys():
151       for i in range(0, len(nodeList1)):               if self.numericCompareL2(nodeMap1[n1], nodeMap2[n2]): v.append(n2)
152         resstr = nodeList1[i]             if len(v)==0:
153         for j in range(len(nodeList2)-1, -1, -1):                return False, "Error: no matching node for node %s %s."%(n1,nodeMap1[n1])
154           if self.numericCompareL2(resstr, nodeList2[j]):             nodeMap1to2[n1]=v
            nodeMap1to2[i] = j  
            nodeList2[j] = None  
            break  
   
      if nodeMap1to2.count(-1) > 0:  
        return False, "Error: Some nodes didn't correspond in the two files"  
155    
156       # Find the list of elements       # Find the list of elements
157       elementList1 = []       elementList1 = []
      elementList2 = []  
158       withinTheElementList = False       withinTheElementList = False
159       for i in range(0, len(lineList1)):       for i in range(0, len(lineList1)):
160         if withinTheElementList and lineList1[i].startswith('</DataArray'): break    # Finished reading elements         if withinTheElementList and lineList1[i].startswith('</DataArray'): break    # Finished reading elements
161         if withinTheElementList:         if withinTheElementList:
162           elementList1.append(lineList1[i])  # The two files are guaranteed to have the elements on           elementList1.append([ int(x) for x in lineList1[i].split()])  
          elementList2.append(lineList2[i])  # the same lines at this point  
163         if lineList1[i].startswith('<DataArray Name="connectivity"'): withinTheElementList = True         if lineList1[i].startswith('<DataArray Name="connectivity"'): withinTheElementList = True
164    
165         # Find the list of elements
166         elementList2 = []
167         withinTheElementList = False
168         for i in range(0, len(lineList2)):
169           if withinTheElementList and lineList2[i].startswith('</DataArray'): break    # Finished reading elements
170           if withinTheElementList:
171             elementList2.append([ int(x) for x in lineList2[i].split()])  
172           if lineList2[i].startswith('<DataArray Name="connectivity"'): withinTheElementList = True
173    
174       if len(elementList1) != len(elementList2):       if len(elementList1) != len(elementList2):
175         return False, "Error: The two files have different numbers of elements"         return False, "Error: The two files have different numbers of elements"
176    
177       # Compute the element mapping from file1 to file2       # Compute the element mapping from file1 to file2
178       elementMap1to2 = []       elementMap1to2 = {}
179       for i in range(0, len(elementList1)):       for n1 in range(0, len(elementList1)):
180         elementMap1to2.append(-1)           v=None
181       for i in range(0, len(elementList1)):           for n2 in range(0, len(elementList2)):
182         resstr = elementList1[i]              if len(elementList1[n1]) == len(elementList2[n2]):
183         for j in range(len(elementList2)-1, -1, -1):                 if min([ nnn in elementList2[n2] for nnn in elementList1[n1] ] ):
184           if self.elementCompareWithMap(resstr, elementList2[j], nodeMap1to2):                    v=n2
185             elementMap1to2[i] = j                    break
186             elementList2[j] = None           if v == None:
187             break                return False, "Error: element %s is missing."%elementList1[n1]
188             else:
189       if elementMap1to2.count(-1) > 0:              elementMap1to2[n1]=[n2]
        return False, "Error: Some elements didn't correspond in the two files"  
   
190       # Find the data sets and compare them       # Find the data sets and compare them
191       dataList1 = []       dataList1 = []
192       dataList2 = []       dataList2 = []
# Line 205  class Test_VisualizationInterface(unitte Line 201  class Test_VisualizationInterface(unitte
201           if withinPointdata and not self.compareDataSetWithMap(dataList1, dataList2, nodeMap1to2):           if withinPointdata and not self.compareDataSetWithMap(dataList1, dataList2, nodeMap1to2):
202             return False, "Error: point data in '%s' did not match" % dataName             return False, "Error: point data in '%s' did not match" % dataName
203         if withinDataSet:         if withinDataSet:
204           dataList1.append(lineList1[i]) # The two files are guaranteed to have the elements on           dataList1.append([ float(d) for d in lineList1[i].split()] )   # The two files are guaranteed to have the elements on
205           dataList2.append(lineList2[i]) # the same lines at this point           dataList2.append([ float(d) for d in lineList2[i].split()] )   # the same lines at this point
206         if (withinCelldata or withinPointdata) and lineList1[i].startswith('<DataArray'):         if (withinCelldata or withinPointdata) and lineList1[i].startswith('<DataArray'):
207           dataName = re.sub('" .*', '', lineList1[i])           dataName = re.sub('" .*', '', lineList1[i])
208           dataName = re.sub('.*"', '', dataName)           dataName = re.sub('.*"', '', dataName)
# Line 2977  class Test_DXFiles(Test_VisualizationInt Line 2973  class Test_DXFiles(Test_VisualizationInt
2973    
2974  if __name__ == '__main__':  if __name__ == '__main__':
2975     suite = unittest.TestSuite()     suite = unittest.TestSuite()
2976       # suite.addTest(Test_VTKFiles("test_hex_contact_3D_order2_onFace_ReducedFunctionOnContactZero_Vector_vtk"))
2977     suite.addTest(unittest.makeSuite(Test_VTKFiles))     suite.addTest(unittest.makeSuite(Test_VTKFiles))
2978     # saveDX is not MPI parallel     # saveDX is not MPI parallel
2979     if getMPISizeWorld() == 1: suite.addTest(unittest.makeSuite(Test_DXFiles))     # if getMPISizeWorld() == 1: suite.addTest(unittest.makeSuite(Test_DXFiles))
2980     s=unittest.TextTestRunner(verbosity=2).run(suite)     s=unittest.TextTestRunner(verbosity=2).run(suite)
2981     if not s.wasSuccessful(): sys.exit(1)     if not s.wasSuccessful(): sys.exit(1)

Legend:
Removed from v.2256  
changed lines
  Added in v.2257

  ViewVC Help
Powered by ViewVC 1.1.26