Skip to Content
PhotonStack Gallery
Validation

Analytic and Meep correctness suite

Eight small 2D/3D problems checked against closed-form solutions, against Meep on an identical grid, and GPU-vs-CPU on an RTX 4090.

This page covers the PSFDTD correctness suite: a set of small canonical problems (point dipoles in vacuum, a waveguide bend, dielectric cylinders, a dielectric slab, a dispersive Lorentz slab, a dipole next to a sphere). Each problem is checked three ways: against an analytic solution where one exists, against a local Meep run on exactly the same grid, time step and source, and, for the CUDA backend, against the PSFDTD CPU backend. Every check carries a threshold that was written into the case definition, and the runner exits non-zero if any check fails.

Two baselines exist and they are kept separate below:

  • Apple M3 Max (CPU, with Meep): 7 cases, 82/82 checks passed. This is the run that contains the Meep comparison columns.
  • RTX 4090 (CUDA, no Meep): 8 cases, 82/82 checks passed, of which 46 are GPU-vs-CPU checks. Meep is not installed on that machine, so the Meep comparisons were not re-run there.

Setup

Method. Each case is described once (Meep units, a = 1 µm) and adapters generate both the PSFDTD scene and the Meep simulation. Grid, time step (Courant 0.5, dt = 0.5/res), number of steps, source waveform and time centering are identical in both solvers, so remaining differences come from genuine implementation differences (PML formulation, sub-pixel geometry quadrature) and not from discretization. Both FP64 and FP32 are run: FP64 to push implementation differences to the visible limit, FP32 because it is the default run precision.

Cases.

CaseWhat it exercisesCompared against
dipole2d_vacuum2D TM Yee update, CPML, point-source normalization, time centeringMeep time traces sample by sample; 2D Green's function ratio |H0(k r2)/H0(k r1)| between r=2 and r=4
dipole3d_vacuum3D Yee update, six-plane flux box, DFT normalizationMeep time traces and flux spectrum; Larmor formula F(ω) = ω² |J(ω)|² / 6π
wgbend2dε=12 waveguide of width 1, line source, 100-frequency flux spectra, 90° bend (Meep tutorial)Meep transmission and raw flux spectra
cylinder2d_tmCurved interface, sub-pixel smoothing (diagonal tensor terms); cylinder r=1.13, ε=6.25Meep time traces, flux, point DFT
cylinder2d_teSame cylinder, TE: also exercises the off-diagonal tensor termsMeep time traces, flux, point DFT
slab3d_fresnel3D periodic x/y, PML z, plane source, n=1.5, d=1 slab; uniform 30/µm, coarse uniform 12/µm, and an automatic non-uniform grid (12/µm in vacuum, 30/µm in the slab)Meep; analytic Fabry-Perot transmission
lorentz_slab3dDispersive (lossy Lorentz) ADE: ε∞=2.25 plus one pole (f0=1.5, γ=0.05, σ=1)Analytic complex-index Fabry-Perot at 60 cells/µm with default smoothing
sphere3d_dipole3D sub-pixel smoothing with the full anisotropic tensor: Ez dipole 0.4 µm above an ε=4, r=0.55 sphereMeep flux spectrum and time traces

Hardware and software.

BaselineMachineMeep
M3 MaxApple M3 Max, 16 cores, Darwin 25.6.0 (arm64); run dated 2026-09-271.33.0-beta (serial: conda-forge nompi; MPI: conda-forge mpich)
RTX 4090AMD Ryzen 9 9950X 16-Core, 32 cores, Windows 11; GPU cuda:0 NVIDIA GeForce RTX 4090; run dated 2026-09-29none

Results

All values are errors (lower is better).

Agreement with Meep and analytic solutions (Apple M3 Max, CPU)

CaseChecks passedAgreement with Meep (range over checks)Analytic check
dipole2d_vacuum16/163.3e-06 .. 2.5e-051.7e-05, 1.8e-05, 1.4e-05
dipole3d_vacuum12/122.8e-08 .. 7.3e-041.2e-02
wgbend2d8/85.8e-04 .. 5.7e-03-
cylinder2d_tm14/142.7e-04 .. 4.0e-03-
cylinder2d_te14/144.8e-04 .. 3.9e-03-
slab3d_fresnel10/102.2e-06 .. 4.7e-063.6e-03, 7.1e-03
sphere3d_dipole8/81.3e-05 .. 1.2e-02-

Selected individual checks from the same run (PSFDTD double / single precision, with the threshold):

CaseCheckvsFP64FP32Threshold
dipole2d_vacuumr4 time trace rel-L2Meep2.50e-052.50e-051e-03
dipole2d_vacuum|E(r=4)/E(r=2)| vs Hankel at f=1.0analytic1.76e-051.76e-051e-02
dipole3d_vacuumtotal flux spectrum max rel. diffMeep7.30e-047.30e-041e-03
dipole3d_vacuumflux vs Larmor (0.7 ≤ f ≤ 1.3) max rel.analytic1.21e-021.21e-023e-02
wgbend2dbend transmission max |dT|Meep4.19e-034.19e-032e-02
cylinder2d_tmtran flux max rel. diffMeep3.98e-033.98e-036e-03
cylinder2d_tepoint DFT max rel. diffMeep3.89e-033.89e-036e-03
slab3d_fresneltransmission vs Meep max |dT|Meep2.19e-063.97e-062e-03
slab3d_fresneluniform 30/µm: max |T - T_FP|analytic3.56e-033.56e-031e-02
sphere3d_dipoletotal flux spectrum max rel. diffMeep3.00e-033.00e-036e-03
sphere3d_dipolebelow time trace rel-L2Meep1.19e-021.19e-022e-02

Radiated flux of a 3D dipole in vacuum, PSFDTD vs Meep vs Larmor

dipole3d_vacuum on the M3 Max: total flux through the enclosing box compared with Meep and with the Larmor formula.

Transmission of the 2D waveguide bend, PSFDTD vs Meep

wgbend2d on the M3 Max: bend transmission spectrum, PSFDTD against Meep (max |dT| 4.19e-03).

Flux spectra for TE scattering from a dielectric cylinder

cylinder2d_te on the M3 Max: transmitted and reflected flux for the curved-interface case that exercises the off-diagonal smoothing terms.

Flux spectrum of a dipole next to a dielectric sphere

sphere3d_dipole on the M3 Max: flux spectrum for a curved 3D interface, PSFDTD against Meep (max relative difference 3.00e-03).

GPU backend (RTX 4090, CUDA)

The CPU backend is the reference validated above. On the RTX 4090 the same physics cases are re-run on cuda:0; analytic checks are evaluated as usual and GPU-vs-CPU checks are added (probe-trace rel-L2, flux spectra, point DFT values). GPU-vs-CPU thresholds are 1e-09 (FP64) and 1e-04 (FP32).

CaseChecks passedAnalytic checkLargest GPU-vs-CPU difference (FP64 / FP32)
dipole2d_vacuum14/141.7e-05, 1.8e-05, 1.4e-051.5e-15 / 1.2e-06
dipole3d_vacuum8/81.2e-025.8e-15 / 4.1e-06
wgbend2d8/8-1.2e-15 / 2.2e-07
cylinder2d_tm6/6-2.0e-15 / 9.8e-07
cylinder2d_te6/6-6.5e-16 / 3.7e-07
slab3d_fresnel24/243.6e-03, 9.7e-034.7e-15 / 1.1e-07
lorentz_slab3d12/127.1e-031.6e-14 / 5.1e-07
sphere3d_dipole4/4-6.0e-15 / 3.7e-06

Across all cases the largest GPU-vs-CPU difference is 1.6e-14 in FP64 and 4.1e-06 in FP32.

Fabry-Perot transmission of a dielectric slab on uniform and non-uniform grids

slab3d_fresnel on the RTX 4090: transmission against the analytic Fabry-Perot formula for the fine uniform, coarse uniform and non-uniform grids.

Transmission of a lossy Lorentz slab against the analytic complex-index result

lorentz_slab3d on the RTX 4090: transmission of the dispersive slab against complex-index Fabry-Perot (max |T - T_FP| 7.14e-03).

The GPU backend is additionally compared with the CPU backend at lower levels (RTX 4090):

