---
title: "Stretch the Dye, Keep the Rotation Ledger Interactive Lab | Sandbox Physics"
description: "How can a flow with no viscosity stir dye into fine threads without losing energy or rotation? With no viscosity, the flow carries its rotation along without spreading it out, so energy and enstrophy, the total squared rotation, stay fixed. The same flow stretches and folds the dye into ever finer threads. When those threads blur on a computer grid, that is the numerical method smoothing the dye, not the flow losing rotation."
canonical_url: "https://sandboxphysics.com/labs/euler-vorticity-mixing/"
language: "en"
page_type: "lab"
alternate_languages:
  zh-CN: "https://sandboxphysics.com/zh/labs/euler-vorticity-mixing/"
last_modified: "2026-10-22"
---

Fluid memory · spectral dynamics

# 2D Euler Vorticity & Mixing

**How can a flow with no viscosity stir dye into fine threads without losing energy or rotation?** With no viscosity, the flow carries its rotation along without spreading it out, so energy and enstrophy, the total squared rotation, stay fixed. The same flow stretches and folds the dye into ever finer threads. When those threads blur on a computer grid, that is the numerical method smoothing the dye, not the flow losing rotation.

Watch co-rotating vortex patches, a traveling dipole and a perturbed shear layer evolve in a periodic vorticity solver. Probe the same point in the rotation and dye fields, follow fluid parcels along their paths, and see how energy, enstrophy and the spectra across scales respond.

> Interactive simulation: open this page in a web browser to change the parameters and run the model.

The flow is smooth, incompressible and 2D, periodic in both directions, with zero mean vorticity and zero mean velocity. The solver is a truncated Fourier Galerkin method with strict two-thirds dealiasing and RK4 time stepping. With nonzero viscosity it solves the 2D Navier–Stokes equations. The dye is moved by a separate scheme that adds numerical diffusion. The model has no walls, no forcing, no 3D vortex stretching and no turbulence closure.

Physics tutorial

## Euler: stretch a pattern without destroying its rotation

**Background** In a two-dimensional fluid, each parcel carries its rotation along with it. The vorticity determines a streamfunction, the streamfunction gives the velocity, and that velocity moves the vorticity around. The Lab solves this loop on a periodic square.

**Why it matters** Colorful filaments alone cannot tell a fluid solver from an animation. Energy, enstrophy, spectral bandwidth and an exact decay test show what the algorithm actually conserves and what it loses.

Start with the essentials

- **Focus question**: How can the dye fold into ever finer filaments while the inviscid vorticity, as long as the grid resolves it, keeps its quadratic invariants?
- **One-sentence intuition**: At zero viscosity, vorticity is carried along with the fluid, not diffused. The same velocity carries the dye, but the dye scheme uses interpolation, so dye that looks well mixed does not show that $\omega$ has physically dissipated.

### Core mathematical model

#### Vorticity feedback loop

$$
\partial_t\omega+\mathbf u\cdot\nabla\omega=\nu\Delta\omega,\qquad -\Delta\psi=\omega,\qquad \mathbf u=(\partial_y\psi,-\partial_x\psi)
$$

With zero viscosity these are the Euler equations; with positive viscosity they are the unforced 2D Navier–Stokes equations. In the divergence of the velocity, the two mixed derivatives cancel. A periodic domain requires zero mean vorticity, and the mean velocity is set to zero.

#### Time stepping in Fourier space, with dealiasing

$$
\widehat\psi_{\mathbf k}=\frac{\widehat\omega_{\mathbf k}}{|\mathbf k|^2},\quad \partial_t\widehat\omega_{\mathbf k}=-\mathcal P_K\widehat{\mathbf u\cdot\nabla\omega}_{\mathbf k}-\nu|\mathbf k|^2\widehat\omega_{\mathbf k},\quad 3K<N
$$

The zero mode is removed. Derivatives and the Poisson inversion are done in Fourier space; the nonlinear product is computed on the grid and projected back. A rectangular cutoff that meets the strict two-thirds condition keeps aliases of the quadratic term out of the retained modes. RK4 advances the coefficients, and the energy is never renormalized along the way.

#### Energy and enstrophy balance

$$
E=\tfrac12\langle|\mathbf u|^2\rangle,\quad Z=\tfrac12\langle\omega^2\rangle,\quad \frac{dE}{dt}=-2\nu Z,\quad \frac{dZ}{dt}=-\nu\langle|\nabla\omega|^2\rangle
$$

Energy and enstrophy are defined as averages over the domain and then normalized. Both stay constant in smooth inviscid flow. With viscosity, the dissipation is integrated alongside RK4 with the same stage weights. The balance error compares the current value plus the accumulated loss with the initial value. Time stepping still leaves a measurable residual.

#### Dye moved by a separate scheme

$$
\partial_t c+\mathbf u\cdot\nabla c=\kappa\Delta c,\qquad V_c=\langle(c-\langle c\rangle)^2\rangle
$$

The dye is advanced by tracing back along the flow with a midpoint rule, interpolating bilinearly on the periodic grid and then applying an explicit five-point diffusion step. The interpolation smooths the dye even at zero diffusivity and does not conserve dye mass exactly. The dye does not affect the velocity. Tracer paths come from interpolated velocity and midpoint integration, so they only approximate the true paths of fluid parcels.

#### Taylor–Green vortex as an exact check

