-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_sod.py
More file actions
executable file
·61 lines (54 loc) · 1.77 KB
/
Copy pathplot_sod.py
File metadata and controls
executable file
·61 lines (54 loc) · 1.77 KB
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
#!/usr/bin/env python3
# Example python plotting script for the 1D Sod Shock Tube test
import h5py
import numpy as np
import matplotlib
matplotlib.rcParams['mathtext.default']='regular'
matplotlib.rcParams['xtick.direction']='in'
matplotlib.rcParams['ytick.direction']='in'
matplotlib.rcParams['xtick.top']=True
matplotlib.rcParams['ytick.right']=True
import matplotlib.pyplot as plt
dnamein='../../../data/sod2/'
dnameout='../../../plots/sod2/'
DE = 0 # dual energy flag - 1 if the test was run with dual energy
iend = 10 # output file number
for i in range(iend):
f = h5py.File(dnamein+str(i)+'.h5.0', 'r')
head = f.attrs
nx = head['dims'][0]
gamma = head['gamma'][0]
d = np.array(f['density']) # mass density
mx = np.array(f['momentum_x']) # x-momentum
my = np.array(f['momentum_y']) # y-momentum
mz = np.array(f['momentum_z']) # z-momentum
E = np.array(f['Energy']) # total energy density
vx = mx/d
vy = my/d
vz = mz/d
if DE:
e = np.array(f['GasEnergy'])
p = e*(gamma-1.0)
ge = e/d
else:
p = (E - 0.5*d*(vx*vx + vy*vy + vz*vz)) * (gamma - 1.0)
ge = p/d/(gamma - 1.0)
fig = plt.figure(figsize=(6,6))
ax1 = plt.axes([0.1, 0.6, 0.35, 0.35])
plt.axis([0, nx, 0, 1.1])
ax1.plot(d, 'o', markersize=2, color='black')
plt.ylabel('Density')
ax2 = plt.axes([0.6, 0.6, 0.35, 0.35])
plt.axis([0, nx, -0.1, 1.1])
ax2.plot(vx, 'o', markersize=2, color='black')
plt.ylabel('Velocity')
ax3 = plt.axes([0.1, 0.1, 0.35, 0.35])
plt.axis([0, nx, 0, 1.1])
ax3.plot(p, 'o', markersize=2, color='black')
plt.ylabel('Pressure')
ax4 = plt.axes([0.6, 0.1, 0.35, 0.35])
plt.axis([0, nx, 1.5, 3.7])
ax4.plot(ge, 'o', markersize=2, color='black')
plt.ylabel('Internal Energy')
plt.savefig(dnameout+str(i+1)+".png", dpi=300);
plt.close(fig)