Apply the program to solve a wave equation problem where the wave velocity is very small in a square-shaped subdomain in the center of the domain, while the wave velocity is of order unity outside this subdomain. As initial condition, choose a u(x,y,0)=cos(pi*x) for x<1/2 and u=0 otherwise, and make sure the length of the domain in x direction much larger than the extent of this initial disturbance (say 0 <= x <=L, with L=20). This initial condition leads to an incoming plane left from the left (x=0), which is disturbed by the subdomain with low wave velocity in the center of the domain. Stop the simulation before the wave hits the right boundary (x=L) and gets reflected there by the boundary condition du/dn=0. Present results with and without damping.
How can you verify that the program works? Or equivalently, if the program doesn't work, how can you find errors? Suggestions: 1) create a test problem with u=const as solution; 2) choose a constant wave velocity, Courant number 1, no damping, wave propagating in the x direction, and use the property that 1D waves are exactly reproduced by the scheme, regardless of the spatial and temporal mesh partition; 3) argue that the solution observed in the real application is physically reasonable (and point out numerical artifacts if you can see such).
Information on combining Python with Fortran or C++ can be found in Chapters 9 and 10 of a book that can be downloaded by
wget http://simula.no/~hpl/scripting/Langtangen_TCSE3_3rd.pdfThere is also a paper on the effect of using Cython to speed up a wave equation solver. The new tool for treating Fortran code, fwrap, builds on Cython.
Tentative suggestions:
Make sure you use a correct stability criterion - the max timestep in 2D is a factor 1/sqrt(2) smaller than in 1D.
hg clone https://scitools.googlecode.com/hg/ scitools cd scitools python setup.py installWhen scitools is updated, just go to the scitools directory and run the python setup.py install command.
By default, scitools applies matplotlib for plotting, but matplotlib is not very suited for animating elevated surfaces u(x,y,t) (it runs very slowly). Gnuplot is a better choice. Go into the file
lib/scitools/scitools.cfgand change the line
backend = matplotlibto
backend = gnuplotReinstall. Now, gnuplot is the default plotting engine, and it is well suited for animating 2D scalar fields.