Changeset 1409


Ignore:
Timestamp:
May 17, 2005, 4:38:26 PM (20 years ago)
Author:
matthew
Message:

the function readmg in mg2ga.py now returns triangles_per_proc instead of nodes_per_proc, since, in contrast to nodes (vertices), triangles are unique to a processor. This allows for cleaner construction of Linda's submesh in the case where
some nodes are common to several processors.

Location:
inundation/ga/storm_surge/parallel
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/parallel/linda_dummy.py

    r1399 r1409  
    22from os import sep
    33sys.path.append('..'+sep+'pyvolution')
    4 
    5 
    6 
    74from mg2ga import *
    8 from parallel_advection import *
    9 
    105# open file
    11 
    12 f=open('test_3l_2c.out', 'r')
     6f=open('test_3l_2cc.out', 'r')
    137print f
    14 
    158# read in nodes and triangles
    16 
    17 [nodes, triangles, nodes_per_proc] = mg2ga(f)
    18 
     9[nodes, triangles, triangles_per_proc] = mg2ga(f)
     10f.close
    1911# find whole mesh on host
    20 
    21 #mesh = Parallel_Domain(nodes, triangles)
    2212mesh = Mesh(nodes, triangles)
    23 
    2413# find sub domains (i.e. full triangles)
    25 
    2614submesh = []
    27 nlower = 0
    28 nproc = len(nodes_per_proc)
     15tlower = 0
     16nproc = len(triangles_per_proc)
    2917nnodes = len(nodes)
    30 
    3118# loop over processors
    3219for p in range(nproc):
    33     # find triangles in processor p
    34 
    35     nupper = nodes_per_proc[p]+nlower
    36     subtriangles = filter(lambda t: nlower<=max(t)<nupper, triangles)
    37 
     20    # find triangles on processor p
     21    tupper = triangles_per_proc[p]+tlower
     22    subtriangles = triangles[tlower:tupper]
    3823    # find nodes in processor p
    39 
    4024    nodemap = map(lambda n: 0, nodes)
    4125    for t in subtriangles:
     
    4327        nodemap[t[1]]=1
    4428        nodemap[t[2]]=1
    45     subnodes = []
     29    subnodes = [] 
    4630    for i in range(nnodes):
    4731        if nodemap[i] == 1:
    4832            subnodes.append([i,nodes[i][0],nodes[i][1]])
    49 
    5033    # renumber nodes (have to change to store local/global map)
    51 
    5234    [GAnodes, GAtriangles] = restructure(subnodes, subtriangles)
    53 
    5435    # build GA data structure (maybe not needed, maybe can just remember
    5536    # GAnodes, GAtriangles and build mesh on processors)
    56 
    5737    submesh.append(Mesh(GAnodes, GAtriangles))
    58     nlower = nupper
    59 
     38    tlower = tupper
    6039# check results
    61 
     40#write a data file for use by scilab script
     41#START160505 VISUALISE MESH IN SCILAB
     42#write triangles as (x0,y0,x1,y1,x2,y2,processor), for use in a scilab visualisation script.
     43fp=open("visualise_mesh","w");
     44tlower=0
     45for p in range(len(triangles_per_proc)):
     46    nodes=submesh[p].coordinates
     47    triangles=submesh[p].triangles
     48    for t in range(shape(triangles)[0]):
     49        x=[]
     50        y=[]
     51        string=repr(t)+ ' '
     52        for i in range(3):
     53            x.append(nodes[triangles[t][i]][0])
     54            y.append(nodes[triangles[t][i]][1])
     55            string=string+repr(x[i])+' '+repr(y[i])+' '
     56        string=string+repr(p)+'\n'
     57        fp.write(string)
     58        if ((x[1]-x[0])*(y[2]-y[0])-(x[2]-x[0])*(y[1]-y[0])<=0):
     59            string='Error: Triangle '+repr(t)+' on processor '+repr(p)+' is oriented clockwise or degenerate'
     60            print(string)
     61fp.close()
     62#END160505 VISUALISE MESH IN SCILAB
    6263mesh
    6364mesh.vertex_coordinates
    6465mesh.triangles
    65 
    6666submesh
  • inundation/ga/storm_surge/parallel/mg2ga.py

    r1403 r1409  
    11from string import atoi
    22from string import atof
    3 from general_mesh import General_mesh as Mesh
     3import os
     4from mesh import Mesh
    45from Numeric import shape
    56##################################################################################
     
    3536    # know first nodes_per_proc[0] belong to cell 0, next
    3637    # nodes_per_proc[1] belong to cell 1 etc.
    37     nodes_per_proc = []
    38     triangles_per_proc = []
     38    #nodes_per_proc = [] This is worked out later
     39    triangles_per_proc = [] #each triangle belongs to a unique processor
    3940    # loop over the processors
    4041    for q in range(no_proc):
     
    4243        # read the nodes
    4344        no_nodes = str2array(f.readline(), atoi)[1]
    44         nodes_per_proc.append(no_nodes)
     45        #nodes_per_proc.append(no_nodes)
    4546        f.readline()
    4647        for i in range(no_nodes):
     
    8990        f.readline()
    9091        f.readline()
    91     return nodes, triangles, nodes_per_proc
     92    return nodes, triangles, triangles_per_proc
    9293##################################################################################
    9394# Convert the format of the data to that used by pyvolution
     
    121122    return GAnodes, triangles
    122123def mg2ga(f):
    123     [nodes, triangles, nodes_per_proc] = readmg(f)
     124    [nodes, triangles, triangles_per_proc] = readmg(f)
    124125    [nodes, triangles] = restructure(nodes, triangles)
    125     return nodes, triangles, nodes_per_proc
     126    return nodes, triangles, triangles_per_proc
Note: See TracChangeset for help on using the changeset viewer.