.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/fluids/instabilities/plot_rayleigh_taylor.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_instabilities_plot_rayleigh_taylor.py: Rayleigh-Taylor plumes from a heavy-over-light interface ============================================================ A denser fluid layer sits atop a lighter one -- exactly the unstable arrangement -- separated by an interface with a small sinusoidal ripple. The two layers are represented not as a sharp density jump but through the Boussinesq approximation: a dimensionless buoyancy field :math:`b=-\delta\rho/\rho_0` (positive where the fluid is locally lighter than the reference density), advected and diffused like vorticity but also exerting a baroclinic torque :math:`g\,\partial_x b` on it wherever the density gradient is non-vertical: .. math:: \partial_t \omega + (\mathbf{u}\cdot\nabla)\omega = \nu \nabla^2 \omega + g\,\partial_x b, \qquad \partial_t b + (\mathbf{u}\cdot\nabla) b = \kappa \nabla^2 b, with :math:`\mathbf{u}` recovered from :math:`\omega` exactly as in :mod:`physicskit.fluids.systems.navier_stokes`. Rayleigh's 1883 linear stability analysis (extended by Taylor in 1950) shows that any interface with heavy fluid sitting on light fluid under gravity :math:`g` is unconditionally unstable, growing a small ripple of wavenumber :math:`k` at rate .. math:: \sigma(k) = \sqrt{A\,g\,k}, \qquad A = \frac{\rho_{heavy}-\rho_{light}}{\rho_{heavy}+\rho_{light}}, where :math:`A` is the Atwood number setting the buoyancy jump across the interface. This example builds that heavy-over-light arrangement with :func:`~physicskit.fluids.systems.instabilities.rayleigh_taylor_ic`, checks the early growth against :func:`~physicskit.fluids.systems.instabilities.rayleigh_taylor_growth_rate`, and then evolves the coupled equations above with :func:`~physicskit.fluids.systems.instabilities.simulate_rayleigh_taylor` well into the nonlinear regime, where the interface rolls up into the mushroom-shaped plumes the instability is named for. .. GENERATED FROM PYTHON SOURCE LINES 41-53 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from physicskit.fluids.core.grid import spectral_grid from physicskit.fluids.systems.instabilities import ( rayleigh_taylor_growth_rate, rayleigh_taylor_ic, simulate_rayleigh_taylor, ) from physicskit.fluids.visualizers.flow_fields import animate_rayleigh_taylor .. GENERATED FROM PYTHON SOURCE LINES 54-56 A rippled heavy-over-light interface --------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 56-61 .. code-block:: Python n, length = 96, 2 * np.pi atwood, g, nu, kappa = 0.3, 1.0, 0.001, 0.001 omega0, buoyancy0 = rayleigh_taylor_ic(n, length, atwood_number=atwood, perturbation_amplitude=0.01) .. GENERATED FROM PYTHON SOURCE LINES 62-64 Grow it and compare against the linear prediction ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 64-81 .. code-block:: Python k0 = 2 * np.pi / length sigma_predicted = rayleigh_taylor_growth_rate(k=k0, atwood_number=atwood, g=g) omega, buoyancy = omega0.copy(), buoyancy0.copy() amps, times = [], [] dt, chunk = 0.01, 50 for i in range(14): result = simulate_rayleigh_taylor(omega, buoyancy, nu=nu, kappa=kappa, g=g, dt=dt, steps=chunk, length=length) omega, buoyancy = result["omega"], result["buoyancy"] dev = buoyancy - buoyancy.mean(axis=0, keepdims=True) amps.append(np.sqrt(np.mean(dev**2))) times.append((i + 1) * dt * chunk) amps, times = np.array(amps), np.array(times) print(f"growth rate: linear theory sigma = {sigma_predicted:.3f}") print(f"interface roughness grew by a factor of {amps[-1] / amps[0]:.2f} over the run") .. rst-class:: sphx-glr-script-out .. code-block:: none growth rate: linear theory sigma = 0.548 interface roughness grew by a factor of 11.62 over the run .. GENERATED FROM PYTHON SOURCE LINES 82-84 The nonlinear mushroom plumes --------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 84-99 .. code-block:: Python X, Y, _, _, _ = spectral_grid(n, length) fig, axes = plt.subplots(1, 2, figsize=(11, 5)) axes[0].pcolormesh(X, Y, buoyancy0, cmap="RdBu", shading="auto") axes[0].set_title("t = 0") axes[0].set_aspect("equal") im1 = axes[1].pcolormesh(X, Y, buoyancy, cmap="RdBu", shading="auto") axes[1].set_title(f"t = {times[-1]:.1f}: mushroom plumes") axes[1].set_aspect("equal") fig.colorbar(im1, ax=axes, label="buoyancy") fig.suptitle("Rayleigh-Taylor instability (buoyancy field)") plt.show() .. image-sg:: /api/gallery/fluids/instabilities/images/sphx_glr_plot_rayleigh_taylor_001.png :alt: Rayleigh-Taylor instability (buoyancy field), t = 0, t = 7.0: mushroom plumes :srcset: /api/gallery/fluids/instabilities/images/sphx_glr_plot_rayleigh_taylor_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 100-105 Watching the mushroom plumes form, continuously ------------------------------------------------------------------ Rather than a single before/after comparison, redrawing the buoyancy field every few RK4 steps shows the rippled interface rolling up into the characteristic mushroom-shaped plumes as it happens. .. GENERATED FROM PYTHON SOURCE LINES 105-109 .. code-block:: Python anim = animate_rayleigh_taylor(omega0, buoyancy0, nu=nu, kappa=kappa, g=g, dt=dt, steps_per_frame=chunk, n_frames=20, length=length) plt.show() .. container:: sphx-glr-animation .. raw:: html .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.836 seconds) .. _sphx_glr_download_api_gallery_fluids_instabilities_plot_rayleigh_taylor.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_rayleigh_taylor.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_rayleigh_taylor.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_rayleigh_taylor.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_