# Changeset 2130 for inundation/parallel/build_submesh.py

Ignore:
Timestamp:
Dec 8, 2005, 8:29:24 AM (18 years ago)
Message:

Modified the parallel code to agree with the python style files

File:
1 edited

Unmodified
Removed
• ## inundation/parallel/build_submesh.py

 r2105 import sys from mesh import * from Numeric import * from Numeric import zeros, Float, Int, concatenate, \ reshape, arrayrange, take, nonzero from mesh import Mesh ######################################################### def submesh_full(nodes, triangles, boundary, triangles_per_proc): # initialise # Initialise tlower = 0 boundary_list = [] submesh = {} tsubnodes = concatenate((reshape(arrayrange(nnodes),(nnodes,1)), nodes), 1) # loop over processors node_range = reshape(arrayrange(nnodes),(nnodes,1)) tsubnodes = concatenate((node_range, nodes), 1) # Loop over processors for p in range(nproc): # find triangles on processor p # Find triangles on processor p tupper = triangles_per_proc[p]+tlower triangle_list.append(subtriangles) # find the boundary edges on processor p # Find the boundary edges on processor p subboundary = {} boundary_list.append(subboundary) # find nodes in processor p # Find nodes in processor p nodemap = zeros(nnodes, 'i') node_list.append(take(tsubnodes,nonzero(nodemap))) # move to the next processor # Move to the next processor tlower = tupper # put the results in a dictionary # Put the results in a dictionary submesh["full_nodes"] = node_list submesh["full_boundary"] = boundary_list # clean up before exiting # Clean up before exiting del (nodemap) ntriangles = len(mesh.triangles) # find the first layer of boundary triangles # Find the first layer of boundary triangles trianglemap = zeros(ntriangles, 'i') trianglemap[n] = 1 # find the second layer of boundary triangles # Find the second layer of boundary triangles for t in range(len(trianglemap)): trianglemap[n] = 1 # build the triangle list and make note of the vertices # Build the triangle list and make note of the vertices nodemap = zeros(ncoord, 'i') subtriangles = take(tsubtriangles, nonzero(trianglemap)) # keep a record of the triangle vertices, if they are not already there # Keep a record of the triangle vertices, if they are not already there subnodes = [] subnodes = take(tsubnodes, nonzero(nodemap)) # clean up before exiting # Clean up before exiting del (nodelist) del (trianglemap) # return the triangles and vertices sitting on the boundary layer # Return the triangles and vertices sitting on the boundary layer return subnodes, subtriangles def ghost_commun_pattern(subtri, p, tri_per_proc): # loop over the ghost triangles # Loop over the ghost triangles ghost_commun = zeros((len(subtri), 2), Int) global_no = subtri[i][0] # find which processor contains the full triangle # Find which processor contains the full triangle nproc = len(tri_per_proc) sum = sum+tri_per_proc[q] # keep a copy of the neighbour processor number # Keep a copy of the neighbour processor number ghost_commun[i] = [global_no, neigh] full_commun = [] # loop over the processor # Loop over the processor for p in range(nproc): # loop over the full triangles in the current processor # Loop over the full triangles in the current processor # and build an empty dictionary tlower = tupper # loop over the processor again # Loop over the processor again for p in range(nproc): # loop over the ghost triangles in the current processor, # Loop over the ghost triangles in the current processor, # find which processor contains the corresponding full copy # and note that the processor must send updates to this ghost_commun = [] # loop over processors # Loop over the processors for p in range(nproc): # find the full triangles in this processor # Find the full triangles in this processor tupper = triangles_per_proc[p]+tlower # build the ghost boundary layer [subnodes, subtri] = ghost_layer(submesh, mesh, p, tupper, tlower) # Build the ghost boundary layer [subnodes, subtri] = \ ghost_layer(submesh, mesh, p, tupper, tlower) ghost_triangles.append(subtri) ghost_nodes.append(subnodes) # build the communication pattern for the ghost nodes gcommun = ghost_commun_pattern(subtri, p, triangles_per_proc) # Build the communication pattern for the ghost nodes gcommun = \ ghost_commun_pattern(subtri, p, triangles_per_proc) ghost_commun.append(gcommun) # move to the next processor # Move to the next processor tlower = tupper # record the ghost layer and communication pattern # Record the ghost layer and communication pattern submesh["ghost_nodes"] = ghost_nodes submesh["ghost_commun"] = ghost_commun # build the communication pattern for the full triangles # Build the communication pattern for the full triangles full_commun = full_commun_pattern(submesh, triangles_per_proc) submesh["full_commun"] = full_commun # return the submesh # Return the submesh return submesh lower = 0 # build an empty dictionary to hold the quantites # Build an empty dictionary to hold the quantites submesh["full_quan"] = {} submesh["ghost_quan"][k] = [] # loop trough the subdomains # Loop trough the subdomains for p in range(nproc): upper =   lower+triangles_per_proc[p] # find the global ID of the ghost triangles # Find the global ID of the ghost triangles global_id = [] global_id.append(submesh["ghost_triangles"][p][j][0]) # use the global ID to extract the quantites information from # Use the global ID to extract the quantites information from # the full domain submesh["ghost_quan"][k].append(zeros( (M,3) , Float)) for j in range(M): submesh["ghost_quan"][k][p][j] = quantities[k][global_id[j]] submesh["ghost_quan"][k][p][j] = \ quantities[k][global_id[j]] lower = upper triangles_per_proc): # temporarily build the mesh to find the neighbouring # Temporarily build the mesh to find the neighbouring # triangles mesh = Mesh(nodes, triangles) # subdivide into non-overlapping partitions submeshf = submesh_full(nodes, triangles, edges, triangles_per_proc) # add any extra ghost boundary layer information # Subdivide into non-overlapping partitions submeshf = submesh_full(nodes, triangles, edges, \ triangles_per_proc) # Add any extra ghost boundary layer information submeshg = submesh_ghost(submeshf, mesh, triangles_per_proc) # order the quantities information to be the same as the triangle # Order the quantities information to be the same as the triangle # information submesh = submesh_quantities(submeshg, quantities, triangles_per_proc) submesh = submesh_quantities(submeshg, quantities, \ triangles_per_proc) return submesh
Note: See TracChangeset for help on using the changeset viewer.