The staggered finite-difference method

Maple

Why stagger the grid?

A staggered finite-difference method places selected unknowns at different spatial locations. This lets a difference between neighboring face values approximate a derivative at the cell center, while a difference between center values gives a derivative at a face. The layout is useful for first-order wave systems, where different field components are coupled through spatial derivatives.

I originally started this note with a one-dimensional acoustic model.[1] The finite-cavity solver in our 3D-CWT repository now provides a concrete application: four optical envelopes live on cell faces, their coupling is evaluated at cell centers, and incoming boundary waves are eliminated exactly. This post connects the elementary stencil to that implementation. For the optical derivation, see CWT in PCSEL.

Spatial staggering in one dimension and the face-centered four-wave CWT layout
Spatial staggering in one dimension and the face-centered four-wave CWT layout

(a) A one-dimensional staggered pair. (b) The finite-CWT layout: orange circles carry Rx,SxR_x,S_x, blue squares carry Ry,SyR_y,S_y, and gray crosses mark the equation centers. Each boundary label constrains only the named incoming wave; the outgoing wave at the same location remains free.

One-dimensional problem

A first-order wave system

Consider the constant-speed system

∂u∂t=c∂v∂x,∂v∂t=c∂u∂x.\frac{\partial u}{\partial t}=c\frac{\partial v}{\partial x}, \qquad \frac{\partial v}{\partial t}=c\frac{\partial u}{\partial x}.

Here uu and vv are scaled wave variables and c>0c>0 is the propagation speed. Eliminating either variable gives the wave equation, for example utt=c2uxxu_{tt}=c^2u_{xx}. The original normalized example corresponds to c=1c=1.

Let the cell faces be xi=ihx_i=ih, and the centers be xi+1/2=(i+1/2)hx_{i+1/2}=(i+1/2)h. Store viv_i on faces and ui+1/2u_{i+1/2} at centers. Then

∂v∂x∣i+1/2≈vi+1−vih,∂u∂x∣i≈ui+1/2−ui−1/2h.\left.\frac{\partial v}{\partial x}\right|_{i+1/2} \approx\frac{v_{i+1}-v_i}{h}, \qquad \left.\frac{\partial u}{\partial x}\right|_i \approx\frac{u_{i+1/2}-u_{i-1/2}}{h}.

Although each expression uses two values, it is centered about the location where the derivative is evaluated. Taylor expansion about that midpoint gives

f(x+h/2)−f(x−h/2)h=f′(x)+h224f′′′(x)+O(h4).\frac{f(x+h/2)-f(x-h/2)}{h} =f'(x)+\frac{h^2}{24}f'''(x)+O(h^4).

The approximation is therefore second order for a smooth field. Its denominator is hh, the distance between the two samples, not 2h2h.

One motivation is the grid-scale alternating pattern vi=(−1)iv_i=(-1)^i. A collocated centered derivative (vi+1−vi−1)/(2h)(v_{i+1}-v_{i-1})/(2h) vanishes on this pattern, while the staggered derivative (vi+1−vi)/h(v_{i+1}-v_i)/h does not. Staggering changes the derivative’s discrete nullspace; boundary treatment and the complete coupled operator still require their own checks.

Optional staggering in time: leapfrog

For explicit wave propagation, also place uu at integer times and vv at half times:

ui+1/2n+1=ui+1/2n+cΔth(vi+1n+1/2−vin+1/2),vin+3/2=vin+1/2+cΔth(ui+1/2n+1−ui−1/2n+1).\begin{aligned} u_{i+1/2}^{n+1} &=u_{i+1/2}^{n} +\frac{c\Delta t}{h}\left(v_{i+1}^{n+1/2}-v_i^{n+1/2}\right),\\ v_i^{n+3/2} &=v_i^{n+1/2} +\frac{c\Delta t}{h}\left(u_{i+1/2}^{n+1}-u_{i-1/2}^{n+1}\right). \end{aligned}

The two updates alternate, each using values at the other variable’s latest time level. Half-time initial data must be supplied consistently, for example through a half-step from the prescribed initial fields.

