Changeset 4474


Ignore:
Timestamp:
May 22, 2007, 5:10:24 PM (17 years ago)
Author:
ole
Message:

Documented new inverted structure for listing triangles that per node.

Location:
anuga_core/source/anuga/abstract_2d_finite_volumes
Files:
2 edited

Legend:

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

    r4471 r4474  
    380380
    381381    def build_vertexlist(self):
    382         """Build vertexlist indexed by vertex ids and for each entry (point id)
    383         build a list of (triangles, vertex_id) pairs that use the point
    384         as vertex.
    385 
    386         The vertex list will have length N, where N is the number of nodes
    387         in the mesh.
     382        """Build information about which triangles belong to each node
     383
     384        Two arrays are created and store as mesh attributes
     385
     386        number_of_triangles_per_node: An integer array of length N
     387        listing for each node how many triangles use it. N is the number of
     388        nodes in mesh.
     389       
     390        vertex_value_indices: An array of length M listing indices into
     391        triangles ordered by node number. The (triangle_id, vertex_id)
     392        pairs are obtained from each index as (index/3, index%3) or each
     393        index can be used directly into a flattened triangles array. This
     394        is for example the case in the quantity.c where this structure is
     395        used to average vertex values efficiently.
     396
     397       
     398        Example:
     399       
     400        a = [0.0, 0.0] # node 0
     401        b = [0.0, 2.0] # node 1
     402        c = [2.0, 0.0] # node 2
     403        d = [0.0, 4.0] # node 3
     404        e = [2.0, 2.0] # node 4
     405        f = [4.0, 0.0] # node 5
     406
     407        nodes = array([a, b, c, d, e, f])
     408       
     409        #bac, bce, ecf, dbe, daf, dae
     410        triangles = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])       
     411
     412
     413        For this structure
     414
     415        number_of_triangles_per_node = [1 3 3 1 3 1]
     416        which means that node a has 1 triangle associated with it, node b
     417        has 3, node has 3 and so on.
     418       
     419        vertex_value_indices = [ 1  0  3 10  2  4  7  9  5  6 11  8]
     420        which reflects the fact that
     421        node 0 is used by triangle 0, vertex 1 (index = 1)
     422        node 1 is used by triangle 0, vertex 0 (index = 0)
     423                   and by triangle 1, vertex 0 (index = 3)
     424                   and by triangle 3, vertex 1 (index = 10)
     425        node 2 is used by triangle 0, vertex 2 (index = 2)
     426                   and by triangle 1, vertex 1 (index = 4)
     427                   and by triangle 2, vertex 1 (index = 7)
     428        node 3 is used by triangle 3, vertex 0 (index = 9)
     429        node 4 is used by triangle 1, vertex 2 (index = 5)
     430                   and by triangle 2, vertex 0 (index = 6)
     431                   and by triangle 3, vertex 2 (index = 11)
     432        node 5 is used by triangle 2, vertex 2 (index = 8)                   
     433       
    388434
    389435        Preconditions:
     
    391437
    392438        Postcondition:
    393           self.vertexlist is built
     439          self.number_of_triangles_per_node is built
     440          self.vertex_value_indices is built         
    394441        """
    395442
     
    442489        self.number_of_triangles_per_node = number_of_triangles_per_node
    443490        self.vertex_value_indices = vertex_value_indices
    444         self.vertexlist = vertexlist
     491       
    445492
    446493        #print
  • anuga_core/source/anuga/abstract_2d_finite_volumes/test_general_mesh.py

    r4471 r4474  
    6666        """
    6767        from mesh_factory import rectangular
    68         from Numeric import zeros, Float
     68        from Numeric import zeros, Float, array
    6969
    70         #Create basic mesh
     70        a = [0.0, 0.0]
     71        b = [0.0, 2.0]
     72        c = [2.0, 0.0]
     73        d = [0.0, 4.0]
     74        e = [2.0, 2.0]
     75        f = [4.0, 0.0]
     76
     77        nodes = array([a, b, c, d, e, f])
     78        #bac, bce, ecf, dbe, daf, dae
     79        triangles = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]])
     80
     81        domain1 = General_mesh(nodes, triangles)
     82       
     83        #Create larger mesh
    7184        nodes, triangles, _ = rectangular(3, 6)
    72         domain = General_mesh(nodes, triangles)
     85        domain2 = General_mesh(nodes, triangles)
    7386
    74         assert sum(domain.number_of_triangles_per_node) ==\
    75                len(domain.vertex_value_indices)
     87        # Test both meshes
     88        for domain in [domain1, domain2]:
     89            assert sum(domain.number_of_triangles_per_node) ==\
     90                   len(domain.vertex_value_indices)
    7691
    77         # Check number of triangles per node
    78         count = [0]*domain.number_of_nodes
    79         for triangle in triangles:
    80             for i in triangle:
    81                 count[i] += 1
     92            # Check number of triangles per node
     93            count = [0]*domain.number_of_nodes
     94            for triangle in domain.triangles:
     95                for i in triangle:
     96                    count[i] += 1
    8297
    83         assert allclose(count, domain.number_of_triangles_per_node)
     98            assert allclose(count, domain.number_of_triangles_per_node)
    8499
    85         #print nodes
    86         #print triangles
    87         #print domain.number_of_triangles_per_node
    88         #print domain.vertex_value_indices       
     100            # Check indices
     101            current_node = 0
     102            k = 0 # Track triangles touching on node
     103            for index in domain.vertex_value_indices:
     104                k += 1
     105               
     106                triangle = index / 3
     107                vertex = index % 3
    89108
     109                assert domain.triangles[triangle, vertex] == current_node
    90110
    91         # Check indices
    92         current_node = 0
    93         k = 0 # Track triangles touching on node
    94         for index in domain.vertex_value_indices:
    95             k += 1
    96            
    97             triangle = index / 3
    98             vertex = index % 3
    99 
    100             assert triangles[triangle, vertex] == current_node
    101 
    102             if domain.number_of_triangles_per_node[current_node] == k:
    103                 # Move on to next node
    104                 k = 0
    105                 current_node += 1
     111                if domain.number_of_triangles_per_node[current_node] == k:
     112                    # Move on to next node
     113                    k = 0
     114                    current_node += 1
    106115               
    107116
Note: See TracChangeset for help on using the changeset viewer.