Skip to content

KineticForces: QuadGK adaptive quadrature for energy/pitch/psi integration#220

Closed
logan-nc wants to merge 1 commit into
kineticfrom
feature/quadgk-kinetic-integration
Closed

KineticForces: QuadGK adaptive quadrature for energy/pitch/psi integration#220
logan-nc wants to merge 1 commit into
kineticfrom
feature/quadgk-kinetic-integration

Conversation

@logan-nc
Copy link
Copy Markdown
Collaborator

Summary

  • Replace ODE accumulation (Tsit5) with adaptive Gauss-Kronrod quadrature (QuadGK.jl) for all three KineticForces integration levels (energy, pitch angle, psi)
  • Energy integration uses u-substitution u = 1 - exp(-x) mapping [0,∞) → [0,1) absorbing the Maxwellian weight, eliminating xmax=72 truncation
  • Resonance poles handled analytically via Sokhotski-Plemelj decomposition with complex logarithm formula — works for both collisional (ν > 0) and collisionless (ν → 0) without ximag workaround
  • Trapped-passing boundary (λ = B₀/Bmax) passed as QuadGK breakpoint for pitch integration
  • Both paths switchable via ctrl.integration_method ("quadgk" default, "ode" fallback); matrix methods stay on ODE

Key changes

File Change
Project.toml Add QuadGK dependency
EnergyIntegration.jl find_resonance_energies, collision_frequency, energy_numerator, integrate_energy_quadgk
PitchIntegration.jl integrate_pitch_gar_quadgk, integrate_pitch_quadgk
Compute.jl integrate_psi_quadgk, dispatch in compute_torque_all_methods!
Torque.jl Thread integration_method kwarg through tpsi!calculate_gar
KineticForcesStructs.jl Add integration_method, xmax, ximag to KineticForcesControl
runtests_kinetic.jl 20 new unit tests (resonance roots, CGL analytical, ODE cross-validation)

Test plan

  • 121 kinetic unit tests pass (20 new)
  • Full test suite passes (all test files)
  • Regression: solovev_kinetic_calculated — 15 quantities, 0 diff vs kinetic
  • Regression: solovev_n1 — 20 quantities, 0 diff vs kinetic

🤖 Generated with Claude Code

…itch/psi integration

Replace ODE accumulation (Tsit5) with purpose-built adaptive Gauss-Kronrod
quadrature (QuadGK.jl) for all three KineticForces integration levels.

Energy integration uses a u-substitution u=1-exp(-x) mapping [0,∞)→[0,1)
that absorbs the Maxwellian weight exactly, eliminating the xmax=72
truncation. Resonance poles are handled analytically via Sokhotski-Plemelj
decomposition: the singular part is subtracted and its contribution computed
via the complex logarithm formula, which handles both collisional (ν>0) and
collisionless (ν→0) regimes without the ximag complex contour workaround.

Pitch integration passes the trapped-passing boundary (λ=B₀/Bmax) as a
QuadGK breakpoint to handle the leff/nueff discontinuity. Psi integration
uses QuadGK for scalar torque methods; matrix methods remain on the ODE
path.

Both paths are switchable via ctrl.integration_method ("quadgk" or "ode").
Default is "quadgk". All existing tests pass; 20 new unit tests added
including CGL analytical verification, ODE cross-validation, and resonance
root finding. Regression: 0 diff on solovev_kinetic_calculated and
solovev_n1.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
logan-nc added a commit that referenced this pull request May 23, 2026
…lytic resonance poles

Port the QuadGK energy-integration robustness from PR #220 into the
KineticForces energy integrator, with a corrected pole decomposition.

- Map x = E/T to u = 1-exp(-x) on [0,1), absorbing the Maxwellian weight
  into du, so the integral covers [0,infinity) without an xmax cutoff.
- Remove each resonance pole analytically by a Sokhotski-Plemelj
  decomposition: subtract R/(u-u_pole) and add back the elementary
  integral R*(log(1-u_pole)-log(-u_pole)). The same complex pole u_pole
  (x_pole = x_res - i*nu/Omega') is used in both the subtraction and the
  add-back, so the decomposition is exact and converges for nu > 0 as well
  as nu -> 0 (PR #220 subtracted at the real u_res but added at the
  complex u_pole, which diverges for collisional cases).
- Collisionless limit uses the causal Sokhotski-Plemelj branch.
- CGL has no resonance denominator: integrate the physical x-space
  integrand directly over [0,infinity) via QuadGK.
- ximag is accepted for signature compatibility but is now unused.

Adds find_resonance_energies and unit tests: resonance-root cases, a
collisional cross-check against direct x-space quadrature, and a
collisionless-limit continuity check. 110 kinetic unit tests pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@logan-nc
Copy link
Copy Markdown
Collaborator Author

Superseded by #224.

#224 ported the three robustness techniques from this PR into KineticForces/EnergyIntegration.jl:

  • u-substitution u = 1 − exp(−x) mapping [0,∞) → [0,1), absorbing the Maxwellian weight into du so the energy integral covers the full domain without an xmax cutoff.
  • Analytic resonance-pole extraction via Sokhotski-Plemelj decomposition, with a corrected, consistent subtraction: the same complex u_pole (with x_pole = x_res − iν/Ω′) is used in both the subtraction R/(u − u_pole) and the analytic add-back R·[log(1−u_pole) − log(−u_pole)]. This PR subtracted at the real u_res and added at the complex u_pole, which diverges for collisional ν > 0 — that bug is fixed in KineticForces — Complete PE→KF pipeline and validate DIIID-PENTRC benchmark #224.
  • Resonance locations as QuadGK breakpoints; collisionless ν → 0 handled via the causal Sokhotski-Plemelj branch (∓iπ·sign(Ω′)).

Two additional NaN guards were needed in the calculated-source pipeline that this PR did not exercise: xr > 700 (Maxwellian weight underflows) and !isfinite(ν/Ω′) (collisionally broadened past the localized-pole regime). See #224 for the corrected implementation.

Closing as superseded; the feature/quadgk-kinetic-integration branch will be deleted next.

@logan-nc logan-nc closed this May 23, 2026
@logan-nc logan-nc deleted the feature/quadgk-kinetic-integration branch May 23, 2026 16:57
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