For a uniform infinite or periodic grid, Fourier analysis gives

sin⁡2(ωΔt2)=(cΔth)2sin⁡2(kh2).\sin^2\left(\frac{\omega\Delta t}{2}\right) =\left(\frac{c\Delta t}{h}\right)^2 \sin^2\left(\frac{kh}{2}\right).

For unrestricted staggered initial data, a sufficient stability condition is cΔt/h<1c\Delta t/h<1. The familiar upper bound cΔt/h≤1c\Delta t/h\le1 follows from the real-frequency condition, but equality needs separate treatment: when the grid admits the Nyquist mode, its amplification matrix has a nontrivial Jordan block and generic initial data can grow linearly in the step count. Space and time staggering are separate choices: the CWT eigenproblem below uses the spatial layout without this leapfrog time update.

Two-dimensional problem

A two-dimensional wave system needs two directional components:

ut=c(∂xvx+∂yvy),(vx)t=c ∂xu,(vy)t=c ∂yu.\begin{aligned} u_t&=c\left(\partial_xv_x+\partial_yv_y\right),\\ (v_x)_t&=c\,\partial_xu,\\ (v_y)_t&=c\,\partial_yu. \end{aligned}

Use ui+1/2,j+1/2u_{i+1/2,j+1/2} at cell centers, (vx)i,j+1/2(v_x)_{i,j+1/2} at xx faces, and (vy)i+1/2,j(v_y)_{i+1/2,j} at yy faces. The discrete divergence is

(∇h⋅v)i+1/2,j+1/2=(vx)i+1,j+1/2−(vx)i,j+1/2hx+(vy)i+1/2,j+1−(vy)i+1/2,jhy.(\nabla_h\cdot\mathbf v)_{i+1/2,j+1/2} =\frac{(v_x)_{i+1,j+1/2}-(v_x)_{i,j+1/2}}{h_x} +\frac{(v_y)_{i+1/2,j+1}-(v_y)_{i+1/2,j}}{h_y}.

The corresponding gradient at an xx face is

(∂xhu)i,j+1/2=ui+1/2,j+1/2−ui−1/2,j+1/2hx,(\partial_x^hu)_{i,j+1/2} =\frac{u_{i+1/2,j+1/2}-u_{i-1/2,j+1/2}}{h_x},

with the analogous expression at a yy face. These differences connect face and center grids naturally. For the constant-speed explicit leapfrog scheme on a uniform periodic grid, a sufficient two-dimensional CFL condition is

c2Δt2(1hx2+1hy2)<1.c^2\Delta t^2\left(\frac{1}{h_x^2}+\frac{1}{h_y^2}\right)<1.

The equality endpoint has the same critical-mode qualification as in one dimension. Boundary conditions must match the underlying wave problem. A closed acoustic boundary and an open optical aperture impose different conditions even when their variable locations look similar.

Application: the finite-cavity CWT equations

Four envelopes and four transport directions

For the square-lattice TE model, write the slowly varying envelopes as

V=(Rx,Sx,Ry,Sy)T.\mathbf V=(R_x,S_x,R_y,S_y)^{\mathsf T}.

The finite-domain equations are[2]

ΛV=CV+i(∂xRx−∂xSx∂yRy−∂ySy),Λ=δ+iα.\Lambda\mathbf V=C\mathbf V+\mathrm{i} \begin{pmatrix} \partial_xR_x\\-\partial_xS_x\\ \partial_yR_y\\-\partial_yS_y \end{pmatrix}, \qquad \Lambda=\delta+\mathrm{i}\alpha.

CC is a uniform 4×44\times4 coupling matrix calculated from the vertical waveguide and photonic-crystal geometry. Here β0=2π/a\beta_0=2\pi/a, with lattice period aa, and δ=(β2−β02)/(2β0)≃β−β0\delta=(\beta^2-\beta_0^2)/(2\beta_0)\simeq\beta-\beta_0 is the linearized Bragg detuning of the reference guided propagation constant β\beta. In the package, lengths are in µm, while CC, δ\delta, and α\alpha have units µm⁻¹. The convention is exp⁡(+iωt)\exp(+\mathrm{i}\omega t), and α\alpha is an amplitude-loss coefficient; power loss uses 2α2\alpha. Thus Λ\Lambda is not a complex angular frequency, and α\alpha is not a temporal decay rate.

