Shallow Water Equations. Simulation in C++ ImGui

Markus Buchholz
3 min readJun 18, 2023


The shallow water equations are fundamental equations used to model the behavior of water in shallow regions, such as rivers, lakes, and coastal areas. They provide a simplified representation of fluid flow dynamics, making them valuable in various applications, including flood forecasting, storm surge prediction, and coastal engineering design. This article provides a brief introduction to the shallow water equations, their derivation, and their practical significance.

The source code for this article you will find on my GitHub.

The shallow water equations are derived based on several assumptions and simplifications. They assume that the fluid depth is much smaller compared to the horizontal length scale, neglecting vertical accelerations. Furthermore, they consider incompressible and high-viscosity flow, ignoring frictional effects and compressibility of water. These assumptions lead to the depth-averaged conservation equations for mass and momentum.

The shallow water equations consist of two primary equations: the continuity equation and the momentum equation. The continuity equation states that the rate of change of water depth with time is proportional to the divergence of the horizontal velocity field. The momentum equation expresses the conservation of momentum, accounting for gravitational forces and pressure gradients.

In these equations, h represents the water height, u represents the velocity component in the x-direction, and v represents the velocity component in the y-direction. g is the acceleration due to gravity, and x and y are the spatial coordinates. H is the height of the horizontal pressure surface. The equations describe the conservation of mass and momentum in the shallow water system.

Solving the shallow water equations analytically is often challenging due to their nonlinear nature. Therefore, numerical methods play a crucial role in simulating and analyzing shallow water flow.
Please consider the source code included to be familiar with “simple” implementation.
Here is the result.

Shallow water simulation (by author)

The shallow water equations find widespread use in various practical applications. They are instrumental in flood forecasting, enabling the prediction of water levels and flow rates in rivers and channels. In coastal areas, the equations aid in predicting storm surges and evaluating the impact of coastal erosion. Additionally, they assist in designing coastal structures, such as breakwaters and seawalls, by simulating wave propagation and water movements.

The shallow water equations provide a simplified yet effective framework for modeling water flow in shallow regions. Despite their assumptions and limitations, they serve as valuable tools in understanding and predicting the behavior of water bodies. By leveraging numerical methods, these equations enable the simulation and analysis of complex hydrodynamic scenarios, contributing to various fields, including hydrology, hydraulics, and coastal engineering.

Thank you for reading.