-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
634 lines (511 loc) · 16.6 KB
/
plot.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
import time
import datetime
import os
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import shutil
def plot_data(time_step, xs, cylinder_temps, cylinder_temps_out, cylinder_temps_in, coolant_temps, coolant_presses,
Q_ins, Q_in_per_areas, Q_outs, Reynolds, Nusselts, T_gases, h_gs, h_ls, clt_vels, Q_in_fulls, Q_out_fulls,
geom_x, geom_y, flow_areas, wet_perimeters, D_hydros, m_engine, L_skirt_chan_width, L_chamber_chan_width,
L_min_chan_width, L_max_chan_width, engine_lengths, mdot_clts, T_films, rT_layers_plot, T_effectives,
coolant_press_drops, total_clt_press_drops, vis_model, filename=None):
# stop max. number of figures warning (because death to your RAM, that's why!)
plt.rcParams.update({'figure.max_open_warning': 0})
# PRINT TOTAL Q
Q_in_total = 0
for Q in Q_in_fulls:
Q_in_total += Q
Q_out_total = 0
for Q in Q_out_fulls:
Q_out_total += Q
## print("\nTotal Q_in:", Q_in_total * 100)
## print("Total Q_out:", Q_out_total * 100)
## print("Net Q:", (Q_in_total - Q_out_total) * 100)
def plot_engine_contour(ax):
ax.set_aspect("equal")
ax.set_ylim([-max(geom_y)*0.7, max(max(geom_x), max(geom_y))])
ax.plot(geom_x, geom_y, color="black")
ax.fill_between(geom_x, geom_y, where=[True]*len(geom_x), interpolate=True, color='black')
ax.set_ylabel("Engine Contour (m)")
ax.yaxis.set_label_position("right")
ax.yaxis.tick_right()
num_frames = len(cylinder_temps)
fig, ax = plt.subplots()
plotnum = 0
# WALL TEMP. PLOT
plotnum += 1
plt.figure(plotnum)
ax2 = ax.twinx()
plot_engine_contour(ax)
ax2.set_aspect("auto")
ax2.yaxis.set_label_position("left")
ax2.yaxis.tick_left()
for i in range(0, num_frames, int(num_frames/10)):
red = max(min(1, max(cylinder_temps[i])/600),0)
blue = 1 - red
ax2.plot(xs, cylinder_temps[i], color=(red, 0, blue))
plt.grid()
plt.title("Wall Temperature")
ax.set_xlabel("Position (m)")
ax2.set_ylabel("Temperature (C)")
# WALL OUTER - INNER TEMP. PLOT (FOR THE LAST FRAME)
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
ax2 = ax.twinx()
plot_engine_contour(ax)
ax2.set_aspect("auto")
ax2.yaxis.set_label_position("left")
ax2.yaxis.tick_left()
ax2.plot(xs, cylinder_temps_out[-1], color=(0,0,1))
ax2.plot(xs, cylinder_temps_in[-1], color=(1,0,0))
plt.grid()
plt.title("Inner & Outer Wall Surface Temperatures")
ax.set_xlabel("Position (m)")
ax2.set_ylabel("Temperature (C)")
# COOLANT TEMP. PLOT
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
ax2 = ax.twinx()
plot_engine_contour(ax)
ax2.set_aspect("auto")
ax2.yaxis.set_label_position("left")
ax2.yaxis.tick_left()
for i in range(0, num_frames, int(num_frames/10)):
red = max(min(1, max(coolant_temps[i])/350),0)
blue = 1 - red
ax2.plot(xs, coolant_temps[i], color=(red, 0, blue))
plt.grid()
plt.title("Coolant Temperature")
ax.set_xlabel("Position (m)")
ax2.set_ylabel("Temperature (C)")
# COOLANT PRESS. PLOT
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
ax2 = ax.twinx()
plot_engine_contour(ax)
ax2.set_aspect("auto")
ax2.yaxis.set_label_position("left")
ax2.yaxis.tick_left()
for i in range(0, num_frames, int(num_frames/10)):
ax2.plot(xs, coolant_presses[i])
plt.grid()
plt.title("Coolant Pressure")
ax.set_xlabel("Position (m)")
ax2.set_ylabel("Pressure (Pa)")
# HEAT PLOT
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
ax2 = ax.twinx()
plot_engine_contour(ax)
ax2.set_aspect("auto")
ax2.yaxis.set_label_position("left")
ax2.yaxis.tick_left()
for i in range(0, num_frames, int(num_frames/10)):
ax2.plot(xs, Q_ins[i], color=(1,0,0))
ax2.plot(xs, Q_outs[i], color=(0,0,1))
plt.grid()
plt.title("Heat Transfer")
ax.set_xlabel("Position (m)")
ax2.set_ylabel("Heat Transferred (W)")
# HEAT PER AREA PLOT
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
ax2 = ax.twinx()
plot_engine_contour(ax)
ax2.set_aspect("auto")
ax2.yaxis.set_label_position("left")
ax2.yaxis.tick_left()
for i in range(0, num_frames, int(num_frames/10)):
ax2.plot(xs, Q_in_per_areas[i], color=(1,0,0))
plt.grid()
plt.title("Heat Transfer Per Area")
ax.set_xlabel("Position (m)")
ax2.set_ylabel("Heat Transferred (W m-2)")
# REYNOLDS NUMBER PLOT
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
ax2 = ax.twinx()
plot_engine_contour(ax)
ax2.set_aspect("auto")
ax2.yaxis.set_label_position("left")
ax2.yaxis.tick_left()
for i in range(0, num_frames, int(num_frames/10)):
ax2.plot(xs, Reynolds[i])
plt.grid()
plt.title("Reynolds Number")
ax.set_xlabel("Position (m)")
ax2.set_ylabel("Reynolds Number")
# NUSSELT NUMBER PLOT
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
ax2 = ax.twinx()
plot_engine_contour(ax)
ax2.set_aspect("auto")
ax2.yaxis.set_label_position("left")
ax2.yaxis.tick_left()
for i in range(0, num_frames, int(num_frames/10)):
ax2.plot(xs, Nusselts[i])
plt.grid()
plt.title("Nusselts Number")
ax.set_xlabel("Position (m)")
ax2.set_ylabel("Nusselts Number")
# COMBUSTION GAS TEMP. PLOT
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
ax2 = ax.twinx()
plot_engine_contour(ax)
ax2.set_aspect("auto")
ax2.yaxis.set_label_position("left")
ax2.yaxis.tick_left()
ax2.plot(xs, T_gases)
plt.grid()
plt.title("Gas Temperature (K)")
ax.set_xlabel("Position (m)")
ax2.set_ylabel("Gas Temperature")
# GAS CONVECTION COEFF. PLOT
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
ax2 = ax.twinx()
plot_engine_contour(ax)
ax2.set_aspect("auto")
ax2.yaxis.set_label_position("left")
ax2.yaxis.tick_left()
for i in range(0, num_frames, int(num_frames/10)):
ax2.plot(xs, h_gs[i])
plt.grid()
plt.title("hg")
ax.set_xlabel("Position (m)")
ax2.set_ylabel("hg")
# LIQUID FILM COEFF. PLOT
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
ax2 = ax.twinx()
plot_engine_contour(ax)
ax2.set_aspect("auto")
ax2.yaxis.set_label_position("left")
ax2.yaxis.tick_left()
for i in range(0, num_frames, int(num_frames/10)):
ax2.plot(xs, h_ls[i])
plt.grid()
plt.title("hl")
ax.set_xlabel("Position (m)")
ax2.set_ylabel("hl")
# COOLANT VELOCITY PLOT
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
ax2 = ax.twinx()
plot_engine_contour(ax)
ax2.set_aspect("auto")
ax2.yaxis.set_label_position("left")
ax2.yaxis.tick_left()
for i in range(0, num_frames, int(num_frames/10)):
ax2.plot(xs, clt_vels[i])
plt.grid()
plt.title("Coolant Flow Velocity")
ax.set_xlabel("Position (m)")
ax2.set_ylabel("Velocity (m s-1)")
# TOTAL Q IN PLOT
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
plt.plot(Q_in_fulls)
plt.grid()
plt.title("Total Q In")
plt.xlabel("Time")
plt.ylabel("Total Q In")
# TOTAL Q OUT PLOT
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
plt.plot(Q_out_fulls)
plt.grid()
plt.title("Total Q Out")
plt.xlabel("Time")
plt.ylabel("Total Q Out")
## # HEAT PLOT (3D)
## plt.figure(12)
## ax = plt.axes(projection='3d')
##
## times = []
## for i in range(num_frames):
## times.append(i*time_step)
##
## for i in range(0, num_frames, int(num_frames/10)):
## ax.plot3D(Q_ins[i], xs, times[i], color="red")
##
## for i in range(0, num_frames, int(num_frames/10)):
## ax.plot3D(Q_outs[i], xs, times[i], color="blue")
##
## # HEAT DIFF. PLOT (3D)
## plt.figure(13)
## ax = plt.axes(projection='3d')
##
## Q_nets = []
## for i in range(len(Q_ins)):
## Q_nets.append([])
## for j in range(len(Q_ins[0])):
## Q_nets[i].append(Q_ins[i][j] - Q_outs[i][j])
##
## for i in range(0, num_frames, int(num_frames/10)):
## ax.plot3D(Q_nets[i], xs, times[i], color="green")
# ENGINE GEOMETRY
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
ax.set_aspect('equal')
geom_y_negative = []
for y in geom_y:
geom_y_negative.append(-y)
ax.plot(geom_x, geom_y)
ax.plot(geom_x, geom_y_negative)
plt.grid()
plt.title("Thrust Chamber Geometry")
ax.set_xlabel("X")
ax.set_ylabel("Y")
# FLOW AREA
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
plt.plot(xs, flow_areas)
plt.grid()
plt.title("Coolant Flow Area")
plt.xlabel("X")
plt.ylabel("Area m2")
# WET PERIMETER
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
plt.plot(xs, wet_perimeters)
plt.grid()
plt.title("Wet Perimeter")
plt.xlabel("X")
plt.ylabel("Perimeter m")
# HYDRAULIC DIAMETERS
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
plt.plot(xs, D_hydros)
plt.grid()
plt.title("Hydraulic Diameter")
plt.xlabel("X")
plt.ylabel("Diameter m")
# COOLANT MDOT PLOT
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
ax2 = ax.twinx()
plot_engine_contour(ax)
ax2.set_aspect("auto")
ax2.yaxis.set_label_position("left")
ax2.yaxis.tick_left()
ax2.plot(xs, mdot_clts)
plt.grid()
plt.title("Cooling Channel Mass Flow")
ax.set_xlabel("Position (m)")
ax2.set_ylabel("Flow (kg s-1)")
# FILM TEMPERATURE PLOT
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
ax2 = ax.twinx()
plot_engine_contour(ax)
ax2.set_aspect("auto")
ax2.yaxis.set_label_position("left")
ax2.yaxis.tick_left()
for i in range(0, num_frames, int(num_frames/10)):
ax2.plot(xs, T_films[i])
plt.grid()
plt.title("Film Temperature")
ax.set_xlabel("Position (m)")
ax2.set_ylabel("Film Temperature (K)")
# LAYER RATIO PLOT
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
ax2 = ax.twinx()
plot_engine_contour(ax)
ax2.set_aspect("auto")
ax2.yaxis.set_label_position("left")
ax2.yaxis.tick_left()
for i in range(0, num_frames, int(num_frames/10)):
ax2.plot(xs, rT_layers_plot[i])
plt.grid()
plt.title("Layer Comp.")
ax.set_xlabel("Position (m)")
ax2.set_ylabel("S/F Ratio")
# EFFECTIVE TEMP. PLOT
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
ax2 = ax.twinx()
plot_engine_contour(ax)
ax2.set_aspect("auto")
ax2.yaxis.set_label_position("left")
ax2.yaxis.tick_left()
for i in range(0, num_frames, int(num_frames/10)):
ax2.plot(xs, T_effectives[i])
plt.grid()
plt.title("Effective Temp.")
ax.set_xlabel("Position (m)")
ax2.set_ylabel("Effective Temp. (K)")
# COOLANT PRESS. DROP PLOT
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
ax2 = ax.twinx()
plot_engine_contour(ax)
ax2.set_aspect("auto")
ax2.yaxis.set_label_position("left")
ax2.yaxis.tick_left()
for i in range(0, num_frames, int(num_frames/10)):
ax2.plot(xs, coolant_press_drops[i])
plt.grid()
plt.title("Coolant Pressure Drop")
ax.set_xlabel("Position (m)")
ax2.set_ylabel("Pressure Drop")
# TOTAL COOLANT PRESS. DROP PLOT
_, ax = plt.subplots()
plotnum += 1
plt.figure(plotnum)
plt.plot(total_clt_press_drops)
plt.grid()
plt.title("Total Coolant Pressure Drop")
plt.xlabel("Time")
plt.ylabel("Total Coolant Pressure Drop (Pa)")
### ANIMATED FIGURES
anims = []
anim_plotnum = 0
# WALL TEMP ANIMATED
fig, ax = plt.subplots()
anim_plotnum += 1
plt.figure(plotnum + anim_plotnum)
plt.title("Wall Temp.")
plt.xlabel("X Position (mm)")
plt.ylabel("Temperature (C)")
plt.grid()
plt.xlim = (0, xs[-1])
plt.ylim(0, max(cylinder_temps[-1]) + 50)
wall_temp_line, = ax.plot(xs, cylinder_temps[-1])
def animate_wall_temp(i):
wall_temp_line.set_ydata(cylinder_temps[i])
return wall_temp_line,
anim_wall_temp = animation.FuncAnimation(
fig, animate_wall_temp, blit=True, frames=list(range(len(cylinder_temps))))
anims.append(anim_wall_temp)
# COOLANT TEMP ANIMATED
fig, ax = plt.subplots()
anim_plotnum += 1
plt.figure(plotnum + anim_plotnum)
plt.title("Coolant Temp.")
plt.xlabel("X Position (mm)")
plt.ylabel("Coolant Temp. (C)")
plt.grid()
plt.xlim = (0, xs[-1])
plt.ylim(0, max(coolant_temps[-1]) + 50)
coolant_temp_line, = ax.plot(xs, coolant_temps[-1])
def animate_coolant_temp(i):
coolant_temp_line.set_ydata(coolant_temps[i])
return coolant_temp_line,
anim_coolant_temp = animation.FuncAnimation(
fig, animate_coolant_temp, blit=True, frames=list(range(len(coolant_temps))))
anims.append(anim_coolant_temp)
# HEAT FLOWS TEMP ANIMATED
fig, ax = plt.subplots()
anim_plotnum += 1
plt.figure(plotnum + anim_plotnum)
plt.title("Heat Transferred")
plt.xlabel("X Position (mm)")
plt.ylabel("Heat (W)")
plt.grid()
plt.xlim = (0, xs[-1])
plt.ylim(min(Q_outs[-1]), max(Q_ins[-1]) + 500)
Q_ins_line, = ax.plot(xs, Q_ins[-1])
Q_outs_line, = ax.plot(xs, Q_outs[-1])
def animate_heat_transfer(i):
Q_ins_line.set_ydata(Q_ins[i])
Q_outs_line.set_ydata(Q_outs[i])
return Q_ins_line, Q_outs_line,
anim_heat_trans = animation.FuncAnimation(
fig, animate_heat_transfer, blit=True, frames=list(range(len(Q_ins))))
anims.append(anim_heat_trans)
print("")
if not filename:
folder_name = "heat_analysis_" + datetime.datetime.now().strftime("%y%m%d%H%M%S")
else:
if "/" in filename:
folder_name = filename.split("/")[2].split(".")[0]
else:
folder_name = filename.split(".")[0]
print("Exporting data to folder: " + folder_name)
try:
if not os.path.exists(folder_name):
os.makedirs(folder_name)
except:
print("ERROR: Could not create folder. Try saving figures by hand.")
plt.show()
return
try:
with open(str(folder_name + "/geometry.txt"), "w") as f:
f.write("xs=" + str(geom_x))
f.write("\n\n")
f.write("ys=" + str(geom_y))
f.write("\n\n")
f.write("Engine mass (kg): " + str(m_engine) + "\n\n")
#f.write("Min. coolant channel width (m): " + str(L_min_chan_width) + "\n")
#f.write("Max. coolant channel width (m): " + str(L_max_chan_width) + "\n")
#f.write("Chamber coolant channel width (m): " + str(L_chamber_chan_width) + "\n")
#f.write("Skirt coolant channel width (m): " + str(L_skirt_chan_width) + "\n\n")
f.write("Engine contour change positions (m) = " + str(engine_lengths))
except:
print("WARNING: Could not export geometry data.")
try:
with open(str(folder_name + "/3d_model.txt"), "w") as f:
for vertex in vis_model:
f.write(str(vertex)+"\n")
except:
print("WARNING: Couldn't export 3D model!")
try:
shutil.copy(filename, folder_name)
except:
print("WARNING: Could not copy inputs file to analysis folder.")
try:
shutil.copy("modelviewer.py", folder_name)
except:
print("WARNING: Could not copy modelviewer utility to analysis folder.")
try:
for i in range(1, plotnum + 1):
new_fig = plt.figure(i)
save_str = folder_name + "/figure_" + str(i) + ".png"
new_fig.savefig(save_str)
except:
print("ERROR: Could not save some or all of the figures. Try saving figures by hand.")
plt.show()
return
try:
for anim_idx in range(len(anims)):
plt.figure(plotnum + anim_idx)
anim = anims[anim_idx]
save_str = folder_name + "/anim_" + str(anim_idx + 1) + ".gif"
anim.save(save_str)
except:
print("ERROR: Could not save some or all of animated figures. Try saving figures by hand.")
#plt.show()
return
print("Figures exported successfully!")
print("Clearing figures from memory...")
for i in range(1, plotnum + anim_plotnum + 1):
new_fig = plt.figure(i)
new_fig.clear()
plt.close()
print("Analysis done!")