Changeset 6545


Ignore:
Timestamp:
Mar 18, 2009, 3:00:24 PM (16 years ago)
Author:
ole
Message:

Removed more cluttter in search functions.

Location:
anuga_core/source/anuga/fit_interpolate
Files:
4 edited

Legend:

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

    r6537 r6545  
    279279           
    280280            element_found, sigma0, sigma1, sigma2, k = \
    281                            search_tree_of_vertices(self.root, self.mesh, x)
     281                           search_tree_of_vertices(self.root, x)
    282282           
    283283            if element_found is True:
  • anuga_core/source/anuga/fit_interpolate/interpolate.py

    r6223 r6545  
    484484            x = point_coordinates[i]
    485485            element_found, sigma0, sigma1, sigma2, k = \
    486                            search_tree_of_vertices(self.root, self.mesh, x)
     486                           search_tree_of_vertices(self.root, x)
    487487           
    488488            # Update interpolation matrix A if necessary
  • anuga_core/source/anuga/fit_interpolate/search_functions.py

    r6544 r6545  
    1919search_more_cells_time = initial_search_value
    2020
     21# FIXME(Ole): Could we come up with a less confusing structure?
    2122LAST_TRIANGLE = [[-10,
    22                    (num.array([[max_float,max_float],
    23                                [max_float,max_float],
    24                                [max_float,max_float]]),
    25                     (num.array([1,1], num.Int),      #array default#
    26                      num.array([0,0], num.Int),      #array default#
     23                   (num.array([[max_float, max_float],
     24                               [max_float, max_float],
     25                               [max_float, max_float]]),
     26                    (num.array([1.,1.]),     
     27                     num.array([0.,0.]),     
    2728                     num.array([-1.1,-1.1])))]]
    2829
    29 def search_tree_of_vertices(root, mesh, x):
     30def search_tree_of_vertices(root, x):
    3031    """
    3132    Find the triangle (element) that the point x is in.
     
    3334    Inputs:
    3435        root: A quad tree of the vertices
    35         mesh: The underlying mesh
    3636        x:    The point being placed
    3737   
     
    4848    global search_more_cells_time
    4949
    50     # This will be returned if element_found = False
    51     element_found = False   
    52     sigma2 = -10.0
    53     sigma0 = -10.0
    54     sigma1 = -10.0
    55     k = -10.0
    56 
    5750    # Search the last triangle first
    58     try:
    59         element_found, sigma0, sigma1, sigma2, k = \
    60             _search_triangles_of_vertices(mesh, last_triangle, x)
    61            
    62     except:
    63         print 'This should never happen:', last_triangle
    64         element_found = False
     51    element_found, sigma0, sigma1, sigma2, k = \
     52        _search_triangles_of_vertices(last_triangle, x)
    6553                   
    6654    if element_found is True:
     
    7260    # second element the triangle
    7361    triangles = root.search(x[0], x[1])
     62    element_found, sigma0, sigma1, sigma2, k = \
     63                   _search_triangles_of_vertices(triangles, x)
     64
    7465    is_more_elements = True
    75     element_found, sigma0, sigma1, sigma2, k = \
    76                    _search_triangles_of_vertices(mesh,
    77                                                  triangles, x)
    78     #search_one_cell_time += time.time()-t0
    79     #print "search_one_cell_time",search_one_cell_time
    80     #t0 = time.time()
    8166    while not element_found and is_more_elements:
    8267        triangles, branch = root.expand_search()
     
    8570            # been searched.  This is the last try
    8671            element_found, sigma0, sigma1, sigma2, k = \
    87                            _search_triangles_of_vertices(mesh, triangles, x)
     72                           _search_triangles_of_vertices(triangles, x)
    8873            is_more_elements = False
    8974        else:
    9075            element_found, sigma0, sigma1, sigma2, k = \
    91                        _search_triangles_of_vertices(mesh, triangles, x)
    92         #search_more_cells_time += time.time()-t0
    93     #print "search_more_cells_time", search_more_cells_time
     76                       _search_triangles_of_vertices(triangles, x)
     77                       
    9478       
    9579    return element_found, sigma0, sigma1, sigma2, k
    9680
    9781
    98 def _search_triangles_of_vertices(mesh, triangles, x):
    99     """Search for triangle containing x amongs candidate_vertices in mesh
     82def _search_triangles_of_vertices(triangles, x):
     83    """Search for triangle containing x amongs candidate_vertices in triangles
    10084
    10185    This is called by search_tree_of_vertices once the appropriate node
    10286    has been found from the quad tree.
    10387   
    104 
    10588    This function is responsible for most of the compute time in
    10689    fit and interpolate.
     
    10992   
    11093    # These statments are needed if triangles is empty
    111     element_found = False
    11294    sigma2 = -10.0
    11395    sigma0 = -10.0
     
    11698
    11799    # For all vertices in same cell as point x
     100    element_found = False   
    118101    for k, tri_verts_norms in triangles:
    119102        tri = tri_verts_norms[0]
     
    163146   
    164147def search_times():
    165 
    166148    global search_one_cell_time
    167149    global search_more_cells_time
     
    170152
    171153def reset_search_times():
    172 
    173154    global search_one_cell_time
    174155    global search_more_cells_time
  • anuga_core/source/anuga/fit_interpolate/test_search_functions.py

    r6544 r6545  
    5353
    5454        x = [0.2, 0.7]
    55         found, s0, s1, s2, k = search_tree_of_vertices(root,
    56                                                        mesh,
    57                                                        ensure_numeric(x))
     55        found, s0, s1, s2, k = search_tree_of_vertices(root, x)
    5856        assert k == 1 # Triangle one
    5957        assert found is True
     
    8078           
    8179            found, s0, s1, s2, k = search_tree_of_vertices(root,
    82                                                            mesh,
    8380                                                           ensure_numeric(x))
    8481
     
    112109                      [10, 3]]:
    113110               
    114                 found, s0, s1, s2, k = search_tree_of_vertices(root,
    115                                                                mesh,
    116                                                                x)
     111                found, s0, s1, s2, k = search_tree_of_vertices(root, x)
    117112
    118113                if k >= 0:
     
    145140        # print x, candidate_vertices
    146141        found, sigma0, sigma1, sigma2, k = \
    147                _search_triangles_of_vertices(mesh,
    148                                              candidate_vertices,
     142               _search_triangles_of_vertices(candidate_vertices,
    149143                                             x)
    150144
     
    167161            #print x, candidate_vertices
    168162            found, sigma0, sigma1, sigma2, k = \
    169                    _search_triangles_of_vertices(mesh,
    170                                                  candidate_vertices,
     163                   _search_triangles_of_vertices(candidate_vertices,
    171164                                                 ensure_numeric(x))
    172165            if k >= 0:
     
    215208        x = [2.5, 1.5]
    216209        element_found, sigma0, sigma1, sigma2, k = \
    217                        search_tree_of_vertices(root, mesh, x)
     210                       search_tree_of_vertices(root, x)
    218211        # One point
    219212        x = [3.00005, 2.999994]
    220213        element_found, sigma0, sigma1, sigma2, k = \
    221                        search_tree_of_vertices(root, mesh, x)
     214                       search_tree_of_vertices(root, x)
    222215        assert element_found is True
    223216        assert k == 1
Note: See TracChangeset for help on using the changeset viewer.