Examples#

This gallery walks through every physical regime in physicskit.fluids: inviscid potential flow, classic viscous exact solutions, point-vortex N-body dynamics, the Kelvin-Helmholtz and Rayleigh-Taylor instabilities, 1D compressible shocks, and the 2D incompressible Navier-Stokes solver that underlies the instability and turbulence-spectrum tools. Each script reproduces the signature observable of a specific breakthrough in Breakthroughs in Fluid Dynamics.

Each script in this gallery is self-contained and can be run directly with python examples/fluids/<section>/<script>.py. Every script also carries an RST module docstring as its title/description and uses # %% markers to split narrative text from code, which is exactly what Sphinx-Gallery renders into the pages below – the script is the source of truth for what you see, not a copy of it.

Sections#

  • potential_flow – inviscid, irrotational flow built by superposing elementary solutions: source, sink, and doublet streamline patterns, d’Alembert’s zero-drag paradox for a circulation-free cylinder, and the classic lifting-cylinder problem with the Kutta-Joukowski lift compared against a direct pressure-integral calculation.

  • viscous_flow – classic exact viscous solutions: Couette and Poiseuille flow profiles side by side, Stokes drag on a settling sphere, the Reynolds number as the single dimensionless ratio governing flow regime regardless of size or fluid, and the Blasius boundary layer solved by shooting.

  • vortex_dynamics – point-vortex N-body dynamics via the Biot-Savart law: a co-rotating vortex pair versus a translating vortex dipole, and a von Karman vortex street holding its staggered shape at the stable spacing ratio.

  • instabilities – the Kelvin-Helmholtz shear instability rolling a rippled interface into vortex cores, and the Rayleigh-Taylor instability growing a heavy-over-light interface into mushroom plumes, each checked against its linear growth-rate law.

  • compressible_flow – the 1D Euler equations: normal shock relations across a range of Mach numbers, and the classic Sod shock tube resolving a rarefaction fan, contact discontinuity, and shock in one Riemann problem.

  • navier_stokes – the 2D incompressible vorticity-streamfunction solver: viscous decay of a periodic vortex patch, and a decaying turbulence simulation whose energy spectrum is checked against Kolmogorov’s -5/3 law.

Compressible Flow#

Once a flow moves fast enough that the fluid can no longer get out of its own way, incompressible potential and viscous flow stop applying entirely: the 1D Euler equations support genuinely discontinuous solutions that no smooth velocity field can produce. The normal-shock example sweeps the upstream Mach number through the exact Rankine-Hugoniot jump relations, showing a supersonic flow is always driven back to subsonic on the other side of a shock, at the cost of a sharp pressure and density jump. The Sod shock tube then resolves that same jump dynamically, from a simple burst initial condition, alongside the two other waves – a rarefaction fan and a contact discontinuity – that a general compressible flow problem produces alongside a shock. Watch, in the shock-tube profiles, how a first-order finite-volume scheme smears the shock over several cells even as it gets its speed and downstream state right.

Normal shock relations across a range of Mach numbers

Normal shock relations across a range of Mach numbers

The Sod shock tube

The Sod shock tube

Instabilities#

Some flows are unstable to any perturbation, no matter how small: the smallest ripple grows exponentially until it reorganizes the whole flow. Kelvin-Helmholtz instability needs nothing but shear – two layers sliding past each other supply their own energy to grow a ripple into a row of rolled-up vortex cores, the mechanism behind everything from billow clouds to a flapping flag. Rayleigh-Taylor instability needs nothing but an unstable density stratification – heavy fluid sitting on light fluid under gravity – and grows a rippled interface into the mushroom-shaped plumes seen in everything from a lava lamp to a supernova remnant. Both examples below compare the simulated early-time growth against the exact linear growth-rate law for that instability, then run well past the point where that linear theory stops applying, into the fully rolled-up nonlinear state.

Roll-up of a shear layer into vortex cores

Roll-up of a shear layer into vortex cores

Rayleigh-Taylor plumes from a heavy-over-light interface

Rayleigh-Taylor plumes from a heavy-over-light interface

Potential Flow#

Away from any boundary layer or wake, a great deal of real aerodynamics is governed by a flow with no vorticity at all: a velocity potential obeying Laplace’s equation, which is linear, so entire flow fields can be built by just adding together a handful of elementary solutions. The examples below build up from a bare source/sink/doublet, through d’Alembert’s paradox of exactly zero drag on a circulation-free cylinder, to the textbook result that made potential theory indispensable to early aerodynamics – a spinning cylinder, or by extension a cambered airfoil, generates lift in direct proportion to its bound circulation, with no viscosity anywhere in the calculation. Watch, in the streamline plots, how a source and sink merge into a doublet as they’re brought together, and how adding circulation to a symmetric cylinder flow breaks its front-back symmetry and shifts its stagnation points – the geometric signature of lift.

Flow past a lifting cylinder

Flow past a lifting cylinder

D’Alembert’s paradox: zero net drag on a cylinder in inviscid flow

D'Alembert's paradox: zero net drag on a cylinder in inviscid flow

Source, sink, and doublet: building blocks of potential flow

Source, sink, and doublet: building blocks of potential flow

Viscous Flow#

Viscosity is what potential flow leaves out, and these are the handful of problems simple enough that adding it back in still yields an exact, closed-form answer. Couette and Poiseuille flow show how the same viscous term produces a straight-line profile under a moving wall but a parabola under a pressure gradient; Stokes drag captures the opposite extreme, where viscosity so dominates inertia that a settling sphere never notices its own momentum; the Reynolds number sweep shows that same Stokes-drag physics recast to make a different point – that a single dimensionless ratio, not the sphere’s size or the fluid’s identity separately, decides the flow regime; and the Blasius boundary layer shows what happens in between – a thin viscous layer clinging to a wall in an otherwise fast, nearly inviscid stream, thickening as the square root of downstream distance. Watch how thin that layer stays even at a middling free-stream speed, and how the wall shear stress it predicts falls off as the flow moves downstream.

The Blasius laminar boundary layer

The Blasius laminar boundary layer

Couette versus Poiseuille flow

Couette versus Poiseuille flow

The Reynolds number: one ratio, regardless of size or fluid

The Reynolds number: one ratio, regardless of size or fluid

Stokes drag and the terminal velocity of a settling sphere

Stokes drag and the terminal velocity of a settling sphere

Vortex Dynamics#

Concentrate all of a flow’s vorticity into a handful of points and the Navier-Stokes equations collapse to ordinary differential equations: each point vortex simply drifts in the velocity field induced by every other one. The examples below show how differently two vortices behave depending only on the relative sign of their circulation – a rigid, orbiting pair if the signs match, a self-propelling dipole that runs off in a straight line if they don’t – and then scale that same Biot-Savart mechanics up to a full von Karman street, the staggered double row shed behind every bluff body from a chimney to a violin string in the wind. Watch how the street holds its staggered spacing intact at von Karman’s stable ratio, in stark contrast to the pairwise dynamics of the first example.

A von Karman vortex street holds its shape

A von Karman vortex street holds its shape

Co-rotating pair versus translating dipole

Co-rotating pair versus translating dipole

Gallery generated by Sphinx-Gallery