Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
188 commits
Select commit Hold shift + click to select a range
0df034b
Start envelope 2D module
austin-hoover Jan 5, 2026
1ef0323
Envelope stores empty Bunch object
austin-hoover Jan 5, 2026
1b037fb
Add track method to Envelope2D
austin-hoover Jan 5, 2026
6b84711
Start test script for envelope2D tracker
austin-hoover Jan 5, 2026
13d36e9
Add empty spaceChargeMatrix method
austin-hoover Jan 5, 2026
86fd680
Merge branch 'PyORBIT-Collaboration:main' into env-tracker
austin-hoover Apr 24, 2026
75c133c
Add .idea to .gitignore
austin-hoover Apr 24, 2026
e6efd34
Merge branch 'env-tracker' of https://github.com/austin-hoover/PyORBI…
austin-hoover Apr 24, 2026
7aa7a47
Change Envelope2D to Envelope
austin-hoover Apr 24, 2026
3d0d65c
Update example
austin-hoover Apr 24, 2026
63eb825
Docstrings
austin-hoover Apr 24, 2026
dfeadbd
Add envelope/matrix.py
austin-hoover Apr 24, 2026
a1b32fa
Add MatrixFactory class
austin-hoover Apr 24, 2026
3003c0b
Add several classes to teapot __init__
austin-hoover Apr 24, 2026
e27c57a
Add node types to ignore in matrix factory
austin-hoover Apr 24, 2026
fe81902
Add envelope tracker
austin-hoover Apr 24, 2026
6fad0f7
Delete test script
austin-hoover Apr 24, 2026
d7586c7
Format
austin-hoover Apr 24, 2026
6982c2f
Format
austin-hoover Apr 24, 2026
bc002e1
Fix error in centroid coordinates in example
austin-hoover Apr 24, 2026
7c9abab
Add space charge calculation
austin-hoover Apr 24, 2026
2f67e2c
Add space charge in PIC test + visual comparison of distribution
austin-hoover Apr 24, 2026
7cbe59a
Plot dots
austin-hoover Apr 24, 2026
33b3f16
Fix factor of 2 in perveance calculation
austin-hoover Apr 24, 2026
38f884e
Add kv/waterbag/gauss dist
austin-hoover Apr 24, 2026
c37fc3a
Add tilt to 2D envelope space charge calculation
austin-hoover Apr 24, 2026
752bae3
Add corner plot and tilt test
austin-hoover Apr 24, 2026
e704cdc
Format
austin-hoover Apr 24, 2026
f8987bb
Format
austin-hoover Apr 24, 2026
b9fec41
Add comment on cholesky issue
austin-hoover Apr 24, 2026
09838f6
Delete commented line
austin-hoover Apr 24, 2026
271717a
Edit .gitignore
austin-hoover Apr 24, 2026
5fa7c2b
Docstrings
austin-hoover Apr 24, 2026
0b28b9b
Plot centroid offset for envelope comparison
austin-hoover Apr 27, 2026
18be375
Remove print
austin-hoover Apr 27, 2026
82334dd
Start fixing centroid issue
austin-hoover Apr 27, 2026
ae12bda
Fix centroid issue
austin-hoover Apr 27, 2026
95a45ab
Use eigenvector decomposition
austin-hoover Apr 27, 2026
ff4e888
Start 3D envelope
austin-hoover Apr 27, 2026
478ad15
Move envelope space charge transfer matrix calculations
austin-hoover Apr 27, 2026
ae864df
Add helper functions
austin-hoover Apr 27, 2026
6775b0c
Set perveance_3d to 0
austin-hoover Apr 27, 2026
f918721
Keep trying to implement 3D space charge
austin-hoover Apr 27, 2026
6b876e7
Add 3D drift test
austin-hoover Apr 27, 2026
6def869
Add comment
austin-hoover Apr 27, 2026
d43cbf3
Clarify attempt to calculate 3D sc matrix
austin-hoover Apr 28, 2026
b75520b
Add comment
austin-hoover Apr 30, 2026
db2212a
Correct formula for 3D space charge matrix
austin-hoover May 1, 2026
68f5d63
Update matrices
austin-hoover May 1, 2026
9f268e2
Fix plotting
austin-hoover May 1, 2026
6671086
Format
austin-hoover May 1, 2026
2fe1c2c
Add comments
austin-hoover May 1, 2026
5a34ee6
Delete a few unused lines
austin-hoover May 1, 2026
1537400
Add test_env_sns_ring
austin-hoover May 1, 2026
edec43d
Add options for handling matrix elements without known matrix
austin-hoover May 1, 2026
3c0c1b8
Add tests
austin-hoover May 1, 2026
328af0b
Typo
austin-hoover May 1, 2026
391acb0
Fix type
austin-hoover May 1, 2026
6921eda
Check dipole matrix
austin-hoover May 1, 2026
b9bc1bf
Update tests_sns_ring.py
austin-hoover May 1, 2026
5834bc2
Fix dipole matrix calculation for parts
austin-hoover May 1, 2026
a2ad2ac
Typo
austin-hoover May 1, 2026
789f70c
Test sns ring
austin-hoover May 1, 2026
64e83f4
Scale last column of matrix by dp_p coeff
austin-hoover May 12, 2026
1860df5
Merge branch 'main' into env-tracker
austin-hoover Jun 10, 2026
889391f
Update tests
austin-hoover Jun 10, 2026
9882d71
Modify atol and rtol in np.isclose
austin-hoover Jun 10, 2026
7c30aa2
Add energy spread and rms z to cov matrix tests
austin-hoover Jun 10, 2026
4897409
Fix dp/p to dE correction in transfer matrices
austin-hoover Jun 11, 2026
1f73d39
Fix kick matrix
austin-hoover Jun 11, 2026
f674b12
Fix atol/rtol in tests
austin-hoover Jun 11, 2026
ae9f605
Fix confusion on covariance vs. moments matrix
austin-hoover Jun 11, 2026
1327296
Clean up script
austin-hoover Jun 11, 2026
1a86b99
Clean up script
austin-hoover Jun 11, 2026
74ff3e0
Fix test
austin-hoover Jun 11, 2026
6ca2ada
Add simplified SNS ring example
austin-hoover Jun 11, 2026
303d11a
Add test_tilt
austin-hoover Jun 11, 2026
989e0fd
Add nparts to tests
austin-hoover Jun 11, 2026
37f70c6
Remove docstring
austin-hoover Jun 12, 2026
ff9e322
Add NodeTEAPOT to ignore list
austin-hoover Jun 12, 2026
cb323d6
Replace MultipoleTEAPOT with drift if all strengths are zero
austin-hoover Jun 12, 2026
2962c54
Don't change sync particle time in matrixfactor
austin-hoover Jun 12, 2026
c743dd4
Add solenoid to envelope tracker
austin-hoover Jun 12, 2026
7b11821
Fix drift replacement
austin-hoover Jun 12, 2026
913fd6e
Start adding nodes from orbit.py_linac
austin-hoover Jun 19, 2026
6ff8c16
Fix x-axis label in 3d drift example
austin-hoover Jun 19, 2026
05fa0de
Start 3D drift with rotation example
austin-hoover Jun 19, 2026
4ab6ab2
Fix longitudinal coordinate of 3D space charge matrix
austin-hoover Jun 19, 2026
40d18cf
Change argument in gen_dist examples
austin-hoover Jun 19, 2026
511b585
Move functions out of MatrixFactory
austin-hoover Jun 23, 2026
81eac6d
Remove funcs
austin-hoover Jun 23, 2026
7c2d22c
Write `matrix` function for each node
austin-hoover Jun 24, 2026
83c2d79
Print node when matrix function not implemented
austin-hoover Jun 24, 2026
0547877
Clean up
austin-hoover Jun 24, 2026
4414c89
Move matrix calculation to new module
austin-hoover Jun 24, 2026
f06d073
Fix lorentz transform of xyz cov matrix in example
austin-hoover Jun 24, 2026
5dbf992
Fix arg in gen_dist
austin-hoover Jun 24, 2026
9e018b7
Remove comment
austin-hoover Jun 24, 2026
38b80cf
Remove skip line
austin-hoover Jun 24, 2026
1167aaf
Rename self.perveance to self.sc_factor
austin-hoover Jun 24, 2026
4e14a44
Add empty test function test_sc_3d_cold_expansion
austin-hoover Jun 24, 2026
d215c68
Lorentz transform was not used in 3D space charge
austin-hoover Jun 24, 2026
7be8745
Add comments
austin-hoover Jun 24, 2026
5cd2ba0
Use matrix for lorentz transform of cov matrix
austin-hoover Jun 24, 2026
d1ce6fc
Remove comments
austin-hoover Jun 24, 2026
0136565
Fix gamma factor in 3D space charge
austin-hoover Jun 24, 2026
9008457
Looking good for upright beams relativistic + nonrelativistic
austin-hoover Jun 24, 2026
9898015
Fix lorentz boost for x' and y'
austin-hoover Jun 24, 2026
ce89cac
Use eigh instead of eig for cov matrix eigvectors
austin-hoover Jun 24, 2026
90a6dc5
Formatting and comments
austin-hoover Jun 24, 2026
6b6148b
Merge branch 'PyORBIT-Collaboration:main' into env-tracker
austin-hoover Jun 24, 2026
a079b33
Remove commented lines
austin-hoover Jun 24, 2026
e7b0958
Add rf_gap_matrix function
austin-hoover Jun 24, 2026
1c5250d
Remove setting sync part time (does nothing in MatrixRFGap)
austin-hoover Jun 24, 2026
a6c1879
Print time when tracking through sns ring
austin-hoover Jun 24, 2026
7358600
Return drift or none if params are zero in TEAPOT nodes
austin-hoover Jun 24, 2026
41d245d
Remove comment
austin-hoover Jun 24, 2026
5b9349a
Add decimal to time per turm when printing
austin-hoover Jun 24, 2026
b149eb5
Add profiler
austin-hoover Jun 24, 2026
8b28895
Small speedup: conversion from dp_p to dE
austin-hoover Jun 24, 2026
674c743
Remove handle_unknown
austin-hoover Jun 24, 2026
3b2ac80
Longer lines
austin-hoover Jun 24, 2026
389a1b1
Add test_env_sns_ring_speed.py
austin-hoover Jun 24, 2026
85b4dd9
Remove old argument handle-unknown
austin-hoover Jun 24, 2026
f232115
Formatting
austin-hoover Jun 24, 2026
43d850f
Change defaults in test_env_sns_ring_speed.py
austin-hoover Jun 24, 2026
bdca2f3
Add checks for linac node transfer matrices
austin-hoover Jun 24, 2026
14f0947
Run tests at different energies
austin-hoover Jun 24, 2026
d2bd722
Split lattice in test_env_sns_ring_speed
austin-hoover Jun 24, 2026
850666a
Use @property for accessing cov_matrix and mean attributes
austin-hoover Jun 24, 2026
d705ffc
Reduce default turns
austin-hoover Jun 24, 2026
b04d0e4
Avoid using np.linalg.inv
austin-hoover Jun 24, 2026
3ec7131
Use -1 instead of dim
austin-hoover Jun 24, 2026
7295de4
Use cov matrix for bunch length calculation
austin-hoover Jun 24, 2026
14fb649
Use rotation instead of eigenvector calc for 2D space charge
austin-hoover Jun 24, 2026
3c6b8c9
Track cov and mean instead of 7 x 7 moment matrix
austin-hoover Jun 24, 2026
1e1da89
Add charge as argument everywhere
austin-hoover Jun 25, 2026
ed1fb0a
Start SNS linac envelope tracking example
austin-hoover Jun 25, 2026
8bd62e6
Add charge param to tests
austin-hoover Jun 25, 2026
0edcfa4
Turn off fringe fields in sns linac example
austin-hoover Jun 25, 2026
f7da0aa
Change default seq stop
austin-hoover Jun 25, 2026
c2cb355
Start linac benchmark
austin-hoover Jun 25, 2026
cf4d7c7
Copy bunch in envelope constructor
austin-hoover Jun 25, 2026
9e5c25c
track kin energy
austin-hoover Jun 25, 2026
0885fba
Improve sns linac benchmark
austin-hoover Jun 25, 2026
6049381
Fix envelope tracker position
austin-hoover Jun 25, 2026
763dd48
Add show arg
austin-hoover Jun 25, 2026
dd367b9
SNS linac benchmark working
austin-hoover Jun 25, 2026
1709bca
Don't connect dots when plotting rms history
austin-hoover Jun 25, 2026
4d34da7
Fix space charge factor: make dynamic
austin-hoover Jun 25, 2026
0b0467a
Decrease step size for diagnostics
austin-hoover Jun 25, 2026
64f4276
Move all envelope tracking code to orbit.envelope module
austin-hoover Jun 25, 2026
add4f9f
Rename examples
austin-hoover Jun 25, 2026
75adc28
Format tests
austin-hoover Jun 25, 2026
9930326
Undo old changes to modules outside orbit.envelope
austin-hoover Jun 25, 2026
6c405e2
Use covariance matrix from initial bunch in sns ring example
austin-hoover Jun 25, 2026
41c0de5
Documentation
austin-hoover Jun 25, 2026
10d329a
Change bend nparts to match teapot
austin-hoover Jun 25, 2026
46b78bd
Increase nparts in bend test
austin-hoover Jun 25, 2026
af17446
Change axis label in yrms and yavg plots
austin-hoover Jun 25, 2026
99987a1
Set edge angles to zero with warning
austin-hoover Jun 25, 2026
17af040
Combine space charge and body transfer matrices by transform
austin-hoover Jun 25, 2026
bd954db
Zero ea1 ea2 in sns_ring script
austin-hoover Jun 25, 2026
febd45f
Fix bunch length calculation in 2D space charge
austin-hoover Jun 25, 2026
c8dc962
SNS linac default
austin-hoover Jun 26, 2026
6911001
Calculate space charge matrix before calculating transfer matrix
austin-hoover Jun 26, 2026
0bf05a0
Fix comment
austin-hoover Jun 26, 2026
3064cc3
Use rest length in space charge kick
austin-hoover Jun 26, 2026
9175260
Typo: remove self
austin-hoover Jun 26, 2026
573e38f
Formatting
austin-hoover Jun 26, 2026
c23a80f
Add choice of phase space distribution for sns linac benchmark
austin-hoover Jun 26, 2026
0dc141a
Format
austin-hoover Jun 26, 2026
d1a32f1
Add to-do comment
austin-hoover Jun 27, 2026
95f53ab
Add continuous linear focusing element to envelope tracking
austin-hoover Jun 27, 2026
76c68e6
Add continous linear focusing element to envelope tests
austin-hoover Jun 27, 2026
bff8f34
Add envelope.copy function
austin-hoover Jun 27, 2026
2db3220
Pre-calculate matrices for ring tracking
austin-hoover Jun 29, 2026
21dc3dc
Fix bunch length in 2D fodo example; use track_ring
austin-hoover Jun 29, 2026
edbc9f1
Move tests to /tests folder for use with pytest
austin-hoover Jun 29, 2026
39fd357
Add to-do comment
austin-hoover Jun 29, 2026
1532fce
Rename track_sync_part_ to get_matrix_
austin-hoover Jun 29, 2026
2526673
Remove comment
austin-hoover Jun 29, 2026
c279777
Add docstring
austin-hoover Jun 29, 2026
db5cd49
Organize orbit.envelope module
austin-hoover Jun 29, 2026
0f782bf
Clean up examples
austin-hoover Jun 30, 2026
1311f4e
Fix tests
austin-hoover Jun 30, 2026
42163eb
Merge branch 'PyORBIT-Collaboration:env-tracker' into env-tracker
austin-hoover Jun 30, 2026
3403d5d
Move get_classical_radius to utils.py
austin-hoover Jun 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store
.idea
build
PyORBIT.egg-info
.vscode
Expand Down
129 changes: 129 additions & 0 deletions examples/Envelope/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches


