source: inundation/ga/storm_surge/parallel/linda_dummy.py @ 1452

Last change on this file since 1452 was 1409, checked in by matthew, 20 years ago

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.

File size: 2.1 KB
RevLine 
[1409]1import sys
2from os import sep
3sys.path.append('..'+sep+'pyvolution')
4from mg2ga import *
5# open file
6f=open('test_3l_2cc.out', 'r')
7print f
8# read in nodes and triangles
9[nodes, triangles, triangles_per_proc] = mg2ga(f)
10f.close
11# find whole mesh on host
12mesh = Mesh(nodes, triangles)
13# find sub domains (i.e. full triangles)
14submesh = []
15tlower = 0
16nproc = len(triangles_per_proc)
17nnodes = len(nodes)
18# loop over processors
19for p in range(nproc):
20    # find triangles on processor p
21    tupper = triangles_per_proc[p]+tlower
22    subtriangles = triangles[tlower:tupper]
23    # find nodes in processor p
24    nodemap = map(lambda n: 0, nodes)
25    for t in subtriangles:
26        nodemap[t[0]]=1
27        nodemap[t[1]]=1
28        nodemap[t[2]]=1
29    subnodes = [] 
30    for i in range(nnodes):
31        if nodemap[i] == 1:
32            subnodes.append([i,nodes[i][0],nodes[i][1]])
33    # renumber nodes (have to change to store local/global map)
34    [GAnodes, GAtriangles] = restructure(subnodes, subtriangles)
35    # build GA data structure (maybe not needed, maybe can just remember
36    # GAnodes, GAtriangles and build mesh on processors)
37    submesh.append(Mesh(GAnodes, GAtriangles))
38    tlower = tupper
39# check results
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
63mesh
64mesh.vertex_coordinates
65mesh.triangles
66submesh
Note: See TracBrowser for help on using the repository browser.