Skip to content

Uniform grid: energy and divergence ​

CasesIssuesTypeBackendsFigureRegression
periodic-pulse-blocks— (base)PCPU, FNLnoperiodic-pulse-blocks (digest + residuals, CPU and FNL)

Case and scope ​

A Gaussian pulse travels once around a box periodic on every face. On a uniform grid the source-free Maxwell system keeps two discrete invariants: the electromagnetic energy, up to the time integrator, and the divergences ∇h⋅D and ∇h⋅B, exactly. The centred curl and divergence are built from the same antisymmetric first-derivative stencil, so ∇h⋅(∇h×⋅)=0 holds to round-off.

What the case catches:

  • a dissipative or unstable space operator: the energy must stay flat over one crossing;
  • a broken discrete identity: the divergence histories must stay at round-off;
  • broken periodicity across blocks and ranks: the 64 blocks are split 32/32 over two ranks, so the pulse crosses block faces owned by different ranks and the periodic faces themselves. The former same-block wrap fails the digest on all 192 residual rows.

Every other page builds on these identities: the AMR and inter-realm pages measure what a seam does to them.

Models and numerics ​

ItemChoiceCode
EquationsMaxwell in D, B, SI units (physical_model = EM), no sourcesmodels
Spacecentred finite differences of order 6 (fd_centered, fdv_order = 6)compute_curl_fd_centered, compute_divergence_fd_centered, adam_fdv_operators_library.F90; numerics
TimeSSP Runge–Kutta, 5 stages, 4th order (runge-kutta-ssp-54), CFL 0.5: Δt=Δx/(4c)adam_rk_object.F90; numerics
Periodic facesthe library periodicity (BC_PERIODIC): periodic tree neighbours and the ghost exchange across blocks and ranksboundary conditions
FNL backendthe same kernels on the deviceadam_prism_fnl_object.F90

Initial and boundary conditions ​

ItemValue
Domain[−0.1,0.1]3 m
Grid483 cells: 64 blocks of 123 (iu_ref_levels = 2), Δx=0.2/48, ngc = 3
Ranks2 (32 blocks each)
Initial conditionGaussian pulse along +x, r0 = 0.07, sigma = 0.015, k0 = 0, B0 = 10
Boundariesperiodic on all six faces
Steps192 = one crossing of the box

Input files ​

FileRole
src/tests/prism/regression/periodic-pulse-blocks/input.inithe case
src/tests/prism/regression/periodic-pulse-blocks/golden/{cpu,fnl}/the digest and the residuals log run.sh compares
src/tests/tutorials/compare_saves.pycompares two saves of a run block by block (the return error)
bash
REGRESSION_CASES=periodic-pulse-blocks src/tests/prism/regression/run.sh cpu --no-build   # the digest

The case is also tutorial 1, which walks through the run and its outputs.

Results ​

CheckBoundCPUFNL
digest and residuals against the goldenrtol = 1e-6, atol = 1e-3passpass
total energy WD+WB, relative drift over 192 steps—1.2⋅10−61.2⋅10−6
WD against WBequal (travelling wave)equal to 15 digitsequal to 15 digits
|∇⋅D|, |∇⋅B|, last row of the divergence historyround-off0, 00, 0
64 blocks on 2 ranks against one 483 block—≈2⋅10−15—
return after one crossing, max|q(192)−q(0)|/max|q(0)|, Bz and Dy—3.961⋅10−2—

Findings ​

  • The energy drift, 1.2⋅10−6 over one crossing, is the Runge–Kutta's: the centred scheme is non-dissipative.
  • The divergences stay at zero: on a uniform grid the identity ∇h⋅∇h×=0 is exact.
  • The 4 % return error is not the scheme's. The initial Gaussian is not wrapped across the periodic faces, so the field jumps by 18 % of the peak at x=0.1; a 1-D model of the run gives 4.0 % with the cut and 0.14 % with a wrapped pulse (tutorial 1).
  • The block layout does not change the solution beyond round-off: the 64-block run matches the single-block run to 2⋅10−15.