import sys from os import sep sys.path.append('..'+sep+'pyvolution') from mg2ga import * # open file f=open('test_3l_2cc.out', 'r') print f # read in nodes and triangles [nodes, triangles, triangles_per_proc] = mg2ga(f) f.close # find whole mesh on host mesh = Mesh(nodes, triangles) # find sub domains (i.e. full triangles) submesh = [] tlower = 0 nproc = len(triangles_per_proc) nnodes = len(nodes) # loop over processors for p in range(nproc): # find triangles on processor p tupper = triangles_per_proc[p]+tlower subtriangles = triangles[tlower:tupper] # find nodes in processor p nodemap = map(lambda n: 0, nodes) for t in subtriangles: nodemap[t[0]]=1 nodemap[t[1]]=1 nodemap[t[2]]=1 subnodes = [] for i in range(nnodes): if nodemap[i] == 1: subnodes.append([i,nodes[i][0],nodes[i][1]]) # renumber nodes (have to change to store local/global map) [GAnodes, GAtriangles] = restructure(subnodes, subtriangles) # build GA data structure (maybe not needed, maybe can just remember # GAnodes, GAtriangles and build mesh on processors) submesh.append(Mesh(GAnodes, GAtriangles)) tlower = tupper # check results #write a data file for use by scilab script #START160505 VISUALISE MESH IN SCILAB #write triangles as (x0,y0,x1,y1,x2,y2,processor), for use in a scilab visualisation script. fp=open("visualise_mesh","w"); tlower=0 for p in range(len(triangles_per_proc)): nodes=submesh[p].coordinates triangles=submesh[p].triangles for t in range(shape(triangles)[0]): x=[] y=[] string=repr(t)+ ' ' for i in range(3): x.append(nodes[triangles[t][i]][0]) y.append(nodes[triangles[t][i]][1]) string=string+repr(x[i])+' '+repr(y[i])+' ' string=string+repr(p)+'\n' fp.write(string) if ((x[1]-x[0])*(y[2]-y[0])-(x[2]-x[0])*(y[1]-y[0])<=0): string='Error: Triangle '+repr(t)+' on processor '+repr(p)+' is oriented clockwise or degenerate' print(string) fp.close() #END160505 VISUALISE MESH IN SCILAB mesh mesh.vertex_coordinates mesh.triangles submesh