.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/plasma/single_particle/plot_03_exb_drift_gyroaverage.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_api_gallery_plasma_single_particle_plot_03_exb_drift_gyroaverage.py: Recovering the ExB drift as a time-average of the full orbit ================================================================== Modern magnetic-confinement fusion research is dominated by *gyrokinetic* theory: rather than track a particle's full gyration (as the Boris pusher does, :doc:`plot_02_boris_pusher`) or reduce all the way to a fluid (as MHD does), gyrokinetics analytically averages the Vlasov equation over the fast gyro-angle while retaining the finite-Larmor-radius physics needed for turbulence. This closes the gap between the guiding-center drift theory of the 1950s (:doc:`plot_01_guiding_center_drifts_and_mirror`) and full kinetic simulation, and is the theoretical foundation of every modern turbulent-transport code (GENE, GYRO, GS2) used to predict a fusion reactor's confinement performance. The guiding-center machinery in :mod:`physicskit.plasma.single_particle` -- drifts, the adiabatic invariant, mirror bounce motion -- is precisely the single-particle foundation gyrokinetic theory builds on. This script makes that connection concrete: the closed-form guiding-center prediction .. math:: \mathbf{v}_E = \frac{\mathbf{E}\times\mathbf{B}}{B^2} from :func:`~physicskit.plasma.single_particle.exb_drift` -- independent of the particle's charge, mass, and gyro-phase -- is recovered by time-averaging a *full* orbit that integrates the exact Lorentz force :math:`m\dot{\mathbf{v}}=q(\mathbf{E}+\mathbf{v}\times\mathbf{B})` with the Boris pusher: a uniform crossed :math:`\mathbf{E}` and :math:`\mathbf{B}` field are applied to a charged particle started from rest, and its gyrating-*and*-drifting trajectory is averaged over many gyro-periods -- exactly the gyro-average gyrokinetics performs analytically. .. GENERATED FROM PYTHON SOURCE LINES 39-44 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import physicskit as pk .. GENERATED FROM PYTHON SOURCE LINES 45-48 The closed-form guiding-center prediction: pure E x B drift ------------------------------------------------------------------ Independent of the particle's gyro-phase, mass, or charge. .. GENERATED FROM PYTHON SOURCE LINES 48-53 .. code-block:: Python E = np.array([0.0, 1e3, 0.0]) B = np.array([0.0, 0.0, 1.0]) v_exb = pk.plasma.exb_drift(E, B) .. GENERATED FROM PYTHON SOURCE LINES 54-57 The full Boris-pusher orbit gyrates *and* drifts; averaging its trajectory over many gyro-periods recovers the same drift velocity that gyrokinetic theory retains after averaging away the gyration. .. GENERATED FROM PYTHON SOURCE LINES 57-72 .. code-block:: Python omega_c = pk.plasma.cyclotron_frequency(pk.plasma.QE, pk.plasma.MP, 1.0) dt = (2 * np.pi / omega_c) / 200 pos_hist, vel_hist = pk.plasma.boris_integrate(np.zeros(3), np.zeros(3), pk.plasma.QE, pk.plasma.MP, E, B, dt, steps=4000) v_avg = (pos_hist[-1] - pos_hist[0]) / (4000 * dt) print("guiding-center v_ExB:", v_exb) print("full-orbit time-averaged velocity:", v_avg) fig, ax = plt.subplots(figsize=(6, 5)) pk.plasma.plot_drift_trajectory(pos_hist, ax=ax) ax.set_title("Full gyro-orbit drifting at the guiding-center ExB speed") fig.tight_layout() plt.show() .. image-sg:: /api/gallery/plasma/single_particle/images/sphx_glr_plot_03_exb_drift_gyroaverage_001.png :alt: Full gyro-orbit drifting at the guiding-center ExB speed :srcset: /api/gallery/plasma/single_particle/images/sphx_glr_plot_03_exb_drift_gyroaverage_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none guiding-center v_ExB: [1000. 0. 0.] full-orbit time-averaged velocity: [ 1.00008224e+03 -8.66816231e-04 0.00000000e+00] .. GENERATED FROM PYTHON SOURCE LINES 73-86 The gyro-average made visible: a velocity-space hodograph ------------------------------------------------------------------------ Time-averaging the *position* history above recovers the drift speed, but the gyroaveraging gyrokinetics performs is really an average over velocity space: the full velocity subtracts into a fast gyration circling a fixed center plus the slow drift. Reusing the same ``vel_hist`` already returned by :func:`~physicskit.plasma.single_particle.boris_integrate` -- no new integration needed -- and plotting :math:`v_x` against :math:`v_y` traces exactly that circle, centered on the closed-form :math:`\mathbf{v}_E` from :func:`~physicskit.plasma.single_particle.exb_drift` rather than on the origin: the gyration is what gyrokinetics averages away, and the offset center is what survives the average. .. GENERATED FROM PYTHON SOURCE LINES 86-99 .. code-block:: Python fig, ax = plt.subplots(figsize=(5.5, 5.5)) sc = ax.scatter(vel_hist[:, 0], vel_hist[:, 1], c=np.arange(len(vel_hist)), cmap="viridis", s=4) fig.colorbar(sc, ax=ax, label="step") ax.plot(v_exb[0], v_exb[1], "r+", markersize=14, markeredgewidth=2, label=r"$\mathbf{v}_E$ (guiding-center prediction)") ax.set_xlabel(r"$v_x$ (m/s)") ax.set_ylabel(r"$v_y$ (m/s)") ax.set_title("Velocity-space gyration circle, centered on the ExB drift") ax.set_aspect("equal", adjustable="datalim") ax.legend() fig.tight_layout() plt.show() .. image-sg:: /api/gallery/plasma/single_particle/images/sphx_glr_plot_03_exb_drift_gyroaverage_002.png :alt: Velocity-space gyration circle, centered on the ExB drift :srcset: /api/gallery/plasma/single_particle/images/sphx_glr_plot_03_exb_drift_gyroaverage_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.092 seconds) .. _sphx_glr_download_api_gallery_plasma_single_particle_plot_03_exb_drift_gyroaverage.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_exb_drift_gyroaverage.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_exb_drift_gyroaverage.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_exb_drift_gyroaverage.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_