2D Navier-Stokes Back
CFD Simulator

2D Navier-Stokes Flow Simulator

Run vorticity-stream function CFD for lid-driven cavity flow. Adjust Reynolds number and grid size, then watch vorticity contours and streamlines develop.

Parameters
Reynolds number Re
Grid size N
Steps per frame
Results
400
Re
0
Iteration
0.00
Max vorticity
0.00
Min vorticity
Vorticity contours (red=positive, blue=negative) + streamlines
Theory & Key Formulas

Vorticity transport:

$$\frac{\partial \omega}{\partial t}+ u\frac{\partial \omega}{\partial x}+ v\frac{\partial \omega}{\partial y}= \nu \nabla^2 \omega$$

Stream-function Poisson equation:

$$\nabla^2 \psi = -\omega, \quad u=\partial\psi/\partial y, \quad v=-\partial\psi/\partial x$$

What is Lid-Driven Cavity Flow?

🙋
What exactly is a "lid-driven cavity" in this simulator? It sounds like a box with a moving lid?
🎓
Exactly right! It's a classic benchmark problem in CFD. Imagine a square container filled with fluid, where the top wall (the "lid") slides sideways. That motion drags the fluid inside, creating complex swirling patterns. In this simulator, you control the speed of that lid, which directly changes the Reynolds number.
🙋
Wait, really? So the Reynolds number isn't just a property of the fluid? How does changing the lid speed here affect the flow?
🎓
Great question! The Reynolds number ($Re$) here represents the ratio of inertial forces to viscous forces. A higher lid speed increases inertia, making the flow more chaotic. Try it: slide the "Reynolds Number" control up from 100 to 1000. You'll see the single, centered vortex break apart into smaller, off-center vortices in the corners.
🙋
So the colored contours show vorticity, and the lines are streamlines. What's the practical difference, and why do engineers care about both?
🎓
In practice, they tell complementary stories. Vorticity (the colors) shows where the fluid is rotating locally—like pinpointing tiny whirlpools. Streamlines (the black lines) show the overall path a fluid particle would take. Engineers use both to identify recirculation zones, mixing efficiency, and stress points. For instance, adjusting the "Grid Size" parameter refines these visuals, showing more detail in the corner vortices.

Physical Model & Key Equations

The simulator solves the 2D, incompressible Navier-Stokes equations using the vorticity-stream function formulation. This approach eliminates pressure and enforces mass conservation automatically. The governing equation for vorticity ($\omega$) transport is:

$$\frac{\partial \omega}{\partial t}+ (\mathbf{u}\cdot \nabla)\omega = \frac{1}{Re}\nabla^2 \omega$$

Where $\omega = \nabla \times \mathbf{u}$ is the vorticity (a scalar in 2D, measuring local rotation), $\mathbf{u}$ is the velocity vector, $t$ is time, and $Re$ is the Reynolds number. The term $(\mathbf{u}\cdot \nabla)\omega$ represents convection, and $\frac{1}{Re}\nabla^2 \omega$ represents viscous diffusion.

The stream function ($\psi$) is solved from the vorticity to obtain the flow field. It is defined such that velocity components are its derivatives, guaranteeing an incompressible flow:

$$\nabla^2 \psi = -\omega$$

$$ u = \frac{\partial \psi}{\partial y}, \quad v = -\frac{\partial \psi}{\partial x}$$ Here, $\psi$ is the stream function. Lines of constant $\psi$ are the streamlines you see in the simulation. The velocity components $(u, v)$ are derived from it, ensuring the flow satisfies $\nabla \cdot \mathbf{u} = 0$ (incompressibility).

Frequently Asked Questions

The Reynolds number (Re) is the ratio of advection to diffusion strength. When Re is small, viscosity dominates and the flow remains stable and laminar. Increasing Re makes vortices more likely to form, and the flow field becomes more complex. The position and strength of the main vortex in the cavity also change, so try moving the Re slider to compare.
The main cause of divergence is that the time step is too large. In the settings panel on the screen, reduce Δt (time step) or adjust it to satisfy the CFL condition. Also, if the Reynolds number is extremely high (e.g., Re > 10000), numerical instability is more likely, so we recommend first trying a low Re (e.g., 100 to 1000).
This simulator is based on the vorticity-stream function method assuming a 2D, incompressible, steady state, and has been widely validated as a benchmark problem for lid-driven cavity flow. At low to moderate Reynolds numbers (Re < about 5000), it agrees well with experiments and high-precision calculations, but at high Re, it ignores 3D effects and turbulence, making it suitable for learning qualitative trends.
In the display settings panel on the right or top of the screen, you can toggle checkboxes such as 'Velocity Vectors,' 'Streamlines,' and 'Vorticity Contours' on or off. You can also adjust the color map type and transparency. If the display is cluttered and hard to see, temporarily turning off unnecessary items will make it clearer.

