Changeset 2130 for inundation/parallel/build_submesh.py
- Timestamp:
- Dec 8, 2005, 8:29:24 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/parallel/build_submesh.py
r2105 r2130 13 13 14 14 import sys 15 from mesh import * 16 from Numeric import * 15 16 from Numeric import zeros, Float, Int, concatenate, \ 17 reshape, arrayrange, take, nonzero 18 19 from mesh import Mesh 20 17 21 18 22 ######################################################### … … 41 45 def submesh_full(nodes, triangles, boundary, triangles_per_proc): 42 46 43 # initialise47 # Initialise 44 48 45 49 tlower = 0 … … 50 54 boundary_list = [] 51 55 submesh = {} 52 tsubnodes = concatenate((reshape(arrayrange(nnodes),(nnodes,1)), nodes), 1) 53 54 # loop over processors 56 node_range = reshape(arrayrange(nnodes),(nnodes,1)) 57 tsubnodes = concatenate((node_range, nodes), 1) 58 59 # Loop over processors 55 60 56 61 for p in range(nproc): 57 62 58 # find triangles on processor p63 # Find triangles on processor p 59 64 60 65 tupper = triangles_per_proc[p]+tlower … … 62 67 triangle_list.append(subtriangles) 63 68 64 # find the boundary edges on processor p69 # Find the boundary edges on processor p 65 70 66 71 subboundary = {} … … 70 75 boundary_list.append(subboundary) 71 76 72 # find nodes in processor p77 # Find nodes in processor p 73 78 74 79 nodemap = zeros(nnodes, 'i') … … 80 85 node_list.append(take(tsubnodes,nonzero(nodemap))) 81 86 82 # move to the next processor87 # Move to the next processor 83 88 84 89 tlower = tupper 85 90 86 # put the results in a dictionary91 # Put the results in a dictionary 87 92 88 93 submesh["full_nodes"] = node_list … … 90 95 submesh["full_boundary"] = boundary_list 91 96 92 # clean up before exiting97 # Clean up before exiting 93 98 94 99 del (nodemap) … … 128 133 ntriangles = len(mesh.triangles) 129 134 130 # find the first layer of boundary triangles135 # Find the first layer of boundary triangles 131 136 132 137 trianglemap = zeros(ntriangles, 'i') … … 145 150 trianglemap[n] = 1 146 151 147 # find the second layer of boundary triangles152 # Find the second layer of boundary triangles 148 153 149 154 for t in range(len(trianglemap)): … … 162 167 trianglemap[n] = 1 163 168 164 # build the triangle list and make note of the vertices169 # Build the triangle list and make note of the vertices 165 170 166 171 nodemap = zeros(ncoord, 'i') … … 179 184 subtriangles = take(tsubtriangles, nonzero(trianglemap)) 180 185 181 # keep a record of the triangle vertices, if they are not already there186 # Keep a record of the triangle vertices, if they are not already there 182 187 183 188 subnodes = [] … … 189 194 subnodes = take(tsubnodes, nonzero(nodemap)) 190 195 191 # clean up before exiting196 # Clean up before exiting 192 197 193 198 del (nodelist) … … 197 202 del (trianglemap) 198 203 199 # return the triangles and vertices sitting on the boundary layer204 # Return the triangles and vertices sitting on the boundary layer 200 205 201 206 return subnodes, subtriangles … … 220 225 def ghost_commun_pattern(subtri, p, tri_per_proc): 221 226 222 # loop over the ghost triangles227 # Loop over the ghost triangles 223 228 224 229 ghost_commun = zeros((len(subtri), 2), Int) … … 227 232 global_no = subtri[i][0] 228 233 229 # find which processor contains the full triangle234 # Find which processor contains the full triangle 230 235 231 236 nproc = len(tri_per_proc) … … 238 243 sum = sum+tri_per_proc[q] 239 244 240 # keep a copy of the neighbour processor number245 # Keep a copy of the neighbour processor number 241 246 242 247 ghost_commun[i] = [global_no, neigh] … … 273 278 full_commun = [] 274 279 275 # loop over the processor280 # Loop over the processor 276 281 277 282 for p in range(nproc): 278 283 279 # loop over the full triangles in the current processor284 # Loop over the full triangles in the current processor 280 285 # and build an empty dictionary 281 286 … … 287 292 tlower = tupper 288 293 289 # loop over the processor again294 # Loop over the processor again 290 295 291 296 for p in range(nproc): 292 297 293 # loop over the ghost triangles in the current processor,298 # Loop over the ghost triangles in the current processor, 294 299 # find which processor contains the corresponding full copy 295 300 # and note that the processor must send updates to this … … 334 339 ghost_commun = [] 335 340 336 # loop overprocessors341 # Loop over the processors 337 342 338 343 for p in range(nproc): 339 344 340 # find the full triangles in this processor345 # Find the full triangles in this processor 341 346 342 347 tupper = triangles_per_proc[p]+tlower 343 348 344 # build the ghost boundary layer 345 346 [subnodes, subtri] = ghost_layer(submesh, mesh, p, tupper, tlower) 349 # Build the ghost boundary layer 350 351 [subnodes, subtri] = \ 352 ghost_layer(submesh, mesh, p, tupper, tlower) 347 353 ghost_triangles.append(subtri) 348 354 ghost_nodes.append(subnodes) 349 355 350 # build the communication pattern for the ghost nodes 351 352 gcommun = ghost_commun_pattern(subtri, p, triangles_per_proc) 356 # Build the communication pattern for the ghost nodes 357 358 gcommun = \ 359 ghost_commun_pattern(subtri, p, triangles_per_proc) 353 360 ghost_commun.append(gcommun) 354 361 355 # move to the next processor362 # Move to the next processor 356 363 357 364 tlower = tupper 358 365 359 # record the ghost layer and communication pattern366 # Record the ghost layer and communication pattern 360 367 361 368 submesh["ghost_nodes"] = ghost_nodes … … 363 370 submesh["ghost_commun"] = ghost_commun 364 371 365 # build the communication pattern for the full triangles372 # Build the communication pattern for the full triangles 366 373 367 374 full_commun = full_commun_pattern(submesh, triangles_per_proc) 368 375 submesh["full_commun"] = full_commun 369 376 370 # return the submesh377 # Return the submesh 371 378 372 379 return submesh … … 397 404 lower = 0 398 405 399 # build an empty dictionary to hold the quantites406 # Build an empty dictionary to hold the quantites 400 407 401 408 submesh["full_quan"] = {} … … 405 412 submesh["ghost_quan"][k] = [] 406 413 407 # loop trough the subdomains414 # Loop trough the subdomains 408 415 409 416 for p in range(nproc): 410 417 upper = lower+triangles_per_proc[p] 411 418 412 # find the global ID of the ghost triangles419 # Find the global ID of the ghost triangles 413 420 414 421 global_id = [] … … 417 424 global_id.append(submesh["ghost_triangles"][p][j][0]) 418 425 419 # use the global ID to extract the quantites information from426 # Use the global ID to extract the quantites information from 420 427 # the full domain 421 428 … … 424 431 submesh["ghost_quan"][k].append(zeros( (M,3) , Float)) 425 432 for j in range(M): 426 submesh["ghost_quan"][k][p][j] = quantities[k][global_id[j]] 433 submesh["ghost_quan"][k][p][j] = \ 434 quantities[k][global_id[j]] 427 435 428 436 lower = upper … … 448 456 triangles_per_proc): 449 457 450 # temporarily build the mesh to find the neighbouring458 # Temporarily build the mesh to find the neighbouring 451 459 # triangles 452 460 453 461 mesh = Mesh(nodes, triangles) 454 462 455 # subdivide into non-overlapping partitions 456 457 submeshf = submesh_full(nodes, triangles, edges, triangles_per_proc) 458 459 # add any extra ghost boundary layer information 463 # Subdivide into non-overlapping partitions 464 465 submeshf = submesh_full(nodes, triangles, edges, \ 466 triangles_per_proc) 467 468 # Add any extra ghost boundary layer information 460 469 461 470 submeshg = submesh_ghost(submeshf, mesh, triangles_per_proc) 462 471 463 # order the quantities information to be the same as the triangle472 # Order the quantities information to be the same as the triangle 464 473 # information 465 474 466 submesh = submesh_quantities(submeshg, quantities, triangles_per_proc) 475 submesh = submesh_quantities(submeshg, quantities, \ 476 triangles_per_proc) 467 477 468 478 return submesh
Note: See TracChangeset
for help on using the changeset viewer.