Changeset 8538 for trunk/anuga_core/source/anuga_parallel
- Timestamp:
- Aug 28, 2012, 4:06:09 PM (13 years ago)
- Location:
- trunk/anuga_core/source/anuga_parallel
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga_parallel/distribute_mesh.py
r8537 r8538 266 266 ######################################################### 267 267 268 def submesh_full( nodes, triangles, boundary, triangles_per_proc):268 def submesh_full(mesh, triangles_per_proc): 269 269 270 270 # Initialise 271 272 273 nodes = mesh.nodes 274 triangles = mesh.triangles 275 boundary = mesh.boundary 271 276 272 277 tlower = 0 … … 353 358 ######################################################### 354 359 355 def ghost_layer(submesh, mesh, p, tupper, tlower ):360 def ghost_layer(submesh, mesh, p, tupper, tlower, parameters = None): 356 361 357 362 ncoord = mesh.number_of_nodes 358 363 ntriangles = mesh.number_of_triangles 359 364 360 361 layer_width = config.ghost_layer_width 362 363 print layer_width 365 if parameters is None: 366 layer_width = 2 367 else: 368 layer_width = parameters['ghost_layer_width'] 369 364 370 365 371 trianglemap = num.zeros(ntriangles, 'i') … … 443 449 # Return the triangles and vertices sitting on the boundary layer 444 450 445 return subnodes, subtriangles 451 return subnodes, subtriangles, layer_width 446 452 447 453 ######################################################### … … 479 485 def ghost_bnd_layer(ghosttri, tlower, tupper, mesh, p): 480 486 487 488 boundary = mesh.boundary 489 481 490 ghost_list = [] 482 491 subboundary = {} 483 492 484 493 494 # FIXME SR: For larger layers need to pass through the correct 495 # boundary tag! 496 485 497 for t in ghosttri: 486 498 ghost_list.append(t[0]) … … 490 502 n = mesh.neighbours[t[0], 0] 491 503 if not is_in_processor(ghost_list, tlower, tupper, n): 492 subboundary[t[0], 0] = 'ghost' 504 if boundary.has_key( (t[0], 0) ): 505 subboundary[t[0], 0] = boundary[t[0],0] 506 else: 507 subboundary[t[0], 0] = 'ghost' 508 493 509 494 510 n = mesh.neighbours[t[0], 1] 495 511 if not is_in_processor(ghost_list, tlower, tupper, n): 496 subboundary[t[0], 1] = 'ghost' 512 if boundary.has_key( (t[0], 1) ): 513 subboundary[t[0], 1] = boundary[t[0],1] 514 else: 515 subboundary[t[0], 1] = 'ghost' 516 497 517 498 518 n = mesh.neighbours[t[0], 2] 499 519 if not is_in_processor(ghost_list, tlower, tupper, n): 500 subboundary[t[0], 2] = 'ghost' 520 if boundary.has_key( (t[0], 2) ): 521 subboundary[t[0], 2] = boundary[t[0],2] 522 else: 523 subboundary[t[0], 2] = 'ghost' 501 524 502 525 return subboundary … … 629 652 ######################################################### 630 653 631 def submesh_ghost(submesh, mesh, triangles_per_proc ):654 def submesh_ghost(submesh, mesh, triangles_per_proc, parameters = None): 632 655 633 656 nproc = len(triangles_per_proc) … … 637 660 ghost_commun = [] 638 661 ghost_bnd = [] 662 ghost_layer_width = [] 639 663 640 664 # Loop over the processors … … 648 672 # Build the ghost boundary layer 649 673 650 [subnodes, subtri] = \ 651 ghost_layer(submesh, mesh, p, tupper, tlower) 674 [subnodes, subtri, layer_width] = \ 675 ghost_layer(submesh, mesh, p, tupper, tlower, parameters) 676 ghost_layer_width.append(layer_width) 652 677 ghost_triangles.append(subtri) 653 678 ghost_nodes.append(subnodes) … … 671 696 672 697 # Record the ghost layer and communication pattern 673 698 submesh["ghost_layer_width"] = ghost_layer_width 674 699 submesh["ghost_nodes"] = ghost_nodes 675 700 submesh["ghost_triangles"] = ghost_triangles … … 760 785 ######################################################### 761 786 762 def build_submesh(nodes, triangles, edges, quantities,763 triangles_per_proc ):787 def build_submesh(nodes, triangles, boundary, quantities, 788 triangles_per_proc, parameters = None): 764 789 765 790 # Temporarily build the mesh to find the neighbouring 766 791 # triangles and true boundary polygon 767 792 768 mesh = Mesh(nodes, triangles )793 mesh = Mesh(nodes, triangles, boundary) 769 794 boundary_polygon = mesh.get_boundary_polygon() 770 795 … … 772 797 # Subdivide into non-overlapping partitions 773 798 774 submeshf = submesh_full(nodes, triangles, edges, \ 775 triangles_per_proc) 799 submeshf = submesh_full(mesh, triangles_per_proc) 776 800 777 801 # Add any extra ghost boundary layer information 778 802 779 submeshg = submesh_ghost(submeshf, mesh, triangles_per_proc )803 submeshg = submesh_ghost(submeshf, mesh, triangles_per_proc, parameters) 780 804 781 805 # Order the quantities information to be the same as the triangle … … 957 981 nodes = num.concatenate((submesh["full_nodes"], \ 958 982 submesh["ghost_nodes"])) 983 984 ghost_layer_width = submesh["ghost_layer_width"] 959 985 960 986 # Combine the full triangles and ghost triangles … … 1009 1035 1010 1036 return GAnodes, GAtriangles, GAboundary, quantities, ghost_rec, \ 1011 full_send, tri_map, node_map 1037 full_send, tri_map, node_map, ghost_layer_width 1012 1038 1013 1039 … … 1051 1077 myid = pypar.rank() 1052 1078 1053 if verbose: print ' process %d sending submesh to process%d' %(myid, p)1079 if verbose: print 'P%d: Sending submesh to P%d' %(myid, p) 1054 1080 1055 1081 # build and send the tagmap for the boundary conditions … … 1078 1104 pypar.send(triangles_per_proc, p) 1079 1105 1106 # ghost layer width 1107 1108 pypar.send(submesh["ghost_layer_width"][p], p) 1109 1080 1110 # compress full_commun 1081 1111 … … 1185 1215 triangles_per_proc = pypar.receive(p) 1186 1216 1217 # ghost layer width 1218 1219 submesh_cell["ghost_layer_width"] = pypar.receive(p) 1220 1187 1221 # recieve information about the array sizes 1188 1222 … … 1303 1337 1304 1338 [GAnodes, GAtriangles, boundary, quantities, \ 1305 ghost_rec, full_send, tri_map, node_map ] = \1339 ghost_rec, full_send, tri_map, node_map, ghost_layer_width] = \ 1306 1340 build_local_mesh(submesh_cell, lower_t, upper_t, \ 1307 1341 numproc) … … 1309 1343 return GAnodes, GAtriangles, boundary, quantities,\ 1310 1344 ghost_rec, full_send,\ 1311 number_of_full_nodes, number_of_full_triangles, tri_map, node_map 1345 number_of_full_nodes, number_of_full_triangles, tri_map, node_map,\ 1346 ghost_layer_width 1312 1347 1313 1348 … … 1332 1367 1333 1368 submesh_cell = {} 1369 submesh_cell["ghost_layer_width"] = submesh["ghost_layer_width"][0] 1334 1370 submesh_cell["full_nodes"] = submesh["full_nodes"][0] 1335 1371 submesh_cell["ghost_nodes"] = submesh["ghost_nodes"][0] … … 1348 1384 numprocs = len(triangles_per_proc) 1349 1385 points, vertices, boundary, quantities, ghost_recv_dict, \ 1350 full_send_dict, tri_map, node_map = \1386 full_send_dict, tri_map, node_map, ghost_layer_width = \ 1351 1387 build_local_mesh(submesh_cell, 0, triangles_per_proc[0], numprocs) 1352 1388 1353 1389 1354 1390 return points, vertices, boundary, quantities, ghost_recv_dict, \ 1355 full_send_dict, tri_map, node_map 1391 full_send_dict, tri_map, node_map, ghost_layer_width 1356 1392 1357 1393 -
trunk/anuga_core/source/anuga_parallel/parallel_api.py
r8518 r8538 36 36 37 37 38 def distribute(domain, verbose=False, debug=False ):38 def distribute(domain, verbose=False, debug=False, parameters = None): 39 39 """ Distribute the domain to all processes 40 40 """ … … 112 112 ghost_recv_dict, full_send_dict,\ 113 113 number_of_full_nodes, number_of_full_triangles,\ 114 s2p_map, p2s_map, tri_map, node_map =\ 115 distribute_mesh(domain, verbose=verbose, debug=debug) 116 117 118 119 114 s2p_map, p2s_map, tri_map, node_map, ghost_layer_width =\ 115 distribute_mesh(domain, verbose=verbose, debug=debug, parameters=parameters) 120 116 121 117 # Extract l2g maps … … 146 142 ghost_recv_dict, full_send_dict,\ 147 143 number_of_full_nodes, number_of_full_triangles, \ 148 tri_map, node_map =\144 tri_map, node_map, ghost_layer_width =\ 149 145 rec_submesh(0, verbose) 150 146 … … 178 174 p2s_map = p2s_map, ## jj added this 179 175 tri_l2g = tri_l2g, ## SR added this 180 node_l2g = node_l2g) 176 node_l2g = node_l2g, 177 ghost_layer_width = ghost_layer_width) 181 178 182 179 #------------------------------------------------------------------------ … … 213 210 214 211 215 def distribute_mesh(domain, verbose=False, debug=False ):212 def distribute_mesh(domain, verbose=False, debug=False, parameters=None): 216 213 217 214 … … 236 233 if verbose: print 'Build submeshes' 237 234 submesh = build_submesh(nodes, triangles, boundary,\ 238 quantities, triangles_per_proc )235 quantities, triangles_per_proc, parameters) 239 236 240 237 if verbose: … … 257 254 # Build the local mesh for processor 0 258 255 points, vertices, boundary, quantities, \ 259 ghost_recv_dict, full_send_dict, tri_map, node_map =\256 ghost_recv_dict, full_send_dict, tri_map, node_map, ghost_layer_width =\ 260 257 extract_hostmesh(submesh, triangles_per_proc) 261 258 … … 294 291 ghost_recv_dict, full_send_dict,\ 295 292 number_of_full_nodes, number_of_full_triangles, \ 296 s2p_map, p2s_map, tri_map, node_map 293 s2p_map, p2s_map, tri_map, node_map, ghost_layer_width 297 294 298 295 -
trunk/anuga_core/source/anuga_parallel/parallel_shallow_water.py
r8513 r8538 41 41 p2s_map=None, #jj added this 42 42 tri_l2g = None, ## SR added this 43 node_l2g = None): ## SR added this 43 node_l2g = None, #): ## SR added this 44 ghost_layer_width = 2): 44 45 45 46 Domain.__init__(self, … … 53 54 number_of_full_nodes=number_of_full_nodes, 54 55 number_of_full_triangles=number_of_full_triangles, 55 geo_reference=geo_reference) #jj added this 56 geo_reference=geo_reference, #) #jj added this 57 ghost_layer_width = ghost_layer_width) 56 58 57 58 59 59 60 self.parallel = True … … 89 90 self.node_l2g = node_l2g 90 91 92 self.ghost_counter = 0 93 91 94 92 95 def set_name(self, name): … … 122 125 receive the information for the ghost cells 123 126 """ 124 127 125 128 generic_comms.communicate_ghosts_asynchronous(self) 126 129 #generic_comms.communicate_ghosts_blocking(self) -
trunk/anuga_core/source/anuga_parallel/run_parallel_sw_rectangular_cross.py
r8531 r8538 52 52 53 53 54 if myid == 0 and verbose: print 'DISTRIBUTING DOMAIN' 55 domain = distribute(domain,verbose=verbose) 54 if myid == 0 and verbose: 55 print 'DISTRIBUTING DOMAIN' 56 sys.stdout.flush() 57 58 barrier() 56 59 57 print 'after parallel domain' 60 # setup parameters to test using different ghost_layer_widths 61 parameters = dict(ghost_layer_width = 4) 62 domain = distribute(domain,verbose=verbose, parameters=parameters) 63 64 if myid == 0 : print 'after parallel domain' 58 65 59 66 … … 69 76 70 77 71 print 'after set_boundary'78 if myid == 0 : print 'after set_boundary' 72 79 73 80 74 81 75 82 domain.check_integrity() 76 print 'after check_integrity' 83 84 if myid == 0 : print 'after check_integrity' 77 85 78 86 class Set_Stage: … … 96 104 97 105 98 print 'after set quantity'106 if myid == 0 : print 'after set quantity' 99 107 100 108 # Set Evolve parameters … … 142 150 143 151 144 152 domain.dump_triangulation(filename="rectangular_cross_%g.png"% numprocs) 145 153 146 154 finalize() -
trunk/anuga_core/source/anuga_parallel/test_distribute_mesh.py
r8011 r8538 47 47 48 48 49 true_points = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] 50 51 true_vertices = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8]] 49 true_points = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], \ 50 [0.5, 0.5], [0.5, 1.0], [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], \ 51 [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] 52 53 true_vertices = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [1, 10, 2], \ 54 [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7], 55 [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8]] 52 56 53 57 … … 70 74 71 75 72 true_nodes = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] 73 74 true_triangles = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8]] 76 true_nodes = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], \ 77 [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] 78 79 true_triangles = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [1, 10, 2], [4, 10, 1], \ 80 [5, 10, 4], [2, 10, 5], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7], [4, 12, 5], \ 81 [7, 12, 4], [8, 12, 7], [5, 12, 8]] 75 82 76 83 … … 90 97 91 98 92 true_points = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] 93 94 true_vertices = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8]] 99 true_points = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], \ 100 [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] 101 102 true_vertices = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [1, 10, 2], [4, 10, 1], \ 103 [5, 10, 4], [2, 10, 5], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7], [4, 12, 5], \ 104 [7, 12, 4], [8, 12, 7], [5, 12, 8]] 95 105 96 106 … … 113 123 114 124 115 true_nodes = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] 116 117 118 true_triangles = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [4, 10, 1], [3, 11, 4], [4, 11, 7], [4, 12, 5], [1, 10, 2], [5, 10, 4], [2, 10, 5], [6, 11, 3], [7, 11, 6], [7, 12, 4], [8, 12, 7], [5, 12, 8]] 125 true_nodes = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], \ 126 [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] 127 128 129 true_triangles = [[0, 9, 1], [3, 9, 0], [4, 9, 3], [1, 9, 4], [4, 10, 1], [3, 11, 4], \ 130 [4, 11, 7], [4, 12, 5], [1, 10, 2], [5, 10, 4], [2, 10, 5], [6, 11, 3], [7, 11, 6], \ 131 [7, 12, 4], [8, 12, 7], [5, 12, 8]] 119 132 120 133 … … 132 145 """ 133 146 134 nodes = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] 135 136 137 triangles = [[4, 9, 3], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8], [0, 9, 1], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 9, 0], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7]] 138 139 140 edges = {(13, 1): 'bottom', (7, 1): 'left', (3, 1): 'right', (14, 1): 'right', (11, 1): 'bottom', (10, 1): 'top', (5, 1): 'left', (4, 1): 'top'} 147 nodes = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], [1.0, 0.0], \ 148 [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] 149 150 151 triangles = [[4, 9, 3], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8], [0, 9, 1], \ 152 [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 9, 0], [3, 11, 4], \ 153 [6, 11, 3], [7, 11, 6], [4, 11, 7]] 154 155 156 boundary = {(13, 1): 'bottom', (7, 1): 'left', (3, 1): 'right', (14, 1): 'right', \ 157 (11, 1): 'bottom', (10, 1): 'top', (5, 1): 'left', (4, 1): 'top'} 141 158 142 159 triangles_per_proc = [5, 6, 5] … … 222 239 223 240 224 true_submesh = {'full_boundary': [{(3, 1): 'right', (4, 1): 'top'}, {(5, 1): 'left', (10, 1): 'top', (7, 1): 'left'}, {(13, 1): 'bottom', (14, 1): 'right', (11, 1): 'bottom'}], 241 true_submesh = {'full_boundary': [{(3, 1): 'right', (4, 1): 'top'},\ 242 {(5, 1): 'left', (10, 1): 'top', (7, 1): 'left'}, \ 243 {(13, 1): 'bottom', (14, 1): 'right', (11, 1): 'bottom'}], 225 244 'ghost_nodes': [num.array([[ 0. , 0. , 0. ], 226 245 [ 1. , 0. , 0.5 ], … … 275 294 [ 5, 0, 9, 1], 276 295 [ 6, 1, 9, 4]])], 277 'ghost_boundary': [{(13, 1): 'ghost', (8, 0): 'ghost', (14, 1): 'ghost', (11, 1): 'ghost', (10, 1): 'ghost', (5, 1): 'ghost', (10, 2): 'ghost'}, {(12, 2): 'ghost', (12, 0): 'ghost', (2, 1): 'ghost', (11, 1): 'ghost', (2, 2): 'ghost', (4, 1): 'ghost', (4, 0): 'ghost'}, {(3, 2): 'ghost', (6, 1): 'ghost', (3, 1): 'ghost', (5, 1): 'ghost', (1, 0): 'ghost', (1, 1): 'ghost'}], 278 'full_triangles': [[[4, 9, 3], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8]], [[0, 9, 1], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5]], [[3, 9, 0], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7]]], 279 'full_commun': [{0: [1, 2], 1: [1, 2], 2: [1, 2], 3: [2], 4: [1]}, {5: [0, 2], 6: [0, 2], 7: [], 8: [0], 9: [0], 10: [0]}, {11: [0, 1], 12: [0, 1], 13: [0], 14: [0], 15: [0]}], 296 'ghost_boundary': [{(13, 1): 'ghost', (8, 0): 'ghost', (14, 1): 'ghost', \ 297 (11, 1): 'ghost', (10, 1): 'ghost', (5, 1): 'ghost', (10, 2): 'ghost'}, \ 298 {(12, 2): 'ghost', (12, 0): 'ghost', (2, 1): 'ghost', (11, 1): 'ghost',\ 299 (2, 2): 'ghost', (4, 1): 'ghost', (4, 0): 'ghost'}, {(3, 2): 'ghost', \ 300 (6, 1): 'ghost', (3, 1): 'ghost', (5, 1): 'ghost', (1, 0): 'ghost', (1, 1): 'ghost'}], 301 'full_triangles': [[[4, 9, 3], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8]], \ 302 [[0, 9, 1], [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5]], \ 303 [[3, 9, 0], [3, 11, 4], [6, 11, 3], [7, 11, 6], [4, 11, 7]]], 304 'full_commun': [{0: [1, 2], 1: [1, 2], 2: [1, 2], 3: [2], 4: [1]}, \ 305 {5: [0, 2], 6: [0, 2], 7: [], 8: [0], 9: [0], 10: [0]}, \ 306 {11: [0, 1], 12: [0, 1], 13: [0], 14: [0], 15: [0]}], 280 307 'ghost_commun': [num.array([[ 5, 1], 281 308 [ 6, 1], … … 462 489 from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh 463 490 464 mesh = Mesh(nodes, triangles )491 mesh = Mesh(nodes, triangles, boundary) 465 492 boundary_polygon = mesh.get_boundary_polygon() 466 493 … … 468 495 # Subdivide into non-overlapping partitions 469 496 470 submesh = submesh_full(nodes, triangles, edges, \ 471 triangles_per_proc) 497 submesh = submesh_full(mesh, triangles_per_proc) 472 498 473 499 #print submesh … … 509 535 510 536 511 #print submesh 537 538 def test_build_submesh_3_layer_4(self): 539 """ 540 Test 3 Layer 4 way build_submesh with ghost_layer_width = 4 541 """ 542 543 nodes = [[0.0, 0.0], [0.0, 0.5], [0.0, 1.0], [0.5, 0.0], [0.5, 0.5], [0.5, 1.0], \ 544 [1.0, 0.0], [1.0, 0.5], [1.0, 1.0], [0.25, 0.25], [0.25, 0.75], [0.75, 0.25], [0.75, 0.75]] 545 546 547 triangles = [[4, 9, 3], [4, 12, 5], [7, 12, 4], [8, 12, 7], [5, 12, 8], [0, 9, 1], \ 548 [1, 9, 4], [1, 10, 2], [4, 10, 1], [5, 10, 4], [2, 10, 5], [3, 9, 0], [3, 11, 4], \ 549 [6, 11, 3], [7, 11, 6], [4, 11, 7]] 550 551 552 boundary = {(13, 1): 'bottom', (7, 1): 'left', (3, 1): 'right', (14, 1): 'right', \ 553 (11, 1): 'bottom', (10, 1): 'top', (5, 1): 'left', (4, 1): 'top'} 554 555 """ 556 top 557 (10,1) (4,1) 558 2 ---------- 5 ---------- 8 559 | \ 10 / | \ 04 / | 560 | \ / | \ / | 561 (7,1) | 07 10 09 | 01 12 03 | (3,1) 562 | / \ | / \ | 563 | / 08 \ | / 02 \ | 564 left 1 ---------- 4 ---------- 7 right 565 | \ 06 / | \ 15 / | 566 | \ / | \ / | 567 (5,1) | 05 09 00 | 12 11 14 | (14,1) 568 | / \ | / \ | 569 | / 11 \ | / 13 \ | 570 0 ---------- 3 ---------- 6 571 (11,1) (13,1) 572 bottom 573 574 575 Processor 0 Full Triangles 00,01,02,03,04 576 Processor 1 Full Triangles 05,06,07,08,09,10 577 Processor 2 Full Triangles 11,12,13,14,15 578 """ 579 580 581 triangles_per_proc = [5, 6, 5] 582 583 584 585 586 true_submesh = {'full_boundary': [{(3, 1): 'right', (4, 1): 'top'}, {(5, 1): 'left', \ 587 (10, 1): 'top', (7, 1): 'left'}, {(13, 1): 'bottom', (14, 1): 'right', (11, 1): 'bottom'}], 588 'ghost_nodes': [num.array([[ 0. , 0. , 0. ], 589 [ 1. , 0. , 0.5 ], 590 [ 2. , 0. , 1. ], 591 [ 6. , 1. , 0. ], 592 [ 10. , 0.25, 0.75], 593 [ 11. , 0.75, 0.25]]), num.array([[ 3. , 0.5 , 0. ], 594 [ 7. , 1. , 0.5 ], 595 [ 8. , 1. , 1. ], 596 [ 11. , 0.75, 0.25], 597 [ 12. , 0.75, 0.75]]), num.array([[ 1. , 0. , 0.5 ], 598 [ 5. , 0.5 , 1. ], 599 [ 8. , 1. , 1. ], 600 [ 12. , 0.75, 0.75]])], 601 'full_nodes': [num.array([[ 3. , 0.5 , 0. ], 602 [ 4. , 0.5 , 0.5 ], 603 [ 5. , 0.5 , 1. ], 604 [ 7. , 1. , 0.5 ], 605 [ 8. , 1. , 1. ], 606 [ 9. , 0.25, 0.25], 607 [ 12. , 0.75, 0.75]]), num.array([[ 0. , 0. , 0. ], 608 [ 1. , 0. , 0.5 ], 609 [ 2. , 0. , 1. ], 610 [ 4. , 0.5 , 0.5 ], 611 [ 5. , 0.5 , 1. ], 612 [ 9. , 0.25, 0.25], 613 [ 10. , 0.25, 0.75]]), num.array([[ 0. , 0. , 0. ], 614 [ 3. , 0.5 , 0. ], 615 [ 4. , 0.5 , 0.5 ], 616 [ 6. , 1. , 0. ], 617 [ 7. , 1. , 0.5 ], 618 [ 9. , 0.25, 0.25], 619 [ 11. , 0.75, 0.25]])], 620 'ghost_triangles': [num.array([[ 5, 0, 9, 1], 621 [ 6, 1, 9, 4], 622 [ 8, 4, 10, 1], 623 [ 9, 5, 10, 4], 624 [10, 2, 10, 5], 625 [11, 3, 9, 0], 626 [12, 3, 11, 4], 627 [13, 6, 11, 3], 628 [14, 7, 11, 6], 629 [15, 4, 11, 7]]), num.array([[ 0, 4, 9, 3], 630 [ 1, 4, 12, 5], 631 [ 2, 7, 12, 4], 632 [ 4, 5, 12, 8], 633 [11, 3, 9, 0], 634 [12, 3, 11, 4]]), num.array([[ 0, 4, 9, 3], 635 [ 1, 4, 12, 5], 636 [ 2, 7, 12, 4], 637 [ 3, 8, 12, 7], 638 [ 5, 0, 9, 1], 639 [ 6, 1, 9, 4]])], 640 'ghost_boundary': [{(13, 1): 'ghost', (8, 0): 'ghost', \ 641 (14, 1): 'ghost', (11, 1): 'ghost', (10, 1): 'ghost', \ 642 (5, 1): 'ghost', (10, 2): 'ghost'}, {(12, 2): 'ghost', \ 643 (12, 0): 'ghost', (2, 1): 'ghost', (11, 1): 'ghost', \ 644 (2, 2): 'ghost', (4, 1): 'ghost', (4, 0): 'ghost'}, \ 645 {(3, 2): 'ghost', (6, 1): 'ghost', (3, 1): 'ghost', \ 646 (5, 1): 'ghost', (1, 0): 'ghost', (1, 1): 'ghost'}], 647 'full_triangles': [[[4, 9, 3], [4, 12, 5], [7, 12, 4], \ 648 [8, 12, 7], [5, 12, 8]], [[0, 9, 1], [1, 9, 4], [1, 10, 2], \ 649 [4, 10, 1], [5, 10, 4], [2, 10, 5]], [[3, 9, 0], [3, 11, 4], \ 650 [6, 11, 3], [7, 11, 6], [4, 11, 7]]], 651 'full_commun': [{0: [1, 2], 1: [1, 2], 2: [1, 2], 3: [2], 4: [1]}, \ 652 {5: [0, 2], 6: [0, 2], 7: [], 8: [0], 9: [0], 10: [0]}, \ 653 {11: [0, 1], 12: [0, 1], 13: [0], 14: [0], 15: [0]}], 654 'ghost_commun': [num.array([[ 5, 1], 655 [ 6, 1], 656 [ 8, 1], 657 [ 9, 1], 658 [10, 1], 659 [11, 2], 660 [12, 2], 661 [13, 2], 662 [14, 2], 663 [15, 2]]), num.array([[ 0, 0], 664 [ 1, 0], 665 [ 2, 0], 666 [ 4, 0], 667 [11, 2], 668 [12, 2]]), num.array([[0, 0], 669 [1, 0], 670 [2, 0], 671 [3, 0], 672 [5, 1], 673 [6, 1]])], 'ghost_quan': {'stage': [num.array([[-0. , -0.125, -0. ], 674 [-0. , -0.125, -0.25 ], 675 [-0.25 , -0.125, -0. ], 676 [-0.25 , -0.125, -0.25 ], 677 [-0. , -0.125, -0.25 ], 678 [-0.25 , -0.125, -0. ], 679 [-0.25 , -0.375, -0.25 ], 680 [-0.5 , -0.375, -0.25 ], 681 [-0.5 , -0.375, -0.5 ], 682 [-0.25 , -0.375, -0.5 ]]), num.array([[-0.25 , -0.125, -0.25 ], 683 [-0.25 , -0.375, -0.25 ], 684 [-0.5 , -0.375, -0.25 ], 685 [-0.25 , -0.375, -0.5 ], 686 [-0.25 , -0.125, -0. ], 687 [-0.25 , -0.375, -0.25 ]]), num.array([[-0.25 , -0.125, -0.25 ], 688 [-0.25 , -0.375, -0.25 ], 689 [-0.5 , -0.375, -0.25 ], 690 [-0.5 , -0.375, -0.5 ], 691 [-0. , -0.125, -0. ], 692 [-0. , -0.125, -0.25 ]])], 'elevation': [num.array([[-0. , -0.125, -0. ], 693 [-0. , -0.125, -0.25 ], 694 [-0.25 , -0.125, -0. ], 695 [-0.25 , -0.125, -0.25 ], 696 [-0. , -0.125, -0.25 ], 697 [-0.25 , -0.125, -0. ], 698 [-0.25 , -0.375, -0.25 ], 699 [-0.5 , -0.375, -0.25 ], 700 [-0.5 , -0.375, -0.5 ], 701 [-0.25 , -0.375, -0.5 ]]), num.array([[-0.25 , -0.125, -0.25 ], 702 [-0.25 , -0.375, -0.25 ], 703 [-0.5 , -0.375, -0.25 ], 704 [-0.25 , -0.375, -0.5 ], 705 [-0.25 , -0.125, -0. ], 706 [-0.25 , -0.375, -0.25 ]]), num.array([[-0.25 , -0.125, -0.25 ], 707 [-0.25 , -0.375, -0.25 ], 708 [-0.5 , -0.375, -0.25 ], 709 [-0.5 , -0.375, -0.5 ], 710 [-0. , -0.125, -0. ], 711 [-0. , -0.125, -0.25 ]])], 'ymomentum': [num.array([[ 0. , 0.25, 0.5 ], 712 [ 0.5 , 0.25, 0.5 ], 713 [ 0.5 , 0.75, 0.5 ], 714 [ 1. , 0.75, 0.5 ], 715 [ 1. , 0.75, 1. ], 716 [ 0. , 0.25, 0. ], 717 [ 0. , 0.25, 0.5 ], 718 [ 0. , 0.25, 0. ], 719 [ 0.5 , 0.25, 0. ], 720 [ 0.5 , 0.25, 0.5 ]]), num.array([[ 0.5 , 0.25, 0. ], 721 [ 0.5 , 0.75, 1. ], 722 [ 0.5 , 0.75, 0.5 ], 723 [ 1. , 0.75, 1. ], 724 [ 0. , 0.25, 0. ], 725 [ 0. , 0.25, 0.5 ]]), num.array([[ 0.5 , 0.25, 0. ], 726 [ 0.5 , 0.75, 1. ], 727 [ 0.5 , 0.75, 0.5 ], 728 [ 1. , 0.75, 0.5 ], 729 [ 0. , 0.25, 0.5 ], 730 [ 0.5 , 0.25, 0.5 ]])], 'friction': [num.array([[ 0., 0., 0.], 731 [ 0., 0., 0.], 732 [ 0., 0., 0.], 733 [ 0., 0., 0.], 734 [ 0., 0., 0.], 735 [ 0., 0., 0.], 736 [ 0., 0., 0.], 737 [ 0., 0., 0.], 738 [ 0., 0., 0.], 739 [ 0., 0., 0.]]), num.array([[ 0., 0., 0.], 740 [ 0., 0., 0.], 741 [ 0., 0., 0.], 742 [ 0., 0., 0.], 743 [ 0., 0., 0.], 744 [ 0., 0., 0.]]), num.array([[ 0., 0., 0.], 745 [ 0., 0., 0.], 746 [ 0., 0., 0.], 747 [ 0., 0., 0.], 748 [ 0., 0., 0.], 749 [ 0., 0., 0.]])], 'xmomentum': [num.array([[ 2., 2., 2.], 750 [ 2., 2., 2.], 751 [ 2., 2., 2.], 752 [ 2., 2., 2.], 753 [ 2., 2., 2.], 754 [ 2., 2., 2.], 755 [ 2., 2., 2.], 756 [ 2., 2., 2.], 757 [ 2., 2., 2.], 758 [ 2., 2., 2.]]), num.array([[ 2., 2., 2.], 759 [ 2., 2., 2.], 760 [ 2., 2., 2.], 761 [ 2., 2., 2.], 762 [ 2., 2., 2.], 763 [ 2., 2., 2.]]), num.array([[ 2., 2., 2.], 764 [ 2., 2., 2.], 765 [ 2., 2., 2.], 766 [ 2., 2., 2.], 767 [ 2., 2., 2.], 768 [ 2., 2., 2.]])]}, 'full_quan': {'stage': [num.array([[-0.25 , -0.125, -0.25 ], 769 [-0.25 , -0.375, -0.25 ], 770 [-0.5 , -0.375, -0.25 ], 771 [-0.5 , -0.375, -0.5 ], 772 [-0.25 , -0.375, -0.5 ]]), num.array([[-0. , -0.125, -0. ], 773 [-0. , -0.125, -0.25 ], 774 [-0. , -0.125, -0. ], 775 [-0.25 , -0.125, -0. ], 776 [-0.25 , -0.125, -0.25 ], 777 [-0. , -0.125, -0.25 ]]), num.array([[-0.25 , -0.125, -0. ], 778 [-0.25 , -0.375, -0.25 ], 779 [-0.5 , -0.375, -0.25 ], 780 [-0.5 , -0.375, -0.5 ], 781 [-0.25 , -0.375, -0.5 ]])], 'elevation': [num.array([[-0.25 , -0.125, -0.25 ], 782 [-0.25 , -0.375, -0.25 ], 783 [-0.5 , -0.375, -0.25 ], 784 [-0.5 , -0.375, -0.5 ], 785 [-0.25 , -0.375, -0.5 ]]), num.array([[-0. , -0.125, -0. ], 786 [-0. , -0.125, -0.25 ], 787 [-0. , -0.125, -0. ], 788 [-0.25 , -0.125, -0. ], 789 [-0.25 , -0.125, -0.25 ], 790 [-0. , -0.125, -0.25 ]]), num.array([[-0.25 , -0.125, -0. ], 791 [-0.25 , -0.375, -0.25 ], 792 [-0.5 , -0.375, -0.25 ], 793 [-0.5 , -0.375, -0.5 ], 794 [-0.25 , -0.375, -0.5 ]])], 'ymomentum': [num.array([[ 0.5 , 0.25, 0. ], 795 [ 0.5 , 0.75, 1. ], 796 [ 0.5 , 0.75, 0.5 ], 797 [ 1. , 0.75, 0.5 ], 798 [ 1. , 0.75, 1. ]]), num.array([[ 0. , 0.25, 0.5 ], 799 [ 0.5 , 0.25, 0.5 ], 800 [ 0.5 , 0.75, 1. ], 801 [ 0.5 , 0.75, 0.5 ], 802 [ 1. , 0.75, 0.5 ], 803 [ 1. , 0.75, 1. ]]), num.array([[ 0. , 0.25, 0. ], 804 [ 0. , 0.25, 0.5 ], 805 [ 0. , 0.25, 0. ], 806 [ 0.5 , 0.25, 0. ], 807 [ 0.5 , 0.25, 0.5 ]])], 'friction': [num.array([[ 0., 0., 0.], 808 [ 0., 0., 0.], 809 [ 0., 0., 0.], 810 [ 0., 0., 0.], 811 [ 0., 0., 0.]]), num.array([[ 0., 0., 0.], 812 [ 0., 0., 0.], 813 [ 0., 0., 0.], 814 [ 0., 0., 0.], 815 [ 0., 0., 0.], 816 [ 0., 0., 0.]]), num.array([[ 0., 0., 0.], 817 [ 0., 0., 0.], 818 [ 0., 0., 0.], 819 [ 0., 0., 0.], 820 [ 0., 0., 0.]])], 'xmomentum': [num.array([[ 2., 2., 2.], 821 [ 2., 2., 2.], 822 [ 2., 2., 2.], 823 [ 2., 2., 2.], 824 [ 2., 2., 2.]]), num.array([[ 2., 2., 2.], 825 [ 2., 2., 2.], 826 [ 2., 2., 2.], 827 [ 2., 2., 2.], 828 [ 2., 2., 2.], 829 [ 2., 2., 2.]]), num.array([[ 2., 2., 2.], 830 [ 2., 2., 2.], 831 [ 2., 2., 2.], 832 [ 2., 2., 2.], 833 [ 2., 2., 2.]])]}} 834 835 836 # setup parameters to test using different ghost_layer_widths 837 parameters = dict(ghost_layer_width = 1) 838 839 from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh 840 841 mesh = Mesh(nodes, triangles, boundary) 842 boundary_polygon = mesh.get_boundary_polygon() 843 844 845 # Subdivide into non-overlapping partitions 846 847 submesh = submesh_full(mesh, triangles_per_proc) 848 849 850 851 for i in range(3): 852 assert num.allclose(true_submesh['full_triangles'][i],submesh['full_triangles'][i]) 853 assert num.allclose(true_submesh['full_nodes'][i],submesh['full_nodes'][i]) 854 assert true_submesh['full_boundary'] == submesh['full_boundary'] 855 856 # Add any extra ghost boundary layer information 857 858 submesh = submesh_ghost(submesh, mesh, triangles_per_proc, parameters) 859 860 print submesh 861 862 print 'ghost_triangles', submesh['ghost_triangles'] 863 print 'ghost_boundary[0]', submesh['ghost_boundary'][0] 864 print 'ghost_boundary[1]', submesh['ghost_boundary'][1] 865 print 'ghost_boundary[2]', submesh['ghost_boundary'][2] 866 print 'ghost_nodes', submesh['ghost_nodes'] 867 print 'ghost_commun', submesh['ghost_commun'] 868 869 for i in range(3): 870 assert num.allclose(true_submesh['ghost_triangles'][i],submesh['ghost_triangles'][i]) 871 assert num.allclose(true_submesh['ghost_nodes'][i],submesh['ghost_nodes'][i]) 872 assert num.allclose(true_submesh['ghost_commun'][i],submesh['ghost_commun'][i]) 873 874 assert true_submesh['full_commun'] == submesh['full_commun'] 875 876 877 # Order the quantities information to be the same as the triangle 878 # information 879 880 881 submesh = submesh_quantities(submesh, quantities, \ 882 triangles_per_proc) 883 884 885 886 for key, value in true_submesh['ghost_quan'].iteritems(): 887 for i in range(3): 888 assert num.allclose(true_submesh['ghost_quan'][key][i],submesh['ghost_quan'][key][i]) 889 assert num.allclose(true_submesh['full_quan'][key][i],submesh['full_quan'][key][i]) 890 891 892 submesh["boundary_polygon"] = boundary_polygon 893 894 895 896 512 897 513 898 #-------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.