Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Discrete Operators

Authors
Affiliations
University of Valencia

With fields placed on the staggered grid from the previous chapter, the differential operators of fluid dynamics become finite differences and averages that move fields between stagger positions. This chapter walks through the four operator families finitevolX provides — differences, interpolations, advection, and the Laplacian — and shows each one mapping a field from one set of grid points to another Durran (2010)LeVeque (2002).

What you will learn

  • How Difference2D builds gradients, divergence, and curl as stagger-changing differences

  • How Interpolation2D averages fields between stagger positions

  • How Advection2D reconstructs fluxes with upwind / WENO schemes

  • How the Laplacian assembles into the elliptic operators the models invert

The stagger-changing rule

The defining feature of C-grid operators is that a derivative changes the stagger. A centred difference of a T-point field along xx naturally lives on the U-points half a cell away:

(∂xh)j, i+12  ≈  hj,i+1−hj,iΔx,\big(\partial_x h\big)_{j,\,i+\frac12} \;\approx\; \frac{h_{j,i+1} - h_{j,i}}{\Delta x},

which is exactly the T → U map. Likewise ∂y\partial_y of a T-field lands on V-points (T → V). The divergence of a velocity reverses this — it consumes face-staggered fluxes and returns a centred tendency,

(∇⋅u)j,i  ≈  uj, i+12−uj, i−12Δx+vj+12, i−vj−12, iΔy,\big(\nabla\cdot\mathbf{u}\big)_{j,i} \;\approx\; \frac{u_{j,\,i+\frac12} - u_{j,\,i-\frac12}}{\Delta x} + \frac{v_{j+\frac12,\,i} - v_{j-\frac12,\,i}}{\Delta y},

i.e. (U, V) → T. Because the same face values that the divergence consumes are the ones the gradient produces, the discrete divergence is the negative adjoint of the discrete gradient — the property that gives C-grid schemes their clean energy budgets Arakawa & Lamb (1977).

watermark extension not installed; skipping reproducibility readout.

Setup: a smooth test field

We build a 64×64 grid and a smooth, analytically-differentiable test field ψ(x,y)=sin⁡(2πx)cos⁡(2πy)\psi(x,y) = \sin(2\pi x)\cos(2\pi y) so we can compare the discrete operators against their exact continuous counterparts.

test field psi: (66, 66)

Differences: gradient, divergence, curl

Difference2D names each method by the stagger map it performs, so the code reads like (1)–(2). The exact xx-derivative of ψ\psi is 2πcos⁡(2πx)cos⁡(2πy)2\pi\cos(2\pi x)\cos(2\pi y); the discrete diff_x_T_to_U should reproduce it (up to the half-cell shift and truncation error).

diff_x_T_to_U           : shape (66, 66)
diff_y_T_to_V           : shape (66, 66)
divergence (U,V->T)     : shape (66, 66)
curl (U,V->X)           : shape (66, 66)
laplacian (T->T)        : shape (66, 66)

Figure 1 shows the field and its discrete xx-derivative side by side with the exact derivative. The discrete operator tracks the analytic one across the interior; the agreement is the evidence that the stagger map in (1) is faithful.

<Figure size 1800x500 with 6 Axes>
A smooth test field (left), its discrete x-derivative from
diff_x_T_to_U (centre), and the exact analytic derivative (right). The
discrete C-grid difference reproduces the continuous gradient across the
interior.

Figure 1:A smooth test field (left), its discrete xx-derivative from diff_x_T_to_U (centre), and the exact analytic derivative (right). The discrete C-grid difference reproduces the continuous gradient across the interior.

Interpolations: moving between stagger positions

Many terms mix fields from different stagger positions — the mass flux h uh\,u needs hh (a T-field) evaluated at the U-points where uu lives. Interpolation2D provides the averaging maps, named by the same source-to-target convention as the differences. The methods are summarised in Table 1.

Table 1:A representative set of Interpolation2D averaging maps. Every map is a local average; the name encodes the source-to-target stagger.