Unlike the acoustic example, this is a stationary eigenvalue problem. We reuse the face–center discretization structure, not derive the optical equations from the acoustic system. Spatially staggering the envelopes does not introduce a time step or a CFL condition into its solution.

Locations, array shapes, and incoming boundaries

Divide [0,Lx]×[0,Ly][0,L_x]\times[0,L_y] into Nx×NyN_x\times N_y cells:

hx=Lx/Nx,hy=Ly/Ny.h_x=L_x/N_x,\qquad h_y=L_y/N_y.

Store the fields as follows. NumPy arrays use row =y=y, column =x=x.

FieldLocationFull array shapeFixed incoming boundary
RxR_x(xi,yj+1/2)(x_i,y_{j+1/2})(Ny, Nx+1)Rx[:, 0] = 0
SxS_x(xi,yj+1/2)(x_i,y_{j+1/2})(Ny, Nx+1)Sx[:, -1] = 0
RyR_y(xi+1/2,yj)(x_{i+1/2},y_j)(Ny+1, Nx)Ry[0, :] = 0
SyS_y(xi+1/2,yj)(x_{i+1/2},y_j)(Ny+1, Nx)Sy[-1, :] = 0

For example, the left boundary fixes RxR_x, but leaves SxS_x free to leave the cavity. Applying zero to both would change the open-boundary problem.

The free arrays are Rx[:, 1:], Sx[:, :-1], Ry[1:, :], and Sy[:-1, :]. Each has NxNyN_xN_y entries, giving exactly

ndof=4NxNyn_{\mathrm{dof}}=4N_xN_y

free complex amplitudes and the same number of cell-centered equations. The implementation packs them component by component in the order (Rx,Sx,Ry,Sy)(R_x,S_x,R_y,S_y), flattening each block in C order. Incoming values are omitted from the unknown vector and restored as exact zeros when reconstructing fields; there are no penalty constants or extra corner variables.

These cells resolve the slow cavity envelope, not the individual photonic-crystal periods. NxN_x and NyN_y are numerical controls, not counts of unit cells in the physical device.

Average the field; difference the transport

Every local coupling term needs all four fields at the same cell center. In the expressions below, center subscripts i,ji,j label the cell at (xi+1/2,yj+1/2)(x_{i+1/2},y_{j+1/2}). For example,

Rˉx;i,j=Rx;i,j+1/2+Rx;i+1,j+1/22,\bar R_{x;i,j} =\frac{R_{x;i,j+1/2}+R_{x;i+1,j+1/2}}{2},

(DxRx)i,j=Rx;i+1,j+1/2−Rx;i,j+1/2hx.(D_xR_x)_{i,j} =\frac{R_{x;i+1,j+1/2}-R_{x;i,j+1/2}}{h_x}.

Use the same average for SxS_x, but reverse the derivative sign. For Ry,SyR_y,S_y, average bottom and top faces and difference along yy, again reversing the sign for SyS_y.

For any component ff, the adjacent-face average satisfies

f(x−h/2)+f(x+h/2)2=f(x)+h28f′′(x)+O(h4).\frac{f(x-h/2)+f(x+h/2)}{2} =f(x)+\frac{h^2}{8}f''(x)+O(h^4).

Both the interpolation and the derivative are second order. The local RxR_x equation is therefore

ΛRˉx;i,j=∑ℓ=14C1ℓVˉℓ;i,j+iRx;i+1,j+1/2−Rx;i,j+1/2hx.\Lambda\bar R_{x;i,j} =\sum_{\ell=1}^4 C_{1\ell}\bar V_{\ell;i,j} +\mathrm{i}\frac{R_{x;i+1,j+1/2}-R_{x;i,j+1/2}}{h_x}.

The eigenvalue multiplies the average, not one of the face values. This distinction produces the matrix BB in the generalized problem.

Sparse assembly: Av=ΛBvAv=\Lambda Bv

