-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPost_Process.py
154 lines (108 loc) · 3.58 KB
/
Post_Process.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python
# coding: utf-8
# # Importing necessary libraries:
# ******************************************************
# In[1]:
import numpy as np
# In[2]:
import matplotlib.pyplot as plt
# In[3]:
import matplotlib
# In[4]:
from matplotlib.colors import Normalize
# # Post Processing:
# **************************************************
# In[5]:
def Post_Process(phi,string,Element_Node_Connectivity_new,Node_Coordinates,Img_file):
"""
Input:
phi: Scalar
string: String for the title
Element_Node_Connectivity_new:
Node_Coordinates:
Output:
A contour plot showing the value of phi in different elements
"""
temp = np.zeros((4,2))
x = Node_Coordinates[:,0]
y = Node_Coordinates[:,1]
# cmap = "YlGn"
# cmap = "viridis"
# cmap = "rainbow"
# cmap = "jet"
cmap = "turbo"
cmap = matplotlib.colormaps.get_cmap(cmap)
norm = Normalize(vmin=min(phi), vmax=max(phi)) # Normalize the scalar values
fig, ax = plt.subplots()
for i in range(Element_Node_Connectivity_new.shape[0]):
Nodes = Element_Node_Connectivity_new[i,1:]
Nodes = np.array(Nodes,dtype = int)
temp[:3,0] = x[Nodes]
temp[:3,1] = y[Nodes]
temp[-1,0] = x[Nodes[0]]
temp[-1,1] = y[Nodes[0]]
X = temp[:,0]
Y = temp[:,1]
ax.plot(X,Y,"k")
# color = plt.cm.get_cmap(cmap)((phi[i] - min(phi)) / (max(phi) - min(phi)))
color = cmap(norm(phi[i]))
ax.fill(X,Y,color=color,linewidth = 1)
# Debug Script:
# plt.plot(x[Nodes[0]],y[Nodes[0]],"-b*")
scalar_map = plt.cm.ScalarMappable(cmap=cmap,norm=plt.Normalize(vmin=min(phi), vmax=max(phi)))
scalar_map.set_array(phi)
plt.colorbar(scalar_map,ax = ax)
# cbar = plt.colorbar(scalar_map)
# cbar.set_label(r'$\Phi$: '+string)
plt.title(string)
plt.axis("scaled")
plt.savefig(Img_file)
# plt.show()
plt.close()
# In[6]:
def Post_Process_Without_Grid(phi,string,Element_Node_Connectivity_new,Node_Coordinates,Img_file):
"""
Input:
phi: Scalar
string: String for the title
Element_Node_Connectivity_new:
Node_Coordinates:
Output:
A contour plot showing the value of phi in different elements
"""
temp = np.zeros((4,2))
x = Node_Coordinates[:,0]
y = Node_Coordinates[:,1]
# cmap = "YlGn"
# cmap = "viridis"
# cmap = "rainbow"
# cmap = "jet"
cmap = "turbo"
cmap = matplotlib.colormaps.get_cmap(cmap)
norm = Normalize(vmin=min(phi), vmax=max(phi)) # Normalize the scalar values
fig, ax = plt.subplots()
for i in range(Element_Node_Connectivity_new.shape[0]):
Nodes = Element_Node_Connectivity_new[i,1:]
Nodes = np.array(Nodes,dtype = int)
temp[:3,0] = x[Nodes]
temp[:3,1] = y[Nodes]
temp[-1,0] = x[Nodes[0]]
temp[-1,1] = y[Nodes[0]]
X = temp[:,0]
Y = temp[:,1]
# ax.plot(X,Y,"k")
# color = plt.cm.get_cmap(cmap)((phi[i] - min(phi)) / (max(phi) - min(phi)))
color = cmap(norm(phi[i]))
ax.fill(X,Y,color=color)
# Debug Script:
# plt.plot(x[Nodes[0]],y[Nodes[0]],"-b*")
scalar_map = plt.cm.ScalarMappable(cmap=cmap,norm=plt.Normalize(vmin=min(phi), vmax=max(phi)))
scalar_map.set_array(phi)
plt.colorbar(scalar_map,ax = ax)
# cbar = plt.colorbar(scalar_map)
# cbar.set_label(r'$\Phi$: '+string)
plt.title(string)
plt.axis("scaled")
plt.savefig(Img_file)
# plt.show()
plt.close()