Skip to content

Control steps on the change of H instead of relaxing back to H = 0 - #89

Merged
DavidMStraub merged 1 commit into
proximafusion:mainfrom
DavidMStraub:feat/h-aware-step-control
Nov 5, 2026
Merged

DavidMStraub merged 1 commit into
proximafusion:mainfrom
DavidMStraub:feat/h-aware-step-control

Conversation

@DavidMStraub

@DavidMStraub DavidMStraub commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

A step that enters the plasma from vacuum can jump over the thin edge-density ramp (a few mm in real space) without placing a Runge-Kutta stage inside it. The embedded error estimate then misses the refraction, and the ray continues off the dispersion surface. Until now a relaxation term in dN/ds pulled H back to zero.

This PR removes the term. Instead, the step-size controller adds the change of H over each step to its error estimate. H is conserved along exact rays, so a step that skips the ramp changes H and is rejected. The cost: traces take 1.3-1.75x longer (see Cost).

Why this approach

  • What actually goes wrong at the edge. The H error comes from one accepted step that crosses the ramp from vacuum. Even with a C2 analytic ramp, the same step misses the refraction (H jumps to 4e-2, tau off by 57% on W7-X). Smaller maximum steps or a smoother ramp don't fix it reliably. Checking the change of H does.
  • Why not keep the relaxation term. It moves N along dH/dN, which is not refraction, and it changes the equations everywhere off the dispersion surface. That breaks invariants (R N_phi drifts by 2e-3 in a tokamak) and the term grows like H / |dH/dN| near cutoffs and reflections. Without it the equations stay Hamiltonian and R N_phi is conserved to integration accuracy (drift 5e-7 in a tokamak O-mode reflection off the cutoff; reflections at cutoffs where |dH/dN| gets very small are not tested yet). Simply dropping it is not enough either: without the H check, tau is off by 16-26% in the same tokamak case.
  • Why cubic profiles anyway. On their own they do not fix the edge at default tolerances, but they make the right-hand side C1 in the profiles, cut steps with the H check by 20-45%, and remove one source of wrong AD gradients (Gradients through trace() are wrong when B, rho or the profiles are linearly interpolated #86).
  • H drift inside the plasma. The remaining drift and most of the extra steps come from the trilinear B and rho (Gradients through trace() are wrong when B, rho or the profiles are linearly interpolated #86), not from the profiles.

Changes

  • New TracerSettings.dispersion_error_weight (default 30). constraint_relaxation_rate is removed, so code that passes it breaks.
  • Density and temperature profiles use a shape-preserving cubic spline instead of linear interpolation. The edge-density ramp starts with the profile's edge slope and ends with zero slope, so the density has a continuous gradient.
  • The Hamiltonian switches to its vacuum form only at ne = 0 (was ne < 1e-6), so H has no jump at the end of the ramp.
  • Steps are accepted at a minimum size of 1 µm, so a remaining jump in H cannot stall the solve.

Accuracy

Optical depth at default settings compared with the same code at tight tolerances (rtol 1e-7, atol 1e-9, max step 5 mm), on 259 absorbing rays from the TRAVIS step-2 scan:

Relative tau error main this PR
Median 0.044% 0.0073%
p90 0.89% 0.53%
Worst 42.6% 11.4%

In a tokamak O-mode case with finite edge density, the drift of R N_phi along the ray drops from 2.4e-3 to 1e-6.

Cost

Traces take 1.3-1.75x longer in five test cases (median of 100 warm calls each), and 1.6-1.7x longer in the TRAVIS scans. Most of the extra steps and rejections come from the trilinear B and rho: H changes in jumps where the ray crosses a cell face. With C1 field interpolation (#86), the controller added only 10-35% steps in tokamak tests.

Validation against TRAVIS

1000 rays per step, compared on the samples that succeed in both versions. Failed samples are nearly unchanged: 18 on main and 17 here in step 1, 48 and 49 in step 2, mostly TRAVIS crashes. The one extra step-2 failure is fixed by #88. These scans ran before #88 was merged.

main this PR
Step 1, median position RMS 0.71 mm 0.61 mm
Step 2, median position RMS 0.47 mm 0.36 mm
Step 2, median tau error 6.5% 6.4%

Tests

  • A finite-edge tokamak trace matches a converged trace (tau within 0.5%), and R N_phi stays constant.
  • The density ramp continues the profile's slope; H is continuous where ne reaches 0.
  • The controller keeps AD gradients correct on an analytic conserved flow.

A step entering the plasma from vacuum can jump over the thin edge-density
ramp without a Runge-Kutta stage inside it, so the embedded error estimate
misses the refraction. Instead of a relaxation term in dN/ds, which breaks
invariants such as R N_phi, the step-size controller adds the change of H
over each step to its error estimate (TracerSettings.dispersion_error_weight,
default 30) and accepts steps at a minimum size of 1 um.

Density and temperature profiles use a shape-preserving cubic spline, the
edge ramp continues the profile slope, and the Hamiltonian switches to its
vacuum form only at ne = 0, so H is continuous at the end of the ramp.

TracerSettings.constraint_relaxation_rate is removed.
@DavidMStraub
DavidMStraub merged commit 7158e17 into proximafusion:main Nov 5, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant