- Timestamp:
- Aug 6, 2007, 9:56:50 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/fit_interpolate/search_functions.py
r4651 r4653 37 37 k = -10.0 38 38 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]) 41 43 is_more_elements = True 42 44 43 45 element_found, sigma0, sigma1, sigma2, k = \ 44 46 _search_triangles_of_vertices(mesh, 45 candidate_vertices, x)47 triangles, x) 46 48 while not element_found and is_more_elements: 47 candidate_vertices, branch = root.expand_search()49 triangles, branch = root.expand_search() 48 50 if branch == []: 49 51 # Searching all the verts from the root cell that haven't 50 52 # been searched. This is the last try 51 53 element_found, sigma0, sigma1, sigma2, k = \ 52 _search_triangles_of_vertices(mesh, 53 candidate_vertices, x) 54 _search_triangles_of_vertices(mesh,triangles, x) 54 55 is_more_elements = False 55 56 else: 56 57 element_found, sigma0, sigma1, sigma2, k = \ 57 _search_triangles_of_vertices(mesh, 58 candidate_vertices, x) 58 _search_triangles_of_vertices(mesh,triangles, x) 59 59 60 60 return element_found, sigma0, sigma1, sigma2, k 61 61 62 62 63 def _search_triangles_of_vertices(mesh, candidate_vertices, x):63 def _search_triangles_of_vertices(mesh, triangles, x): 64 64 """Search for triangle containing x amongs candidate_vertices in mesh 65 65 … … 82 82 83 83 #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 98 89 # 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) 110 92 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 113 94 break 114 115 95 return element_found, sigma0, sigma1, sigma2, k 116 96 117 97 118 98 119 def find_triangle_compute_interpolation( mesh, k, x):99 def find_triangle_compute_interpolation(triangle, n0, n1, n2, x): 120 100 """Compute linear interpolation of point x and triangle k in mesh. 121 101 It is assumed that x belongs to triangle k. … … 123 103 124 104 # 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 126 106 127 107 # this is where we can call some fast c code. … … 138 118 139 119 if x[0] > xmax + epsilon: 140 return False,0,0,0 ,0120 return False,0,0,0 141 121 if x[0] < xmin - epsilon: 142 return False,0,0,0 ,0122 return False,0,0,0 143 123 if x[1] > ymax + epsilon: 144 return False,0,0,0 ,0124 return False,0,0,0 145 125 if x[1] < ymin - epsilon: 146 return False,0,0,0 ,0126 return False,0,0,0 147 127 148 128 # 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] 153 132 154 133 # Compute interpolation … … 171 150 else: 172 151 element_found = False 173 return element_found, sigma0, sigma1, sigma2 , k152 return element_found, sigma0, sigma1, sigma2
Note: See TracChangeset
for help on using the changeset viewer.