-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
188 additions
and
131 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import numpy as np | ||
|
||
from sylt.tracking import Bunch, Ring, Tracker | ||
|
||
from properties import ring_properties, bunch_properties | ||
|
||
ring = Ring(**ring_properties) | ||
|
||
NUM_TURNS = 5_000 # number of tracked turns | ||
N = 200e10 # bunch intensity | ||
n = 30_000 # number of macro particles | ||
ng = n - 1_000 # number of ghost particles | ||
|
||
# Define Trackers | ||
trackers = { | ||
'SPM': Tracker(Bunch(**bunch_properties, n=n), ring), | ||
'SPM+SC': Tracker(Bunch(**bunch_properties, n=n, N=N), ring), | ||
'SPM+SC+TM': Tracker(Bunch(**bunch_properties, n=n, N=N, eps=None), ring) | ||
} | ||
|
||
if __name__ == "__main__": | ||
|
||
for key, tracker in trackers.items(): | ||
|
||
# Define "Ghost" Particles | ||
tracker.UPDATE = False | ||
tracker.bunch.w[:ng] = np.zeros(ng) | ||
tracker.bunch.tau[:ng] = np.random.choice( | ||
np.linspace(-1, 1, 300)*tracker.tau_hat, ng) | ||
|
||
# Track Particles | ||
data = np.empty((2, NUM_TURNS, n)) | ||
for turn in range(NUM_TURNS): | ||
tracker.track() | ||
data[:, turn] = tracker.bunch.tau, tracker.bunch.w | ||
|
||
# Clean Distribution | ||
data[:, :, tracker.clean(tracker.bunch.tau, tracker.bunch.w)] = np.nan | ||
|
||
# Export Data | ||
np.savez(f"./data/{key}", tau=data[0], w=data[1], | ||
N=tracker.bunch.N, eps=tracker.bunch.eps, | ||
**ring_properties, **bunch_properties, ng=ng, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import matplotlib.pyplot as plt | ||
|
||
from sylt.tracking import Bunch, Ring, Tracker | ||
|
||
from properties import ring_properties, bunch_properties | ||
|
||
ring = Ring(**ring_properties) | ||
|
||
bunch = Bunch( | ||
**bunch_properties, | ||
n=50_000, # number of macroparticles | ||
# N=200e10, # include intensity effects | ||
eps=None, # initialize transverse distribution | ||
) | ||
|
||
tracker = Tracker(bunch, ring) | ||
|
||
tracker.show('start') | ||
|
||
tracker.match(k=0.5) | ||
tracker.show('mismatched') | ||
|
||
for turn in range(1_000): | ||
tracker.track() | ||
|
||
tracker.clean() | ||
tracker.show('stop') | ||
|
||
plt.savefig('./figs/demo.png') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import matplotlib.pyplot as plt | ||
from matplotlib.animation import FuncAnimation | ||
|
||
import numpy as np | ||
from glob import glob | ||
|
||
import os | ||
|
||
from demo_comparison import ng, trackers | ||
|
||
files = sorted(glob('./data/*.npz'))[::-1] | ||
|
||
# Load Data into Memory | ||
data = {} | ||
for file in files: | ||
path, ext = os.path.splitext(file) | ||
key = os.path.basename(path) | ||
tmp = np.load(file) | ||
data[key] = {'tau': tmp['tau']*1e9, 'w': tmp['w']*1e-6} | ||
|
||
NUM_TURNS, n = data['SPM']['tau'].shape | ||
|
||
fig, ax = plt.subplots(num='comparison', constrained_layout=True) | ||
|
||
artists = [] | ||
|
||
|
||
def init(turn=0): | ||
|
||
for i, (key, tracker) in enumerate(trackers.items()): | ||
ax.plot([], [], f"C{i}", label=key) | ||
|
||
tau = data[key]['tau'][turn] | ||
w = data[key]['w'][turn] | ||
|
||
artists.append([ | ||
ax.plot(tau[:ng], w[:ng], f'C{i}.', zorder=5-i)[0], | ||
ax.plot(tau[ng:], w[ng:], f'C{i},', zorder=2-i)[0], | ||
]) | ||
|
||
ts, ws = tracker.separatrix() | ||
ax.plot(ts*1e9, +ws*1e-6, 'm-') | ||
ax.plot(ts*1e9, -ws*1e-6, 'm-') | ||
|
||
ax.set_xlabel(r"$\tau$ (ns)") | ||
ax.set_ylabel(r"$w$ (MeV)") | ||
ax.legend() | ||
|
||
|
||
init(2_500) | ||
|
||
fig.savefig('./figs/comparison.png') | ||
|
||
|
||
def update(turn): | ||
for key, (p1, p2) in zip(trackers.keys(), artists): | ||
tau = data[key]['tau'][turn] | ||
w = data[key]['w'][turn] | ||
p1.set_data(tau[0:ng], w[0:ng]) | ||
p2.set_data(tau[ng:], w[ng:]) | ||
return sum(artists, []) | ||
|
||
|
||
ani = FuncAnimation(fig, update, frames=range( | ||
0, NUM_TURNS, 20), blit=True, interval=0) | ||
|
||
plt.show() | ||
ani.save('./figs/comparison.gif', fps=60) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
ring_properties = { | ||
'R': 100, # machine radius (m) | ||
'h': 8, # rf harmonic | ||
'Vg': 80e3, # gap voltage (V) | ||
'gamma_t': 6.1, # transition | ||
|
||
'beta': 17, # nominal beta function | ||
'D': (2.66, 0), # nominal dispersion function | ||
'b': (73e-3, 35e-3), # aperture radius (m) | ||
} | ||
|
||
bunch_properties = { | ||
'E': 2.938272e9, # beam energy (eV) | ||
'sig_w': 5e6, # energy spread (eV) | ||
'sig_tau': 30e-9, # bunch length (s) | ||
'sig_eps': 1e-6, # transverse emittance (m) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters