On this page are a few basic codes that may be of interest to students of computational hydraulics. These codes have been developed for instructional and research purposes, and have been shared with students of my graduate courses in the past.

Here is a zip file containing a set of Matlab files that implement a Godunov-type finite volume scheme for solving the 1D shallow-water equations. The equations solved by the code are depth-integrated, as opposed to cross-sectionally integrated, and flow resistance is ignored. As such, the code has little practical value. Further, this particular code is not suited to problems involving a dry bed. It should only be run in problems where all cells are wetted with a least a millimeter or so of water. These simplifications are made to emphasize the simplicity of the code. The problem of wetting and drying requires a number of

To execute this code using Matlab, copy all of the

The code can be implemented in either a first-order or second-order accurate mode. In first-order mode, the code only uses the

In my class, I encourage students to begin by running the code as-is, to experiment with different initial conditions, grid spacings, and time steps, and then to implement bigger changes. For example, students should try to implement different boundary conditions, account for flow resistance, account for dry-bed problems, and extend the model to 2D.

Here is a zip file containing a set of Matlab files that implement a numerical solution to the 2D shallow-water equations on a Cartesian grid. The numerical method is a first-order accurate Godunov-type finite volume scheme that utilizes Roe's approximate Riemann solver. Like the 1D code above, the 2D code is highly simplistic: It is set up to model long wave action in a square tank with a flat bottom and no flow resistance. It wouldn't take much effort to update the model for variable topography and flow resistance. In fact, I recommend it to students in graduate courses on hydraulic modeling. It would be a worthwhile homework exercise. Please be warned that the code runs slowly. The same logic coded in Fortran would run much, much faster.

To execute this code using Matlab, copy all of the

A worthwhile exercise for students would be to extend this code to second-order accuracy. The 1D solver above can be used as a guide, and the numerical methods are comprehensively described Bradford and Sanders (2002)

.

Here is a zip file containing a set of Matlab files very similar to the 2D solver above, except that the local time-stepping scheme described in Sanders (2008) is implemented.

To execute this code using Matlab, copy all of the

Experiment with the number of LTS levels (e.g., 1, 2, 3 and 4) and examine how both run-time and the accuracy change. Using

Here is a zip file containing a pair of Matlab files that solve the steady state gradually varied flow equation using Matlab's built-in Runge Kutta solver,

Here is a zip file containing a Matlab program to solve the 2D advection equation on an unstructured grid. This program was developed to introduce students to unstructured grids, and those seeking an introduction to unstructured grids might find it worthwhile to run. This can be done by unzipping the folder and executing the

Here is a zip file containing a Matlab program to solve the 2D diffusion equation using a random-walk particle tracking method. The solution corresponds to an instantaneous load of particles at the origin at time zero. The program was designed to help students understand the diffusion process and as an introduction to particle tracking methods. When executed, the

Here is a script file taylor.m containing a Matlab program to solve the advection diffusion equation in a 2D channel flow with a parabolic velocity distribution (laminar flow). The solution corresponds to an instantaneous load of particles along an

RETURN TO MAIN PAGE