$$
\omega=A\sin x\sin y\,e^{-2\nu t},\quad \psi=\frac{A}{2}\sin x\sin y\,e^{-2\nu t},\quad \frac{E}{E_0}=\frac{Z}{Z_0}=e^{-4\nu t}
$$

This flow is a single eigenfunction of the Laplacian, so its nonlinear advection term is zero. Its vorticity decays at a known rate, and the relative error compares the solver with this independent formula, including the inviscid case where the pattern does not change. Patch width and separation play no role here, so they are disabled.

### Common difficulties

#### Two different kinds of mixing

**Typical misconception** The dye variance is falling, so the Euler flow must be losing enstrophy.

**Better mental model** Vorticity and dye are computed by different algorithms. The dye folds into ever smaller structures, and its interpolation smooths them out. Check energy and enstrophy on their own, change the dye diffusivity, and repeat on a finer grid. At zero viscosity the Euler equations have no physical diffusion.

#### An accurate Poisson solve does not mean the flow is resolved

**Typical misconception** A tiny Poisson residual proves every fine filament is accurate.

**Better mental model** The Poisson residual checks that the Fourier inversion and the round trip between grid and spectrum agree algebraically; it does not measure truncation error. The near-cutoff enstrophy counts modes with either wavenumber component in the top fifth of the retained square. If that tail is large, compare with another resolution. The two shell spectra are each scaled to their own peak, so compare their shapes, not their bar heights against each other.

#### Periodic patches are not isolated vortices

**Typical misconception** The dipole and same-sign patches move exactly like isolated point vortices.

**Better mental model** These patches are smooth, have finite width and repeat periodically. Same-sign patches need a uniform background to balance them. A finite Fourier truncation can produce ringing, and it conserves only the two quadratic invariants checked here, not the vorticity of every fluid parcel or every Casimir. This is not a 3D turbulence simulation, and it is not evidence for a universal cascade.

### Run the experiment

1. 01

   #### Follow rotation and dye together

   Start with Co-rotating patches. Turn on Velocity vectors, pause, and advance one solver step at a time. Click a point in either field to probe the same spot in both.

   **What to observe:** Streamlines show the velocity at this instant; tracer tails show where the fluid has recently been. The dye folds while the inviscid energy and enstrophy stay close to their starting values. The same-sign patches orbit each other and deform, but the model does not guarantee that they merge for good.

2. 02

   #### Separate viscosity from numerical loss

   Run a patch experiment with zero viscosity, then with positive viscosity. Change the dye diffusivity separately. Every change to a physical parameter restarts from the same initial state.

   **What to observe:** Viscosity lowers both quadratic invariants, and the integrated dissipation can still account for the loss accurately. Dye diffusion smooths only the dye. A small balance error says nothing about whether dye mass is conserved.

3. 03

   #### Test the resolution

   Compare Perturbed shear at 32, 64 and 128 cells per side at the same simulation time. Then lower the retained bandwidth; dealiasing always stays on.

   **What to observe:** Fine structure and dye loss both change with resolution. The near-cutoff tail and the spectra show what the truncation leaves out. An animation that runs faster in real time does not mean a smaller physical time step.

4. 04

   #### Check an exact solution

   Select Exact decay test, step forward, and change viscosity. Compare the Taylor–Green relative error and both invariant ratios.

   **What to observe:** The error is computed from the Fourier coefficients the solver actually evolved. At zero viscosity the vorticity pattern stays still while the dye and tracers keep moving.

5. 05

   #### Scientific basis and inspiration

   Numerical basis: Trefethen, Spectral Methods in MATLAB (SIAM, 2000), people.maths.ox.ac.uk/trefethen/spectral.html; Bardos and Tadmor, Stability and spectral convergence of Fourier method for nonlinear problems (2013), arXiv:1308.5314. Taylor–Green reference: IncompressibleNavierStokes.jl, TaylorGreenVortex2D validation example.

   **What to observe:** Inspired by the Euler equations, vortices and pathlines at bugman123.com/FluidMotion/. All code and graphics are original. Automated tests check FFT normalization, the invariant balance of the nonlinear term, exact viscous decay, periodic dye transport, and refinement of the grid and time step.

Physical conclusion

A folded picture and a conservation law are different kinds of evidence. Check both, and repeat at another resolution before you trust any fine-scale fluid structure.

Conceptual inspiration: [FluidMotion](http://www.bugman123.com/FluidMotion/index.html). Original simulations and graphics; the model limits are described above.

Fields & matter · Starter path

## From a field to an electron microscope

Map an electric field and steer a charged particle. Then find the electron's wavelength and use electron beams to see a crystal and a surface.

[Start here → **Make an Electric Field Visible** Move the probe around a dipole and check that the field always points downhill on the potential landscape. Observe · 8 min](https://sandboxphysics.com/labs/electric-field/)

1. [1 Make an Electric Field Visible](https://sandboxphysics.com/labs/electric-field/)
2. [2 A Charge Bending through Fields](https://sandboxphysics.com/labs/charged-particle/)
3. [3 Electron Wavelength & Voltage](https://sandboxphysics.com/labs/electron-wavelength/)
4. [4 Electron Diffraction & Reciprocal Space](https://sandboxphysics.com/labs/electron-diffraction/)
5. [5 TEM Bright Field, Dark Field & SAED](https://sandboxphysics.com/labs/tem-mode-selector/)
6. [6 SEM Secondary-Electron Topography](https://sandboxphysics.com/labs/sem-topography/)

[View the full path →](https://sandboxphysics.com/topics/fields-and-matter/#starter-path)
