eta_initial = h_array[
0]
# Initial panel
ax0.fill_between(x, -2, b, color="silver")
ax0.fill_between(x, b, eta_initial, color="skyblue")
ax0.plot(x, eta_initial, color="midnightblue", lw=2, label="Initial Surface")
ax0.plot(x, b, color="silver", lw=3, zorder=10, label="Bottom")
ax0.axhline(0, color='black', lw=1, linestyle=':')
ax0.legend()
vel_line, = ax2.plot([], [], lw=2)
plt.tight_layout()
def update(frame):
eta = h_array[frame]
v = v_array[frame]
for coll in list(ax1.collections):
coll.remove()
ax1.fill_between(x, -2, b, color="silver")
ax1.fill_between(x, b, eta, color="skyblue")
ax1.plot(x, b, color="silver", lw=3, zorder=10)
ax1.axhline(0, color='black', lw=1, linestyle=':')
ax1.set_title(f"Wave Propagation (t = {t_store[frame]:.2f})", color="midnightblue")
vel_line.set_data(x, v)
ax2.set_title(f"Velocity (t = {t_store[frame]:.2f})", color="midnightblue")
return (vel_line,)
#Animation
frames = min(200, nt)
ani = animation.FuncAnimation(
fig,
update,
frames=frames,
interval=100,
blit=False
)
save_path = "flatbottomtopo_dam_break.gif"
ani.save(save_path, writer="pillow", fps=8)
print("Saved:", save_path)
plt.close(fig)