Skip to content

Implement envelope tracker#112

Merged
azukov merged 188 commits into
PyORBIT-Collaboration:env-trackerfrom
austin-hoover:env-tracker
Jun 30, 2026
Merged

Implement envelope tracker#112
azukov merged 188 commits into
PyORBIT-Collaboration:env-trackerfrom
austin-hoover:env-tracker

Conversation

@austin-hoover

@austin-hoover austin-hoover commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

This PR implements an envelope/centroid tracker (Issue #51). We track the centroid $\mathbf{\mu} = \langle \mathbf{x} \rangle$ and covariance matrix $\mathbf{\Sigma} = \langle (\mathbf{x} - \mathbf{\mu}) (\mathbf{x} - \mathbf{\mu})^T \rangle$, where $\mathbf{x} = [x, x', y, y', z, \Delta E ]^T$ is the 6D phase space vector.

Evolution equations:

$$ \begin{align} \mathbf{x} &\rightarrow \mathbf{M} \mathbf{x} + \mathbf{u} , \\ \mathbf{\mu} &\rightarrow \mathbf{M} \mathbf{\mu} + \mathbf{u} , \\ \mathbf{\Sigma} &\rightarrow \mathbf{M} \mathbf{\Sigma} \mathbf{M}^T . \end{align} $$

Accelerator nodes and child nodes are mapped to transfer matrices at the Python level. An error is raised if the node is not recognized. Space charge is handled by assuming a uniform charge density within an ellipsoid in the $x$-$y$-$z$ plane (for 3D space charge) or within an ellipse in the $x$-$y$ plane (for 2D space charge).

@austin-hoover

Copy link
Copy Markdown
Contributor Author

The SNS linac benchmark uses the SpaceChargeCalcUniformElllipse solver with one ellipsoid and the MatrixRFGap model for rf cavities. The tracking shows dependence on the initial distribution; the closest result is for the 6D KV distribution.

python test_sns_linac.py --seq-stop CCL1 --sc 0 --dist kv
fig_history_rms
python test_sns_linac.py --seq-stop CCL1 --sc 1 --dist kv
fig_history_rms
python test_sns_linac.py --seq-stop CCL1 --sc 1 --dist waterbag
fig_history_rms
python test_sns_linac.py --seq-stop CCL1 --sc 1 --dist gauss
fig_history_rms

@austin-hoover austin-hoover marked this pull request as ready for review June 26, 2026 19:00
@austin-hoover austin-hoover marked this pull request as draft June 26, 2026 19:02
@austin-hoover austin-hoover added the enhancement New feature or request label Jun 26, 2026
@austin-hoover austin-hoover self-assigned this Jun 26, 2026
Added method `track_ring` to EnvelopeTracker. It will pre-calculate the
transfer matrices in the ring and mark the locations of space charge kicks.
If tracking without space charge, it will compute and apply the one-turn
matrix. Otherwise it will step through each element.

This assumes there is no change of the synchronous particle energy and that
all nodes in the lattice are static.

parser.add_argument("--nparts", type=int, default=10_000)
parser.add_argument("--turns", type=int, default=25)
parser.add_argument("--sc", type=int, default=0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't really matter, but just an FYI: instead of storing an int, if you want an on/off switch you can do something like

parser.add_argument("--sc", action="store_true")

Which will toggle space charge by just calling the script with that flag

script.py --sc

@austin-hoover

Copy link
Copy Markdown
Contributor Author

Notes from meeting:

  • Do not merge yet.
  • Try implementing trackEnvelope functions for each node rather than current implementation.
  • Add option to use matrix fitting for unknown or nonlinear elements.
  • Look into SNS linac example a bit more. I think it makes sense but want to check against OpenXAL implementation.

Separate files:
- envelopy.py has Envelope class definition.
- track.py has EnvelopeTracker class definition.
- matrix.py has functions to get transfer matrices from AccNode
@austin-hoover austin-hoover changed the base branch from main to env-tracker June 30, 2026 01:09
@austin-hoover austin-hoover marked this pull request as ready for review June 30, 2026 01:24
@azukov azukov merged commit 0a0b2d2 into PyORBIT-Collaboration:env-tracker Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants