Skip to content

Spatial discretization

the d spatial dimensions are indexed by α{1,,d}. The α-th unit vector is denoted eα=(eαβ)β=1d, where the Kronecker symbol eαβ is 1 if α=β and 0 otherwise. We note hα=eα/2. The Cartesian index I=(I1,,Id) is used to avoid repeating terms and equations d times, where Iα is a scalar index (typically one of i, j, and k in common notation). This notation is dimension-agnostic, since we can write uI instead of uij in 2D or uijk in 3D. In our Julia implementation of the solver we use the same Cartesian notation (u[I] instead of u[i, j] or u[i, j, k]).

For the discretization scheme, we use a staggered Cartesian grid as proposed by Harlow and Welch [12]. Consider a rectangular domain Ω=α=1d[aα,bα], where aα<bα are the domain boundaries and is a Cartesian product. Let Ω=IIΩI be a partitioning of Ω, where I=α=1d{12,212,,Nα12} are volume center indices, N=(N1,,Nd)Nd are the number of volumes in each dimension, ΩI=α=1dΔIαα is a finite volume, ΓIα=ΩIhαΩI+hα=βαΔIββ is a volume face, Δiα=[xi12α,xi+12α] is a volume edge, x0α,,xNαα are volume boundary coordinates, and xiα=12(xi12α+xi+12α) for i{1/2,,Nα1/2} are volume center coordinates. We also define the operator δα which maps a discrete scalar field φ=(φI)I to

(δαφ)I=φI+hαφIhα|ΔIαα|.

It can be interpreted as a discrete equivalent of the continuous operator xα. All the above definitions are extended to be valid in volume centers II, volume faces II+hα, or volume corners II+α=1dhα. The discretization is illustrated below:

Finite volume discretization of the Navier-Stokes equations

We now define the unknown degrees of freedom. The average pressure in ΩI, II is approximated by the quantity pI(t). The average α-velocity on the face ΓIα, II+hα is approximated by the quantity uIα(t). Note how the pressure p and the d velocity fields uα are each defined in their own canonical positions xI and xI+hα for II. In the following, we derive equations for these unknowns.

Using the pressure control volume O=ΩI with II in the mass integral constraint and approximating the face integrals with the mid-point quadrature rule ΓIudΓ|ΓI|uI results in the discrete divergence-free constraint

α=1d(δαuα)I=0.

Note how dividing by the volume size results in a discrete equation resembling the continuous one (since |ΩI|=|ΓIα||ΔIαα|).

Similarly, choosing an α-velocity control volume O=ΩI with II+hα in the integral momentum equation, approximating the volume- and face integrals using the mid-point quadrature rule, and replacing remaining spatial derivatives in the diffusive term with a finite difference approximation gives the discrete momentum equations

ddtuIα=β=1d(δβ(uαuβ))I+νβ=1d(δβδβuα)I+fα(xI)(δαp)I.

where we made the assumption that f is constant in time for simplicity. The outer discrete derivative in (δβδβuα)I is required at the position I, which means that the inner derivative is evaluated as (δβuα)I+hβ and (δβuα)Ihβ, thus requiring uI2hβα, uIα, and uI+2hβα, which are all in their canonical positions. The two velocity components in the convective term uαuβ are required at the positions Ihβ and I+hβ, which are outside the canonical positions. Their value at the required position is obtained using averaging with weights 1/2 for the α-component and with linear interpolation for the β-component. This preserves the skew-symmetry of the convection operator, such that energy is conserved (in the convective term) [13].

Boundary conditions

Storage convention

We use the column-major convention (Julia, MATLAB, Fortran), and not the row-major convention (Python, C). Thus the x1-index i will vary for one whole cycle in the vectors before the x2-index j, x3 index k, and component-index α are incremented, e.g. uh=(u(1,1,1)1,u(2,1,1)1,u(Nu3(1),Nu3(2),Nu3(3))3) in 3D.

Fourth order accurate discretization

The above discretization is second order accurate. A fourth order accurate discretization can be obtained by judiciously combining the second order discretization with itself on a grid with three times larger cells in each dimension [13] [14]. The coarse discretization is identical, but the mass equation is derived for the three times coarser control volume

ΩI3=α=1dΩIeαΩIΩI+eα,

while the momentum equation is derived for its shifted variant ΩI+hα3. The resulting fourth order accurate equations are given by

α=1d(δαuα)I|ΩI3|32+d|ΩI|α=1d(δα3uα)I=0

and

