Skip to content
This repository was archived by the owner on Jun 16, 2022. It is now read-only.

Commit aee8589

Browse files
committed
Add script to plot
1 parent d1c186a commit aee8589

1 file changed

Lines changed: 110 additions & 0 deletions

File tree

hard/plot-plate-hard.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
67+
nodes_small = np.array(nodes_small)
68+
u_small = np.array(u_small)
69+
d_small = np.array(d_small)
70+
71+
72+
plt.quiver(nodes_small[:,0],nodes_small[:,1],u_small[:,0],u_small[:,1])
73+
plt.show()
74+
75+
76+
ax = plt.gca()
77+
plt.scatter(nodes_small[:,0]+u_small[:,0],nodes_small[:,1]+u_small[:,1],c=u_small[:,1],cmap=grayscale_cmap("seismic"),marker="s",s=np.sqrt(30))
78+
#ax.xaxis.tick_top()
79+
#ax.xaxis.set_label_position('top')
80+
fig = plt.gcf()
81+
ax.set_facecolor('#F0F8FF')
82+
plt.xlabel(r"Position $x$")
83+
plt.ylabel(r"Poistion $y$")
84+
#plt.ylim([-2,21])
85+
#plt.xlim([0,max(nodes[:,1]+uCurrent[:,1])])
86+
v = np.linspace(min(u_small[:,1]), max(u_small[:,1]), 6, endpoint=True)
87+
clb = plt.colorbar(ticks=v,format='%.1e')
88+
clb.set_label(r'Displacement $u_y$')
89+
#plt.show()
90+
plt.savefig("bond-based-2d-plate-"+str(h)+"-"+str(delta_factor)+"-"+str(iter)+"-u-y-rotated-hard.pdf",bbox_inches='tight')
91+
plt.clf()
92+
93+
#plt.figure(figsize=(20,1)) grayscale_cmap(plt.get_cmap("viridis"))
94+
plt.scatter(nodes_small[:,0],nodes_small[:,1],c=d_small,cmap="seismic",marker="s",s=np.sqrt(30))
95+
ax = plt.gca()
96+
#ax.xaxis.tick_top()
97+
#ax.xaxis.set_label_position('top')
98+
fig = plt.gcf()
99+
ax.set_facecolor('#F0F8FF')
100+
plt.xlabel(r"Position $x$")
101+
plt.ylabel(r"Poistion $y$")
102+
#plt.ylim([-2,21])
103+
#plt.xlim([0,max(nodes[:,1])])
104+
v = np.linspace(min(damage), max(damage), 6, endpoint=True)
105+
clb = plt.colorbar(ticks=v,format='%.1e')
106+
clb.set_label(r'Damage')
107+
plt.savefig("bond-based-2d-plate-"+str(h)+"-"+str(delta_factor)+"-"+str(iter)+"-d-rotated-hard.pdf",bbox_inches='tight')
108+
109+
110+

0 commit comments

Comments
 (0)