Changeset 8260


Ignore:
Timestamp:
Nov 30, 2011, 7:57:30 PM (13 years ago)
Author:
janes
Message:

Adding anuga.error_api.py

Location:
trunk/anuga_core/source
Files:
1 added
4 edited

Legend:

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

    r7461 r8260  
    101101
    102102def pmesh_divide_metis(domain, n_procs):
     103    # Wrapper for old pmesh_divide_metis which does not return tri_index or r_tri_index
     104    nodes, ttriangles, boundary, triangles_per_proc, quantities, tri_index, r_tri_index = pmesh_divide_metis_helper(domain, n_procs)
     105    return nodes, ttriangles, boundary, triangles_per_proc, quantities
     106
     107def pmesh_divide_metis_with_map(domain, n_procs):
     108    return pmesh_divide_metis_helper(domain, n_procs)
     109
     110def pmesh_divide_metis_helper(domain, n_procs):
    103111   
    104112    # Initialise the lists
     
    110118   
    111119    tri_list = []
     120
     121    # Serial to Parallel and Parallel to Serial Triangle index maps
     122    tri_index = {}
     123    r_tri_index = {} # reverse tri index, parallel to serial triangle index mapping
    112124   
    113125    # List indexed by processor of cumulative total of triangles allocated.
     
    148160        # (local to the processor)
    149161       
    150         tri_index = {}
    151162        triangles = []       
    152163        for i in range(n_tri):
     
    154165            tri_list[epart[i]].append(domain.triangles[i])
    155166            tri_index[i] = ([epart[i], len(tri_list[epart[i]]) - 1])
     167            r_tri_index[epart[i], len(tri_list[epart[i]]) - 1] = i
    156168       
    157169        # Order the triangle list so that all of the triangles belonging
     
    202214    for i in range(len(triangles)):
    203215        ttriangles[i] = triangles[i]
    204    
    205     return nodes, ttriangles, boundary, triangles_per_proc, quantities
     216
     217    #return nodes, ttriangles, boundary, triangles_per_proc, quantities
     218   
     219    return nodes, ttriangles, boundary, triangles_per_proc, quantities, tri_index, r_tri_index
    206220
    207221
  • trunk/anuga_core/source/anuga_parallel/parallel_api.py

    r8114 r8260  
    2020    # Mesh partitioning using Metis
    2121    from anuga_parallel.distribute_mesh import build_submesh
    22     from anuga_parallel.distribute_mesh import pmesh_divide_metis
     22    from anuga_parallel.distribute_mesh import pmesh_divide_metis_with_map
    2323
    2424    from anuga_parallel.parallel_shallow_water import Parallel_domain
     
    9797        points, vertices, boundary, quantities,\
    9898                ghost_recv_dict, full_send_dict,\
    99                 number_of_full_nodes, number_of_full_triangles =\
     99                number_of_full_nodes, number_of_full_triangles,\
     100                s2p_map, p2s_map =\
    100101                distribute_mesh(domain, verbose=verbose)
    101102
     103        # Send serial to parallel (s2p) and parallel to serial (p2s) triangle mapping to proc 1 .. numprocs
     104        for p in range(1, numprocs):
     105            send(s2p_map, p)
     106            send(p2s_map, p)
    102107
    103108        if verbose: print 'Communication done'
     
    112117                rec_submesh(0, verbose)
    113118
     119        # Recieve serial to parallel (s2p) and parallel to serial (p2s) triangle mapping
     120        s2p_map = receive(0)
     121        p2s_map = receive(0)
     122
    114123
    115124    #------------------------------------------------------------------------
     
    125134                             number_of_full_nodes=number_of_full_nodes,
    126135                             number_of_full_triangles=number_of_full_triangles,
    127                              geo_reference=georef) ## jj added this
     136                             geo_reference=georef,
     137                             tri_map = s2p_map,
     138                             inv_tri_map = p2s_map) ## jj added this
    128139
    129140    #------------------------------------------------------------------------
     
    165176    # Subdivide the mesh
    166177    if verbose: print 'Subdivide mesh'
    167     nodes, triangles, boundary, triangles_per_proc, quantities = \
    168            pmesh_divide_metis(domain, numprocs)
    169 
    170 
     178    nodes, triangles, boundary, triangles_per_proc, quantities, s2p_map, p2s_map = \
     179           pmesh_divide_metis_with_map(domain, numprocs)
     180
     181    #PETE: s2p_map (maps serial domain triangles to parallel domain triangles)
     182    #p2_map (maps parallel domain triangles to domain triangles)
    171183
    172184
     
    227239    return points, vertices, boundary, quantities,\
    228240           ghost_recv_dict, full_send_dict,\
    229            number_of_full_nodes, number_of_full_triangles
    230    
    231 
    232 
    233 
     241           number_of_full_nodes, number_of_full_triangles, s2p_map, p2s_map
     242   
     243
     244
     245
  • trunk/anuga_core/source/anuga_parallel/parallel_shallow_water.py

    r8224 r8260  
    2020
    2121
     22#Import matplotlib
     23
     24import matplotlib
     25matplotlib.use('Agg')
     26import matplotlib.pyplot as plt
     27import matplotlib.tri as tri
    2228
    2329class Parallel_domain(Domain):
     
    2935                 number_of_full_nodes=None,
    3036                 number_of_full_triangles=None,
    31                  geo_reference=None): #jj added this
     37                 geo_reference=None,
     38                 tri_map=None,
     39                 inv_tri_map=None): #jj added this
    3240
    3341        Domain.__init__(self,
     
    5765
    5866        setup_buffers(self)
     67
     68        self.tri_map = tri_map
     69        self.inv_tri_map = inv_tri_map
    5970
    6071
     
    122133        return N[:self.number_of_full_nodes_tmp,:]
    123134
     135    def get_tri_map(self):
     136        return self.tri_map
     137
     138    def get_inv_tri_map(self):
     139        return self.inv_tri_map
     140
     141    '''
     142    Outputs domain triangulation, full triangles are shown in green while ghost triangles are shown in blue.
     143    The default filename is "domain.png"
     144    '''
     145    def dump_triangulation(self, filename="domain.png"):
     146        # Get vertex coordinates, partition full and ghost triangles based on self.tri_full_flag
     147        vertices = self.get_vertex_coordinates()
     148        full_mask = num.repeat(self.tri_full_flag == 1, 3)
     149        ghost_mask = num.repeat(self.tri_full_flag == 0, 3)
     150       
     151        myid = pypar.rank()
     152        numprocs = pypar.size()
     153
     154        if myid == 0:
     155            fx = {}
     156            fy = {}
     157            gx = {}
     158            gy = {}
     159
     160            # Proc 0 gathers full and ghost nodes from self and other processors
     161            fx[0] = vertices[full_mask,0]
     162            fy[0] = vertices[full_mask,1]
     163            gx[0] = vertices[ghost_mask,0]
     164            gy[0] = vertices[ghost_mask,1]
     165           
     166            for i in range(1,numprocs):
     167                fx[i] = pypar.receive(i)
     168                fy[i] = pypar.receive(i)
     169                gx[i] = pypar.receive(i)
     170                gy[i] = pypar.receive(i)
     171
     172            # Plot full triangles
     173            for i in range(0, numprocs):
     174                n = int(len(fx[i])/3)
     175                           
     176                triang = num.array(range(0,3*n))
     177                triang.shape = (n, 3)
     178                plt.triplot(fx[i], fy[i], triang, 'g-')
     179
     180            # Plot ghost triangles
     181            for i in range(0, numprocs):
     182                n = int(len(gx[i])/3)
     183                           
     184                triang = num.array(range(0,3*n))
     185                triang.shape = (n, 3)
     186                plt.triplot(gx[i], gy[i], triang, 'b--')
     187
     188            # Save triangulation to location pointed by filename
     189            plt.savefig(filename)
     190
     191        else:
     192            # Proc 1..numprocs send full and ghost triangles to Proc 0
     193            pypar.send(vertices[full_mask,0], 0)
     194            pypar.send(vertices[full_mask,1], 0)
     195            pypar.send(vertices[ghost_mask,0], 0)
     196            pypar.send(vertices[ghost_mask,1], 0)
     197
  • trunk/anuga_core/source/anuga_parallel/test_parallel_frac_op.py

    r8229 r8260  
    105105##-----------------------------------------------------------------------
    106106
    107     if parallel: domain = distribute(domain)
     107    if parallel:
     108        domain = distribute(domain)
     109        domain.dump_triangulation("frac_op_domain.png")
    108110   
    109111
     
    147149
    148150    ################ Define Fractional Operators ##########################
     151
     152    inlet0 = None
     153    inlet1 = None
     154    boyd_box0 = None
    149155   
    150156    inlet0 = Inlet_operator(domain, line0, Q0, debug = False)
     
    152158   
    153159    # Enquiry point [ 19.    2.5] is contained in two domains in 4 proc case
     160   
    154161    boyd_box0 = Boyd_box_operator(domain,
    155162                                  end_points=[[9.0, 2.5],[19.0, 2.5]],
     
    161168                                  manning=0.013,
    162169                                  verbose=False, debug = False)
    163 
     170       
    164171    if inlet0 is not None: inlet0.print_statistics()
    165172    if inlet1 is not None: inlet1.print_statistics()
     
    202209    ##-----------------------------------------------------------------------
    203210
    204     for t in domain.evolve(yieldstep = 1.0, finaltime = 38):
     211    for t in domain.evolve(yieldstep = 0.1, finaltime = 38):
    205212        domain.write_time()
    206213
Note: See TracChangeset for help on using the changeset viewer.