Changeset 4478
- Timestamp:
- May 23, 2007, 12:13:06 PM (17 years ago)
- Location:
- anuga_core/source/anuga
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/general_mesh.py
r4474 r4478 210 210 211 211 212 # Build vertex list213 if verbose: print 'Building vertex list'214 self.build_ vertexlist()212 # Build structure listing which trianglse belong to which nodet. 213 if verbose: print 'Building inverted triangle structure' 214 self.build_inverted_triangle_structure() 215 215 216 216 … … 379 379 380 380 381 def build_vertexlist(self): 382 """Build information about which triangles belong to each node 381 def get_triangles_and_vertices_per_node(self, node=None): 382 """Get triangles associated with given node. 383 384 Return list of triangle_ids, vertex_ids for specified node. 385 If node in None or absent, this information will be returned 386 for all (full) nodes. 387 """ 388 389 triangle_list = [] 390 if node is not None: 391 # Get index for this node 392 first = sum(self.number_of_triangles_per_node[:node]) 393 394 # Get number of triangles for this node 395 count = self.number_of_triangles_per_node[node] 396 397 for i in range(count): 398 index = self.vertex_value_indices[first+i] 399 400 volume_id = index / 3 401 vertex_id = index % 3 402 403 triangle_list.append( (volume_id, vertex_id) ) 404 else: 405 # Get info for all nodes recursively. 406 # If need be, we can speed this up by 407 # working directly with the inverted triangle structure 408 for i in range(self.number_of_full_nodes): 409 L = self.get_triangles_and_vertices_per_node(node=i) 410 triangle_list.append(L) 411 412 return triangle_list 413 414 415 def build_inverted_triangle_structure(self): 416 """Build structure listing triangles belonging to each node 383 417 384 418 Two arrays are created and store as mesh attributes … … 441 475 """ 442 476 443 # FIXME (Ole): Refactor this based on algorithm in test and get 444 # rid of the old vertexlist 445 477 # Count number of triangles per node 478 number_of_triangles_per_node = zeros(self.number_of_nodes) 479 for volume_id, triangle in enumerate(self.triangles): 480 for vertex_id in triangle: 481 number_of_triangles_per_node[vertex_id] += 1 482 483 # Allocate space for inverted structure 484 number_of_entries = sum(number_of_triangles_per_node) 485 vertex_value_indices = zeros(number_of_entries) 486 487 # Register (triangle, vertex) indices for each node 446 488 vertexlist = [None]*self.number_of_nodes 447 for i in range(self.number_of_triangles): 448 449 a = self.triangles[i, 0] 450 b = self.triangles[i, 1] 451 c = self.triangles[i, 2] 452 453 #Register the vertices v as lists of 454 #(triangle_id, vertex_id) tuples associated with them 455 #This is used for averaging multiple vertex values. 456 for vertex_id, v in enumerate([a,b,c]): 457 if vertexlist[v] is None: 458 vertexlist[v] = [] 459 460 vertexlist[v].append( (i, vertex_id) ) 461 462 463 # Register number of triangles touching each nodes 464 number_of_triangles_per_node = zeros(self.number_of_nodes) 465 number_of_entries = 0 466 for i, vertices in enumerate(vertexlist): 467 try: 468 v = len(vertices) 469 except: 470 v = 0 # Lone node - e.g. not part of the mesh 471 472 number_of_triangles_per_node[i] = v 473 number_of_entries += v 474 475 476 # Build vertex value index array 477 vertex_value_indices = zeros(number_of_entries) 489 for volume_id in range(self.number_of_triangles): 490 491 a = self.triangles[volume_id, 0] 492 b = self.triangles[volume_id, 1] 493 c = self.triangles[volume_id, 2] 494 495 for vertex_id, node_id in enumerate([a,b,c]): 496 if vertexlist[node_id] is None: 497 vertexlist[node_id] = [] 498 499 vertexlist[node_id].append( (volume_id, vertex_id) ) 500 501 502 # Build inverted triangle index array 478 503 k = 0 479 504 for vertices in vertexlist: 480 505 if vertices is not None: 481 for i, v_id in vertices:482 vertex_value_indices[k] = 3* i + v_id483 506 for volume_id, vertex_id in vertices: 507 vertex_value_indices[k] = 3*volume_id + vertex_id 508 484 509 k += 1 485 510 486 assert k == number_of_entries 487 self.vertexlist = vertexlist 488 511 # Save structure 489 512 self.number_of_triangles_per_node = number_of_triangles_per_node 490 513 self.vertex_value_indices = vertex_value_indices 491 492 493 #print 494 #print number_of_triangles_per_node 495 #print vertex_value_indices 496 #print vertexlist 497 514 515 516 498 517 499 518 def get_extent(self, absolute=False): -
anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py
r4471 r4478 407 407 elif location == 'unique vertices': 408 408 if indices is None: 409 self.edge_values[:] = X 409 self.edge_values[:] = X #FIXME (Ole): Shouldn't this be vertex_values? 410 410 else: 411 411 412 412 #Go through list of unique vertices 413 413 for unique_vert_id in indices: 414 triangles = self.domain.vertexlist[unique_vert_id] 415 414 415 triangles = self.domain.get_triangles_and_vertices_per_node(node=unique_vert_id) 416 416 417 #In case there are unused points 417 if triangles is None: continue 418 418 if len(triangles) == 0: 419 continue 420 419 421 #Go through all triangle, vertex pairs 420 422 #and set corresponding vertex value … … 932 934 #Go through list of unique vertices 933 935 for unique_vert_id in indices: 934 triangles = self.domain. vertexlist[unique_vert_id]935 936 triangles = self.domain.get_triangles_and_vertices_per_node(node=unique_vert_id) 937 936 938 #In case there are unused points 937 if triangles is None:939 if len(triangles) == 0: 938 940 msg = 'Unique vertex not associated with triangles' 939 941 raise msg … … 958 960 """Set vertex values for all unique vertices based on input array A 959 961 which has one entry per unique vertex, i.e. 960 one value for each row in array self.domain.coordinates or 961 one value for each row in vertexlist. 962 one value for each row in array self.domain.nodes. 962 963 963 964 indices is the list of vertex_id's that will be set. … … 982 983 983 984 #Go through list of unique vertices 985 984 986 for i_index, unique_vert_id in enumerate(vertex_list): 985 triangles = self.domain.vertexlist[unique_vert_id] 986 987 if triangles is None: continue #In case there are unused points 987 988 989 triangles = self.domain.get_triangles_and_vertices_per_node(node=unique_vert_id) 990 991 #In case there are unused points 992 if len(triangles) == 0: continue 988 993 989 994 #Go through all triangle, vertex pairs -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_general_mesh.py
r4474 r4478 96 96 count[i] += 1 97 97 98 #print count 99 # 98 100 assert allclose(count, domain.number_of_triangles_per_node) 99 101 100 102 # Check indices 101 103 current_node = 0 … … 115 117 116 118 117 119 def test_get_triangles_and_vertices_per_node(self): 120 """test_get_triangles_and_vertices_per_node - 121 122 Test that tuples of triangle, vertex can be extracted 123 from inverted triangles structure 124 125 """ 126 127 a = [0.0, 0.0] 128 b = [0.0, 2.0] 129 c = [2.0, 0.0] 130 d = [0.0, 4.0] 131 e = [2.0, 2.0] 132 f = [4.0, 0.0] 133 134 nodes = array([a, b, c, d, e, f]) 135 #bac, bce, ecf, dbe, daf, dae 136 triangles = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 137 138 domain = General_mesh(nodes, triangles) 139 140 # One node 141 L = domain.get_triangles_and_vertices_per_node(node=2) 142 143 assert allclose(L[0], [0, 2]) 144 assert allclose(L[1], [1, 1]) 145 assert allclose(L[2], [2, 1]) 146 147 # All nodes 148 ALL = domain.get_triangles_and_vertices_per_node() 149 150 assert len(ALL) == 6 151 for i, Lref in enumerate(ALL): 152 L = domain.get_triangles_and_vertices_per_node(node=i) 153 assert allclose(L, Lref) 154 155 156 157 158 118 159 119 160 … … 156 197 #------------------------------------------------------------- 157 198 if __name__ == "__main__": 158 suite = unittest.makeSuite(Test_General_Mesh,'test ')199 suite = unittest.makeSuite(Test_General_Mesh,'test_vertex_value_indices') 159 200 runner = unittest.TextTestRunner() 160 201 runner.run(suite) -
anuga_core/source/anuga/fit_interpolate/search_functions.py
r3865 r4478 64 64 #FIXME (DSG-DSG): this catches verts with no triangle. 65 65 #Currently pmesh is producing these. 66 #this should be stopped, 67 if mesh.vertexlist[v] is None: 66 #this should be stopped, 67 68 if mesh.number_of_triangles_per_node[v] == 0: 68 69 continue 70 69 71 #for each triangle id (k) which has v as a vertex 70 for k, _ in mesh.vertexlist[v]: 72 73 vertexlist = mesh.get_triangles_and_vertices_per_node(node=v) 74 for k, _ in vertexlist: 71 75 #Get the three vertex_points of candidate triangle 72 76 xi0 = mesh.get_vertex_coordinate(k, 0)
Note: See TracChangeset
for help on using the changeset viewer.