Real-World Applications

Chemical Mixing Tanks: The flow inside a stirred tank reactor is very similar to a lid-driven cavity. Engineers use this model to optimize paddle design and placement, ensuring chemicals mix thoroughly and efficiently without dead zones where fluid stagnates.

Microfluidic Devices: In lab-on-a-chip devices, fluids are often manipulated in tiny etched chambers. Understanding the vortex formation at different flow speeds (Reynolds numbers) is crucial for designing efficient cell sorters, mixers, and sensors.

Building Ventilation: Airflow in a room with a ceiling fan or a ventilation inlet creating a shear flow along the ceiling can be modeled as a cavity flow. This helps HVAC engineers design systems that minimize drafts and ensure proper air circulation.

Coating and Painting Processes: When applying a liquid coating (like paint or a protective film) over a surface contained within a raised border, the fluid dynamics resemble a driven cavity. Simulating this helps predict coating thickness uniformity and avoid defects.

Common Misconceptions and Points to Note

When you start using this simulator, there are a few points that are easy to misunderstand. First, you might tend to think "higher Reynolds numbers are closer to real flow," but that's not correct. Increasing Re does make the vortices more complex, but that's a state attempting to mimic "unsteady, near-turbulent behavior." However, this simulation is 2D and calculates under the assumption of "laminar flow." It's fundamentally different from real-world 3D turbulence, so directly using results from, say, Re=10000 for pump design is risky. Remember, it's a tool for observing the "trend" of a phenomenon.

Next, the grid size N setting. With N=32 or 64, calculations are fast, but especially at high Reynolds numbers, the vortex shapes can be coarse, and sometimes the solution can become unstable and oscillate. This happens because numerical diffusion becomes strong and cancels out the actual physical viscous effects. In practice, mesh (grid) resolution is the lifeline of simulation, and a "mesh dependency study"—the essential process of refining the mesh until results no longer depend on its coarseness—is mandatory. With this tool too, you can experience its importance by comparing, for example at Re=1000, how the bottom-left secondary vortex is represented when you change N to 64, 128, and 256.

Finally, understand the implication of the fact that "pressure is not calculated." The vorticity-stream function method is stable and excellent for computation, but it cannot be used directly for phenomena where you "need to know the pressure itself," such as wing lift/drag or pressure loss in pipes. For those cases, you need "primitive variable methods" (like the MAC or SIMPLE methods) that solve for velocity and pressure directly. This tool is your first step for understanding flow "patterns" and "structure."

How to Use

  1. Set Reynolds number (Re) between 100 and 10000 using the slider—higher Re produces finer vortex structures and instability
  2. Adjust grid resolution (n) from 32 to 256 cells per side; finer grids capture smaller eddies but require longer computation
  3. Configure time step (dt) between 0.0001 and 0.01 to ensure numerical stability; smaller dt prevents divergence at high Re
  4. Click Run to solve the incompressible Navier-Stokes equations on the cavity domain with no-slip walls and moving lid velocity
  5. Monitor vorticity extrema and iteration count; streamlines reveal recirculation zones

Worked Example

Lid-driven cavity with Re=1000, 128x128 grid, dt=0.001: top wall moves at 1 m/s in a 1 m square domain (kinematic viscosity ν=0.001 m²/s). After 5000 iterations, primary vortex center stabilizes near (0.5, 0.35) with max vorticity ≈ 12 s⁻¹ and min vorticity ≈ -8 s⁻¹. Secondary corner eddies appear at lower-left and lower-right with weaker circulation. Using 64x64 grid underresolves corner features; 256x256 resolves them but requires dt≤0.0005 for stability.

Practical Notes

  1. For Re<100, flow becomes steady and symmetric; above Re=1000, transient vortex shedding and chaotic behavior emerge in coarse grids
  2. Vorticity magnitude scales with shear rate; high min/max ratio indicates strong jets or boundary layers typical in viscous regimes
  3. CFL condition: set dt such that advective Courant number remains <0.5 to prevent oscillations
  4. Compare 128 vs 256 resolution at same Re to validate grid independence—identical streamline topology confirms convergence