Changeset 4654
- Timestamp:
- Aug 6, 2007, 10:02:39 AM (18 years ago)
- Location:
- anuga_core/source/anuga
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/fit_interpolate/search_functions.py
r4653 r4654 37 37 k = -10.0 38 38 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]) 39 #Find vertices near x 40 candidate_vertices = root.search(x[0], x[1]) 43 41 is_more_elements = True 44 42 45 43 element_found, sigma0, sigma1, sigma2, k = \ 46 44 _search_triangles_of_vertices(mesh, 47 triangles, x)45 candidate_vertices, x) 48 46 while not element_found and is_more_elements: 49 triangles, branch = root.expand_search()47 candidate_vertices, branch = root.expand_search() 50 48 if branch == []: 51 49 # Searching all the verts from the root cell that haven't 52 50 # been searched. This is the last try 53 51 element_found, sigma0, sigma1, sigma2, k = \ 54 _search_triangles_of_vertices(mesh,triangles, x) 52 _search_triangles_of_vertices(mesh, 53 candidate_vertices, x) 55 54 is_more_elements = False 56 55 else: 57 56 element_found, sigma0, sigma1, sigma2, k = \ 58 _search_triangles_of_vertices(mesh,triangles, x) 57 _search_triangles_of_vertices(mesh, 58 candidate_vertices, x) 59 59 60 60 return element_found, sigma0, sigma1, sigma2, k 61 61 62 62 63 def _search_triangles_of_vertices(mesh, triangles, x):63 def _search_triangles_of_vertices(mesh, candidate_vertices, 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 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 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 89 98 # Find triangle that contains x (if any) and interpolate 90 element_found, sigma0, sigma1, sigma2 =\ 91 find_triangle_compute_interpolation(tri, n0, n1, n2, x) 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 92 110 if element_found is True: 93 # Don't look for any other triangles in the triangle list 111 # Don't look for any other triangle_lists from the 112 # candidate_vertices 94 113 break 114 95 115 return element_found, sigma0, sigma1, sigma2, k 96 116 97 117 98 118 99 def find_triangle_compute_interpolation( triangle, n0, n1, n2, x):119 def find_triangle_compute_interpolation(mesh, k, x): 100 120 """Compute linear interpolation of point x and triangle k in mesh. 101 121 It is assumed that x belongs to triangle k. … … 103 123 104 124 # Get the three vertex_points of candidate triangle k 105 xi0, xi1, xi2 = triangle125 xi0, xi1, xi2 = mesh.get_vertex_coordinates(triangle_id=k) 106 126 107 127 # this is where we can call some fast c code. … … 118 138 119 139 if x[0] > xmax + epsilon: 120 return False,0,0,0 140 return False,0,0,0,0 121 141 if x[0] < xmin - epsilon: 122 return False,0,0,0 142 return False,0,0,0,0 123 143 if x[1] > ymax + epsilon: 124 return False,0,0,0 144 return False,0,0,0,0 125 145 if x[1] < ymin - epsilon: 126 return False,0,0,0 146 return False,0,0,0,0 127 147 128 148 # Get the three normals 129 #n0 = norms[0] 130 #n1 = norms[1] 131 #n2 = norms[2] 149 n0 = mesh.get_normal(k, 0) 150 n1 = mesh.get_normal(k, 1) 151 n2 = mesh.get_normal(k, 2) 152 132 153 133 154 # Compute interpolation … … 150 171 else: 151 172 element_found = False 152 return element_found, sigma0, sigma1, sigma2 173 return element_found, sigma0, sigma1, sigma2, k -
anuga_core/source/anuga/fit_interpolate/ticket178_benchmark.py
r4653 r4654 14 14 ofile = 'lbm_resultsII.csv' 15 15 delimiter = ',' 16 run_profile = False #True16 run_profile = True #False #True 17 17 is_fit_list = [True, False] 18 18 num_of_points_list = [3, 200, 600, 2000, 6000, 10000, 20000] -
anuga_core/source/anuga/utilities/quad.py
r4653 r4654 72 72 73 73 74 def search(self, x, y, get_vertices=False): 74 def search(self, x, y): 75 #def search_new(self, x, y): 75 76 """Find all point indices sharing the same cell as point (x, y) 76 77 """ … … 83 84 brothers.remove(child) 84 85 branch.append(brothers) 85 points, branch = child.search_branch(x,y, branch, 86 get_vertices=get_vertices) 86 points, branch = child.search_branch(x,y, branch) 87 87 else: 88 88 # Leaf node: Get actual waypoints 89 points = self.retrieve(get_vertices=get_vertices) 89 points = self.retrieve() 90 90 91 self.branch = branch 91 92 return points 92 93 93 94 94 def search_branch(self, x, y, branch , get_vertices=False):95 def search_branch(self, x, y, branch): 95 96 """Find all point indices sharing the same cell as point (x, y) 96 97 """ … … 102 103 brothers.remove(child) 103 104 branch.append(brothers) 104 points, branch = child.search_branch(x,y, branch, 105 get_vertices=get_vertices) 105 points, branch = child.search_branch(x,y, branch) 106 106 107 107 else: 108 108 # Leaf node: Get actual waypoints 109 points = self.retrieve( get_vertices=get_vertices)109 points = self.retrieve() 110 110 return points, branch 111 111 112 112 113 def expand_search(self , get_vertices=False):113 def expand_search(self): 114 114 """Find all point indices 'up' one cell from the last search 115 115 """ … … 121 121 for cell in three_cells: 122 122 #print "cell ", cell.show() 123 points += cell.retrieve( get_vertices=get_vertices)123 points += cell.retrieve() 124 124 return points, self.branch 125 125 … … 200 200 201 201 202 def retrieve_triangles(self): 203 """return a list of lists. For the inner lists, 204 The first element is the triangle index, 205 the second element is a list.for this list 206 the first element is a list of three (x, y) vertices, 207 the following elements are the three triangle normals. 208 209 This info is used in searching for a triangle that a point is in. 210 """ 211 # FIXME Tidy up the structure that is returned. 212 # if the triangles att has been made 213 # return it. 214 if not hasattr(self,'triangles'): 215 # use a dictionary to remove duplicates 216 triangles = {} 217 verts = self.retrieve_vertices() 218 # print "verts", verts 219 for vert in verts: 220 triangle_list = self.__class__.mesh.get_triangles_and_vertices_per_node(vert) 221 for k, _ in triangle_list: 222 if not triangles.has_key(k): 223 # print 'k',k 224 tri = self.__class__.mesh.get_vertex_coordinates(k) 225 n0 = self.__class__.mesh.get_normal(k, 0) 226 n1 = self.__class__.mesh.get_normal(k, 1) 227 n2 = self.__class__.mesh.get_normal(k, 2) 228 triangles[k]=(tri, (n0, n1, n2)) 229 self.triangles = triangles.items() 230 return self.triangles 231 232 def retrieve_vertices(self): 202 def retrieve(self): 233 203 objects = [] 234 204 if self.children is None: … … 239 209 return objects 240 210 241 242 def retrieve(self, get_vertices=True):243 if get_vertices is True:244 return self.retrieve_vertices()245 else:246 return self.retrieve_triangles()247 248 211 249 212 def count(self, keywords=None): -
anuga_core/source/anuga/utilities/test_quad.py
r4653 r4654 1 1 import unittest 2 from Numeric import array, allclose2 from quad import Cell, build_quadtree 3 3 4 from quad import Cell, build_quadtree 4 #from domain import * 5 5 from anuga.abstract_2d_finite_volumes.general_mesh import General_mesh as Mesh 6 6 … … 24 24 25 25 points = [a, b, c, d, e, f, g, h] 26 27 26 #bac, bce, ecf, dbe, daf, dae 28 27 vertices = [[1,0,2], [1,3,4], [1,2,3], [5,4,7], [4,6,7]] … … 57 56 self.cell.split(4) 58 57 59 result = self.cell.search(x = 1, y = 101 , get_vertices=True)58 result = self.cell.search(x = 1, y = 101) 60 59 assert type(result) in [types.ListType,types.TupleType],\ 61 60 'should be a list' … … 127 126 128 127 129 result = Q.search(3, 105 , get_vertices=True)128 result = Q.search(3, 105) 130 129 assert type(result) in [types.ListType,types.TupleType],\ 131 130 'should be a list' … … 152 151 Q = build_quadtree(mesh) 153 152 154 def test_retrieve_triangles(self):155 156 cell = Cell(0, 6, 0, 6, 'cell', max_points_per_cell=4)157 158 p0 = [2,1]159 p1 = [4,1]160 p2 = [4.,4]161 p3 = [2,4]162 p4 = [5,4]163 164 points = [p0,p1,p2, p3, p4]165 #166 vertices = [[0,1,2],[0,2,3],[1,4,2]]167 168 mesh = Mesh(points, vertices)169 170 Q = build_quadtree(mesh)171 results = Q.search(5,1)172 assert len(results),2173 #print "results", results174 #print "results[0][0]", results[0][0]175 assert results[0],0176 assert results[1],2177 assert results[0][1],[[ 2., 1.],178 [ 4., 1.],179 [ 4., 4.]]180 assert results[1][1],[[ 4., 1.],181 [ 5., 4.],182 [ 4., 4.]]183 # this is the normals184 assert results[0][1][1],[[1., 0.],185 [-0.83205029, 0.5547002],186 [ 0., -1.]]187 188 # assert allclose(array(results),[[[ 2., 1.],189 #[ 4., 1.], [ 4., 4.]], [[ 4., 1.],[ 5., 4.],[ 4., 4.]]] )190 results = Q.search(5,4.)191 ### print "results",results192 # results_dic={}193 # results_dic.update(results)194 assert len(results),3195 #print "results_dic[0]", results_dic[0]196 assert results[0][1],[[ 2., 1.],197 [ 4., 1.],198 [ 4., 4.]]199 assert results[1][1],[[ 2., 1.],200 [ 4., 4.],201 [ 2., 4.]]202 assert results[2][1],[[ 4., 1.],203 [ 5., 4.],204 [ 4., 4.]]205 #assert allclose(array(results),[[[ 2., 1.],[ 4., 1.], [ 4., 4.]]206 # ,[[ 2., 1.],[ 4., 4.], [ 2., 4.]],207 #[[ 4., 1.], [ 5., 4.], [ 4., 4.]],208 # [[ 4., 1.], [ 5., 4.], [ 4., 4.]]])209 210 153 #------------------------------------------------------------- 211 154 if __name__ == "__main__": 212 155 213 156 mysuite = unittest.makeSuite(Test_Quad,'test') 214 # mysuite = unittest.makeSuite(Test_Quad,'test_retrieve_triangles')215 157 runner = unittest.TextTestRunner() 216 158 runner.run(mysuite)
Note: See TracChangeset
for help on using the changeset viewer.