I promised in the previous chapter that we’d finally get to some more realistic wave simulations in this chapter. With the additions to the simulator in the final section of this chapter, our water will finally start to move and slosh like real water would (figure 4.4).

Figure 4.4 Simulated wave propagation as a result of nonlinear one-dimensional shallow water equations. A water basin with a uniform depth of 10 m is perturbed with a 1 m high blob. The water height and velocity are then simulated forward in time for 100 seconds, allowing the wave to propagate and slosh back and forth.
As in the previous chapter, we’ll run our simulation for 100 s. We initialize the water height h (this is the perturbation from resting water depth) as a blob with the same shape and amplitude as in the advection example. At time zero (top panel in figure 4.4), the water level is completely flat, except for where we initialized it as a Gaussian shape. So far, so good. A little bit over a second into the simulation, the initial shape splits into two wave packets, which begin propagating in opposite directions (second panel from the top). This is expected! Imagine throwing a pebble into a pond, triggering a series of ripples that radiate away from where the pebble fell in. Our initial perturbation is emulating that pebble. Periodic boundary conditions allow the waves to move past either edge of the domain and reenter from the other side. We thus produce “perpetual” sloshing of water in our small domain.