Method

Map

Use

T_to_U, T_to_V

centre to face

thickness at velocity points (mass flux h uh\,u)

U_to_T, V_to_T

face to centre

kinetic energy 12(u2+v2)\tfrac12(u^2+v^2) at T

T_to_X

centre to corner

thickness at the vorticity point (potential vorticity)

X_to_U, X_to_V

corner to face

vorticity flux in the momentum equation

T_to_U: (66, 66)   T_to_X: (66, 66)   U_to_T: (66, 66)

Advection: upwind and WENO reconstruction

The nonlinear transport term ∇⋅(h u)\nabla\cdot(h\,\mathbf{u}) in (2) is where numerical schemes earn their keep: a naive centred flux is dispersive and produces oscillations at sharp fronts. Advection2D reconstructs the face fluxes with an upwind-biased stencil. The first-order upwind1 is maximally diffusive (robust but smearing); the fifth-order weno5 (weighted essentially non-oscillatory) is high-order in smooth regions yet suppresses oscillations near discontinuities by adaptively weighting its candidate stencils Liu et al. (1994)Shu (1998).

upwind1 tendency: (66, 66)   weno5 tendency: (66, 66)
<Figure size 1800x500 with 6 Axes>
The advective tendency -\nabla\cdot(\phi\,\mathbf{u}) of a Gaussian scalar
under uniform rightward flow, computed with first-order upwind (centre) and
fifth-order WENO (right). WENO resolves the leading and trailing edges far
more sharply for the same grid.

Figure 2:The advective tendency −∇⋅(ϕ u)-\nabla\cdot(\phi\,\mathbf{u}) of a Gaussian scalar under uniform rightward flow, computed with first-order upwind (centre) and fifth-order WENO (right). WENO resolves the leading and trailing edges far more sharply for the same grid.

From the Laplacian to elliptic inversion

The Laplacian diff.laplacian (a T → T map) is the building block of the elliptic problems the geophysical models solve at every step: recovering the streamfunction from vorticity, ∇2ψ=ζ\nabla^2\psi = \zeta, or the pressure from divergence. somax wraps these in dedicated spectral / multigrid solvers (the Helmholtz and Poisson solvers used by the QG and Navier–Stokes models), but they all rest on this discrete second-difference operator.

||laplacian(psi) - exact|| / ||exact|| (interior) = 3.129e-02

Summary

  • C-grid operators are stagger-changing: a derivative of a T-field lands on faces ((1)), a divergence of faces returns to centres ((2)).

  • Difference2D provides gradients, divergence, curl, and laplacian; Interpolation2D moves fields between positions (Table 1); Advection2D reconstructs fluxes with upwind or WENO schemes (Figure 2).

  • The discrete Laplacian underlies the elliptic solvers the QG and Navier–Stokes models invert each step.

The next chapter, boundary conditions, shows how the ghost halo carries the boundary data these operators read at the domain edge.

References

References
  1. Durran, D. R. (2010). Numerical Methods for Fluid Dynamics: With Applications to Geophysics (2nd ed., Vol. 32). Springer. 10.1007/978-1-4419-6412-0
  2. LeVeque, R. J. (2002). Finite Volume Methods for Hyperbolic Problems. Cambridge University Press. 10.1017/CBO9780511791253
  3. Arakawa, A., & Lamb, V. R. (1977). Computational design of the basic dynamical processes of the UCLA general circulation model. Methods in Computational Physics, 17, 173–265.
  4. Liu, X.-D., Osher, S., & Chan, T. (1994). Weighted essentially non-oscillatory schemes. Journal of Computational Physics, 115(1), 200–212. 10.1006/jcph.1994.1187
  5. Shu, C.-W. (1998). Essentially non-oscillatory and weighted essentially non-oscillatory schemes for hyperbolic conservation laws. Advanced Numerical Approximation of Nonlinear Hyperbolic Equations, 1697, 325–432. 10.1007/BFb0096355