Ignore:
Timestamp:
Nov 24, 2005, 10:21:05 AM (19 years ago)
Author:
jack
Message:

Added pmesh_divide_metis to pmesh_divide.py. Note that the arguments have changed, but the return stays the same.

Run_parallel_sw_merimbula_metis.py is the same as run_parallel_sw_merimbula, except it uses pymetis to partition the grid.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/parallel/pmesh_divide.py

    r1585 r2055  
    2020
    2121from math import floor
    22 from Numeric import zeros, Float, Int
     22from Numeric import zeros, Float, Int, reshape
    2323
    2424#########################################################
     
    151151        for i in range(N):
    152152            q_reord[k][index[i]]=quantities[k].vertex_values[i]
    153 
    154153    del index
    155154
     
    268267    tri_index = {}
    269268    N = domain.number_of_elements
    270 
     269 
    271270    #sort by x coordinate of centroid
    272271    from Numeric import argsort
     
    286285
    287286    #print tri_list
    288 
    289287    #print tri_index
    290288
     
    321319
    322320    return nodes, triangles, boundary, triangles_per_proc, quantities
     321
     322
     323from os import sep
     324from sys import path
     325
     326path.append('..' + sep + 'pymetis')
     327
     328from metis import partMeshNodal
     329
     330def pmesh_divide_metis(domain, n_procs):
     331    # initialise the lists
     332    triangles_per_proc = []
     333    tri_list = []
     334    proc_sum = []
     335    for i in range(n_procs):
     336        tri_list.append([])
     337        triangles_per_proc.append(0)
     338        proc_sum.append([])
     339
     340    # Prepare variables for the metis call
     341    n_tri = len(domain.triangles)
     342    n_vert = len(domain.coordinates)
     343    t_list = domain.triangles.copy()
     344    t_list = reshape(t_list, (-1,))
     345
     346    # The 1 here is for triangular mesh elements.
     347    edgecut, epart, npart = partMeshNodal(n_tri, n_vert, t_list, 1, n_procs)
     348
     349    # print edgecut
     350    # print epart
     351    # print npart
     352
     353    del edgecut
     354    del npart
     355
     356    # Assign triangles to processes, according to what metis told us.
     357   
     358    tri_index = {}
     359    triangles = []       
     360    for i in range(n_tri):
     361        triangles_per_proc[epart[i]] = triangles_per_proc[epart[i]] + 1
     362        tri_list[epart[i]].append(domain.triangles[i])
     363        tri_index[i] = ([epart[i], len(tri_list[epart[i]]) - 1])
     364
     365    # print tri_list
     366    # print triangles_per_proc
     367
     368    # order the triangle list so that all of the triangles belonging
     369    # to processor i are listed before those belonging to processor
     370    # i+1
     371
     372    for i in range(n_procs):
     373        for t in tri_list[i]:
     374            triangles.append(t)
     375           
     376    # the boundary labels have to changed in accoradance with the
     377    # new triangle ordering, proc_sum and tri_index help with this
     378
     379    proc_sum[0] = 0
     380    for i in range(n_procs - 1):
     381        proc_sum[i+1]=proc_sum[i]+triangles_per_proc[i]
     382
     383    # relabel the boundary elements to fit in with the new triangle
     384    # ordering
     385
     386    boundary = {}
     387    for b in domain.boundary:
     388        t =  tri_index[b[0]]
     389        boundary[proc_sum[t[0]]+t[1], b[1]] = domain.boundary[b]
     390
     391    quantities = reorder(domain.quantities, tri_index, proc_sum)
     392
     393    # extract the node list
     394    nodes = domain.coordinates.copy()
     395
     396    return nodes, triangles, boundary, triangles_per_proc, quantities
Note: See TracChangeset for help on using the changeset viewer.