ddtuIα=β=1d(δβ(uαuβ))I+νβ=1d(δβδβuα)I+fα(xI)(δαp)I+fourth order,

where

(δα3φ)I=φI+3hαφI3hαΔIα1α+ΔIαα+ΔIα+1α.

Matrix representation

We can write the mass and momentum equations in matrix form. We will use the same matrix notation for the second- and fourth order accurate discretizations. The discrete mass equation becomes

Muh+yM=0,

where M is the discrete divergence operator and yM contains the boundary value contributions of the velocity to the divergence field.

The discrete momentum equations become

duhdt=C(uh)+ν(Duh+yD)+fh(Gph+yG)=F(uh)(Gph+yG),

where C is she convection operator (including boundary contributions), D is the diffusion operator, yD is boundary contribution to the diffusion term, G=Wu1MTW is the pressure gradient operator, yG contains the boundary contribution of the pressure to the pressure gradient (only non-zero for pressure boundary conditions), Wu is a diagonal matrix containing the velocity volume sizes |ΩI+δ(α)/2|, and W is a diagonal matrix containing the reference volume sizes |ΩI|. The term F refers to all the forces except for the pressure gradient.

Volume normalization

All the operators have been divided by the velocity volume sizes. As a result, the operators have the same units as their continuous counterparts.

Discrete pressure Poisson equation

Instead of directly discretizing the continuous pressure Poisson equation, we will rededuce it in the discrete setting, thus aiming to preserve the discrete divergence freeness instead of the continuous one. Applying the discrete divergence operator M to the discrete momentum equations yields the discrete pressure Poisson equation

Lph=WM(F(uh)yG)+WdyMdt,

where L=WMG=WMWu1MTW is a discrete Laplace operator. It is positive symmetric.

Unsteady Dirichlet boundary conditions

If the equations are prescribed with unsteady Dirichlet boundary conditions, for example an inflow that varies with time, the term dyMdt will be non-zero. If this term is not known exactly, for example if the next value of the inflow is unknown at the time of the current value, it must be computed using past values of of the velocity inflow only, for example dyMdt(yM(t)yM(tΔt))/Δt for some Δt.

Uniqueness of pressure field

Unless pressure boundary conditions are present, the pressure is only determined up to a constant, as L will have an eigenvalue of zero. Since only the gradient of the pressure appears in the equations, we can set the unknown constant to zero without affecting the velocity field.

Pressure projection

The pressure field ph can be seen as a Lagrange multiplier enforcing the constraint of discrete divergence freeness. It is also possible to write the momentum equations without the pressure by explicitly solving the discrete Poisson equation:

ph=L1WM(F(uh)yG)+L1WdyMdt.

The momentum equations then become

duhdt=(IGL1WM)(F(uh)yG)GL1WdyMdt.

The matrix (IGL1WM) is a projector onto the space of discretely divergence free velocities. However, using this formulation would require an efficient way to perform the projection without assembling the operator matrix L1, which would be very costly.

Discrete output quantities

Kinetic energy

The local kinetic energy is defined by k=12u22=12α=1duαuα. On the staggered grid however, the different velocity components are not located at the same point. We will therefore interpolate the velocity to the pressure point before summing the squares.

Vorticity

In 2D, the vorticity is a scalar. We define it as

ω=δ2u1+δ1u2.

The 3D vorticity is a vector field (ω1,ω2,ω3). Noting α+=mod3(α+1) and α=mod3(α1), the vorticity is defined as through

ωα=δαuα++δα+uα.

Stream function

In 2D, the stream function is defined at the corners with the vorticity. Integrating the stream function Poisson equation over the vorticity volume yields

ΩI+h1+h2ωdΩ=ΩI+h1+h22ψdΩ=ΓI+e1+h21ψx1dΓΓI+h21ψx1dΓ+ΓI+h1+e22ψx2dΓΓI+h12ψx2dΓ.

Replacing the integrals with the mid-point quadrature rule and the spatial derivatives with central finite differences yields the discrete Poisson equation for the stream function at the vorticity point:

|ΓI+h1+h21|(ψI+3/h1+h2ψI+h1+h2xI1+3/21xI1+1/21ψI+h1+h2ψIh1+h2xI1+1/21xI11/21)+|ΓI+h1+h22|(ψI+h1+3h2ψI+h1+h2xI1+3/22xI1+1/22ψI+h1+h2ψI+h1h2xI2+1/22xI21/22)=|ΩI+h1+h2|ωI+h1+h2