Repository navigation
Spin push for thin kick elements - #1606
Conversation
Merging this PR will not alter performance
Performance Changes
Comparing |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
|
The error is due to a warning associated with a possible loss of precision (double > float conversion) when running w/ SIMD. |
CI is correct, this was a bug. Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
|
Thanks for the PR! 🎉 I fixed the bug that CI caught. |
Used by compilers and our SIMD implementation to optimize write-backs into memory.
The spin push duplicated the complex sqrt/log/division block from operator() and then called operator(), which recomputed it. That evaluated the most expensive part of the element twice per particle. Hoist it into dF_dzeta() and single-source the momentum kick in apply_kick(), so the phase space push and the spin push share one evaluation. F'(zeta) does not change over the thin kick, so the spin push reuses the same value for the magnetic field and for the kick. Numerically identical: both evaluations had identical inputs, and py - m_kick*dF.m_imag is the same IEEE operation as the previous py + dpy with dpy = -m_kick*dF.m_imag. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
@cemitch99 a general question on the implementation of half-kicks here: midpoint is 1 Is there a reason to prefer the half-kick structure that I'm missing? |
The geometric factor -(1 + h*x)/beta_gamma_z in the Thomas-BMT precession vector is a Frenet-Serret Jacobian and needs the design-orbit curvature. Passing h and B_y at half strength and scaling the generator by the full arc length gives the correct half-step contribution for every term that enters linearly, but evaluates (1 + h*x) with half the curvature, an error of order 0.5*x/rc on the field part of the rotation. Reversibility does not catch it: the construction is self-inverting for any value of h. Move the factor of one half from h and B_y onto the arc length, which is equivalent for the linear terms and matches the convention already used by ExactCFbend (h = 1/rc, unscaled fields, generator scaled by the step). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Evaluate the Thomas-BMT generator once, at the momentum halfway through the kick, instead of applying two half rotations around the phase space kick. This is the structure already used by TaperedPL. Both forms are exactly reversible and second order: the reversed element maps p_out back to p_in, so it sees the same midpoint, and the negated strength gives the inverse rotation. They differ at third order, where the midpoint rule has half the error constant of the trapezoidal rule that two half kicks amount to. Per particle this costs 1 tbmt_precession_vector + 1 rotate_spin instead of 2 of each. Measured on the thin Multipole, which has the same structure, that was ~28% off the spin push (~39% of the spin-specific part) and 2x smaller error against a converged reference. Applies to Kicker, Buncher, NonlinearLens and ThinDipole, whose fields depend only on coordinates the kick leaves unchanged. Buncher also changes the energy deviation, so pt is averaged along with the transverse momenta. ShortRF keeps the half kick form: it changes the reference energy, so px/py/pt are renormalized across the kick and a plain average would mix two normalizations. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
In case midpush sounds good to you, I prepared a PR for this branch that you can apply directly: If you merge the linked PR to your fork then the PR here will automatically update. |
Performance: Midpoint Spin Push for Thin Kicks
|
@ax3l Ok, ready for re-review. |
This PR adds the spin push through those
Thinelements not associated with fringe fields. The logic for all of these elements uses the same pattern, and only the evaluation of the magnetic or electric fields should differ.The implementation here is$s$ -symmetric. A reversibility test will be included.
ShortRFto midpush scheme? Performance: Midpoint Spin Push for Thin Kicks cemitch99/impactx#4This closes Issue #1322