.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/fluids/navier_stokes/plot_turbulent_cascade.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_fluids_navier_stokes_plot_turbulent_cascade.py: The Kolmogorov -5/3 cascade in decaying 2D turbulence ========================================================= :class:`~physicskit.fluids.systems.navier_stokes.NavierStokes2D` integrates the 2D incompressible vorticity-transport equation :math:`\partial_t \omega + (\mathbf{u}\cdot\nabla)\omega = \nu \nabla^2 \omega` pseudo-spectrally on a doubly periodic domain, with no external forcing: once set going, the flow's kinetic energy only decays, redistributed across scales by the nonlinear advection term before viscosity ultimately dissipates it. Kolmogorov's 1941 (K41) theory predicts that, in the "inertial range" of scales between where the flow was initially seeded and where viscosity dissipates it, the kinetic energy spectrum follows a universal power law, .. math:: E(k) \propto k^{-5/3}, where :math:`E(k)` is defined so that :math:`\int E(k)\,dk` is the total kinetic energy per unit mass. This example seeds the solver's initial vorticity field with many randomly placed Gaussian vortex blobs of mixed sign and random position, lets their nonlinear interactions cascade energy across scales, and checks the resulting spectrum -- via :func:`~physicskit.fluids.utils.spectral_analysis.energy_spectrum` -- against that -5/3 law. .. GENERATED FROM PYTHON SOURCE LINES 28-37 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from physicskit.fluids.systems.navier_stokes import NavierStokes2D from physicskit.fluids.utils.spectral_analysis import energy_spectrum from physicskit.fluids.visualizers.flow_fields import plot_vorticity_field from physicskit.fluids.visualizers.spectra import plot_energy_spectrum .. GENERATED FROM PYTHON SOURCE LINES 38-40 Seed many random vortex blobs --------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 40-54 .. code-block:: Python n, length = 128, 2 * np.pi solver = NavierStokes2D(n=n, length=length, nu=2e-4) rng = np.random.default_rng(0) n_blobs, core = 40, 0.12 omega0 = np.zeros_like(solver.X) for _ in range(n_blobs): xc, yc = rng.uniform(0, length, size=2) sign = rng.choice([-1.0, 1.0]) dx = np.minimum(np.abs(solver.X - xc), length - np.abs(solver.X - xc)) dy = np.minimum(np.abs(solver.Y - yc), length - np.abs(solver.Y - yc)) omega0 += sign * np.exp(-(dx**2 + dy**2) / (2 * core**2)) .. GENERATED FROM PYTHON SOURCE LINES 55-57 Let the nonlinear interactions cascade energy across scales ----------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 57-64 .. code-block:: Python result = solver.simulate(omega0, dt=0.002, steps=800) fig, ax = plot_vorticity_field(solver.X, solver.Y, result["omega"], result["u"], result["v"]) ax.set_title("Decaying 2D turbulence") fig.tight_layout() .. image-sg:: /api/gallery/fluids/navier_stokes/images/sphx_glr_plot_turbulent_cascade_001.png :alt: Decaying 2D turbulence :srcset: /api/gallery/fluids/navier_stokes/images/sphx_glr_plot_turbulent_cascade_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 65-69 Check the energy spectrum against Kolmogorov's -5/3 law ------------------------------------------------------------- A genuine inertial range shows up as a stretch of the measured spectrum running parallel to the reference line on these log-log axes. .. GENERATED FROM PYTHON SOURCE LINES 69-75 .. code-block:: Python k, E = energy_spectrum(result["u"], result["v"], length) fig, ax = plot_energy_spectrum(k, E) fig.tight_layout() plt.show() .. image-sg:: /api/gallery/fluids/navier_stokes/images/sphx_glr_plot_turbulent_cascade_002.png :alt: Kinetic energy spectrum :srcset: /api/gallery/fluids/navier_stokes/images/sphx_glr_plot_turbulent_cascade_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.931 seconds) .. _sphx_glr_download_api_gallery_fluids_navier_stokes_plot_turbulent_cascade.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_turbulent_cascade.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_turbulent_cascade.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_turbulent_cascade.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_