Picture: This image reveals sediment in the Gulf of Mexico off the Louisiana coast. Credit: USGS (Unsplash).

GeophysicalFlows.jl: Solvers for geophysical fluid dynamics problems in periodic domains on CPUs & GPUs

Often our understanding of physical processes comes from idealised configurations rather than from inspecting the output of realistic (and complicated) general circulation or Earth system models.

In atmospheric and oceanic fluid dynamics, simple conceptual models that capture the essence of certain physics have helped improve our understanding of certain processes and also have helped push the boundaries of the field. In teaching, conceptual models often give students a vivid visual representation of certain phenomena and the concepts the equations are describing. Such simple conceptual models are, for example, two-dimensional turbulence, quasi-geostrophic flow on a beta-plane, Phillips model of baroclinic instability, two-dimensional Rayleigh-Benard convection between parallel plates, and more.

The growth and equilibration of baroclinic instability in a Phillips 2-layer model. The most unstable baroclinic mode for this configuration emerges out of the noise and grows exponentially until it becomes nonlinear. The flow then reorganises into 3 zonal jets.

People often code up these simple models to solve them on a computer. Sometimes they publish their codes on their personal websites. However, often these codes come without any form of documentation. Understanding somebody’s code without documentation is usually much harder than coding up your own version from scratch. This is one reason why we often see people rewrite code to accomplish something that many others have already established.

With this in mind, CLEX researcher Navid Constantinou and collaborators developed GeophysicalFlows.jl, a Julia package that provides solvers for geophysical fluid dynamics problems in periodic domains. Currently, the package includes solvers for two-dimensional turbulence, barotropic or equivalent barotropic quasi-geostrophic flows, surface quasi-geostrophic flows, and multi-layer quasi-geostrophic flows. All modules are well documented and include continuous integration of both simple unit tests and physics-specific tests for each module. The examples in the package’s documentation demonstrate how one can easily set up, customise, solve, and produce animations for the model of their choice. Some tutorials even demonstrate how one can code up a solver for a partial differential equation of their liking. 

GeophysicalFlows.jl is written in Julia, a free, open-source programming language that has been gaining in popularity. Julia is designed with scientific computing in mind – it can be as fast as C but as user-friendly as Python. Julia aims to solve the “two language problem”, i.e. the fact that we often run models in Fortran and analyse output using Python or Matlab. Furthermore, Julia’s functionality enables all modules within GeophysicalFlows.jl to run seamlessly on both CPUs and GPUs, something extremely useful given the recent rise of machine-learning applications in atmospheric and oceanic sciences.

It is said that a picture is worth a thousand words. If an animation is worth a thousand pictures, then animations may be worth around a million words. For scientists, the ability to visualise solutions of particular models with ease while, at the same time, also being able to change parameter values and rerun the simulation is priceless. We can learn so much simply by looking… even before we start quantifying.

Read more about Navid’s experience developing open-source code and publishing in open-source journals in this related blog post.