Fluid Mechanics
Fluid mechanics studies how fluids move and interact with their surroundings. The Navier-Stokes equations describe this behavior, treating fluids as a continuous medium rather than individual particles.
In our Fluid simulation, we use a grid-based approach to solve these equations. We track two main properties for each grid cell: velocity (the direction and speed of the flow) and density (the concentration of a substance like dye).
The Core Principles
The simulation relies on three fundamental steps:
1. Advection: This step moves quantities (like density and velocity itself) along the velocity field. Mathematically, it represents the convective term in the Navier-Stokes equations, ensuring that the fluid's momentum carries properties forward.
2. Diffusion: Fluid properties naturally spread out over time due to viscosity. The diffusion step accounts for this, smoothing out sharp gradients in velocity and density, much like how a drop of ink disperses in water.
3. Projection (Incompressibility): We assume the fluid is incompressible, meaning its volume remains constant. The projection step enforces this constraint by solving a Poisson equation for pressure, ensuring that the total flow into a cell equals the flow out. This is what gives the fluid its characteristic swirling, mass-conserving behavior around obstacles.
By iteratively applying these steps, the simulation produces a visually accurate representation of fluid dynamics, complete with complex phenomena like vortices and boundary layers.