LevelContentThresholdMeasured
Operators10 operators × FP32/FP64 × 3D/TM/TE, odd sizes, asymmetric CPML, DFT boxes wrapping a periodic boundary, random sparse terms; all mutable arrays comparedFP64 1e-12, FP32 2e-6 (relative to array maximum)FP64 ≤ 3e-16, FP32 ≤ 1.5e-7
Time loop20 consecutive steps in engine order10× the single-operator thresholdFP64 ≤ 3e-15, FP32 ≤ 1.7e-6
End to end2D TM/TE dielectric cylinder, 3D dielectric sphere + Lorentz block + dipole, CPML on all sidesFP64 1e-12, FP32 2e-5FP64 ≤ 3e-15, FP32 ≤ 1.3e-6

Comparison

  • Against Meep 1.33.0-beta (local runs, Apple M3 Max, same grid and time step). Vacuum cases agree to about 1e-5 in the time traces (3.3e-06 to 2.5e-05 in 2D; 2.8e-08 at the source point in 3D). Cases with curved dielectric interfaces agree at the 1e-3 level (2.7e-04 to 4.0e-03 for the cylinders, up to 1.2e-02 for a time trace below the sphere). The slab transmission agrees with Meep to 2.19e-06.
  • Against analytic solutions. 2D Green's function ratio: 1.4e-05 to 1.8e-05. Larmor radiated power: 1.21e-02 (threshold 3e-02). Fabry-Perot transmission on the uniform 30/µm grid: 3.56e-03. Lorentz slab against complex-index Fabry-Perot: 7.14e-03.
  • GPU against CPU (RTX 4090). Differences are at rounding level: FP64 ≤ 1.6e-14, FP32 ≤ 4.1e-06. In FP64 the analytic errors on the GPU are identical to the CPU values to the printed digits.

The remaining differences from Meep have identified causes:

  • PML formulation. Meep uses a UPML-style stretched-coordinate PML with D/B auxiliary fields; PSFDTD uses CFS-CPML. Late reflections differ at the 1e-5 level, which is the source of the roughly 1e-5 differences in the vacuum cases.
  • Sub-pixel quadrature. Meep uses adaptive cubature on the exact geometry with analytic normals; PSFDTD uses a planar signed-distance approximation and falls back to supersampling at edges and corners. For the ε=6.25 cylinder the final fields differ at the 1e-3 level.

Limitations

  • Meep was not run on the RTX 4090 machine. The Meep columns exist only for the M3 Max CPU run. The claim that the GPU backend agrees with Meep is indirect: GPU matches CPU to rounding, and CPU matches Meep as tabulated above.
  • lorentz_slab3d has no Meep comparison in either baseline report. It is absent from the M3 Max baseline (7 cases) and the RTX 4090 run has no Meep. Only the analytic check (7.14e-03) is backed by a baseline report on this page.
  • The non-uniform-grid slab error differs between the two baselines. The non-uniform grid gives max |T - T_FP| = 7.07e-03 in the M3 Max report (ratio to the coarse-uniform error 2.87e-01) and 9.75e-03 in the RTX 4090 report (ratio 3.95e-01), on both the CPU and the GPU columns of that report. The two runs were made on different dates, so this is a difference between runs and not a CPU/GPU difference. The 9.75e-03 value is close to the 1e-02 threshold. The coarse uniform 12/µm grid gives 0.0247 in both.
  • Sources inside the PML are not comparable with Meep. When a current is injected inside the PML the two solvers radiate different fields (measured 4% to 27%), so the suite ends line sources at the PML interface.
  • The Larmor check is the loosest analytic check (1.21e-02 against a 3e-02 threshold).
  • Both baseline reports record the commit as uncommitted.

Reproduce

# all cases, FP64 + FP32, with Meep comparison (requires a local Meep)
python -m bench.run correctness

# a single case / precision
python -m bench.run correctness --cases wgbend2d --precision single

# GPU run without Meep: analytic checks plus GPU-vs-CPU checks
python -m bench.run correctness --no-meep --gpu cuda:0

# operator-level and end-to-end GPU-vs-CPU tests
cargo test --release -p psfdtd-kernels --features cuda --test backend_equivalence
cargo test --release -p psfdtd-core --features psfdtd-kernels/cuda --test gpu_backend

See also the Meep test suite port and GPU performance.

On this page