|
| 1 | +import matplotlib.pyplot as plt |
| 2 | +import numpy as np |
| 3 | +import pickle |
| 4 | +import sys |
| 5 | +from matplotlib import rc |
| 6 | +from matplotlib.colors import LinearSegmentedColormap |
| 7 | + |
| 8 | +rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']}) |
| 9 | +rc('text', usetex=True) |
| 10 | +rc('font', size=17) |
| 11 | + |
| 12 | + |
| 13 | +def grayscale_cmap(cmap): |
| 14 | + """Return a grayscale version of the given colormap""" |
| 15 | + cmap = plt.cm.get_cmap(cmap) |
| 16 | + colors = cmap(np.arange(cmap.N)) |
| 17 | + |
| 18 | + # convert RGBA to perceived grayscale luminance |
| 19 | + # cf. http://alienryderflex.com/hsp.html |
| 20 | + RGB_weight = [0.299, 0.587, 0.114] |
| 21 | + luminance = np.sqrt(np.dot(colors[:, :3] ** 2, RGB_weight)) |
| 22 | + colors[:, :3] = luminance[:, np.newaxis] |
| 23 | + |
| 24 | + return LinearSegmentedColormap.from_list(cmap.name + "_gray", colors, cmap.N) |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | +if __name__=="__main__": |
| 29 | + |
| 30 | + |
| 31 | + h = float(sys.argv[1]) |
| 32 | + delta_factor = int(sys.argv[2]) |
| 33 | + iter = int(sys.argv[3]) |
| 34 | + |
| 35 | + n = int(15/h) + 1 |
| 36 | + |
| 37 | + |
| 38 | + nodes = [] |
| 39 | + |
| 40 | + |
| 41 | + filehandler = open("bond-based-2d-plate-"+str(h)+"-"+str(delta_factor)+"-"+str(iter)+"-displacement-hard.npy", "rb") |
| 42 | + uCurrent = np.load(filehandler, allow_pickle=True) |
| 43 | + |
| 44 | + filehandler = open("bond-based-2d-plate-"+str(h)+"-"+str(delta_factor)+"-"+str(iter)+"-damage-hard.npy", "rb") |
| 45 | + damage = np.load(filehandler, allow_pickle=True) |
| 46 | + |
| 47 | + for i in range(0,n): |
| 48 | + for j in range(0,n+2*delta_factor): |
| 49 | + nodes.append([i*h,(j-delta_factor)*h]) |
| 50 | + |
| 51 | + nodes = np.array(nodes) |
| 52 | + |
| 53 | + #plt.figure(figsize=(20,1)) |
| 54 | + |
| 55 | + nodes_small = [] |
| 56 | + u_small = [] |
| 57 | + d_small = [] |
| 58 | + |
| 59 | + for i in range(0,len(nodes)): |
| 60 | + if nodes[i][1] >=0 and nodes[i][1] <= 15: |
| 61 | + |
| 62 | + nodes_small.append(nodes[i]) |
| 63 | + u_small.append(uCurrent[i]) |
| 64 | + d_small.append(damage[i]) |
| 65 | + |
| 66 | + max_d = max(d_small) |
| 67 | + d_pos = [] |
| 68 | + |
| 69 | + for i in range(0,len(d_small)): |
| 70 | + if d_small[i] <= 0.75 * max_d : |
| 71 | + d_small[i] = 0 |
| 72 | + else: |
| 73 | + d_pos.append(nodes[i,0]+u_small[i][0]) |
| 74 | + |
| 75 | + print(max(d_pos)) |
| 76 | + print(d_pos) |
| 77 | + |
| 78 | + nodes_small = np.array(nodes_small) |
| 79 | + u_small = np.array(u_small) |
| 80 | + d_small = np.array(d_small) |
| 81 | + |
| 82 | + |
| 83 | + #plt.quiver(nodes_small[:,0],nodes_small[:,1],u_small[:,0],u_small[:,1]) |
| 84 | + #plt.show() |
| 85 | + |
| 86 | + |
| 87 | + ax = plt.gca() |
| 88 | + plt.scatter(nodes_small[:,0]+u_small[:,0],nodes_small[:,1]+u_small[:,1],c=u_small[:,1],cmap=grayscale_cmap("viridis"),marker="s",s=np.sqrt(30)) |
| 89 | + #ax.xaxis.tick_top() |
| 90 | + #ax.xaxis.set_label_position('top') |
| 91 | + fig = plt.gcf() |
| 92 | + ax.set_facecolor('#F0F8FF') |
| 93 | + plt.xlabel(r"Position $x$") |
| 94 | + plt.ylabel(r"Poistion $y$") |
| 95 | + #plt.ylim([-2,21]) |
| 96 | + #plt.xlim([0,max(nodes[:,1]+uCurrent[:,1])]) |
| 97 | + v = np.linspace(min(u_small[:,1]), max(u_small[:,1]), 6, endpoint=True) |
| 98 | + clb = plt.colorbar(ticks=v,format='%.1e') |
| 99 | + clb.set_label(r'Displacement $u_y$') |
| 100 | + #plt.show() |
| 101 | + plt.savefig("bond-based-2d-plate-"+str(h)+"-"+str(delta_factor)+"-"+str(iter)+"-u-y-rotated-hard.pdf",bbox_inches='tight') |
| 102 | + plt.clf() |
| 103 | + |
| 104 | + #plt.figure(figsize=(20,1)) grayscale_cmap(plt.get_cmap("viridis")) |
| 105 | + plt.scatter(nodes_small[:,0],nodes_small[:,1],c=d_small,cmap=grayscale_cmap("viridis"),marker="s",s=np.sqrt(30)) |
| 106 | + ax = plt.gca() |
| 107 | + #ax.xaxis.tick_top() |
| 108 | + #ax.xaxis.set_label_position('top') |
| 109 | + fig = plt.gcf() |
| 110 | + ax.set_facecolor('#F0F8FF') |
| 111 | + plt.xlabel(r"Position $x$") |
| 112 | + plt.ylabel(r"Poistion $y$") |
| 113 | + #plt.ylim([-2,21]) |
| 114 | + #plt.xlim([0,max(nodes[:,1])]) |
| 115 | + v = np.linspace(min(d_small), max(d_small), 6, endpoint=True) |
| 116 | + clb = plt.colorbar(ticks=v,format='%.1e') |
| 117 | + clb.set_label(r'Damage') |
| 118 | + ax.hlines(y=7.5, xmin=0, xmax=7.5, linewidth=2, color='#FF7E00') |
| 119 | + plt.savefig("bond-based-2d-plate-"+str(h)+"-"+str(delta_factor)+"-"+str(iter)+"-d-rotated-hard.pdf",bbox_inches='tight') |
| 120 | + |
| 121 | + |
| 122 | + |
0 commit comments