Ignore:
Timestamp:
Apr 20, 2005, 5:41:03 PM (20 years ago)
Author:
steve
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution-parallel/general_mesh.py

    r1178 r1237  
    66
    77    A triangular element is defined in terms of three vertex ids,
    8     ordered counter clock-wise, 
     8    ordered counter clock-wise,
    99    each corresponding to a given coordinate set.
    1010    Vertices from different elements can point to the same
     
    1212
    1313    Coordinate sets are implemented as an N x 2 Numeric array containing
    14     x and y coordinates. 
    15    
     14    x and y coordinates.
     15
    1616
    1717    To instantiate:
     
    3333        c = [2.0,0.0]
    3434        e = [2.0, 2.0]
    35        
     35
    3636        points = [a, b, c, e]
    37         triangles = [ [1,0,2], [1,2,3] ]   #bac, bce 
     37        triangles = [ [1,0,2], [1,2,3] ]   #bac, bce
    3838        mesh = Mesh(points, triangles)
    39    
     39
    4040        #creates two triangles: bac and bce
    4141
    4242    Other:
    43    
     43
    4444      In addition mesh computes an Nx6 array called vertex_coordinates.
    45       This structure is derived from coordinates and contains for each 
     45      This structure is derived from coordinates and contains for each
    4646      triangle the three x,y coordinates at the vertices.
    47                                
     47
    4848
    4949        This is a cut down version of mesh from pyvolution\mesh.py
     
    5858
    5959        origin is a 3-tuple consisting of UTM zone, easting and northing.
    60         If specified coordinates are assumed to be relative to this origin. 
     60        If specified coordinates are assumed to be relative to this origin.
    6161        """
    6262
     
    6767
    6868        if geo_reference is None:
    69             self.geo_reference = Geo_reference(DEFAULT_ZONE,0.0,0.0) 
     69            self.geo_reference = Geo_reference(DEFAULT_ZONE,0.0,0.0)
    7070        else:
    7171            self.geo_reference = geo_reference
     
    7676
    7777        msg = 'Coordinates must an Mx2 Numeric array or a sequence of 2-tuples'
    78         assert len(self.coordinates.shape) == 2, msg       
     78        assert len(self.coordinates.shape) == 2, msg
    7979
    8080        msg = 'Vertex indices reference non-existing coordinate sets'
     
    8484        #Register number of elements (N)
    8585        self.number_of_elements = N = self.triangles.shape[0]
    86    
    87         #Allocate space for geometric quantities       
     86
     87        #Allocate space for geometric quantities
    8888        self.normals = zeros((N, 6), Float)
    8989        self.areas = zeros(N, Float)
     
    9292        #Get x,y coordinates for all triangles and store
    9393        self.vertex_coordinates = V = self.compute_vertex_coordinates()
    94        
     94
    9595        #Initialise each triangle
    9696        for i in range(N):
    9797            #if i % (N/10) == 0: print '(%d/%d)' %(i, N)
    98            
     98
    9999            x0 = V[i, 0]; y0 = V[i, 1]
    100100            x1 = V[i, 2]; y1 = V[i, 3]
    101             x2 = V[i, 4]; y2 = V[i, 5]           
     101            x2 = V[i, 4]; y2 = V[i, 5]
    102102
    103103            #Area
     
    107107            msg += ' is degenerate:  area == %f' %self.areas[i]
    108108            assert self.areas[i] > 0.0, msg
    109        
     109
    110110
    111111            #Normals
     
    120120
    121121            n0 = array([x2 - x1, y2 - y1])
    122             l0 = sqrt(sum(n0**2))
     122            l0 = sqrt(sum(n0**2))
    123123
    124124            n1 = array([x0 - x2, y0 - y2])
     
    137137                                  n1[1], -n1[0],
    138138                                  n2[1], -n2[0]]
    139            
     139
    140140            #Edgelengths
    141141            self.edgelengths[i, :] = [l0, l1, l2]
    142142
    143143        #Build vertex list
    144         self.build_vertexlist()       
    145            
     144        self.build_vertexlist()
     145
    146146    def __len__(self):
    147147        return self.number_of_elements
     
    154154        """Return all normal vectors.
    155155        Return normal vectors for all triangles as an Nx6 array
    156         (ordered as x0, y0, x1, y1, x2, y2 for each triangle)       
     156        (ordered as x0, y0, x1, y1, x2, y2 for each triangle)
    157157        """
    158158        return self.normals
     
    163163        Return value is the numeric array slice [x, y]
    164164        """
    165         return self.normals[i, 2*j:2*j+2]     
    166    
    167 
    168            
     165        return self.normals[i, 2*j:2*j+2]
     166
     167
     168
    169169    def get_vertex_coordinates(self):
    170170        """Return all vertex coordinates.
    171171        Return all vertex coordinates for all triangles as an Nx6 array
    172         (ordered as x0, y0, x1, y1, x2, y2 for each triangle)       
     172        (ordered as x0, y0, x1, y1, x2, y2 for each triangle)
    173173        """
    174174        return self.vertex_coordinates
     
    179179        Return value is the numeric array slice [x, y]
    180180        """
    181         return self.vertex_coordinates[i, 2*j:2*j+2]     
     181        return self.vertex_coordinates[i, 2*j:2*j+2]
    182182
    183183
     
    189189        #FIXME: Perhaps they should be ordered as in obj files??
    190190        #See quantity.get_vertex_values
    191        
     191
    192192        from Numeric import zeros, Float
    193193
    194194        N = self.number_of_elements
    195         vertex_coordinates = zeros((N, 6), Float) 
     195        vertex_coordinates = zeros((N, 6), Float)
    196196
    197197        for i in range(N):
     
    203203
    204204        return vertex_coordinates
    205    
     205
    206206    def get_vertices(self,  indexes=None):
    207207        """Get connectivity
    208208        indexes is the set of element ids of interest
    209209        """
    210        
     210
    211211        from Numeric import take
    212        
     212
    213213        if (indexes ==  None):
    214214            indexes = range(len(self))  #len(self)=number of elements
    215            
     215
    216216        return  take(self.triangles, indexes)
    217217
     
    220220        unique_verts = {}
    221221        for triangle in triangles:
    222            unique_verts[triangle[0]] = 0 
    223            unique_verts[triangle[1]] = 0 
     222           unique_verts[triangle[0]] = 0
     223           unique_verts[triangle[1]] = 0
    224224           unique_verts[triangle[2]] = 0
    225         return unique_verts.keys()   
    226        
     225        return unique_verts.keys()
     226
    227227    def build_vertexlist(self):
    228228        """Build vertexlist index by vertex ids and for each entry (point id)
     
    231231
    232232        Preconditions:
    233           self.coordinates and self.triangles are defined 
    234        
     233          self.coordinates and self.triangles are defined
     234
    235235        Postcondition:
    236236          self.vertexlist is built
     
    242242            a = self.triangles[i, 0]
    243243            b = self.triangles[i, 1]
    244             c = self.triangles[i, 2]           
     244            c = self.triangles[i, 2]
    245245
    246246            #Register the vertices v as lists of
     
    251251                    vertexlist[v] = []
    252252
    253                 vertexlist[v].append( (i, vertex_id) )   
     253                vertexlist[v].append( (i, vertex_id) )
    254254
    255255        self.vertexlist = vertexlist
    256    
     256
    257257
    258258    def get_extent(self):
     
    264264        X = C[:,0:6:2].copy()
    265265        Y = C[:,1:6:2].copy()
    266        
     266
    267267        xmin = min(X.flat)
    268268        xmax = max(X.flat)
    269269        ymin = min(Y.flat)
    270         ymax = max(Y.flat)               
    271        
     270        ymax = max(Y.flat)
     271
    272272        return xmin, xmax, ymin, ymax
    273273
     
    275275    def get_area(self):
    276276        """Return total area of mesh
    277         """
    278 
    279         return sum(self.areas)         
    280        
     277        """
     278
     279        return sum(self.areas)
     280
Note: See TracChangeset for help on using the changeset viewer.