def calc_rms_ellipse_params(cov_matrix: np.ndarray) -> tuple[float, float, float]:
"""Return rms ellipse dimensions and orientation."""
i, j = (0, 1)

sii = cov_matrix[i, i]
sjj = cov_matrix[j, j]
sij = cov_matrix[i, j]

angle = -0.5 * np.arctan2(2.0 * sij, sii - sjj)

_sin = np.sin(angle)
_cos = np.cos(angle)
_sin2 = _sin**2
_cos2 = _cos**2

c1 = np.sqrt(abs(sii * _cos2 + sjj * _sin2 - 2 * sij * _sin * _cos))
c2 = np.sqrt(abs(sii * _sin2 + sjj * _cos2 + 2 * sij * _sin * _cos))

return (c1, c2, angle)


def plot_ellipse(
r1: float = 1.0,
r2: float = 1.0,
angle: float = 0.0,
center: tuple[float, float] = None,
ax=None,
**kws,
):
kws.setdefault("fill", False)
kws.setdefault("color", "black")
kws.setdefault("lw", 1.25)

if center is None:
center = (0.0, 0.0)

d1 = r1 * 2.0
d2 = r2 * 2.0
angle = -np.degrees(angle)

ax.add_patch(patches.Ellipse(center, d1, d2, angle=angle, **kws))
return ax


