.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/02_plasma_beamline_simulation.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_02_plasma_beamline_simulation.py: 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. .. GENERATED FROM PYTHON SOURCE LINES 14-16 Create particle bunch --------------------- .. GENERATED FROM PYTHON SOURCE LINES 16-46 .. code-block:: Python 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() .. image-sg:: /tutorials/images/sphx_glr_02_plasma_beamline_simulation_001.png :alt: 02 plasma beamline simulation :srcset: /tutorials/images/sphx_glr_02_plasma_beamline_simulation_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 47-49 Create laser driver ------------------- .. GENERATED FROM PYTHON SOURCE LINES 49-61 .. code-block:: Python 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) .. GENERATED FROM PYTHON SOURCE LINES 62-64 Create LPA ---------- .. GENERATED FROM PYTHON SOURCE LINES 64-80 .. code-block:: Python 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, ) .. GENERATED FROM PYTHON SOURCE LINES 81-83 Create beam capture section --------------------------- .. GENERATED FROM PYTHON SOURCE LINES 83-90 .. code-block:: Python 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) .. GENERATED FROM PYTHON SOURCE LINES 91-93 Make beamline ------------- .. GENERATED FROM PYTHON SOURCE LINES 93-98 .. code-block:: Python from wake_t import Beamline beamline = Beamline([plasma_target, drift_1, apl, drift_2]) .. GENERATED FROM PYTHON SOURCE LINES 99-101 Track bunch ----------- .. GENERATED FROM PYTHON SOURCE LINES 101-104 .. code-block:: Python bunch_list = beamline.track(bunch) .. rst-class:: sphx-glr-script-out .. code-block:: none 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). -------------------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 105-107 Analyze beam evolution ---------------------- .. GENERATED FROM PYTHON SOURCE LINES 107-132 .. code-block:: Python 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() .. image-sg:: /tutorials/images/sphx_glr_02_plasma_beamline_simulation_002.png :alt: 02 plasma beamline simulation :srcset: /tutorials/images/sphx_glr_02_plasma_beamline_simulation_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /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))) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.121 seconds) .. _sphx_glr_download_tutorials_02_plasma_beamline_simulation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 02_plasma_beamline_simulation.ipynb <02_plasma_beamline_simulation.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 02_plasma_beamline_simulation.py <02_plasma_beamline_simulation.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 02_plasma_beamline_simulation.zip <02_plasma_beamline_simulation.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_