.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/fields/solitons/plot_sine_gordon_kink.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_fields_solitons_plot_sine_gordon_kink.py: A topologically protected Sine-Gordon kink ============================================== Yakov Frenkel and Tatiana Kontorova modeled a crystal dislocation as a chain of atoms in a periodic substrate potential -- a chain of coupled pendula; in the continuum limit this becomes the Sine-Gordon equation .. math:: \partial_t^2 u - \partial_x^2 u + \sin u = 0. Its kink solution, .. math:: u(x,t) = 4\arctan\!\left(e^{\,\gamma(x-x_0-vt)}\right), \qquad \gamma = \frac{1}{\sqrt{1-v^2}}, a single :math:`2\pi` twist propagating at speed :math:`v<1` along the chain, is a *topological* soliton: no local, continuous deformation can untwist it. :func:`~physicskit.fields.solitons.sine_gordon_kink` builds this exact traveling-wave solution and :func:`~physicskit.fields.solitons.sine_gordon_evolve` propagates it with independent leapfrog finite differences, confirming the twist survives intact; the same run can be watched frame by frame with :func:`~physicskit.fields.solitons.sine_gordon_evolve_frames`. .. GENERATED FROM PYTHON SOURCE LINES 29-35 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from physicskit.fields import animate_field_1d, plot_field_1d, sine_gordon_evolve, sine_gordon_evolve_frames, sine_gordon_kink .. GENERATED FROM PYTHON SOURCE LINES 36-38 A kink launched at v = 0.5 (natural units, linear wave speed = 1) ------------------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 38-46 .. code-block:: Python N, L, v, x0 = 4000, 200.0, 0.5, -50.0 x = np.linspace(-L / 2, L / 2, N) dx = x[1] - x[0] dt = 0.4 * dx u_prev = sine_gordon_kink(x, -dt, v, x0) u0 = sine_gordon_kink(x, 0.0, v, x0) .. GENERATED FROM PYTHON SOURCE LINES 47-49 Propagate with leapfrog finite differences on the discrete chain ----------------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 49-53 .. code-block:: Python steps = 1000 u, _ = sine_gordon_evolve(u0, u_prev, x, dt, steps) .. GENERATED FROM PYTHON SOURCE LINES 54-57 The :math:`2\pi` twist survives intact, at the position predicted by the exact kink solution -- it cannot be untwisted by the local dynamics, only shifted. .. GENERATED FROM PYTHON SOURCE LINES 57-70 .. code-block:: Python expected = sine_gordon_kink(x, steps * dt, v, x0) max_dev = np.max(np.abs(u - expected)) fig, ax = plot_field_1d(x, u0, label="t = 0") plot_field_1d(x, u, ax=ax, label=f"t = {steps * dt:.0f}") ax.set_title(f"max deviation from exact kink: {max_dev:.2e}") fig.tight_layout() print(f"field before the kink (x -> -L/2): {u[0]:.4f} (expect 0)") print(f"field after the kink (x -> +L/2): {u[-1]:.4f} (expect 2*pi = {2 * np.pi:.4f})") print(f"max deviation from exact traveling kink: {max_dev:.2e}") .. image-sg:: /api/gallery/fields/solitons/images/sphx_glr_plot_sine_gordon_kink_001.png :alt: max deviation from exact kink: 3.23e-03 :srcset: /api/gallery/fields/solitons/images/sphx_glr_plot_sine_gordon_kink_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none field before the kink (x -> -L/2): 0.0000 (expect 0) field after the kink (x -> +L/2): 6.2832 (expect 2*pi = 6.2832) max deviation from exact traveling kink: 3.23e-03 .. GENERATED FROM PYTHON SOURCE LINES 71-77 Animating the traveling kink ---------------------------------- :func:`~physicskit.fields.solitons.sine_gordon_evolve_frames` records the same leapfrog propagation as a sequence of snapshots, so the topologically protected twist can be watched traveling down the chain rather than compared only at the start and end. .. GENERATED FROM PYTHON SOURCE LINES 77-83 .. code-block:: Python frames, times = sine_gordon_evolve_frames(u0, u_prev, x, dt, steps_per_frame=steps // 40, n_frames=40) anim = animate_field_1d(x, frames, times, ylabel="u(x, t)") plt.show() .. container:: sphx-glr-animation .. raw:: html .. GENERATED FROM PYTHON SOURCE LINES 84-88 To save the animation to a file instead of (or in addition to) displaying it interactively, use e.g.:: anim.save("sine_gordon_kink.gif", writer="pillow", fps=20) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.588 seconds) .. _sphx_glr_download_api_gallery_fields_solitons_plot_sine_gordon_kink.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_sine_gordon_kink.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_sine_gordon_kink.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_sine_gordon_kink.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_