Changeset 4901


Ignore:
Timestamp:
Jan 3, 2008, 9:58:32 PM (17 years ago)
Author:
duncan
Message:

Using a numeric array to store mesh triangulation info. The old way is also in place.

Location:
anuga_core/source/anuga
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/abstract_2d_finite_volumes/pmesh2domain.py

    r4098 r4901  
    190190    """
    191191    tri_atts = mesh_dict['triangle_tags']
    192     #print "tri_atts", tri_atts
    193192    tagged_elements = {}
    194     for tri_att_index in range(len(tri_atts)):
    195         tagged_elements.setdefault(tri_atts[tri_att_index],[]).append(tri_att_index)
    196     #print "DSG pm2do tagged_elements", tagged_elements
     193    if tri_atts is None:
     194       tagged_elements[''] = range(len(mesh_dict['triangles']))
     195    else:
     196        for tri_att_index in range(len(tri_atts)):
     197            tagged_elements.setdefault(tri_atts[tri_att_index],
     198                                       []).append(tri_att_index)
    197199    return tagged_elements
    198200
  • anuga_core/source/anuga/load_mesh/loadASCII.py

    r4899 r4901  
    2121    segment_tags : [tag,tag,...] list of strings
    2222    triangles : [(v1,v2,v3), (v4,v5,v6),....] lists of points
    23     triangle_tags: [s1,s2,...] A list of list of strings (probably not
    24     neccecary.  a list of string should be ok)
     23    triangle_tags: [s1,s2,...] A list of strings
    2524    triangle_neighbors: [[t1,t2,t3], [t4,t5,t6],..] lists of triangles
    2625       
     
    512511        # with triangle, and it seems to have the option of returning
    513512        # more than one value for triangle attributex
    514         if triangles_attributes == [] or triangles_attributes[index] == ['']:
     513        if triangles_attributes == None or \
     514               triangles_attributes == [] or \
     515               triangles_attributes[index] == ['']:
    515516            att = ""
    516517        else:
  • anuga_core/source/anuga/mesh_engine/mesh_engine.py

    r4900 r4901  
    148148    #print "mesh eng generatedtrianglelist", trianglelist
    149149    #print "mesh eng mesh_dict['triangleattributelist'] ",mesh_dict['triangleattributelist']
    150     #print "mesh eng mesh_dict['generatedtriangleattributelist'] ", mesh_dict['generatedtriangleattributelist']   
    151    
     150    #print "mesh eng mesh_dict['generatedtriangleattributelist'] ", mesh_dict['generatedtriangleattributelist']   
    152151    if True:
    153152        mesh_dict['generatedtriangleattributelist'] = triangleattributelist
     
    155154        if mesh_dict['generatedtriangleattributelist'].shape[1] == 0:
    156155            mesh_dict['generatedtriangleattributelist'] = None
     156           
    157157        if trianglelist.shape[0] == 0:
    158158            # There are no triangles.
    159159            # this is used by urs_ungridded2sww
    160160            raise NoTrianglesError
    161     #print "mesh eng mesh_dict['generatedtriangleattributelist'] ", mesh_dict['generatedtriangleattributelist']   
     161    #print "mesh eng mesh_dict['generatedtriangleattributelist'] ", mesh_dict['generatedtriangleattributelist'] 
     162   
     163    # the structure of generatedtriangleattributelist is an list of
     164    # list of integers.  It is transformed into a list of list of
     165    # strings later on.  This is then inputted into an triangle
     166    # object.  The triangle object outputs a list of strings.  Note
     167    # the subtle change!  How should I handle this?  For my code, when
     168    # the list of list of integers is transformed, transform it into a
     169    # list of strings, not a list of list of strings.
    162170   
    163171    return mesh_dict
  • anuga_core/source/anuga/pmesh/graphical_mesh_generator.py

    r4830 r4901  
    10831083        """
    10841084        if self.Visualise:
    1085             for triangle in mesh.getTriangulation():
    1086                 self.serial +=1
    1087                 self.uniqueID = 'M*%d' % self.serial
    1088                 self.Triangles.visualise(triangle,
    1089                                         self.uniqueID,
    1090                                         self.canvas,
    1091                                         self.SCALE)
    1092 
    1093         if self.Visualise:
    1094             Triangles = mesh.sets[mesh.setID[self.selSet]]
    1095             for triangle in Triangles:
    1096                 triangle.draw(self.canvas,1,
    1097                               scale = self.SCALE,
    1098                               colour = SET_COLOUR)
     1085            mesh.tri_mesh.draw_triangulation(self.canvas,
     1086                                             scale = self.SCALE)
    10991087
    11001088        for segment in mesh.getUserSegments():
  • anuga_core/source/anuga/pmesh/mesh.py

    r4899 r4901  
    520520                 vertices,
    521521                 triangle_tags,
    522                  triangle_neighbor,
     522                 triangle_neighbors,
    523523                 segment_tags,
    524524                 ):
    525525       
    526         self.triangles=ensure_numeric(triangles)
    527         self.triangle_neighbor=ensure_numeric(triangle_neighbor)
    528         self.triangle_tags=triangle_tags
    529         self.segments=ensure_numeric(segments)
    530        
    531         self.segment_tags=segment_tags # string
    532         self.vertices=ensure_numeric(vertices)
    533 
    534        
     526        self.triangles = ensure_numeric(triangles)
     527        self.triangle_neighbors = ensure_numeric(triangle_neighbors)
     528        self.triangle_tags = triangle_tags # list of strings
     529        self.segments = ensure_numeric(segments)
     530       
     531        self.segment_tags = segment_tags # list of strings
     532        self.vertices = ensure_numeric(vertices)
     533
     534       
     535    def draw_triangulation(self, canvas, scale=1, xoffset=0, yoffset=0,
     536             colour="green"):
     537        """
     538        Draw a triangle, returning the objectID
     539        """
     540       
     541        # FIXME(DSG-DSG) This could be a data structure that is
     542        # remembered and doesn't have any duplicates.
     543        # but I wouldn't be able to use create_polygon.
     544        # regard it as drawing a heap of segments
     545       
     546        for tri in self.triangles:
     547            vertices = []
     548            for v_index in range(3):
     549                vertices.append(self.vertices[tri[v_index]])
     550           
     551            objectID = canvas.create_polygon(
     552                scale*(vertices[1][0] + xoffset),
     553                scale*-1*(vertices[1][1] + yoffset),
     554                scale*(vertices[0][0] + xoffset),
     555                scale*-1*(vertices[0][1] + yoffset),
     556                scale*(vertices[2][0] + xoffset),
     557                scale*-1*(vertices[2][1] + yoffset),
     558                outline = colour,fill = ''
     559                )
     560 
    535561       
    536562class Mesh:
     
    575601        self.meshVertices=[]
    576602
     603        # Rigid
     604        self.tri_mesh=None
     605       
    577606        self.setID={}
    578607        #a dictionary of names.
     
    12111240        #print "generatedMesh",generatedMesh
    12121241        #print "##################"
    1213        
    12141242        self.setTriangulation(generatedMesh)
    12151243   
     
    15641592                    self.meshTriangles[index].setAttribute("")
    15651593                else:
    1566                     self.meshTriangles[index].setAttribute(att[0])
     1594                    self.meshTriangles[index].setAttribute(att)
    15671595                index += 1
    15681596           
     
    15881616                                                   ObjectNeighbor[2])
    15891617            index += 1
     1618       
     1619        # Setting up the rigid triangulation
     1620        self.tri_mesh = Rigid_triangulation(
     1621            genDict['generatedtrianglelist']
     1622            ,genDict['generatedsegmentlist']
     1623            ,genDict['generatedpointlist']
     1624            ,genDict['generatedtriangleattributelist']
     1625            ,genDict['generatedtriangleneighborlist']
     1626            ,genDict['generatedsegmentmarkerlist']
     1627            )
    15901628           
    15911629    def setMesh(self, genDict):
     
    22062244        meshDict['triangle_neighbors'] = triangle_neighbors
    22072245       
     2246        if self.tri_mesh is not None:
     2247            meshDict['triangles'] = self.tri_mesh.triangles
     2248            meshDict['triangle_tags'] = self.tri_mesh.triangle_tags
     2249            #print "mesh meshDict['triangle_tags']", meshDict['triangle_tags']
     2250            meshDict['triangle_neighbors'] = self.tri_mesh.triangle_neighbors
     2251        else:
     2252            meshDict['triangles'] = []
     2253            meshDict['triangle_tags'] = []
     2254            meshDict['triangle_neighbors'] = []
    22082255        #print "mesh.Mesh2IOTriangulationDict*)*)"
    22092256        #print meshDict
     
    22882335        """
    22892336        #Clear the current generated mesh values
    2290         self.meshTriangles=[]
    2291         self.attributeTitles=[]
    2292         self.meshSegments=[]
    2293         self.meshVertices=[]
    2294 
     2337        self.meshTriangles = []
     2338        self.attributeTitles = []
     2339        self.meshSegments = []
     2340        self.meshVertices = []
     2341        self.tri_mesh = None
     2342       
    22952343        #print "mesh.setTriangulation@#@#@#"
    22962344        #print genDict
     
    23532401            index += 1
    23542402
     2403        self.tri_mesh = Rigid_triangulation(
     2404            genDict['triangles']
     2405            ,genDict['segments']
     2406            ,genDict['vertices']
     2407            ,genDict['triangle_tags']
     2408            ,genDict['triangle_neighbors']
     2409            ,genDict['segment_tags']
     2410            )
    23552411
    23562412    def IOOutline2Mesh(self, genDict):
     
    31663222        for i in xrange(len(region_list)):
    31673223            temp = region_list[i]
    3168             returned_region_list.append([convertint2string[int(temp[0])]])
     3224            returned_region_list.append(convertint2string[int(temp[0])])
    31693225    return returned_region_list
    31703226
     
    39323988# instead of functionName
    39333989if __name__ == "__main__":
    3934     #from mesh import *
    3935     # THIS CAN BE DELETED
    3936     m = Mesh()
    3937     dict = importUngenerateFile("ungen_test.txt")
    3938     m.addVertsSegs(dict)
    3939     print m3
     3990    pass
Note: See TracChangeset for help on using the changeset viewer.