Let vv contain the free face amplitudes; this packed optical vector is unrelated to the earlier acoustic variable vv. Define BvBv as the stacked cell-center averages and DvDv as the stacked signed differences. With component-major ordering, let Clift=C⊗INxNyC_{\mathrm{lift}}=C\otimes I_{N_xN_y} denote application of the same local coupling to every cell. Then

A=CliftB+iD,Av=ΛBv.A=C_{\mathrm{lift}}B+\mathrm{i}D, \qquad Av=\Lambda Bv.

This Kronecker product describes the operator mathematically; the implementation assembles local sparse triplets directly without constructing a dense lifted matrix.

For each retained face, averaging contributes 1/21/2. A difference contributes ±1/hx\pm1/h_x or ±1/hy\pm1/h_y, with the transport sign of its component. Coupling into receiver equation rr contributes Crℓ/2C_{r\ell}/2. When a face is a prescribed incoming zero, its column is simply omitted.

For a four-cell xx row, the averaging blocks are

BRx=12(1000110001100011),BSx=BRxT.B_{R_x}=\frac12 \begin{pmatrix} 1&0&0&0\\ 1&1&0&0\\ 0&1&1&0\\ 0&0&1&1 \end{pmatrix}, \qquad B_{S_x}=B_{R_x}^{\mathsf T}.

Thus BB is an interpolation operator and is generally non-Hermitian, even though it is square. On this boundary-eliminated layout its blocks are triangular with nonzero diagonal, so BB is invertible. It is not the symmetric positive-definite mass matrix assumed by some generalized eigensolver interfaces.

For a generic fully populated CC, the local stencil gives at most eight nonzeros per row of AA, and at most two per row of BB. Assembly and sparse storage scale linearly with NxNyN_xN_y. Sparse LU factorization can have additional fill-in; linear assembly storage does not imply linear eigensolve cost.

A one-cell check

A single cell has four free outgoing values and four incoming zeros. Its matrices are

B=12I4,D=diag⁡(hx−1,hx−1,hy−1,hy−1),B=\frac12I_4, \qquad D=\operatorname{diag}\left(h_x^{-1},h_x^{-1},h_y^{-1},h_y^{-1}\right),

A=12C+iD.A=\frac12C+\mathrm{i}D.

All four diagonal entries of DD are positive here. For SxS_x, for instance, the signed difference is −(0−Sx,left)/hx-(0-S_{x,\mathrm{left}})/h_x. This tiny example checks transport signs, averaging factors, and boundary elimination before any large solve.

Shift-invert without forming B−1B^{-1}

To find eigenvalues near a complex target σ\sigma, require A−σBA-\sigma B to be invertible and use

T=(A−σB)−1B.T=(A-\sigma B)^{-1}B.

An eigenpair Tv=μvTv=\mu v gives

Λ=σ+1μ.\Lambda=\sigma+\frac{1}{\mu}.

The code factors the sparse matrix A−σBA-\sigma B once, exposes TT as a linear operator, and calls ARPACK through SciPy. It does not form a dense inverse or blindly pass this non-Hermitian BB as an SPD mass matrix.

The returned vector is checked against the original pencil using

η=∥Av−ΛBv∥2(∥A∥F+∣Λ∣∥B∥F)∥v∥2.\eta=\frac{\|Av-\Lambda Bv\|_2} {\left(\|A\|_F+|\Lambda|\|B\|_F\right)\|v\|_2}.

A small residual shows that the approximate eigenpair satisfies the original discrete equations to the stated tolerance. It does not by itself bound eigenvalue forward error for a non-normal or nearly defective pencil. Mesh refinement is a separate test of how that discrete problem approximates the continuous one. A targeted search also covers only the modes near its selected shift.

A discrete power identity

The face-average construction has an exact telescoping property. For complex face values a,ba,b,

2Re⁡[(a+b2)∗b−ah]=∣b∣2−∣a∣2h.2\operatorname{Re}\left[ \left(\frac{a+b}{2}\right)^*\frac{b-a}{h}\right] =\frac{|b|^2-|a|^2}{h}.

