Interactive three-dimensional simulations & visualizations

Visualizing the beauty in physics and mathematics


Project maintained by zhendrikse Hosted on GitHub Pages — Theme by mattgraham

Euler fluid simulation in pure Javascript


You can move the obstacle with your mouse!

• Copyright 2022 Matthias MüllerTen Minute Physics
• See also his GitHub pages
• Code clean up by Zeger Hendrikse, see euler_fluid.html

Streamlines Velocities Pressure Smoke Overrelax

Implementation


Let’s first assert that:

The three main steps


  1. Modify the velocity values based on the forces. Here we only use the gravitational force. We denote this step as integration.
    for all i, j
        v[i, j] = v[i, j] + Δt * g 
    
  2. Make the fluid incompressible. We call this step projection. An incompressible fluid means that the divergence (i.e. inflow and outflow) at each grid cell needs to be zero.
  3. We move the velocity field in the grid. We call this step advection, as advection is defined as the transfer of a property from one place to another due to the motion of the fluid. So if you’ve got some black dye in some water, and the water is moving to the right, then the black dye moves right.

    Just as black ink would move through the fluid, so too will the velocity field itself! Intuitively you can think of it this way: a particle moving in a certain direction will continue moving in that direction, even after it’s moved.

    Since we’re storing velocity in a grid just like we do with the smoke, we can use the exact same routine to advect velocity through itself.

References



Share on: