Ignore:
Timestamp:
Aug 28, 2012, 4:06:09 PM (13 years ago)
Author:
steve
Message:

added variable ghost_layer_width which is set by the partitioning routine
(distribute) or set to 2

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  
    266266#########################################################
    267267
    268 def submesh_full(nodes, triangles, boundary, triangles_per_proc):
     268def submesh_full(mesh, triangles_per_proc):
    269269
    270270    # Initialise
     271
     272
     273    nodes = mesh.nodes
     274    triangles = mesh.triangles
     275    boundary = mesh.boundary
    271276
    272277    tlower = 0
     
    353358#########################################################
    354359
    355 def ghost_layer(submesh, mesh, p, tupper, tlower):
     360def ghost_layer(submesh, mesh, p, tupper, tlower, parameters = None):
    356361
    357362    ncoord = mesh.number_of_nodes
    358363    ntriangles = mesh.number_of_triangles
    359364
    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
    364370
    365371    trianglemap = num.zeros(ntriangles, 'i')
     
    443449    # Return the triangles and vertices sitting on the boundary layer
    444450
    445     return subnodes, subtriangles
     451    return subnodes, subtriangles, layer_width
    446452
    447453#########################################################
     
    479485def ghost_bnd_layer(ghosttri, tlower, tupper, mesh, p):
    480486
     487
     488    boundary = mesh.boundary
     489
    481490    ghost_list = []
    482491    subboundary = {}
    483492
    484493
     494    # FIXME SR: For larger layers need to pass through the correct
     495    # boundary tag!
     496
    485497    for t in ghosttri:
    486498        ghost_list.append(t[0])
     
    490502        n = mesh.neighbours[t[0], 0]
    491503        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
    493509
    494510        n = mesh.neighbours[t[0], 1]
    495511        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
    497517
    498518        n = mesh.neighbours[t[0], 2]
    499519        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'
    501524           
    502525    return subboundary
     
    629652#########################################################
    630653
    631 def submesh_ghost(submesh, mesh, triangles_per_proc):
     654def submesh_ghost(submesh, mesh, triangles_per_proc, parameters = None):
    632655
    633656    nproc = len(triangles_per_proc)
     
    637660    ghost_commun = []
    638661    ghost_bnd = []
     662    ghost_layer_width = []
    639663
    640664    # Loop over the processors
     
    648672        # Build the ghost boundary layer
    649673
    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)
    652677        ghost_triangles.append(subtri)
    653678        ghost_nodes.append(subnodes)
     
    671696
    672697    # Record the ghost layer and communication pattern
    673 
     698    submesh["ghost_layer_width"] = ghost_layer_width
    674699    submesh["ghost_nodes"] = ghost_nodes
    675700    submesh["ghost_triangles"] = ghost_triangles
     
    760785#########################################################
    761786
    762 def build_submesh(nodes, triangles, edges, quantities,
    763                   triangles_per_proc):
     787def build_submesh(nodes, triangles, boundary, quantities,
     788                  triangles_per_proc, parameters = None):
    764789
    765790    # Temporarily build the mesh to find the neighbouring
    766791    # triangles and true boundary polygon
    767792
    768     mesh = Mesh(nodes, triangles)
     793    mesh = Mesh(nodes, triangles, boundary)
    769794    boundary_polygon = mesh.get_boundary_polygon()
    770795   
     
    772797    # Subdivide into non-overlapping partitions
    773798
    774     submeshf = submesh_full(nodes, triangles, edges, \
    775                             triangles_per_proc)
     799    submeshf = submesh_full(mesh, triangles_per_proc)
    776800   
    777801    # Add any extra ghost boundary layer information
    778802
    779     submeshg = submesh_ghost(submeshf, mesh, triangles_per_proc)
     803    submeshg = submesh_ghost(submeshf, mesh, triangles_per_proc, parameters)
    780804
    781805    # Order the quantities information to be the same as the triangle
     
    957981    nodes = num.concatenate((submesh["full_nodes"], \
    958982                         submesh["ghost_nodes"]))
     983
     984    ghost_layer_width = submesh["ghost_layer_width"]
    959985   
    960986    # Combine the full triangles and ghost triangles
     
    10091035
    10101036    return GAnodes, GAtriangles, GAboundary, quantities, ghost_rec, \
    1011            full_send, tri_map, node_map
     1037           full_send, tri_map, node_map, ghost_layer_width
    10121038
    10131039
     
    10511077    myid = pypar.rank()
    10521078   
    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)
    10541080   
    10551081    # build and send the tagmap for the boundary conditions
     
    10781104    pypar.send(triangles_per_proc, p)
    10791105
     1106    # ghost layer width
     1107
     1108    pypar.send(submesh["ghost_layer_width"][p], p)
     1109
    10801110    # compress full_commun
    10811111
     
    11851215    triangles_per_proc = pypar.receive(p)
    11861216
     1217    # ghost layer width
     1218
     1219    submesh_cell["ghost_layer_width"] = pypar.receive(p)
     1220
    11871221    # recieve information about the array sizes
    11881222
     
    13031337
    13041338    [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] = \
    13061340              build_local_mesh(submesh_cell, lower_t, upper_t, \
    13071341                               numproc)
     
    13091343    return GAnodes, GAtriangles, boundary, quantities,\
    13101344           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
    13121347         
    13131348
     
    13321367   
    13331368    submesh_cell = {}
     1369    submesh_cell["ghost_layer_width"] = submesh["ghost_layer_width"][0]
    13341370    submesh_cell["full_nodes"] = submesh["full_nodes"][0]
    13351371    submesh_cell["ghost_nodes"] = submesh["ghost_nodes"][0]
     
    13481384    numprocs = len(triangles_per_proc)
    13491385    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 = \
    13511387            build_local_mesh(submesh_cell, 0, triangles_per_proc[0], numprocs)
    13521388
    13531389
    13541390    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
    13561392           
    13571393
  • trunk/anuga_core/source/anuga_parallel/parallel_api.py

    r8518 r8538  
    3636
    3737
    38 def distribute(domain, verbose=False, debug=False):
     38def distribute(domain, verbose=False, debug=False, parameters = None):
    3939    """ Distribute the domain to all processes
    4040    """
     
    112112                ghost_recv_dict, full_send_dict,\
    113113                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)
    120116           
    121117        # Extract l2g maps
     
    146142                ghost_recv_dict, full_send_dict,\
    147143                number_of_full_nodes, number_of_full_triangles, \
    148                 tri_map, node_map =\
     144                tri_map, node_map, ghost_layer_width =\
    149145                rec_submesh(0, verbose)
    150146
     
    178174                             p2s_map = p2s_map, ## jj added this
    179175                             tri_l2g = tri_l2g, ## SR added this
    180                              node_l2g = node_l2g)
     176                             node_l2g = node_l2g,
     177                             ghost_layer_width = ghost_layer_width)
    181178
    182179    #------------------------------------------------------------------------
     
    213210
    214211
    215 def distribute_mesh(domain, verbose=False, debug=False):
     212def distribute_mesh(domain, verbose=False, debug=False, parameters=None):
    216213
    217214
     
    236233    if verbose: print 'Build submeshes'   
    237234    submesh = build_submesh(nodes, triangles, boundary,\
    238                             quantities, triangles_per_proc)
     235                            quantities, triangles_per_proc, parameters)
    239236
    240237    if verbose:
     
    257254    # Build the local mesh for processor 0
    258255    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 =\
    260257              extract_hostmesh(submesh, triangles_per_proc)
    261258
     
    294291           ghost_recv_dict, full_send_dict,\
    295292           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
    297294   
    298295
  • trunk/anuga_core/source/anuga_parallel/parallel_shallow_water.py

    r8513 r8538  
    4141                 p2s_map=None, #jj added this
    4242                 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):
    4445
    4546        Domain.__init__(self,
     
    5354                        number_of_full_nodes=number_of_full_nodes,
    5455                        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)
    5658       
    57 
    5859
    5960        self.parallel = True
     
    8990        self.node_l2g = node_l2g
    9091
     92        self.ghost_counter = 0
     93
    9194
    9295    def set_name(self, name):
     
    122125        receive the information for the ghost cells
    123126        """
    124 
     127           
    125128        generic_comms.communicate_ghosts_asynchronous(self)
    126129        #generic_comms.communicate_ghosts_blocking(self)
  • trunk/anuga_core/source/anuga_parallel/run_parallel_sw_rectangular_cross.py

    r8531 r8538  
    5252
    5353
    54 if myid == 0 and verbose: print 'DISTRIBUTING DOMAIN'
    55 domain = distribute(domain,verbose=verbose)
     54if myid == 0 and verbose:
     55    print 'DISTRIBUTING DOMAIN'
     56    sys.stdout.flush()
     57   
     58barrier()
    5659
    57 print 'after parallel domain'
     60# setup parameters to test using different ghost_layer_widths
     61parameters = dict(ghost_layer_width = 4)
     62domain = distribute(domain,verbose=verbose, parameters=parameters)
     63
     64if myid == 0 : print 'after parallel domain'
    5865
    5966
     
    6976
    7077
    71 print 'after set_boundary'
     78if myid == 0 : print 'after set_boundary'
    7279
    7380
    7481
    7582domain.check_integrity()
    76 print 'after check_integrity'
     83
     84if myid == 0 : print 'after check_integrity'
    7785
    7886class Set_Stage:
     
    96104
    97105
    98 print 'after set quantity'
     106if myid == 0 : print 'after set quantity'
    99107
    100108# Set Evolve parameters
     
    142150
    143151
    144 
     152domain.dump_triangulation(filename="rectangular_cross_%g.png"% numprocs)
    145153
    146154finalize()
  • trunk/anuga_core/source/anuga_parallel/test_distribute_mesh.py

    r8011 r8538  
    4747
    4848
    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]]
    5256
    5357
     
    7074
    7175
    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]]
    7582
    7683
     
    9097
    9198
    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]]
    95105
    96106
     
    113123
    114124
    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]]
    119132
    120133
     
    132145        """
    133146
    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'}
    141158
    142159        triangles_per_proc = [5, 6, 5]
     
    222239
    223240       
    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'}],
    225244                        'ghost_nodes': [num.array([[  0.  ,   0.  ,   0.  ],
    226245       [  1.  ,   0.  ,   0.5 ],
     
    275294       [ 5,  0,  9,  1],
    276295       [ 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]}],
    280307                        'ghost_commun': [num.array([[ 5,  1],
    281308       [ 6,  1],
     
    462489        from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh
    463490       
    464         mesh = Mesh(nodes, triangles)
     491        mesh = Mesh(nodes, triangles, boundary)
    465492        boundary_polygon = mesh.get_boundary_polygon()
    466493
     
    468495        # Subdivide into non-overlapping partitions
    469496
    470         submesh = submesh_full(nodes, triangles, edges, \
    471                             triangles_per_proc)
     497        submesh = submesh_full(mesh, triangles_per_proc)
    472498
    473499        #print submesh
     
    509535
    510536
    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
    512897
    513898#-------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.