Hi, I have written some code which solve&#39;s the 2d wave equation (code is below). It seems to work, however when the wave reaches the boundaries it reflects off them and I would like to remove this effect. Does anyone know of a method to do this? <br>
Also, I would like to run it over a large area, but when I do the images take a long time to render (I&#39;ve tried saving them as .png files instead, which is a bit faster) so if anyone has any suggestions how I can improve this I&#39;d appreciate it. <br>
Thanks in advance,<br>D<br><br>import matplotlib.pyplot as plt<br>import numpy as np<br>import pylab as py<br>from mpl_toolkits.mplot3d import Axes3D<br>from matplotlib import cm<br><br>pi = np.pi<br><br>#Set up grid.<br>
<br>fig = py.figure()<br>ax = Axes3D(fig)<br><br>nx = 10<br>nz = 10<br><br>X = np.arange(0, nx, 1)<br>Y = np.arange(0, nz, 1)<br>X, Y = np.meshgrid(X, Y)<br><br>nsteps = 100<br><br># Constants for equation.<br>c = 4000<br>
dt = 1e-4<br>h = 1<br><br><br># Set up source.<br>xs = 0<br>zs = 0<br><br>#fig2 = py.figure()<br>ts = np.arange(dt,nsteps*dt,dt)<br>s = 0.5*np.sin(2*pi*100*ts)<br>#py.plot(ts,s)<br>#py.show()<br><br><br># Homogeneous pressure field.<br>
p = np.zeros([nx, nz, nsteps])<br><br># Solve equation.<br>for t in range(0,nsteps-1):<br><br>    <br>    for z in range(0,nz-1):<br><br>        for x in range(0,nx-1):<br><br>            p[xs,zs,t] = s[t]<br><br>            k = (c*dt/h)**2<br>
<br>            p[x,z,t] = 2*p[x,z,t-1] - p[x,z,t-2] + k*(p[x+1,z,t-1]-4*p[x,z,t-1]+p[x-1,z,t-1]+p[x,z+1,t-1]+p[x,z-1,t-1])<br>    <br>    snap = p[:,:,t]<br>    surf = ax.plot_surface(X,Y,snap, rstride=1, cstride=1, cmap=cm.jet, linewidth=0)<br>
    #fig.colorbar(surf, shrink=0.5, aspect=5)<br>    py.draw()   <br>    #py.savefig(&#39;/home/davcra/Desktop/plots/2Dwave/&#39;+str(t))<br><br>