.. 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.000649/0.020000 m [00:00] Plasma stage: 6%|▋ | 0.001299/0.020000 m [00:00] Plasma stage: 10%|█ | 0.002035/0.020000 m [00:00] Plasma stage: 14%|█▎ | 0.002727/0.020000 m [00:00] Plasma stage: 18%|█▊ | 0.003506/0.020000 m [00:00] Plasma stage: 21%|██▏ | 0.004286/0.020000 m [00:00] Plasma stage: 25%|██▍ | 0.004970/0.020000 m [00:00] Plasma stage: 29%|██▊ | 0.005714/0.020000 m [00:00] Plasma stage: 32%|███▏ | 0.006364/0.020000 m [00:00] Plasma stage: 35%|███▌ | 0.007013/0.020000 m [00:01] Plasma stage: 38%|███▊ | 0.007662/0.020000 m [00:01] Plasma stage: 42%|████▏ | 0.008396/0.020000 m [00:01] Plasma stage: 45%|████▌ | 0.009091/0.020000 m [00:01] Plasma stage: 49%|████▉ | 0.009870/0.020000 m [00:01] Plasma stage: 53%|█████▎ | 0.010649/0.020000 m [00:01] Plasma stage: 57%|█████▋ | 0.011429/0.020000 m [00:01] Plasma stage: 61%|██████ | 0.012208/0.020000 m [00:01] Plasma stage: 65%|██████▍ | 0.012987/0.020000 m [00:02] Plasma stage: 68%|██████▊ | 0.013658/0.020000 m [00:02] Plasma stage: 72%|███████▏ | 0.014350/0.020000 m [00:02] Plasma stage: 75%|███████▌ | 0.015059/0.020000 m [00:02] Plasma stage: 79%|███████▉ | 0.015778/0.020000 m [00:02] Plasma stage: 82%|████████▏ | 0.016494/0.020000 m [00:02] Plasma stage: 86%|████████▋ | 0.017264/0.020000 m [00:02] Plasma stage: 90%|████████▉ | 0.017963/0.020000 m [00:02] Plasma stage: 93%|█████████▎| 0.018654/0.020000 m [00:02] Plasma stage: 97%|█████████▋| 0.019316/0.020000 m [00:02] 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.01909613609313965 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.019280195236206055 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/latest/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.163 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 `_