Changeset 8553


Ignore:
Timestamp:
Sep 4, 2012, 4:26:13 PM (13 years ago)
Author:
steve
Message:

Committing faster ghost_layer code

Location:
trunk/anuga_core/source/anuga_parallel
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/source/anuga_parallel/distribute_mesh.py

    r8550 r8553  
    2424
    2525import numpy as num
     26import numpy.lib.arraysetops as numset
    2627
    2728from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh
     
    498499#########################################################
    499500
    500 def ghost_layer(submesh, mesh, p, tupper, tlower, parameters = None):
     501def ghost_layer_old(submesh, mesh, p, tupper, tlower, parameters = None):
    501502
    502503    ncoord = mesh.number_of_nodes
     
    590591
    591592    return subnodes, subtriangles, layer_width
     593
     594
     595
     596def ghost_layer(submesh, mesh, p, tupper, tlower, parameters = None):
     597
     598    ncoord = mesh.number_of_nodes
     599    ntriangles = mesh.number_of_triangles
     600
     601    if parameters is None:
     602        layer_width  = 2
     603    else:
     604        layer_width = parameters['ghost_layer_width']
     605
     606
     607    full_ids = num.arange(tlower, tupper)
     608
     609    n0 = mesh.neighbours[full_ids, :]
     610    n0 = num.unique(n0.flat)
     611    n0 = num.extract(n0>=0,n0)
     612    n0 = num.extract(num.logical_or(n0<tlower, tupper<= n0), n0)
     613
     614    layer_cells = {}
     615    layer_cells[0] = n0
     616
     617
     618    # Find the subsequent layers of ghost triangles
     619    for i in range(layer_width-1):
     620
     621        # use previous layer as a start
     622        n0 = mesh.neighbours[n0, :]
     623        n0 = num.unique(n0.flat)
     624        n0 = num.extract(n0>=0,n0)
     625        n0 = num.extract(num.logical_or(n0<tlower, tupper<= n0), n0)
     626
     627        for j in xrange(i+1):
     628            n0 = numset.setdiff1d(n0,layer_cells[j])
     629
     630        layer_cells[i+1] = n0
     631
     632
     633    # Build the triangle list and make note of the vertices
     634    new_trianglemap = layer_cells[0]
     635    for i in range(layer_width-1):
     636        new_trianglemap = numset.union1d(new_trianglemap,layer_cells[i+1])
     637
     638    new_subtriangles = num.concatenate((num.reshape(new_trianglemap, (-1,1)), mesh.triangles[new_trianglemap]), 1)
     639
     640
     641
     642
     643    fullnodes = submesh["full_nodes"][p]
     644    full_nodes_ids = num.array(fullnodes[:,0],num.int)
     645
     646    new_nodes = num.unique(mesh.triangles[new_trianglemap].flat)
     647    new_nodes = numset.setdiff1d(new_nodes,full_nodes_ids)
     648
     649    new_subnodes = num.concatenate((num.reshape(new_nodes, (-1,1)), mesh.nodes[new_nodes]), 1)
     650
     651    # Clean up before exiting
     652
     653    del (new_nodes)
     654    del (layer_cells)
     655    del (n0)
     656    del (new_trianglemap)
     657
     658    # Return the triangles and vertices sitting on the boundary layer
     659
     660    return new_subnodes, new_subtriangles, layer_width
    592661
    593662#########################################################
     
    925994#########################################################
    926995
    927 def build_submesh(mesh, quantities,
     996def build_submesh(nodes, triangles, boundary, quantities,
    928997                  triangles_per_proc, parameters = None):
    929998
    930999    # Temporarily build the mesh to find the neighbouring
    931     # triangles and true boundary polygon
    932 
    933     #mesh = Mesh(nodes, triangles, boundary)
     1000    # triangles and true boundary polygon\
     1001
     1002    mesh = Mesh(nodes, triangles, boundary)
    9341003    boundary_polygon = mesh.get_boundary_polygon()
    9351004   
  • trunk/anuga_core/source/anuga_parallel/parallel_api.py

    r8550 r8553  
    266266    #      sp2_map (maps parallel domain triangles to domain triangles)
    267267
    268     mesh = Mesh(new_nodes, new_triangles, new_boundary)
     268
    269269
    270270    # Build the mesh that should be assigned to each processor,
    271271    # this includes ghost nodes and the communication pattern
    272272    if verbose: print 'Build submeshes'   
    273     submesh = build_submesh(mesh, quantities, triangles_per_proc, parameters)
     273    submesh = build_submesh(new_nodes, new_triangles, new_boundary, quantities, triangles_per_proc, parameters)
    274274
    275275    if verbose:
  • trunk/anuga_core/source/anuga_parallel/run_parallel_sw_rectangular_cross.py

    r8550 r8553  
    4242    width = 2.0
    4343    dx = dy = 0.005
    44     dx = dy = 0.0025
     44    dx = dy = 0.005
     45    #dx = dy  = 0.5
    4546    domain = rectangular_cross_domain(int(length/dx), int(width/dy),
    4647                                              len1=length, len2=width)
     
    6465
    6566# setup parameters to test using different ghost_layer_widths
    66 parameters = dict(ghost_layer_width = 2)
     67parameters = dict(ghost_layer_width = 4)
    6768domain = distribute(domain,verbose=verbose, parameters=parameters)
    6869
Note: See TracChangeset for help on using the changeset viewer.