[8867] | 1 | def 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 | |
---|
| 12 | def 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 | |
---|
| 35 | def 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 | |
---|