def plot_rms_ellipse(
cov_matrix: np.ndarray,
level: float = 1.0,
ax=None,
**ellipse_kws,
):
"""Plot rms ellipse from 2 x 2 covariance matrix."""
r1, r2, angle = calc_rms_ellipse_params(cov_matrix)
plot_ellipse(r1 * level, r2 * level, angle=angle, ax=ax, **ellipse_kws)
return ax


def plot_corner(
particles: np.ndarray,
limits: list[tuple[float, float]] = None,
bins: int = 64,
labels: list[str] = None,
blur: float = None,
) -> tuple:
"""Generate corner plot."""
ndim = particles.shape[1]

if limits is None:
xmax = np.max(particles, axis=0)
xmin = np.min(particles, axis=0)
limits = list(zip(xmin, xmax))

if labels is None:
labels = ndim * [""]

fig, axs = plt.subplots(ncols=ndim, nrows=ndim, sharex=None, sharey=None, figsize=(8, 8))
for i in range(ndim):
for j in range(ndim):
axis = (j, i)
ax = axs[i, j]
if i > j:
values, edges = np.histogramdd(
particles[:, axis], bins=bins, range=[limits[k] for k in axis]
)
if blur:
values = scipy.ndimage.gaussian_filter(values, sigma=blur)
ax.pcolormesh(
edges[0],
edges[1],
values.T,
linewidth=0.0,
rasterized=True,
shading="auto",
)
elif i == j:
values, edges = np.histogram(particles[:, i], bins=bins, range=limits[i])
if blur:
values = scipy.ndimage.gaussian_filter(values, sigma=blur)
ax.stairs(values, edges, lw=1.5, color="black")
else:
ax.axis("off")