Summing over cells cancels every interior face contribution. Write U=BvU=Bv and define

Pedge=hy∑j(∣Rx(Lx,yj+1/2)∣2+∣Sx(0,yj+1/2)∣2)+hx∑i(∣Ry(xi+1/2,Ly)∣2+∣Sy(xi+1/2,0)∣2).\begin{aligned} P_{\mathrm{edge}}={}&h_y\sum_j\left( |R_x(L_x,y_{j+1/2})|^2+|S_x(0,y_{j+1/2})|^2\right)\\ &+h_x\sum_i\left( |R_y(x_{i+1/2},L_y)|^2+|S_y(x_{i+1/2},0)|^2\right). \end{aligned}

The exact discrete identity is

2hxhyIm⁡[U†(Av−CliftU)]=Pedge.2h_xh_y\operatorname{Im}\left[ U^\dagger\left(Av-C_{\mathrm{lift}}U\right)\right] =P_{\mathrm{edge}}.

It holds for any free complex vector, not only an eigenmode, so it can test assembly independently of the eigensolver. For an eigenmode, define P=hxhy∥U∥22P=h_xh_y\|U\|_2^2 to obtain

2αP=Pedge+2hxhyIm⁡(U†CliftU).2\alpha P=P_{\mathrm{edge}} +2h_xh_y\operatorname{Im}\left(U^\dagger C_{\mathrm{lift}}U\right).

A Hermitian CC makes the volume term vanish. For the optical coupling matrix, its anti-Hermitian part accounts for open radiation channels under the model’s stated conditions. For an arbitrary complex test matrix, keep this as a signed coupling contribution rather than automatically calling it radiated power.

The package normalizes reconstructed modes to P=1P=1. These quantities are envelope norms and loss budgets; they are not calibrated optical powers in watts. The plotted envelope intensity is the cell-centered sum ∣Rx∣2+∣Sx∣2+∣Ry∣2+∣Sy∣2|R_x|^2+|S_x|^2+|R_y|^2+|S_y|^2, without the fast unit-cell interference pattern.

Verification with smooth manufactured fields

To test spatial accuracy independently of an eigensolver, prescribe smooth complex fields satisfying the incoming zeros. On a 30×20 μm230\times20\ \mu\mathrm m^2 rectangle, use

Rx=a1(x/Lx)3(1+0.2y/Ly),Sx=a2(1−x/Lx)3(1+0.2y/Ly),Ry=a3(y/Ly)3(1+0.2x/Lx),Sy=a4(1−y/Ly)3(1+0.2x/Lx),\begin{aligned} R_x&=a_1(x/L_x)^3(1+0.2y/L_y),\\ S_x&=a_2(1-x/L_x)^3(1+0.2y/L_y),\\ R_y&=a_3(y/L_y)^3(1+0.2x/L_x),\\ S_y&=a_4(1-y/L_y)^3(1+0.2x/L_x), \end{aligned}

with (a1,a2,a3,a4)=(1+2i,2−i,−0.5+i,3+0.7i)(a_1,a_2,a_3,a_4)=(1+2\mathrm{i},2-\mathrm{i},-0.5+\mathrm{i},3+0.7\mathrm{i}). Sample these fields on faces and compare the assembled averages and derivatives with their analytic values at cell centers.

For the full operator, use the deliberately illustrative Hermitian matrix

C=(00.020.010.010.0200.010.010.010.0100.020.010.010.020) μm−1.C=\begin{pmatrix} 0&0.02&0.01&0.01\\ 0.02&0&0.01&0.01\\ 0.01&0.01&0&0.02\\ 0.01&0.01&0.02&0 \end{pmatrix}\ \mu\mathrm m^{-1}.

This matrix is a numerical test input, not a coupling matrix extracted from a particular PCSEL. Define each relative error as the Euclidean norm of the discrete-minus-analytic vector divided by the norm of its analytic reference. The full-operator comparison uses AvAv against the analytic center samples of

CV+i(∂xRx,−∂xSx,∂yRy,−∂ySy)T.C\mathbf V+\mathrm{i}(\partial_xR_x,-\partial_xS_x,\partial_yR_y,-\partial_yS_y)^{\mathsf T}.

