Near the end of the previous chapter, I introduced the shallow water system of equations, which we’ll work to solve over the course of this book to produce a realistic simulation of a tsunami. Here we’ll start implementing the simulator from scratch, both in terms of the source code and the physics that we’ll simulate with it. The first process that we’ll simulate is the motion of an object due to background flow. In physics, we call this linear advection. Advection means movement through space, and the linear property implies that the background flow is independent from the shape and position of the object. Don’t worry if you’re not a math or physics whiz and this sounds daunting! In the following subsections, I’ll illustrate how advection works and show how you can calculate it without having to understand all the math behind it.
If you want to delve deeper into the math behind this problem, head over to appendix B. There, I explain the gradient, which is the key concept behind advection, and how to express it in computer code using finite differences. This step is important, as it forms the foundation to express all other terms in the shallow water equations. Otherwise, if you want to skip the math and jump straight to programming, carry on!
In the next subsection, I’ll state the problem and set some requirements for our app. Then, I’ll guide you through an illustrative example of advection and show how you can calculate it yourself without writing any code. Finally, we’ll work together to implement the first version of our app in the remainder of this chapter.