Repository navigation
Control steps on the change of H instead of relaxing back to H = 0 - #89
Merged
DavidMStraub merged 1 commit intoNov 5, 2026
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Changes
TracerSettings.dispersion_error_weight(default 30).constraint_relaxation_rateis removed, so code that passes it breaks.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:
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.
Tests