pysws is a simple python script for solving the shallow water equations in a doubly-periodic geometry. The method is based on the Fourier pseudospectral method (see Spectral Methods in Matlab
by L.N. Trefethen).
pysws illustrates how simple it is to do Matlab-type computations with numpy. Here is an example from the code where a gradient is calculated with Discrete Fourier transforms.
# Declare background depth profile. background_depth = CONST_DEPTH - 3.0*np.exp(-np.square((x - 0.5*LX)/(LX/5.0))) # Compute bed slopes. background_depth_xderiv = np.real(ifft(1.j*k*fft(background_depth, axis=1), axis=1)) background_depth_yderiv = np.real(ifft(1.j*l*fft(background_depth, axis=0), axis=0))
This project exists a spin-off from my Ph.D. thesis, that involved a lot of work with Shallow Water-type equations in two dimenions.
- Install dependencies (python2.7, numpy, matplotlib).
- Download the source.
- Run with
python pysws.py
. - Start playing with the source code!
The code's current architecture doesn't support automated unit testing, but I'm hoping to contribute a second implementation soon.
Derek Steinmoeller
Licensed under the MIT license.