Ignore:
Timestamp:
Aug 6, 2007, 9:56:50 AM (17 years ago)
Author:
duncan
Message:

checking in for benchmarking. When fitting cell data - triangle vertices and norms - are calculated the first time a point is looked for in a cell. This is to speed thing up.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/fit_interpolate/search_functions.py

    r4651 r4653  
    3737    k = -10.0
    3838           
    39     #Find vertices near x
    40     candidate_vertices = root.search(x[0], x[1])
     39    #Get triangles in the cell that the point is in.
     40    # Triangle is a list, first element triangle_id,
     41    # second element the triangle
     42    triangles = root.search(x[0], x[1])
    4143    is_more_elements = True
    4244
    4345    element_found, sigma0, sigma1, sigma2, k = \
    4446                   _search_triangles_of_vertices(mesh,
    45                                                  candidate_vertices, x)
     47                                                 triangles, x)
    4648    while not element_found and is_more_elements:
    47         candidate_vertices, branch = root.expand_search()
     49        triangles, branch = root.expand_search()
    4850        if branch == []:
    4951            # Searching all the verts from the root cell that haven't
    5052            # been searched.  This is the last try
    5153            element_found, sigma0, sigma1, sigma2, k = \
    52                            _search_triangles_of_vertices(mesh,
    53                                                          candidate_vertices, x)
     54                           _search_triangles_of_vertices(mesh,triangles, x)
    5455            is_more_elements = False
    5556        else:
    5657            element_found, sigma0, sigma1, sigma2, k = \
    57                        _search_triangles_of_vertices(mesh,
    58                                                      candidate_vertices, x)
     58                       _search_triangles_of_vertices(mesh,triangles, x)
    5959
    6060    return element_found, sigma0, sigma1, sigma2, k
    6161
    6262
    63 def _search_triangles_of_vertices(mesh, candidate_vertices, x):
     63def _search_triangles_of_vertices(mesh, triangles, x):
    6464    """Search for triangle containing x amongs candidate_vertices in mesh
    6565
     
    8282   
    8383    #For all vertices in same cell as point x
    84     for v in candidate_vertices:
    85        
    86         #FIXME (DSG-DSG): this catches verts with no triangle.
    87         #Currently pmesh is producing these.
    88         #this should be stopped,
    89 
    90         if mesh.number_of_triangles_per_node[v] == 0:
    91             continue
    92        
    93         # Get all triangles which has v as a vertex
    94         # The list has elements (triangle, vertex), but only the
    95         # first component will be used here
    96         triangle_list = mesh.get_triangles_and_vertices_per_node(node=v)
    97 
     84    for k, tri_verts_norms in triangles:
     85        tri = tri_verts_norms[0]
     86        n0, n1, n2 = tri_verts_norms[1]
     87        # k is the triangle index
     88        # tri is a list of verts (x, y), representing a tringle
    9889        # Find triangle that contains x (if any) and interpolate
    99        
    100         for k, _ in triangle_list:
    101             element_found, sigma0, sigma1, sigma2, k =\
    102                            find_triangle_compute_interpolation(mesh,
    103                                                                k,
    104                                                                x)
    105 
    106             if element_found is True:
    107                 # Don't look for any other triangles in the triangle list
    108                 break
    109 
     90        element_found, sigma0, sigma1, sigma2 =\
     91                       find_triangle_compute_interpolation(tri, n0, n1, n2, x)
    11092        if element_found is True:
    111             # Don't look for any other triangle_lists from the
    112             # candidate_vertices
     93            # Don't look for any other triangles in the triangle list
    11394            break
    114        
    11595    return element_found, sigma0, sigma1, sigma2, k
    11696
    11797
    11898           
    119 def find_triangle_compute_interpolation(mesh, k, x):
     99def find_triangle_compute_interpolation(triangle, n0, n1, n2, x):
    120100    """Compute linear interpolation of point x and triangle k in mesh.
    121101    It is assumed that x belongs to triangle k.
     
    123103
    124104    # Get the three vertex_points of candidate triangle k
    125     xi0, xi1, xi2 = mesh.get_vertex_coordinates(triangle_id=k)
     105    xi0, xi1, xi2 = triangle
    126106
    127107    # this is where we can call some fast c code.
     
    138118   
    139119    if  x[0] > xmax + epsilon:
    140         return False,0,0,0,0
     120        return False,0,0,0
    141121    if  x[0] < xmin - epsilon:
    142         return False,0,0,0,0
     122        return False,0,0,0
    143123    if  x[1] > ymax + epsilon:
    144         return False,0,0,0,0
     124        return False,0,0,0
    145125    if  x[1] < ymin - epsilon:
    146         return False,0,0,0,0
     126        return False,0,0,0
    147127   
    148128    # Get the three normals
    149     n0 = mesh.get_normal(k, 0)
    150     n1 = mesh.get_normal(k, 1)
    151     n2 = mesh.get_normal(k, 2)           
    152        
     129    #n0 = norms[0] 
     130    #n1 = norms[1]
     131    #n2 = norms[2]
    153132       
    154133    # Compute interpolation
     
    171150    else:
    172151        element_found = False
    173     return element_found, sigma0, sigma1, sigma2, k
     152    return element_found, sigma0, sigma1, sigma2
Note: See TracChangeset for help on using the changeset viewer.