Rheon

3 Staggered geometry and discrete operators

A Cartesian staggered grid stores scalars at cell centers and velocity components on faces normal to their axes. Harlow and Welch’s marker-and-cell formulation is the historical foundation [S2]. Pressure has nxnynzn_xn_yn_z entries; x-velocity has (nx+1)nynz(n_x+1)n_yn_z, y-velocity has nx(ny+1)nzn_x(n_y+1)n_z, and z-velocity has nxny(nz+1)n_xn_y(n_z+1). These shapes differ even in a cubic domain.

With origin o\mathbf o and spacing hh, a cell center is o+h(i+1/2,j+1/2,k+1/2)\mathbf o+h(i+1/2,j+1/2,k+1/2). An x-face is at o+h(i,j+1/2,k+1/2)\mathbf o+h(i,j+1/2,k+1/2). Each component therefore requires its own sampling offset. Using cell-centered offsets for all components creates a half-cell error and can destroy an otherwise correct projection.

Divergence from flux balance

Integrate divergence over a cubic cell, approximate each face flux by its stored normal velocity, and divide by volume:

(Du)ijk=ui+1,j,k−ui,j,kh+vi,j+1,k−vi,j,kh+wi,j,k+1−wi,j,kh. (D\mathbf u)_{ijk}= \frac{u_{i+1,j,k}-u_{i,j,k}}{h} +\frac{v_{i,j+1,k}-v_{i,j,k}}{h} +\frac{w_{i,j,k+1}-w_{i,j,k}}{h}.

The pressure gradient at an interior x-face is (pi,j,k−pi−1,j,k)/h(p_{i,j,k}-p_{i-1,j,k})/h. The same face appears in two neighboring divergences with opposite signs. This shared-face requirement gives cancellation of internal fluxes.

For the formal model, define a cells-by-faces matrix BB. Each oriented internal face column contains −1-1 at its tail and +1+1 at its head. At unit spacing, physical divergence is −Bu-B\mathbf u, while pressure difference is BTpB^Tp. The proofs and experiments use this convention. A uniform physical grid inserts factors 1/h1/h. Cut cells require cell-volume and face-area metrics, not an informal reuse of the unweighted identity.

The adjoint identity

Exchange finite sums:

∑ipi∑eBieue=∑e(∑iBiepi)ue. \sum_i p_i\sum_e B_{ie}u_e =\sum_e\left(\sum_iB_{ie}p_i\right)u_e.

This exact discrete integration-by-parts identity says pTBu=(BTp)Tup^TBu=(B^Tp)^Tu. Physical divergence and gradient are negative adjoints. The Lean theorem named adjoint_identity proves the finite-sum statement for every real matrix of the declared shape. It does not prove that array traversal assembled the right matrix.

Two cells connected by one face give

B=[−11],BTp=p1−p0,BBT=[1−1−11]. B=\begin{bmatrix}-1\\1\end{bmatrix}, \qquad B^Tp=p_1-p_0, \qquad BB^T=\begin{bmatrix}1&-1\\-1&1\end{bmatrix}.

Face velocity 3 gives physical divergence (3,−3)(3,-3), whose sum vanishes. Reversing both orientation and stored velocity sign preserves the physical field; reversing only one is a bug.

Layout and indexing

Use x-fastest flattening:

index⁡(i,j,k)=i+nx(j+nyk). \operatorname{index}(i,j,k)=i+n_x(j+n_yk).

The Lean theorem flatten_in_bounds proves this lies below nxnynzn_xn_yn_z for in-range natural coordinates. Machine integers add a separate obligation: shape products and additions must fit before allocation or indexing. Validate shape arithmetic with checked operations when constructing the grid. Retain distinct validated shape types for cells and each face orientation. Repeated handwritten dimension arithmetic spreads the contract across every kernel.

Separate interior stencil loops from boundary updates. Ghost layers simplify sampling but enlarge storage and need one refresh owner. Stale ghost velocities can make transport and pressure use different wall conditions. Tests should include a constant field, linear pressure ramp, one nonzero face and manufactured divergence-free vortex, checking boundaries as well as interiors.

Rectangular cells and physical units

Let cell widths be hx,hy,hzh_x,h_y,h_z, volume V=hxhyhzV=h_xh_yh_z, and x-face area Sx=hyhzS_x=h_yh_z. Integrating mass flux first, then dividing by volume, gives Sx/V=1/hxS_x/V=1/h_x. Thus the rectangular-grid divergence has different denominators per direction. Replacing all three by one average spacing changes both the PDE and the pressure spectrum.

