Fluid Simulation

Stir a real-time fluid with your mouse and watch dye and velocity swirl across the grid. Every frame solves a stable form of the Navier–Stokes equations — the same maths behind real liquids and gases — right here on your device. Drag to inject colour and momentum, load a preset (smoke plume, ink drop, swirling vortex or rainbow), and tune the viscosity and dye fade while the readouts track the flow. Nothing is uploaded.

You are in the Physics lab.

Click and drag to stir the fluid
Colour modeCyan
Viscosity10
Dye fade8
Mean flow (arb.)0
Frames/sec0
Grid128×128
1 · Advection — carry dye along the flow → 2 · Diffusion — spread and smooth it → 3 · Projection — keep the fluid incompressible
Real fluid maths, running on your device. Every frame this solves a stable form of the Navier–Stokes equations using Jos Stam's 1999 "Stable Fluids" method — entirely in your browser, with nothing sent to a server. The same equations, in 3D and at far higher resolution, drive the smoke, water and fire you see in visual-effects shots in films.

Reading the simulation

What your dragging, the swirling colour and the live readouts are telling you.

1

Dragging injects dye and velocity

Every time you drag across the canvas you push two things into the cells under the cursor at once: a splash of coloured dye and a kick of velocity in the direction you moved. The Force slider scales how hard that kick lands, and the Colour mode readout shows which dye you are painting. A preset does the same thing for you — the smoke plume, ink drop and swirling vortex each drop a telling burst of dye and momentum in one shot.

2

The flow advects and diffuses it

Once injected, the dye no longer sits still — the velocity field advects it, carrying each cell's colour to wherever the flow was heading, which is what stretches a blob into ribbons and streaks. At the same time diffusion lets neighbouring cells trade velocity so the motion smooths out; that is viscosity, the fluid's internal friction. Turn Viscosity up and the flow goes thick and syrupy, down and it runs thin and free. The Dye fade slider sets how quickly the colour dissipates, and the Mean flow readout rises as you stir and settles as the motion dies away.

3

Projection keeps it swirling

A real fluid conserves mass — it cannot pile up or leave gaps. After each move the projection step corrects the velocity field so it is incompressible, and that constraint is exactly what turns a straight push into rolling vortices. Without it the flow would look flat and lifeless; with it, every drag leaves curling eddies that keep spinning long after you let go.

How It Works

The three stages the solver runs every frame to move the fluid and its dye.

1

Advection

The fluid carries things along with it. Each cell looks backwards along the velocity field to find where its contents came from a moment ago, then pulls that velocity and dye forward. This is what makes dye streak and swirl instead of sitting still.

2

Diffusion & viscosity

Neighbouring cells exchange velocity so the flow smooths out over time — that is viscosity, the fluid's internal friction. The solver spreads the field with a few Gauss–Seidel iterations; raising the viscosity slider makes the motion thick and syrupy, while lowering it makes it thin and free-flowing.

3

Projection

A real fluid conserves mass — it cannot pile up or vanish. The projection step corrects the velocity field so it is incompressible, which is exactly what creates the rolling vortices. Without it, the flow would look flat and lifeless.

What is this fluid simulation actually computing?
This fluid simulation advances a velocity field and coloured dye across a 128×128 grid every frame, solving a stable form of the Navier–Stokes equations — the equations that govern how liquids and gases move. Each frame runs three steps: advection carries the contents of every cell along the flow, diffusion spreads them slightly, and a projection step removes any net compression so the fluid stays incompressible. When you drag, you inject velocity and dye at the cursor, and the solver carries them along the flow to produce the swirling vortices you see.
What are the Navier–Stokes equations?
The Navier–Stokes equations describe the motion of fluids by conserving momentum and mass. They account for how a fluid is pushed by forces, resists motion through viscosity, and stays incompressible. This simulation uses Jos Stam's 1999 'Stable Fluids' method, which keeps the solver stable at any time step so it can run smoothly in real time.
Is this real physics, and what are its limits?
This fluid simulation uses the same governing equations as real fluid dynamics, so the qualitative behaviour — swirling, mixing, diffusion — is physically motivated. But it trades accuracy for speed: it runs on a coarse 128×128 grid, uses a small number of solver iterations, and Stam's method adds numerical smoothing that dampens the finest turbulent detail. It is a visual, educational model, not an engineering-grade solver.
Can I put this on my own website?
Yes — the fluid simulation has an embeddable build at lkforge.com/embed/fluid-sim/ that you can drop into an <iframe> on your own site. It loads the same solver script as this page, with the surrounding page furniture stripped away. It runs entirely client-side with no tracking.

Teaching or blogging about physics? You can embed this on your own site free — one line of code, no sign-up.

Classroom activity

A ready-to-assign lab using the simulation above. Free to use — nothing to install or sign up for, and no student data leaves the browser.

High school, College10–20 minInteractive simulation

Learning objectives

  • Distinguish laminar from turbulent flow.
  • Describe how obstacles create vortices.
  • Relate flow behavior to speed and viscosity.

Variables to change

  • Flow speed
  • Viscosity
  • Obstacles

Procedure

  1. Start a slow, smooth flow and observe the streamlines.
  2. Increase the speed and watch the flow become turbulent.
  3. Place an obstacle and observe vortices forming downstream.

Observations

Describe the flow pattern (smooth vs chaotic) at low and high speed, and around obstacles.

Questions

  1. What is laminar flow?
  2. What is turbulent flow?
  3. What happens to flow as speed increases?
  4. What is a vortex?
  5. What equations govern fluid flow?

Explanation

Fluids flow smoothly (laminar) at low speed and break into chaotic, swirling turbulence at high speed, especially past obstacles that shed vortices. All of this is governed by the Navier–Stokes equations for momentum and mass conservation.

Answer key (for instructors)
  • 1. Smooth flow in parallel layers that do not mix.
  • 2. Chaotic, mixing flow with eddies and vortices.
  • 3. It tends to transition from laminar to turbulent.
  • 4. A region of swirling, rotating fluid, often shed behind an obstacle.
  • 5. The Navier–Stokes equations, expressing conservation of momentum and mass for a fluid.

Educators: link or embed this simulation freely in your LMS or course guide.

Add This Fluid Simulation to Your Website

Put the Fluid Simulation on your own page — free, no sign-up, no watermark. It runs entirely in your visitors' browsers. Copy the snippet and paste it into your page's HTML.

The credit line under the widget links back to LK Forge — please keep it so others can find it too.