Spatial and temporal discretization
This page describes the discretization used in the solver, in the same notation as the code. The domain is discretized on a staggered Cartesian grid as proposed by Harlow and Welch [5], and the equations are stepped in time with explicit Runge-Kutta methods [6].
Staggered grid
The rectangular domain
indexed by the Cartesian index u[I] instead of u[i, j] or u[i, j, k]). The Setup (the vectors x[α]), from which the volume widths Δ[α]) follow. The grid does not need to be uniform.
The unknowns are staggered:
The pressure
is defined in the volume center. The velocity component
is defined on the right face of volume in direction , i.e. on the boundary between and . In the code, all components are stored in one array with the component as the last index: u[I, α].

In addition to the interior volumes, all fields carry one layer of ghost volumes on each boundary. The ghost values are filled by apply_bc_u! and apply_bc_p! such that the interior finite-volume stencils automatically account for the boundary conditions (Dirichlet, periodic, symmetric, or pressure). This is why the field arrays have size N while the degrees of freedom are indexed by Ip and Iu.
Mass equation
Integrating the mass equation over the pressure volume
a backward difference of the face velocities surrounding the pressure volume. This is the divergence operator. Since we divided by the volume size, the discrete equation resembles the continuous one
Momentum equations
The momentum equation for
where pressuregradient). In the convective term, the two velocity components in the product navierstokes!, with convection and diffusion as separate differentiable operators.
All operators come in two variants: a fast mutating one (e.g. divergence!) and a differentiable non-mutating one (e.g. divergence). See Operators and Differentiating code.
Discrete pressure Poisson equation
Instead of discretizing the continuous pressure Poisson equation, we require that the discrete velocity field stays divergence free. Let
where poisson, see Pressure solvers). Subtracting the resulting pressure gradient projects a velocity field onto the space of discretely divergence-free fields; this is the project operator. Without pressure boundary conditions
Sparse matrix representations of
Time discretization
The spatially discretized system is a differential-algebraic system: an ODE for the velocity subject to the algebraic divergence-free constraint. It is stepped in time with explicit Runge-Kutta methods, where each stage velocity is made divergence free by a pressure projection. This retains the accuracy of the underlying Runge-Kutta method for the velocity; see Sanderse and Koren [6] for an analysis.
Given the state
where LMWray3, a low-storage third-order method of Wray [8] that only needs three vector fields of storage. A large collection of tableaus is available in RKMethods.
The time step can be fixed (Δt) or chosen adaptively from a CFL condition based on the convective and diffusive stability limits (Δt = nothing in solve_unsteady, the default).