Skip to content

Commit 0290cc4

Browse files
committed
Merge branch 'master' of github.com:Open-Astrophysics-Bookshelf/numerical_exercises
2 parents fcd1821 + ebcf3bc commit 0290cc4

File tree

3 files changed

+236
-140
lines changed

3 files changed

+236
-140
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import matplotlib.pyplot as plt
2+
import grid_plot as gp
3+
4+
def simplegrid():
5+
6+
# grid info
7+
xmin = 0.0
8+
xmax = 1.0
9+
10+
nzones = 2
11+
ng = 0
12+
13+
gr = gp.FVGrid(nzones, xmin=xmin, xmax=xmax)
14+
15+
16+
#------------------------------------------------------------------------
17+
# plot a domain without ghostcells
18+
gr.draw_grid(draw_end=False, edge_ticks=False)
19+
20+
gr.label_center(0, r"$i$")
21+
gr.label_center(1, r"$i+1$")
22+
23+
gr.label_edge(1, r"$q_{i+\myhalf}$")
24+
25+
26+
# draw waves
27+
# u - c
28+
plt.plot([gr.xr[0], gr.xr[0]-0.75*gr.dx], [0,1.0], color="C0", ls="-")
29+
plt.text(gr.xr[0]-0.75*gr.dx, 1.0+0.05, "$\lambda^{(-)} =\, u - c$",
30+
horizontalalignment="center")
31+
32+
# u
33+
plt.plot([gr.xr[0], gr.xr[0]-0.2*gr.dx], [0,1.0], color="C0", ls="-")
34+
plt.text(gr.xr[0]-0.2*gr.dx, 1.0+0.05, "$\lambda^{(\circ)} =\, u$",
35+
horizontalalignment="center")
36+
37+
# u + c
38+
plt.plot([gr.xr[0], gr.xr[0]+0.4*gr.dx], [0,1.0], color="C0", ls="-")
39+
plt.text(gr.xr[0]+0.4*gr.dx, 1.0+0.05, "$\lambda^{(+)} =\, u + c$",
40+
horizontalalignment="center")
41+
42+
43+
plt.plot([gr.xl[0], gr.xr[0]], [0.3, 0.3], color="C1", linewidth=2)
44+
plt.text(gr.xc[0], 0.33, r"$\langle q \rangle_i$", color="C1")
45+
46+
plt.plot([gr.xl[1], gr.xr[1]], [0.6, 0.6], color="C1", linewidth=2)
47+
plt.text(gr.xc[1], 0.63, r"$\langle q \rangle_{i+1}$", color="C1")
48+
49+
gr.clean_axes(padding=False)
50+
plt.ylim(-0.2,1.2)
51+
52+
plt.tight_layout()
53+
54+
f = plt.gcf()
55+
f.set_size_inches(6, 3.5)
56+
57+
58+
plt.savefig("riemann-waves-jump.png", dpi=150)
59+
60+
if __name__== "__main__":
61+
simplegrid()

figures/burgers/characteristics.py

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,65 +20,73 @@ def funr(x):
2020
state[x < 0.5] = 0.2
2121
return state
2222

23-
npts_plot = 1000
24-
xplot = np.linspace(0.0, 1.0, npts_plot)
23+
def make_plot(icfun=None, label=""):
2524

26-
nchar = 20
27-
xchar = np.linspace(0.0, 1.0, nchar)
25+
npts_plot = 1000
26+
xplot = np.linspace(0.0, 1.0, npts_plot)
2827

29-
state = funr(xplot)
30-
print(type(state))
28+
nchar = 20
29+
xchar = np.linspace(0.0, 1.0, nchar)
3130

32-
plt.subplot(211)
31+
state = icfun(xplot)
32+
print(type(state))
3333

34-
plt.plot(xplot, state, lw=2)
34+
plt.clf()
3535

36+
plt.subplot(211)
3637

37-
ax = plt.gca()
38-
ax.spines['right'].set_visible(False)
39-
ax.spines['top'].set_visible(False)
40-
ax.spines['right'].set_visible(False)
41-
ax.spines['top'].set_visible(False)
42-
ax.spines['right'].set_visible(False)
43-
ax.spines['top'].set_visible(False)
44-
ax.xaxis.set_ticks_position('bottom')
45-
ax.yaxis.set_ticks_position('left')
38+
plt.plot(xplot, state, lw=2)
4639

47-
plt.ylim(-0.1, 1.1)
4840

49-
plt.xlabel(r"$x$", fontsize="large")
50-
plt.ylabel(r"$u$", fontsize="large")
41+
ax = plt.gca()
42+
ax.spines['right'].set_visible(False)
43+
ax.spines['top'].set_visible(False)
44+
ax.spines['right'].set_visible(False)
45+
ax.spines['top'].set_visible(False)
46+
ax.spines['right'].set_visible(False)
47+
ax.spines['top'].set_visible(False)
48+
ax.xaxis.set_ticks_position('bottom')
49+
ax.yaxis.set_ticks_position('left')
5150

51+
plt.ylim(-0.1, 1.1)
5252

53+
plt.xlabel(r"$x$", fontsize="large")
54+
plt.ylabel(r"$u$", fontsize="large")
5355

54-
plt.subplot(212)
5556

56-
uchar = funr(xchar)
57-
t = np.linspace(0.0, 1.0, 100)
58-
for n in range(nchar):
59-
xc = xchar[n] + uchar[n]*t
60-
plt.plot(xc, t, color="0.5")
6157

62-
ax = plt.gca()
63-
ax.spines['right'].set_visible(False)
64-
ax.spines['top'].set_visible(False)
65-
ax.spines['right'].set_visible(False)
66-
ax.spines['top'].set_visible(False)
67-
ax.spines['right'].set_visible(False)
68-
ax.spines['top'].set_visible(False)
69-
ax.xaxis.set_ticks_position('bottom')
70-
ax.yaxis.set_ticks_position('left')
58+
plt.subplot(212)
7159

72-
plt.xlabel(r"$x$", fontsize="large")
73-
plt.ylabel(r"$t$", fontsize="large")
60+
uchar = icfun(xchar)
61+
t = np.linspace(0.0, 1.0, 100)
62+
for n in range(nchar):
63+
xc = xchar[n] + uchar[n]*t
64+
plt.plot(xc, t, color="0.5")
7465

75-
plt.xlim(0.0, 1.0)
76-
plt.ylim(0.0, 1.1)
66+
ax = plt.gca()
67+
ax.spines['right'].set_visible(False)
68+
ax.spines['top'].set_visible(False)
69+
ax.spines['right'].set_visible(False)
70+
ax.spines['top'].set_visible(False)
71+
ax.spines['right'].set_visible(False)
72+
ax.spines['top'].set_visible(False)
73+
ax.xaxis.set_ticks_position('bottom')
74+
ax.yaxis.set_ticks_position('left')
7775

78-
f = plt.gcf()
79-
f.set_size_inches(6.0, 8.0)
76+
plt.xlabel(r"$x$", fontsize="large")
77+
plt.ylabel(r"$t$", fontsize="large")
8078

81-
plt.tight_layout()
79+
plt.xlim(0.0, 1.0)
80+
plt.ylim(0.0, 1.1)
8281

83-
plt.savefig("burgers-characteristics-rare.pdf")
82+
f = plt.gcf()
83+
f.set_size_inches(6.0, 8.0)
8484

85+
plt.tight_layout()
86+
87+
plt.savefig(f"burgers-characteristics-{label}.png")
88+
89+
if __name__ == "__main__":
90+
91+
make_plot(funr, "rare")
92+
make_plot(funs, "shock")

0 commit comments

Comments
 (0)