Pressure in pascals divided by x-center separation hxh_x gives a pressure gradient in pascals per metre. Multiplying by inverse density and time step gives metres per second, as needed for a velocity correction. The x-face correction is

ui,j,k+=ui,j,k∗−Δtρi,j,kxhx(pi,j,k−pi−1,j,k). u^+_{i,j,k}=u^*_{i,j,k} -\frac{\Delta t}{\rho_{i,j,k}^{x}h_x} (p_{i,j,k}-p_{i-1,j,k}).

Substituting all three face corrections into divergence gives the familiar seven-point operator. With constant density, an interior row has diagonal 2/(ρhx2)+2/(ρhy2)+2/(ρhz2)2/(\rho h_x^2)+2/(\rho h_y^2)+2/(\rho h_z^2), and opposite-direction neighbors receive the corresponding negatives. Every coefficient has units inverse density per square metre. The right-hand side is negative physical divergence divided by time step.

This row-divided form is symmetric when all volumes are equal. For unequal cell volumes, dividing each row by its own volume usually destroys Euclidean symmetry. CG must then use a symmetrized integrated system or a correctly weighted formulation. Calling the nonsymmetric row-divided matrix a Laplacian does not make ordinary CG valid.

Integrated metric construction

Separate topology from geometry. Let B be the unscaled incidence matrix, S the diagonal open-face area matrix, L the diagonal pressure-center distance matrix, and V the diagonal cell-volume matrix. Unknown face speed is u. Let Q be the vector of known outward volume flux through prescribed-velocity boundaries. Then

Du=V−1(Q−BSu),Gp=L−1BTp. D u=V^{-1}(Q-BSu),\qquad G p=L^{-1}B^Tp.

The first expression is affine because of known boundary flux. The two-point gradient assumes pressure sample separation is aligned with the face normal and L contains that normal separation. This holds for the selected Cartesian MAC pressure sample locations. Positive areas, distances and volumes alone do not establish consistency for arbitrary cut-cell centroids. Nonorthogonal centroid corrections require a separately derived gradient and matching adjoint operator; they are outside this baseline. An affine-pressure fixture independently checks the normal-gradient consistency and demonstrates failure on a skew connection. With diagonal face density R, correction is u+=u∗−ΔtR−1Gpu^+=u^*-\Delta t R^{-1}Gp. The symmetric integrated pressure system is

Kp=b,K=BSR−1L−1BT,b=(BSu∗−Q)/Δt. Kp=b,\qquad K=BSR^{-1}L^{-1}B^T, \qquad b=(BSu^*-Q)/\Delta t.

For positive geometry and density, face coefficient Se/(ρeℓe)S_e/(\rho_e\ell_e) is nonnegative. K has the same graph energy structure as the Lean model. It is symmetric in the ordinary Euclidean inner product because cell-volume division was left outside the solve. The physical residual relation is now

Du+=−Δt V−1(b−Kp). D u^+=-\Delta t\,V^{-1}(b-Kp).

Consequently a small integrated residual can still produce large divergence in tiny cells. A stopping test should inspect volume-scaled divergence as well as solver norms. The existing Lean theorem is the unweighted algebraic core; this physical metric interpretation is a derived specification.

For dimensional checking, S/(ρℓ)S/(\rho\ell) has units metres to the fourth per kilogram. Multiplying by pressure gives cubic metres per second squared, matching volume flux divided by time. V then converts the corrected flux mismatch to inverse seconds. This check catches missing density, distance and volume factors before a simulation is run.

Coefficient storage

For a regular rectangular grid, store dimensions and three reciprocal spacings once. For irregular geometry, each active face needs open area, pressure distance and density information, or a precomputed transmissibility with provenance. One transmissibility value must be shared by both adjacent pressure rows. Independently computing it twice can introduce asymmetry through different clipping or density choices.

At a density discontinuity, derive the coefficient from the selected pressure-gradient model. For two segments with lengths ℓa,ℓb\ell_a,\ell_b and densities ρa,ρb\rho_a,\rho_b, a series-resistance argument gives transmissibility S/(ρaℓa+ρbℓb)S/(\rho_a\ell_a+\rho_b\ell_b). This differs from blindly averaging inverse density at the face. The correct choice depends on how pressure and acceleration are integrated; retain the derivation and test a one-dimensional interface fixture.

Cell-volume, face-area and center-distance validity are separate checks. A positive volume does not imply a valid connecting face. A zero area removes a connection; a zero distance is invalid. These distinctions determine graph connectivity and pressure gauges.

Original reference illustration for 3 Staggered geometry and discrete operators

Chapter introduction

Loading 3D…