No eigenvalue is solved for these prescribed fields. For Nx=Ny=NN_x=N_y=N, actual execution of package version 1.4.0 gives:

NNCenter-average errorSigned-derivative errorFull-operator error
81.81128 × 10⁻²2.93064 × 10⁻³4.44798 × 10⁻³
164.48832 × 10⁻³7.29074 × 10⁻⁴1.10709 × 10⁻³
321.11961 × 10⁻³1.82046 × 10⁻⁴2.76467 × 10⁻⁴
642.79749 × 10⁻⁴4.54975 × 10⁻⁵6.90978 × 10⁻⁵

Measured second-order refinement of the actual staggered CWT spatial operators
Measured second-order refinement of the actual staggered CWT spatial operators

Relative errors of center averaging, signed differentiation, and the full spatial operator. The dashed line is an N−2N^{-2} reference. These are manufactured-field consistency checks, not physical-device eigenmode results.

The observed orders log⁡2(eN/e2N)\log_2(e_N/e_{2N}) range from 2.0004 to 2.0128 over these refinements. Separately, random complex vectors on the same grids satisfy the outgoing-flux identity to relative errors below 3×10−163\times10^{-16} in this run. The first test measures spatial truncation; the second checks the discrete algebra. Neither replaces Fourier-cutoff convergence of the optical coupling or tracking the same physical eigenmode across cavity grids.

A runnable Python example

Install the matching package with python -m pip install cwt3d==1.4.0. The following example uses the same illustrative matrix to exercise the actual sparse assembler, eigensolver, and field reconstruction:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import numpy as np
from cwt3d.finite import (
StaggeredGrid, assemble_pencil, solve_finite, reconstruct_modes,
)

# Synthetic test coupling in um^-1, not a device-derived optical matrix.
C = np.array([
[0, 0.02, 0.01, 0.01],
[0.02, 0, 0.01, 0.01],
[0.01, 0.01, 0, 0.02],
[0.01, 0.01, 0.02, 0],
], dtype=complex)

grid = StaggeredGrid(Nx=16, Ny=12, Lx_um=30, Ly_um=20)
pencil = assemble_pencil(grid, C)
result = solve_finite(
pencil, sigma=-0.03 + 0.04j, k=3,
tol=1e-10, residual_tol=1e-9, seed=33,
)
modes = reconstruct_modes(pencil, result)

assert grid.n_dof == 4 * 16 * 12
for mode in modes:
assert mode.boundary_error == 0
assert mode.residual < 1e-9
assert mode.budget["balance_relative_error"] < 1e-10
print(mode.delta, mode.alpha, mode.residual)
print("edge loss:", mode.budget["edge"])
print("center field:", mode.centers.Rx.shape)

The run returns three modes, each with center arrays of shape (12, 16). Because CC is Hermitian, the nonzero α\alpha comes from the outgoing boundaries and the edge budget equals 2α2\alpha after normalization. To calculate a device, replace this test matrix with coupling.C from the optical pipeline described in the repository’s API guide.

The implementation is separated into grid and boundary indexing, sparse assembly, targeted eigensolving, and field reconstruction and power budgets. The assembly tests include independent small-matrix, manufactured-field, and outgoing-flux checks.

References


  1. The staggered finite-difference method (交错网格有限差分方法), 数值分析大巴. The one- and two-dimensional wave examples motivate the introductory sections; the indexing convention here places uu at cell centers. ↩︎

  2. Y. Liang, Three-dimensional coupled-wave theory for photonic-crystal surface-emitting lasers, doctoral thesis, Kyoto University. DOI: 10.14989/doctor.k18283. Chapter 4, Eqs. (4.21)–(4.22), gives the finite-envelope equations and no-incoming-wave boundary conditions. ↩︎

  • Title: The staggered finite-difference method
  • Author: Maple
  • Created at : 2023-06-25 13:52:40
  • Updated at : 2026-11-01 12:50:55
  • Link: https://www.maple367.eu.org/Numerical-Analysis/the-staggered-finite-difference-method/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments