Ignore:
Timestamp:
Dec 8, 2005, 8:29:24 AM (19 years ago)
Author:
linda
Message:

Modified the parallel code to agree with the python style files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/parallel/build_submesh.py

    r2105 r2130  
    1313
    1414import sys
    15 from mesh import *
    16 from Numeric import *
     15
     16from Numeric import zeros, Float, Int, concatenate, \
     17     reshape, arrayrange, take, nonzero
     18
     19from mesh import Mesh
     20
    1721
    1822#########################################################
     
    4145def submesh_full(nodes, triangles, boundary, triangles_per_proc):
    4246
    43     # initialise
     47    # Initialise
    4448
    4549    tlower = 0
     
    5054    boundary_list = []
    5155    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
    5560
    5661    for p in range(nproc):
    5762
    58         # find triangles on processor p
     63        # Find triangles on processor p
    5964
    6065        tupper = triangles_per_proc[p]+tlower
     
    6267        triangle_list.append(subtriangles)
    6368
    64         # find the boundary edges on processor p
     69        # Find the boundary edges on processor p
    6570
    6671        subboundary = {}
     
    7075        boundary_list.append(subboundary)
    7176
    72         # find nodes in processor p
     77        # Find nodes in processor p
    7378
    7479        nodemap = zeros(nnodes, 'i')
     
    8085        node_list.append(take(tsubnodes,nonzero(nodemap)))
    8186
    82         # move to the next processor
     87        # Move to the next processor
    8388
    8489        tlower = tupper
    8590
    86     # put the results in a dictionary
     91    # Put the results in a dictionary
    8792
    8893    submesh["full_nodes"] = node_list
     
    9095    submesh["full_boundary"] = boundary_list
    9196
    92     # clean up before exiting
     97    # Clean up before exiting
    9398
    9499    del (nodemap)
     
    128133    ntriangles = len(mesh.triangles)
    129134
    130     # find the first layer of boundary triangles
     135    # Find the first layer of boundary triangles
    131136
    132137    trianglemap = zeros(ntriangles, 'i')
     
    145150                trianglemap[n] = 1
    146151
    147     # find the second layer of boundary triangles
     152    # Find the second layer of boundary triangles
    148153
    149154    for t in range(len(trianglemap)):
     
    162167                    trianglemap[n] = 1
    163168
    164     # build the triangle list and make note of the vertices
     169    # Build the triangle list and make note of the vertices
    165170
    166171    nodemap = zeros(ncoord, 'i')
     
    179184    subtriangles = take(tsubtriangles, nonzero(trianglemap))
    180185
    181     # keep a record of the triangle vertices, if they are not already there
     186    # Keep a record of the triangle vertices, if they are not already there
    182187
    183188    subnodes = []
     
    189194    subnodes = take(tsubnodes, nonzero(nodemap))
    190195
    191     # clean up before exiting
     196    # Clean up before exiting
    192197
    193198    del (nodelist)
     
    197202    del (trianglemap)
    198203
    199     # return the triangles and vertices sitting on the boundary layer
     204    # Return the triangles and vertices sitting on the boundary layer
    200205
    201206    return subnodes, subtriangles
     
    220225def ghost_commun_pattern(subtri, p, tri_per_proc):
    221226
    222     # loop over the ghost triangles
     227    # Loop over the ghost triangles
    223228
    224229    ghost_commun = zeros((len(subtri), 2), Int)
     
    227232        global_no = subtri[i][0]
    228233
    229         # find which processor contains the full triangle
     234        # Find which processor contains the full triangle
    230235
    231236        nproc = len(tri_per_proc)
     
    238243            sum = sum+tri_per_proc[q]
    239244
    240         # keep a copy of the neighbour processor number
     245        # Keep a copy of the neighbour processor number
    241246
    242247        ghost_commun[i] = [global_no, neigh]
     
    273278    full_commun = []
    274279
    275     # loop over the processor
     280    # Loop over the processor
    276281
    277282    for p in range(nproc):
    278283
    279         # loop over the full triangles in the current processor
     284        # Loop over the full triangles in the current processor
    280285        # and build an empty dictionary
    281286
     
    287292        tlower = tupper
    288293
    289     # loop over the processor again
     294    # Loop over the processor again
    290295
    291296    for p in range(nproc):
    292297
    293         # loop over the ghost triangles in the current processor,
     298        # Loop over the ghost triangles in the current processor,
    294299        # find which processor contains the corresponding full copy
    295300        # and note that the processor must send updates to this
     
    334339    ghost_commun = []
    335340
    336     # loop over processors
     341    # Loop over the processors
    337342
    338343    for p in range(nproc):
    339344
    340         # find the full triangles in this processor
     345        # Find the full triangles in this processor
    341346
    342347        tupper = triangles_per_proc[p]+tlower
    343348
    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)
    347353        ghost_triangles.append(subtri)
    348354        ghost_nodes.append(subnodes)
    349355
    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)
    353360        ghost_commun.append(gcommun)
    354361
    355         # move to the next processor
     362        # Move to the next processor
    356363
    357364        tlower = tupper
    358365
    359     # record the ghost layer and communication pattern
     366    # Record the ghost layer and communication pattern
    360367
    361368    submesh["ghost_nodes"] = ghost_nodes
     
    363370    submesh["ghost_commun"] = ghost_commun
    364371
    365     # build the communication pattern for the full triangles
     372    # Build the communication pattern for the full triangles
    366373
    367374    full_commun = full_commun_pattern(submesh, triangles_per_proc)
    368375    submesh["full_commun"] = full_commun
    369376
    370     # return the submesh
     377    # Return the submesh
    371378
    372379    return submesh
     
    397404    lower = 0
    398405
    399     # build an empty dictionary to hold the quantites
     406    # Build an empty dictionary to hold the quantites
    400407
    401408    submesh["full_quan"] = {}
     
    405412        submesh["ghost_quan"][k] = []
    406413
    407     # loop trough the subdomains
     414    # Loop trough the subdomains
    408415
    409416    for p in range(nproc):
    410417        upper =   lower+triangles_per_proc[p]
    411418
    412         # find the global ID of the ghost triangles
     419        # Find the global ID of the ghost triangles
    413420
    414421        global_id = []
     
    417424            global_id.append(submesh["ghost_triangles"][p][j][0])
    418425
    419         # use the global ID to extract the quantites information from
     426        # Use the global ID to extract the quantites information from
    420427        # the full domain
    421428
     
    424431            submesh["ghost_quan"][k].append(zeros( (M,3) , Float))
    425432            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]]
    427435
    428436        lower = upper
     
    448456                  triangles_per_proc):
    449457
    450     # temporarily build the mesh to find the neighbouring
     458    # Temporarily build the mesh to find the neighbouring
    451459    # triangles
    452460
    453461    mesh = Mesh(nodes, triangles)
    454462
    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
    460469
    461470    submeshg = submesh_ghost(submeshf, mesh, triangles_per_proc)
    462471
    463     # order the quantities information to be the same as the triangle
     472    # Order the quantities information to be the same as the triangle
    464473    # information
    465474
    466     submesh = submesh_quantities(submeshg, quantities, triangles_per_proc)
     475    submesh = submesh_quantities(submeshg, quantities, \
     476                                 triangles_per_proc)
    467477
    468478    return submesh
Note: See TracChangeset for help on using the changeset viewer.