Note
Go to the end to download the full example code.
Plasma beamline simulation#
This tutorial illustrates how to carry out a simulation of a multi-element plasma-acceleration beamline.
The setup considered is an LPA with external injection followed by an active plasma lens for beam capturing.
Create particle bunch#
from wake_t.utilities.bunch_generation import get_gaussian_bunch_from_size
# Beam parameters.
emitt_nx = emitt_ny = 1e-6 # m
s_x = s_y = 3e-6 # m
s_t = 3.0 # fs
gamma_avg = 100 / 0.511
gamma_spread = 1.0 # %
q_bunch = 30 # pC
xi_avg = 0.0 # m
n_part = 1e4
# Create particle bunch.
bunch = get_gaussian_bunch_from_size(
emitt_nx,
emitt_ny,
s_x,
s_y,
gamma_avg,
gamma_spread,
s_t,
xi_avg,
q_bunch,
n_part,
name="elec_bunch",
)
# Show phase space.
bunch.show()

Create laser driver#
from wake_t import GaussianPulse
# Laser parameters.
laser_xi_c = 60e-6 # m (laser centroid in simulation box)
w_0 = 40e-6 # m
a_0 = 3
tau = 30e-15 # fs (FWHM in intensity)
z_foc = 1e-2 # laser focus at center of LPA.
# Create Gaussian laser pulse.
laser = GaussianPulse(laser_xi_c, w_0=w_0, a_0=a_0, tau=tau, z_foc=z_foc)
Create LPA#
from wake_t import PlasmaStage
plasma_target = PlasmaStage(
length=2e-2,
density=1e23,
wakefield_model="quasistatic_2d",
xi_max=90e-6,
xi_min=-40e-6,
r_max=200e-6,
n_xi=260,
n_r=200,
ppc=4,
laser=laser,
n_out=10,
)
Create beam capture section#
from wake_t import Drift, ActivePlasmaLens
drift_1 = Drift(length=0.1, n_out=10)
drift_2 = Drift(length=0.1, n_out=10)
apl = ActivePlasmaLens(length=2e-2, foc_strength=400, wakefields=False, n_out=5)
Make beamline#
from wake_t import Beamline
beamline = Beamline([plasma_target, drift_1, apl, drift_2])
Track bunch#
bunch_list = beamline.track(bunch)
Plasma stage: 0%| | 0.000000/0.020000 m [00:00]
Plasma stage: 3%|▎ | 0.000519/0.020000 m [00:00]
Plasma stage: 6%|▌ | 0.001169/0.020000 m [00:00]
Plasma stage: 9%|▉ | 0.001818/0.020000 m [00:00]
Plasma stage: 12%|█▏ | 0.002468/0.020000 m [00:00]
Plasma stage: 16%|█▌ | 0.003117/0.020000 m [00:00]
Plasma stage: 19%|█▉ | 0.003766/0.020000 m [00:00]
Plasma stage: 22%|██▏ | 0.004416/0.020000 m [00:00]
Plasma stage: 25%|██▌ | 0.005065/0.020000 m [00:00]
Plasma stage: 29%|██▊ | 0.005714/0.020000 m [00:01]
Plasma stage: 32%|███▏ | 0.006364/0.020000 m [00:01]
Plasma stage: 35%|███▌ | 0.007013/0.020000 m [00:01]
Plasma stage: 38%|███▊ | 0.007662/0.020000 m [00:01]
Plasma stage: 42%|████▏ | 0.008312/0.020000 m [00:01]
Plasma stage: 45%|████▍ | 0.008961/0.020000 m [00:01]
Plasma stage: 48%|████▊ | 0.009610/0.020000 m [00:01]
Plasma stage: 51%|█████▏ | 0.010260/0.020000 m [00:01]
Plasma stage: 55%|█████▍ | 0.010909/0.020000 m [00:01]
Plasma stage: 58%|█████▊ | 0.011558/0.020000 m [00:02]
Plasma stage: 61%|██████ | 0.012208/0.020000 m [00:02]
Plasma stage: 64%|██████▍ | 0.012857/0.020000 m [00:02]
Plasma stage: 68%|██████▊ | 0.013506/0.020000 m [00:02]
Plasma stage: 71%|███████ | 0.014156/0.020000 m [00:02]
Plasma stage: 74%|███████▍ | 0.014805/0.020000 m [00:02]
Plasma stage: 77%|███████▋ | 0.015455/0.020000 m [00:02]
Plasma stage: 81%|████████ | 0.016104/0.020000 m [00:02]
Plasma stage: 84%|████████▍ | 0.016753/0.020000 m [00:02]
Plasma stage: 87%|████████▋ | 0.017403/0.020000 m [00:03]
Plasma stage: 90%|█████████ | 0.018052/0.020000 m [00:03]
Plasma stage: 94%|█████████▎| 0.018701/0.020000 m [00:03]
Plasma stage: 97%|█████████▋| 0.019351/0.020000 m [00:03]
Plasma stage: 100%|██████████| 0.020000/0.020000 m [00:03]
Plasma stage: 100%|██████████| 0.020000/0.020000 m [00:03]
Drift
-----
Length = 0.1000 m
CSR off.
Tracking in 10 step(s)... [-- ]
Tracking in 10 step(s)... [---- ]
Tracking in 10 step(s)... [------ ]
Tracking in 10 step(s)... [-------- ]
Tracking in 10 step(s)... [---------- ]
Tracking in 10 step(s)... [------------ ]
Tracking in 10 step(s)... [-------------- ]
Tracking in 10 step(s)... [---------------- ]
Tracking in 10 step(s)... [------------------ ]
Tracking in 10 step(s)... [--------------------] Done (0.014899253845214844 s).
--------------------------------------------------------------------------------
Active plasma lens: 0%| | 0.000000/0.020000 m [00:00]
Active plasma lens: 20%|█▉ | 0.004000/0.020000 m [00:00]
Active plasma lens: 100%|██████████| 0.020000/0.020000 m [00:00]
Drift
-----
Length = 0.1000 m
CSR off.
Tracking in 10 step(s)... [-- ]
Tracking in 10 step(s)... [---- ]
Tracking in 10 step(s)... [------ ]
Tracking in 10 step(s)... [-------- ]
Tracking in 10 step(s)... [---------- ]
Tracking in 10 step(s)... [------------ ]
Tracking in 10 step(s)... [-------------- ]
Tracking in 10 step(s)... [---------------- ]
Tracking in 10 step(s)... [------------------ ]
Tracking in 10 step(s)... [--------------------] Done (0.01707625389099121 s).
--------------------------------------------------------------------------------
Analyze beam evolution#
import matplotlib.pyplot as plt
from wake_t.diagnostics import analyze_bunch_list
params_evolution = analyze_bunch_list(bunch_list)
# Quick plot of results.
z = params_evolution["prop_dist"] * 1e2
fig_1 = plt.figure()
plt.subplot(411)
plt.semilogy(z, params_evolution["beta_x"])
plt.tick_params(axis="x", which="both", labelbottom=False)
plt.ylabel("$\\beta_x$ [m]")
plt.subplot(412)
plt.semilogy(z, params_evolution["gamma_x"])
plt.tick_params(axis="x", which="both", labelbottom=False)
plt.ylabel("$\\gamma_{x}$ [$m^{-1}$]")
plt.subplot(413)
plt.plot(z, params_evolution["emitt_x"] * 1e6)
plt.tick_params(axis="x", which="both", labelbottom=False)
plt.ylabel("$\\epsilon_{nx}$ [$\\mu$m]")
plt.subplot(414)
plt.plot(z, params_evolution["avg_ene"] * 0.511)
plt.xlabel("z [cm]")
plt.ylabel("E [MeV]")
plt.tight_layout()

/home/docs/checkouts/readthedocs.org/user_builds/wake-t/envs/stable/lib/python3.11/site-packages/aptools/data_analysis/beam_diagnostics.py:524: RuntimeWarning: invalid value encountered in sqrt
em_x = np.sqrt(np.linalg.det(cov_x.astype(np.float32, copy=False)))
Total running time of the script: (0 minutes 5.121 seconds)