I am looking for some help finding a numerical solution to the shallow water equations:


$\partial_t \eta+\partial_x(u\eta)=0$.

where $u$ is the depth averaged horizontal velocity, $\eta$ is the depth, and $g$ is a constant.

Using mathematica's NDSolve I quickly develop a compressive shock (and consequentially the solution begins to ring and diverge) and I need a new solver to capture it accurately. It is my current understanding that I can capture the shock in at least three ways:

(a) I can capture the shock to arbitrary precision and guarantee uniqueness by using an artificial viscosity term. For this I have two questions:

  1. What type of viscosity term should I use ($\partial_x^{2n} u$)? And what are the advantages and disadvantages.

  2. Should I build a finite difference scheme and if so, what?

(b) I can capture the shock by having a flag that triggers when the gradient is large which then uses the Rankine–Hugoniot conditions to evolve the shock.

  1. How do I decide on a trigger for the shock?

  2. Should I build a finite difference scheme and if so, what?

(c) I can use a finite difference scheme that has enough numerical diffusion to not run into issues.

  1. What scheme and how do I analyze the numerical diffusion contribution.

I don't know where to start. If you have any insight (maybe a solver on GitHub or a critique of that question itself) please share! Any advice on resources or methods would be helpful.

  • 1
    $\begingroup$ I'd suggest starting with (1) getting a stable solver for the linear shallow water equations (2) going to nonlinear problems but with much smoother initial conditions that are less prone to shocks and then (3) going to problems that do have shocks. You'll almost certainly want to read Leveque's book as well whether or not you opt to use a finite volume discretization. $\endgroup$ Commented Feb 25, 2022 at 16:55
  • 1
    $\begingroup$ Have you taken a look at the literature? The shallow water equation is surely one of the most often solved hyperbolic equations! $\endgroup$ Commented Feb 26, 2022 at 1:27
  • $\begingroup$ @WolfgangBangerth At a surface level. I was hoping to get pointed to some resources. $\endgroup$
    – FluidMan
    Commented Feb 26, 2022 at 14:14
  • $\begingroup$ @DanielShapero Thank you for the insight! I will revisit Leveque to see if I can address these questions. $\endgroup$
    – FluidMan
    Commented Feb 26, 2022 at 14:16

1 Answer 1


Educational resources

The shallow water equations are one of the simplest and most important systems of hyperbolic PDEs, and are frequently used in textbooks as an introductory example. There are several books that cover them from a theoretical viewpoint, but since you are primarily interested in numerical methods, I recommend LeVeque's finite volume book as well as Riemann Problems and Jupyter Solutions (full disclosure: I'm an author of the latter book). Toro's book is also excellent but out of print.

If your goal is to write your own solver (perhaps for educational purposes), then these books are a good place to learn what you'll need. If your goal is to solve some application problem, then you might prefer to use an existing code.


The Clawpack software (disclosure: I'm one of the authors and principal maintainers) is often used for solving the shallow water equations and there are several example setups for that. It's probably easiest to get started using PyClaw. An example of a solution of the 2D shallow water equations solved in PyClaw is here, and more examples (both 1D and 2D, with or without varying bathymetry) can be found in the PyClaw examples directory (all the folders starting with "shallow").

For more advanced geophysical applications, you might want to use the GeoClaw code (also part of Clawpack), which is designed for modeling tsunamis, storm surges, etc.

There are many other solvers that can be found on the web, but I don't have direct experience with them.

  • $\begingroup$ Thank you so much! The resources seem great and I am already learning a lot from both the software documentation and the Riemann Problems and Jupyter Solutions text. This is exactly what I needed! $\endgroup$
    – FluidMan
    Commented Feb 26, 2022 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.