for i in range(0, ndim - 1):
for j in range(0, ndim):
axs[i, j].set_xticklabels([])
for i in range(0, ndim):
for j in range(1, ndim):
axs[i, j].set_yticklabels([])

for ax in axs.flat:
for loc in ["top", "right"]:
ax.spines[loc].set_visible(False)

for i, label in enumerate(labels):
axs[-1, i].set_xlabel(label)
for i, label in enumerate(labels[1:], start=1):
axs[i, 0].set_ylabel(label)

axs[0, 0].set_yticklabels([])
axs[0, 0].set_ylabel(None)

fig.align_ylabels()
fig.align_xlabels()

return fig, axs
56 changes: 56 additions & 0 deletions examples/Envelope/sns_linac/diagnostics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import numpy as np

from orbit.core.bunch import Bunch
from orbit.core.bunch import BunchTwissAnalysis


class BunchMonitor:
def __init__(self) -> None:
self.twiss_calc = BunchTwissAnalysis()
self.position_start = 0.0

self.history = {}
self.history["position"] = []
self.history["rms_x"] = []
self.history["rms_y"] = []
self.history["rms_z"] = []
self.history["kin_energy"] = []

def __call__(self, params_dict: dict) -> None:
bunch = params_dict["bunch"]
node = params_dict["node"]
position = params_dict["path_length"]

if params_dict["old_pos"] == position:
return
if params_dict["old_pos"] + params_dict["pos_step"] > position:
return
params_dict["old_pos"] = position
params_dict["count"] += 1

sync_part = bunch.getSyncParticle()

self.twiss_calc.analyzeBunch(bunch)

cov_matrix = np.zeros((6, 6))
for i in range(6):
for j in range(6):
cov_matrix[i, j] = cov_matrix[j, i] = self.twiss_calc.getCorrelation(i, j)

xrms = 1000.0 * np.sqrt(cov_matrix[0, 0])
yrms = 1000.0 * np.sqrt(cov_matrix[2, 2])
zrms = 1000.0 * np.sqrt(cov_matrix[4, 4])

message = ""
message += " s={:0.3f}".format(position + self.position_start)
message += " xrms={:0.3f}".format(xrms)
message += " yrms={:0.3f}".format(yrms)
message += " zrms={:0.3f}".format(zrms)
message += " node={}".format(node.getName())
print(message)

self.history["position"].append(position + self.position_start)
self.history["rms_x"].append(xrms)
self.history["rms_y"].append(yrms)
self.history["rms_z"].append(zrms)
self.history["kin_energy"].append(sync_part.kinEnergy())
Loading