Repository navigation
Conversation
…ch-angle integral Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
2 open issues
What changed in this PR
Fixes an overestimate of the trapped-particle fraction used in neoclassical resistivity by switching to the exact pitch-angle integral definition used by the Sauter (1999) fits.
Changes:
- Replace the old trapped-fraction estimate with an exact pitch-angle integral using Gauss–Legendre quadrature nodes (
trapped_fraction_nodes+trapped_fraction). - Update
resist_geometryto compute ⟨√(1 − λ h)⟩ consistently with existing θ-averages and removeB_mintracking. - Add regression tests validating the exact integral against reference values and checking the Lin-Liu & Miller approximation accuracy.
| File | Description |
|---|---|
| test/runtests_slayer_params.jl | Adds tests for the exact trapped-fraction integral and Lin-Liu & Miller approximation. |
| src/Utilities/Utilities.jl | Updates exports to expose new trapped-fraction helpers. |
| src/Utilities/NeoclassicalResistivity.jl | Introduces exact integral implementation, quadrature-node generation, and keeps Lin-Liu & Miller approximation as a helper. |
| src/ForceFreeStates/Surfaces/ResistEval.jl | Computes trapped fraction from the exact pitch-angle integral using new θ-integrand columns. |
Review effort: Lite
| lambda, lambda_weight = Utilities.NeoclassicalResistivity.trapped_fraction_nodes() | ||
| ff = zeros(Float64, ntheta, 8 + length(lambda)) | ||
| weight = zeros(Float64, ntheta) |
| all(>(0), avg_sqrt) || throw(ArgumentError("trapped_fraction: ⟨√(1 − λh)⟩ must be > 0")) | ||
| return clamp(1.0 - 0.75 * avg_h2 * sum(weight ./ avg_sqrt), 0.0, 1.0) | ||
| end | ||
|
|
matt-pharr
left a comment
There was a problem hiding this comment.
The physics correction is right, and I would retain it. The exact integral, normalization h = B/B_max, transformed quadrature weights, and jac/v1 flux-surface weighting are consistent. The Lin-Liu–Miller helper also matches the upper and lower bounds in Lin-Liu & Miller (1995), Eqs. (1), (4), and (7), DOI: 10.1063/1.871315.
Requesting two small revisions before merging:
- Qualify the quadrature accuracy and test weak trapping. The docstring at
src/Utilities/NeoclassicalResistivity.jl:185says 16 nodes give approximately 1e-9 accuracy, but this is not generally true. Using the test's model B = 1/(1 + epsilon*cos(theta)) with its uniform theta average, a numerical check of the PR implementation gives:
| epsilon | 16 nodes | Converged result |
|---|---|---|
| 0.05 | 0.3187784577 | 0.3187784522 |
| 0.0001 | 0.0146683403 | 0.0146236428 |
| 0.000001 | 0.0003978316 | 0.0014624244 |
The check used 16,384 equally spaced theta samples. For epsilon = 1e-6, 256 and 512 pitch-angle nodes give 0.00146242437809 and 0.00146242435857 respectively. The current tests start at epsilon = 0.05 and miss this limitation. Please add a weak-trapping convergence test and state the default quadrature's accuracy range. If accurate near-axis values are required, refine the quadrature there; describing the underlying integral as exact does not guarantee numerical accuracy.
- Fix the failing formatting check. JuliaFormatter wants the exports docstring table in
NeoclassicalResistivity.jlrealigned. Package tests and documentation CI otherwise pass.
All five reference values in the added test were reproduced. The posted regression report records unchanged ideal/GGJ results and substantial SLAYER changes, consistent with correcting the resistivity input. That report was reviewed rather than independently rerunning the full harness. The numerical checks above ran under Julia 1.13; a local Julia 1.11 attempt encountered a dependency incompatibility.
…e for the formatter Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BgNxCF8ZswFaPqyk7i111H
There was a problem hiding this comment.
@d-burg — pushed one commit, then what is left.
Pushed
34d8641derealigns the exports table inNeoclassicalResistivity.jlfor JuliaFormatter 1.0.62 (the second item of @matt-pharr's review). Table whitespace only, so no number moves, but it is undersrc/and has made the release-note stamp stale: it only needs moving to34d8641de.
Physics
- Checked independently: f_t = 1 − ¾⟨h²⟩∫₀¹ λ dλ/⟨√(1 − λh)⟩ with h = B/B_max; the λ = 1 − x² map and the weights w·2x(1 − x²) (they sum to ½); and the
jac/v1weighting of the new θ columns. All correct. Thedevelopformula it replaces (h = B_min/B_max with ⟨B⟩²/⟨B²⟩) is neither Lin-Liu–Miller bound, so this is a real fix. - Still open: the quadrature accuracy near the axis (first item of Pharr's review, not yet answered). The integrand varies over 1 − λ ~ 2ε, i.e. x ~ √(2ε), which 16 nodes on [0, 1] stop resolving below ε ~ 1e-3. Rational surfaces rarely sit there, so SLAYER is safe today, but see the reconcile note below: a profile evaluation down to the axis would hit it. Either scale the node map with the surface (e.g. split the x interval at √(1 − h_min)), or state the validity range and leave it. The inline suggestion does the latter.
Reconcile with two other open PRs
Three branches now carry a trapped fraction:
| PR | What it does |
|---|---|
| this one | exact integral in trapped_fraction; trapped_fraction_lin_liu_miller = ¾f_tu + ¼f_tl, exported but used only by the test |
| #665 (modified Rutherford equation) | edits the same trapped_fraction to the Lin-Liu–Miller upper bound f_tu alone, keeping the unused B_min argument; adds sauter2002_trapped_fraction(ε, δ) for RDCON parity |
| #667 (Redl bootstrap current) | adds circulating_fraction = 1 − (¾f_tu + ¼f_tl), the same formula as this PR's helper, on a profile that reaches the axis |
Recommended order:
- Merge this PR first. It is the most accurate of the three.
- #665 drops its hunk in
NeoclassicalResistivity.jl(it conflicts and is superseded) and keepssauter2002_trapped_fractiononly where RDCON parity is the point; elsewhere it readsResistGeometry.f_trap. - #667 calls
trapped_fraction_lin_liu_millerinstead of carrying a second copy, which also gives that helper a caller insrc/. If #667 later wants the exact value on its profile, the near-axis item above becomes binding.
I will make the changes to #665 and #667 once this one is in.
Tests
- The five reference values come from the same integral at higher order. Add one independent check: f_t → 1.46√ε as ε → 0 for this model field (Pharr's converged 1.4624e-3 at ε = 1e-6 is that limit), at whatever ε the final quadrature is claimed to reach.
No merge without approval from a human reviewer. This comment is not an approval.
|
|
||
| Lin-Liu & Miller 1995, Phys. Plasmas **2**, 1666, Eq. (6): | ||
| Pitch-angle nodes for [`trapped_fraction`](@ref): `n`-point Gauss-Legendre in x ∈ [0, 1] with λ = 1 − x², so that | ||
| ∫₀¹ λ g(λ) dλ ≈ Σₖ weight[k] g(lambda[k]). The x map removes the √ edge behavior at λ → 1; 16 nodes give f_t to ~1e-9. |
There was a problem hiding this comment.
The 1e-9 holds only away from the axis: with the test's model field the error is 5e-9 at ε = 0.05, 4.5e-5 at ε = 1e-4 and order one at ε = 1e-6 (numbers from Pharr's review).
| ∫₀¹ λ g(λ) dλ ≈ Σₖ weight[k] g(lambda[k]). The x map removes the √ edge behavior at λ → 1; 16 nodes give f_t to ~1e-9. | |
| ∫₀¹ λ g(λ) dλ ≈ Σₖ weight[k] g(lambda[k]). The x map removes the √ edge behavior at λ → 1; 16 nodes give f_t to ~1e-8 for | |
| inverse aspect ratio ε ≳ 0.05 and lose accuracy below ε ~ 1e-3, where the integrand varies over x ~ √(2ε). |
There was a problem hiding this comment.
Superseded by 3f636f84c, which grades the nodes to √(1 − B_min/B_max) instead of stating a limit. The docstring now gives the measured range (f_t within 1e-10 for 0 ≤ ε ≤ 0.9), and the test pins it, including the small-ε limit 1.4624√ε.
…B_min/B_max A single 16-node Gauss-Legendre panel in x (λ = 1 − x²) misses the integrand's structure at x ~ √(1 − B_min/B_max), so f_t lost accuracy below ε ~ 1e-3 (−1.1e-3 at ε = 1e-6, where f_t = 1.5e-3). trapped_fraction_nodes(h_min) now places 16 nodes on each geometric panel [0, s], [s, 8s], … , 1 with s = √(1 − h_min), holding f_t to 1e-10 for 0 ≤ ε ≤ 0.9 on the model surface. resist_geometry tracks B_min again to supply h_min. The test extends to ε = 1e-6 at atol 1e-10, checks node doubling, uniform |B|, and the independent small-ε limit f_t/√ε → 1.4624249524 from the boundary-layer integral. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@matt-pharr @logan-nc Thanks, both. You were right about weak trapping, and Quadrature. I took Logan's first option. With λ = 1 − x², the integrand varies on x ~ √(1 − B_min/B_max), so
Independent check. The boundary layer at λ → 1 gives f_t → C√ε, with C = ¾∫₀^∞ [y^(−1/2) − 1/⟨√(y + 1 + cos θ)⟩] dy = 1.4624249524 (panel b). The test checks that limit at ε = 1e-5 to 1e-7, along with the references to 1e-10 down to ε = 1e-6, node doubling, and uniform |B| giving zero. Harness (feynman, now in the PR body): the quadrature change alone moves the SLAYER layer inputs by about 1e-10 relative, with γ and ω unchanged. Only CRF Q_peak moves visibly (0.06–0.17 %), from its peak search. Against develop, SLAYER γ still moves by 28–32 %, and the ideal and GGJ cases are unchanged. Order. Agreed: this PR first, then #665 drops its |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>


Release note
f_trapdrops (by about 0.17 at mid radius in the DIII-D-like cases), so the Sauter neoclassical η, the Lundquist number S and every SLAYER growth rate move; SLAYER γ changes by up to 32 % in the harness cases. Ideal and GGJ results are unchanged. (harness @ 3f636f8)Utilities.trapped_fraction(avg_B, avg_Bsq, B_min, B_max)is replaced bytrapped_fraction(avg_h2, avg_sqrt, weight)(pair it withtrapped_fraction_nodes()); for a quick estimate from ⟨B⟩, ⟨B²⟩, B_max and ⟨h⁻²(1 − √(1 − h)(1 + h/2))⟩ usetrapped_fraction_lin_liu_miller. No input files change; regenerate any cached Sauter η tables or SLAYER results.The trapped fraction used for neoclassical resistivity was overestimated.
resist_geometrynow computes it from the exact pitch-angle integral, f_t = 1 − ¾⟨h²⟩∫₀¹ λ dλ / ⟨√(1 − λh)⟩ with h = B/B_max, which is the quantity the Sauter (1999) fits are defined against.Regression report
Run on feynman in a clean worktree at 3f636f8, with
--refs e08c719cb,002db486e,3f636f84c --force --jobs 1, 8 threads; e08c719 is this branch's base on develop. The table compares that base with 3f636f8. Between 002db48 and 3f636f8 (the graded pitch-angle nodes), the SLAYER layer inputs move by about 1e-10 relative, γ, ω and Q_root are unchanged within tolerance, and CRF Q_peak moves by 0.06–0.17 %.Notes for reviewers
What was wrong.
NeoclassicalResistivityevaluated 1 − ⟨B⟩²/⟨B²⟩ (1 − √(1 − h)(1 + h/2)) with h = B_min/B_max. That is neither the exact trapped fraction nor Lin-Liu & Miller (1995), whose upper bound uses h̄ = ⟨B⟩/B_max. The flux-surface averages themselves were correct.What changed.
trapped_fraction_nodes(h_min)returns pitch-angle nodes for the λ integral, mapped through λ = 1 − x² so the √ endpoint singularity at λ = 1 is removed. The integrand varies on the scale x ~ √(1 − h_min) with h_min = B_min/B_max, so the nodes are 16-point Gauss–Legendre on the geometric panels [0, s], [s, 8s], … , 1 with s = √(1 − h_min): 16 nodes for uniform |B|, up to 112 at ε = 1e-10, and f_t within 1e-10 for 0 ≤ ε ≤ 0.9 on the model surface.resist_geometryaverages √(1 − λₖ h) on the same periodic-spline θ integral as the other GGJ columns, then callstrapped_fraction(⟨h²⟩, ⟨√(1 − λh)⟩, w). It tracksB_minto place the nodes.trapped_fraction_lin_liu_milleris kept as the cheap approximation (0.75 f_tu + 0.25 f_tl, as in OMFITfluxSurface.py) for cross-checks.Cross-check against OMFIT (
fluxSurfaces, f_t = 1 − fc, which is Lin-Liu & Miller), on 257×257 g-files:Before this PR the same q = 2 / 3 / 4 surfaces gave 0.844 / 0.886 / 0.900, and the TJ q = 2 surface gave 0.656 (exact 0.492).
With the Lin-Liu & Miller form in
resist_geometrythe code matches OMFIT to 1e-4. The exact integral sits 3–6e-4 above it, which is the expected size of the LLM error.ResistGeometry.f_trapfeeds both the Sauter η and the SLAYER layer inputs, so S, P_⊥, τ_k and Q move together; the harness rows above show exactly that set changing and nothing upstream of it.🤖 Generated with Claude Code