source: trunk/anuga_work/development/gareth/tests/more_plot_util.py

Last change on this file was 8867, checked in by davies, 11 years ago

Updated to bal_dev

File size: 2.0 KB
RevLine 
[8867]1def plot_triangles(p):
2    """ Add mesh triangles to a pyplot plot
3    """
4    for i in range(len(p.vols)):
5        k1=p.vols[i][0]
6        k2=p.vols[i][1]
7        k3=p.vols[i][2]
8        pyplot.plot([p.x[k1], p.x[k2], p.x[k3], p.x[k1]], [p.y[k1], p.y[k2], p.y[k3], p.y[k1]],'-',color='black')
9        #pyplot.plot([p.x[k3], p.x[k2]], [p.y[k3], p.y[k2]],'-',color='black')
10        #pyplot.plot([p.x[k3], p.x[k1]], [p.y[k3], p.y[k1]],'-',color='black')
11
12def find_neighbours(p,ind):
13    """ Find the triangles neighbouring triangle 'ind'
14    """
15    ind_nei=p.vols[ind]
16   
17    shared_nei0=p.vols[:,1]*0.0
18    shared_nei1=p.vols[:,1]*0.0
19    shared_nei2=p.vols[:,1]*0.0
20    # Compute indices that match one of the vertices of triangle ind
21    # Note: Each triangle can only match a vertex, at most, once
22    for i in range(3):
23        shared_nei0+=1*(p.x[p.vols[:,i]]==p.x[ind_nei[0]])*\
24            1*(p.y[p.vols[:,i]]==p.y[ind_nei[0]])
25       
26        shared_nei1+=1*(p.x[p.vols[:,i]]==p.x[ind_nei[1]])*\
27            1*(p.y[p.vols[:,i]]==p.y[ind_nei[1]])
28       
29        shared_nei2+=1*(p.x[p.vols[:,i]]==p.x[ind_nei[2]])*\
30            1*(p.y[p.vols[:,i]]==p.y[ind_nei[2]])
31   
32    out=(shared_nei2 + shared_nei1 + shared_nei0)
33    return((out==2).nonzero())
34
35def calc_edge_elevations(p):
36    pe_x=p.x*0.
37    pe_y=p.y*0.
38    pe_el=p.elev*0.
39
40   
41    # Compute coordinates + elevations
42    pe_x[p.vols[:,0]] = 0.5*(p.x[p.vols[:,1]] + p.x[p.vols[:,2]])
43    pe_y[p.vols[:,0]] = 0.5*(p.y[p.vols[:,1]] + p.y[p.vols[:,2]])
44    pe_el[p.vols[:,0]] = 0.5*(p.elev[p.vols[:,1]] + p.elev[p.vols[:,2]])
45   
46    pe_x[p.vols[:,1]] = 0.5*(p.x[p.vols[:,0]] + p.x[p.vols[:,2]])
47    pe_y[p.vols[:,1]] = 0.5*(p.y[p.vols[:,0]] + p.y[p.vols[:,2]])
48    pe_el[p.vols[:,1]] = 0.5*(p.elev[p.vols[:,0]] + p.elev[p.vols[:,2]])
49
50    pe_x[p.vols[:,2]] = 0.5*(p.x[p.vols[:,0]] + p.x[p.vols[:,1]])
51    pe_y[p.vols[:,2]] = 0.5*(p.y[p.vols[:,0]] + p.y[p.vols[:,1]])
52    pe_el[p.vols[:,2]] = 0.5*(p.elev[p.vols[:,0]] + p.elev[p.vols[:,1]])
53
54    return [pe_x, pe_y, pe_el]
55
56
Note: See TracBrowser for help on using the repository browser.