-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathbeso_plots.py
199 lines (186 loc) · 6.41 KB
/
beso_plots.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# plotting graphs
import matplotlib.pyplot as plt
import os
def plotshow(domain_FI_filled, optimization_base, displacement_graph):
"""prepare figures for incremental plotting"""
fn = 10 # figure number
# plot mass
fn += 1
plt.figure(fn)
plt.pause(0.000001)
if domain_FI_filled: # FI contain something
# plot number of elements with FI > 1
fn += 1
plt.figure(fn)
plt.pause(0.000001)
# plot mean failure index
fn += 1
plt.figure(fn)
plt.pause(0.000001)
# plot maximal failure indices
fn += 1
plt.figure(fn)
plt.pause(0.000001)
if optimization_base == "stiffness":
# plot mean energy density
fn += 1
plt.figure(fn)
plt.pause(0.000001)
if optimization_base == "heat":
# plot mean heat flux
fn += 1
plt.figure(fn)
plt.pause(0.000001)
if displacement_graph:
fn += 1
plt.figure(fn)
plt.pause(0.000001)
if optimization_base == "buckling":
fn += 1
plt.figure(fn)
plt.pause(0.000001)
def replot(path, i, oscillations, mass, domain_FI_filled, domains_from_config, FI_violated, FI_mean, FI_mean_without_state0,
FI_max, optimization_base, energy_density_mean, heat_flux_mean, displacement_graph, disp_max,
buckling_factors_all, savefig=False):
"""plot graphs with actual data"""
fn = 10 # figure number
# plot mass
fn += 1
fig = plt.figure(fn)
plt.cla()
plt.plot(range(i+1), mass, label="mass")
plt.title("Mass of optimization domains")
plt.xlabel("Iteration")
plt.ylabel("Mass")
plt.grid()
plt.tight_layout()
fig.canvas.flush_events()
if savefig:
plt.savefig(os.path.join(path, "Mass"))
if oscillations is True:
i_plot = i - 1 # because other values for i-th iteration are not evaluated
else:
i_plot = i
if domain_FI_filled: # FI contain something
# plot number of elements with FI > 1
fn += 1
fig = plt.figure(fn)
plt.cla()
dno = 0
for dn in domains_from_config:
FI_violated_dn = []
for ii in range(i_plot + 1):
FI_violated_dn.append(FI_violated[ii][dno])
plt.plot(range(i_plot + 1), FI_violated_dn, label=dn)
dno += 1
if len(domains_from_config) > 1:
FI_violated_total = []
for ii in range(i_plot + 1):
FI_violated_total.append(sum(FI_violated[ii]))
plt.plot(range(i_plot+1), FI_violated_total, label="Total")
plt.legend(loc=2, fontsize=10)
plt.title("Number of elements with Failure Index >= 1")
plt.xlabel("Iteration")
plt.ylabel("FI_violated")
plt.grid()
plt.tight_layout()
fig.canvas.flush_events()
if savefig:
plt.savefig(os.path.join(path, "FI_violated"))
# plot mean failure index
fn += 1
fig = plt.figure(fn)
plt.cla()
plt.plot(range(i_plot+1), FI_mean, label="all")
plt.plot(range(i_plot+1), FI_mean_without_state0, label="without state 0")
plt.title("Mean Failure Index weighted by element mass")
plt.xlabel("Iteration")
plt.ylabel("FI_mean")
plt.legend(loc=2, fontsize=10)
plt.grid()
plt.tight_layout()
fig.canvas.flush_events()
if savefig:
plt.savefig(os.path.join(path, "FI_mean"))
# plot maximal failure indices
fn += 1
fig = plt.figure(fn)
plt.cla()
for dn in domains_from_config:
FI_max_dn = []
for ii in range(i_plot + 1):
FI_max_dn.append(FI_max[ii][dn])
plt.plot(range(i_plot + 1), FI_max_dn, label=dn)
plt.legend(loc=2, fontsize=10)
plt.title("Maximal domain Failure Index")
plt.xlabel("Iteration")
plt.ylabel("FI_max")
plt.grid()
plt.tight_layout()
fig.canvas.flush_events()
if savefig:
plt.savefig(os.path.join(path, "FI_max"))
if optimization_base == "stiffness":
# plot mean energy density
fn += 1
fig = plt.figure(fn)
plt.cla()
plt.plot(range(i_plot+1), energy_density_mean)
plt.title("Mean Energy Density weighted by element mass")
plt.xlabel("Iteration")
plt.ylabel("energy_density_mean")
plt.grid()
plt.tight_layout()
fig.canvas.flush_events()
if savefig:
plt.savefig(os.path.join(path, "energy_density_mean"))
if optimization_base == "heat":
# plot mean heat flux
fn += 1
fig = plt.figure(fn)
plt.cla()
plt.plot(range(i_plot+1), heat_flux_mean)
plt.title("Mean Heat Flux weighted by element mass")
plt.xlabel("Iteration")
plt.ylabel("heat_flux_mean")
plt.grid()
plt.tight_layout()
fig.canvas.flush_events()
if savefig:
plt.savefig(os.path.join(path, "heat_flux_mean"))
if displacement_graph:
fn += 1
fig = plt.figure(fn)
plt.cla()
for cn in range(len(displacement_graph)):
disp_max_cn = []
for ii in range(i_plot + 1):
disp_max_cn.append(disp_max[ii][cn])
plt.plot(range(i + 1), disp_max_cn, label=displacement_graph[cn][0] + "(" + displacement_graph[cn][1] + ")")
plt.legend(loc=2, fontsize=10)
plt.title("Node set maximal displacements")
plt.xlabel("Iteration")
plt.ylabel("Displacement")
plt.grid()
plt.tight_layout()
fig.canvas.flush_events()
if savefig:
plt.savefig(os.path.join(path, "Displacement_max"))
if optimization_base == "buckling":
fn += 1
fig = plt.figure(fn)
plt.cla()
for bfn in range(len(buckling_factors_all[0])):
buckling_factors_bfn = []
for ii in range(i_plot + 1):
buckling_factors_bfn.append(buckling_factors_all[ii][bfn])
plt.plot(range(i_plot + 1), buckling_factors_bfn, label="mode " + str(bfn + 1))
plt.legend(loc=2, fontsize=10)
plt.title("Buckling factors")
plt.xlabel("Iteration")
plt.ylabel("buckling_factors")
plt.grid()
plt.tight_layout()
fig.canvas.flush_events()
if savefig:
plt.savefig(os.path.join(path, "buckling_factors"))