Changeset 305


Ignore:
Timestamp:
Sep 15, 2004, 6:00:32 PM (21 years ago)
Author:
ole
Message:

Some renaming
Added tidal cycle data

Location:
inundation/ga/storm_surge/pyvolution
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/least_squares.py

    r304 r305  
    7979
    8080                    #Assign values to matrix
    81                     j = self.vertices[k,0] #Global vertex id
     81                    j = self.triangles[k,0] #Global vertex id
    8282                    self.matrix[i, j] = sigma0
    8383
    84                     j = self.vertices[k,1] #Global vertex id
     84                    j = self.triangles[k,1] #Global vertex id
    8585                    self.matrix[i, j] = sigma1
    8686
    87                     j = self.vertices[k,2] #Global vertex id
     87                    j = self.triangles[k,2] #Global vertex id
    8888                    self.matrix[i, j] = sigma2
    8989
  • inundation/ga/storm_surge/pyvolution/mesh.py

    r303 r305  
    2020
    2121    To instantiate:
    22        Mesh(coordinates, vertices)
     22       Mesh(coordinates, triangles)
    2323
    2424    where
     
    2727      floats representing all x, y coordinates in the mesh.
    2828
    29       vertices is either a list of 3-tuples or an Nx3 Numeric array of
     29      triangles is either a list of 3-tuples or an Nx3 Numeric array of
    3030      integers representing indices of all vertices in the mesh.
    3131      Each vertex is identified by its index i in [0, M-1].
     
    3939       
    4040        points = [a, b, c, e]
    41         vertices = [ [1,0,2], [1,2,3] ]   #bac, bce
    42         mesh = Mesh(points, vertices)
     41        triangles = [ [1,0,2], [1,2,3] ]   #bac, bce
     42        mesh = Mesh(points, triangles)
    4343   
    4444        #creates two triangles: bac and bce
     
    5151    """
    5252
    53     def __init__(self, coordinates, vertices, boundary = None):
     53    def __init__(self, coordinates, triangles, boundary = None):
    5454        """
    5555        Build triangles from x,y coordinates (sequence of 2-tuples or
    56         Mx2 Numeric array of floats) and vertices (sequence of 3-tuples
     56        Mx2 Numeric array of floats) and triangles (sequence of 3-tuples
    5757        or Nx3 Numeric array of non-negative integers).
    5858        """
     
    6060        from Numeric import array, zeros, Int, Float, maximum, sqrt, sum
    6161
    62         self.vertices = array(vertices).astype(Int)
     62        self.triangles = array(triangles).astype(Int)
    6363        self.coordinates = array(coordinates)
    6464
    6565        #Input checks
    66         msg = 'Vertices must an Nx2 Numeric array or a sequence of 2-tuples'
    67         assert len(self.vertices.shape) == 2, msg
     66        msg = 'Triangles must an Nx2 Numeric array or a sequence of 2-tuples'
     67        assert len(self.triangles.shape) == 2, msg
    6868
    6969        msg = 'Coordinates must an Mx2 Numeric array or a sequence of 2-tuples'
     
    7171
    7272        msg = 'Vertex indices reference non-existing coordinate sets'
    73         assert max(max(self.vertices)) <= self.coordinates.shape[0], msg
     73        assert max(max(self.triangles)) <= self.coordinates.shape[0], msg
    7474
    7575
    7676        #Register number of elements (N)
    77         self.number_of_elements = N = self.vertices.shape[0]
     77        self.number_of_elements = N = self.triangles.shape[0]
    7878
    7979        #Allocate space for geometric quantities
    80         self.centroids = zeros((N, 2), Float)
    81         #FIXME: Should be renamed to centroid_coordinates
     80        self.centroid_coordinates = zeros((N, 2), Float)
     81
    8282       
    8383        self.areas = zeros(N, Float)
     
    9292        self.normals = zeros((N, 6), Float)
    9393
    94         #Get x,y coordinates for all vertices for all triangles
    95         #and store
     94        #Get x,y coordinates for all triangles and store
    9695        self.vertex_coordinates = V = self.compute_vertex_coordinates()
    9796       
    98 
    99         ##print 'Initialise mesh'
    10097        #Initialise each triangle
    10198        for i in range(N):
     
    108105            #Compute centroid
    109106            centroid = array([(x0 + x1 + x2)/3, (y0 + y1 + y2)/3])
    110             self.centroids[i] = centroid
     107            self.centroid_coordinates[i] = centroid
    111108
    112109            #Area
     
    191188
    192189    def __repr__(self):
    193         return 'Mesh: %d vertices, %d elements, %d boundary segments'\
     190        return 'Mesh: %d triangles, %d elements, %d boundary segments'\
    194191               %(self.coordinates.shape[0], len(self), len(self.boundary))
    195192
     
    215212            #Register all segments as keys mapping to current triangle
    216213            #and segment id
    217             a = self.vertices[i, 0]
    218             b = self.vertices[i, 1]
    219             c = self.vertices[i, 2]           
     214            a = self.triangles[i, 0]
     215            b = self.triangles[i, 1]
     216            c = self.triangles[i, 2]           
    220217            neighbourdict[a,b] = (i, 2) #(id, edge)
    221218            neighbourdict[b,c] = (i, 0) #(id, edge)
     
    227224        #reverse direction of segments and lookup neighbours.
    228225        for i in range(N):
    229             a = self.vertices[i, 0]
    230             b = self.vertices[i, 1]
    231             c = self.vertices[i, 2]
     226            a = self.triangles[i, 0]
     227            b = self.triangles[i, 1]
     228            c = self.triangles[i, 2]
    232229
    233230            self.number_of_boundaries[i] = 3
     
    255252
    256253        Preconditions:
    257           self.coordinates and self.vertices are defined 
     254          self.coordinates and self.triangles are defined 
    258255       
    259256        Postcondition:
     
    264261        for i in range(self.number_of_elements):
    265262
    266             a = self.vertices[i, 0]
    267             b = self.vertices[i, 1]
    268             c = self.vertices[i, 2]           
     263            a = self.triangles[i, 0]
     264            b = self.triangles[i, 1]
     265            c = self.triangles[i, 2]           
    269266
    270267            #Register the vertices v as lists of
     
    462459        #Check integrity of neighbour structure
    463460        for i in range(N):
    464             for v in self.vertices[i, :]:
     461            for v in self.triangles[i, :]:
    465462                #Check that all vertices have been registered
    466463                assert self.vertexlist[v] is not None
     
    546543        for i in range(N):
    547544            for j in range(3):
    548                 k = self.vertices[i,j]  #Index of vertex 0
     545                k = self.triangles[i,j]  #Index of vertex 0
    549546                v_k = self.coordinates[k]
    550547                vertex_coordinates[i, 2*j+0] = v_k[0]
     
    553550        return vertex_coordinates
    554551 
    555     def get_vertices(self, unique=False):
     552    def get_triangles(self, unique=False):
    556553        """Get connectivity
    557554        If unique is True give them only once as stored internally.
     
    560557
    561558        if unique is True:
    562             return self.vertices
     559            return self.triangles
    563560        else:
    564561            from Numeric import reshape, array, Int
     
    568565            return reshape(array(range(M)).astype(Int), (m,3))
    569566
     567
     568
    570569#FIXME: May get rid of
    571570def rectangular_mesh(m, n, len1=1.0, len2=1.0, origin = (0.0, 0.0)):
    572571    from mesh_factory import rectangular
    573     points, vertices, boundary = rectangular(m, n, len1, len2, origin)
    574 
    575     return Mesh(points, vertices, boundary)
     572    points, triangles, boundary = rectangular(m, n, len1, len2, origin)
     573
     574    return Mesh(points, triangles, boundary)
    576575
    577576
  • inundation/ga/storm_surge/pyvolution/quantity.py

    r297 r305  
    143143
    144144        if location == 'centroids':
    145             P = self.domain.centroids
     145            P = self.domain.centroid_coordinates
    146146            self.set_values(f(P[:,0], P[:,1]), location)
    147147        elif location == 'edges':
     
    282282           
    283283        #Create connectivity
    284         V = self.domain.get_vertices(unique=smooth)
     284        V = self.domain.get_triangles(unique=smooth)
    285285                       
    286286        if smooth == True:
     
    448448    for k in range(quantity.domain.number_of_elements):
    449449        #Centroid coordinates           
    450         x, y = quantity.domain.centroids[k]
     450        x, y = quantity.domain.centroid_coordinates[k]
    451451       
    452452        #vertex coordinates
     
    469469    from util import gradient
    470470   
    471     centroids = quantity.domain.centroids
     471    centroid_coordinates = quantity.domain.centroid_coordinates
    472472    surrogate_neighbours = quantity.domain.surrogate_neighbours   
    473473    centroid_values = quantity.centroid_values   
     
    491491            q2 = centroid_values[k2]                   
    492492
    493             x0, y0 = centroids[k0] #V0 centroid
    494             x1, y1 = centroids[k1] #V1 centroid
    495             x2, y2 = centroids[k2] #V2 centroid
     493            x0, y0 = centroid_coordinates[k0] #V0 centroid
     494            x1, y1 = centroid_coordinates[k1] #V1 centroid
     495            x2, y2 = centroid_coordinates[k2] #V2 centroid
    496496
    497497            #Gradient
     
    512512            q1 = centroid_values[k1]
    513513
    514             x0, y0 = centroids[k0] #V0 centroid
    515             x1, y1 = centroids[k1] #V1 centroid       
     514            x0, y0 = centroid_coordinates[k0] #V0 centroid
     515            x1, y1 = centroid_coordinates[k1] #V1 centroid       
    516516
    517517            #Gradient
  • inundation/ga/storm_surge/pyvolution/quantity_ext.c

    r272 r305  
    298298
    299299  //Get pertinent variables
    300   centroids = (PyArrayObject*) PyObject_GetAttrString(domain, "centroids");
     300  centroids = (PyArrayObject*)
     301    PyObject_GetAttrString(domain, "centroid_coordinates");
    301302  if (!centroids) return NULL;   
    302303 
     
    378379
    379380  //Get pertinent variables
    380   centroids = (PyArrayObject*) PyObject_GetAttrString(domain, "centroids");
     381  centroids = (PyArrayObject*)
     382    PyObject_GetAttrString(domain, "centroid_coordinates");
    381383  if (!centroids) return NULL;   
    382384 
  • inundation/ga/storm_surge/pyvolution/show_balanced_limiters.py

    r287 r305  
    3838domain.visualise = True
    3939domain.default_order = 2
    40 
    41 #domain.store = True
     40domain.filename = 'test_of_pyvolution'
     41domain.store = True
     42domain.format = 'sww'   #Native netcdf visualisation format
    4243
    4344#Set bed-slope and friction
  • inundation/ga/storm_surge/pyvolution/test_least_squares.py

    r301 r305  
    2424        c = [2.0,0.0]
    2525        points = [a, b, c]
    26         vertices = [ [1,0,2] ]   #bac
     26        triangles = [ [1,0,2] ]   #bac
    2727
    2828        data = [ [2.0/3, 2.0/3] ] #Use centroid as one data point       
    2929       
    30         mesh = Interpolation(points, vertices, data)
     30        mesh = Interpolation(points, triangles, data)
    3131        assert allclose(mesh.matrix, [[1./3, 1./3, 1./3]])
    3232       
     
    4141        c = [2.0,0.0]
    4242        points = [a, b, c]
    43         vertices = [ [1,0,2] ]   #bac
     43        triangles = [ [1,0,2] ]   #bac
    4444
    4545        data = points #Use data at vertices       
    4646       
    47         mesh = Interpolation(points, vertices, data)
     47        mesh = Interpolation(points, triangles, data)
    4848        assert allclose(mesh.matrix, [[1., 0., 0.],
    4949                                      [0., 1., 0.],
     
    6161        c = [2.0,0.0]
    6262        points = [a, b, c]
    63         vertices = [ [1,0,2] ]   #bac
     63        triangles = [ [1,0,2] ]   #bac
    6464
    6565        data = [ [0., 1.], [1., 0.], [1., 1.] ]
    6666       
    67         mesh = Interpolation(points, vertices, data)
     67        mesh = Interpolation(points, triangles, data)
    6868       
    6969        assert allclose(mesh.matrix, [[0.5, 0.5, 0.0],  #Affects vertex 1 and 0       
     
    8181        c = [2.0,0.0]
    8282        points = [a, b, c]
    83         vertices = [ [1,0,2] ]   #bac
     83        triangles = [ [1,0,2] ]   #bac
    8484
    8585        data = [ [0., 1.5], [1.5, 0.], [1.5, 0.5] ]
    8686       
    87         mesh = Interpolation(points, vertices, data)
     87        mesh = Interpolation(points, triangles, data)
    8888       
    8989        assert allclose(mesh.matrix, [[0.25, 0.75, 0.0],  #Affects vertex 1 and 0     
     
    101101        c = [2.0,0.0]
    102102        points = [a, b, c]
    103         vertices = [ [1,0,2] ]   #bac
     103        triangles = [ [1,0,2] ]   #bac
    104104
    105105        data = [ [0.2, 1.5], [0.123, 1.768], [1.43, 0.44] ]
    106106       
    107         mesh = Interpolation(points, vertices, data)
     107        mesh = Interpolation(points, triangles, data)
    108108
    109109        assert allclose(sum(mesh.matrix, axis=1), 1.0)
     
    124124        points = [a, b, c, d, e, f]
    125125        #bac, bce, ecf, dbe, daf, dae
    126         vertices = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4], [3,0,5], [3,0,4]]
     126        triangles = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4], [3,0,5], [3,0,4]]
    127127
    128128
     
    130130        data = [ [0., 2.0], [1.15, 0.75], [0.8888, 0.21], [1.000001, 0.00001] ]
    131131
    132         mesh = Interpolation(points, vertices, data)       
     132        mesh = Interpolation(points, triangles, data)       
    133133
    134134        #print mesh.matrix
  • inundation/ga/storm_surge/pyvolution/test_mesh.py

    r297 r305  
    4242
    4343        #Centroid
    44         centroid = mesh.centroids[0]
     44        centroid = mesh.centroid_coordinates[0]
    4545        assert centroid[0] == 4.0/3
    4646        assert centroid[1] == 1.0
     
    151151
    152152        mesh = Mesh(points, vertices)
    153         centroid = mesh.centroids[0]
     153        centroid = mesh.centroid_coordinates[0]
    154154
    155155       
     
    233233        assert mesh.areas[0] == 2.0
    234234
    235         assert allclose(mesh.centroids[0], [2.0/3, 2.0/3])       
     235        assert allclose(mesh.centroid_coordinates[0], [2.0/3, 2.0/3])       
    236236
    237237
     
    269269        assert mesh.edgelengths[1,2] == sqrt(8.0)
    270270
    271         assert allclose(mesh.centroids[0], [2.0/3, 2.0/3])
    272         assert allclose(mesh.centroids[1], [4.0/3, 4.0/3])
    273         assert allclose(mesh.centroids[2], [8.0/3, 2.0/3])
    274         assert allclose(mesh.centroids[3], [2.0/3, 8.0/3])         
     271        assert allclose(mesh.centroid_coordinates[0], [2.0/3, 2.0/3])
     272        assert allclose(mesh.centroid_coordinates[1], [4.0/3, 4.0/3])
     273        assert allclose(mesh.centroid_coordinates[2], [8.0/3, 2.0/3])
     274        assert allclose(mesh.centroid_coordinates[3], [2.0/3, 8.0/3])         
    275275
    276276
Note: See TracChangeset for help on using the changeset viewer.