Euler fluid
Eulerian fluid simulation
Section titled “Eulerian fluid simulation”Below you find an interactive Eulerian fluid simulation including the possibility to visualize flow lines and velocity fields. An obstacle may be moved in or out of the flow by the user. It is also meant as a somewhat more elaborate demo using the Helion library.
©️ Original idea and software: Matthias Müller — Ten Minute Physics
💡️ The streamlines are also for drawing electric field lines!
Implementation
Section titled “Implementation”Let’s first assert that:
- Liquids and gasses behave quite similarly, so they can often be modeled using similar modeling techniques.
- We will opt for a grid-based approach, also known as “Eulerian approach”. This means we start with a grid of some particular size and can only have fluid/gas inside that grid.
- We assume the fluid (or free gas) to be incompressible. Water is actually very close to being incompressible.
- We also assume the liquid to be inviscid (i.e. non-viscous).
+-----------------------------------------------+ | Fluid model (Demo) | | │ | | DiscreteVectorField (Helion) | | │ | | Velocities, pressure, smoke, streaming values | +-----------------------------------------------+ │ │ ▼ +-----------------------------------------------+ | Adapter | | │ | | PressureFieldAdapter / SmokeFieldAdapter | | │ | | Fluid values ==> surface view values | +-----------------------------------------------+ │ │ ▼ +-----------------------------------------------+ | DiscreteFieldSurfaceView (Helion) | | │ | | Generic existing visualisation | | │ | | Velocities, pressure, smoke, streamlines | +-----------------------------------------------+The three main steps
Section titled “The three main steps”-
Modify the velocity values based on the forces. Here we only use the gravitational force. We denote this step as integration.
for all i, jv[i, j] = v[i, j] + Δt * g -
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.
-
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
Section titled “References”- Check out the How to write an Eulerian Fluid Simulator PDF!
- Fluid Simulation (with WebGL demo) by Jamie Wong