# Author: # # Christian Hill # from wave_2d_pde import WaveEqn2D import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation # print ( '' ) print ( 'reflecting():' ) print ( ' Wave equation in 2D with reflecting boundary conditions.' ) # A = 80 T = 50 freq = 2 * np.pi / T nx = 200 ny = 200 dt = 1 sim = WaveEqn2D ( nx, ny, dt=dt, use_mur_abc=False ) fig, ax = plt.subplots() ax.axis("off") ax.set_title ( 'Wave equation, reflecting BC' ) img = ax.imshow ( sim.u[0], vmin=0, vmax=40, cmap='Blues_r' ) def update(i): """Advance the simulation by one tick.""" # A regular sinusoidal signal at the centre of the domain. sim.u[0, ny//2, nx//2] = A * np.sin(i * freq) sim.update() def init(): """ Initialization, because we're blitting and need references to the animated objects. """ return img, def animate(i): """Draw frame i of the animation.""" update(i) img.set_data(sim.u[0]) return img, interval = sim.dt nframes = 1000 ani = animation.FuncAnimation ( fig, animate, frames = nframes, repeat = False, init_func = init, interval = interval, blit = True ) plt.show()