Disclaimer: I have no professional education in Compulational Fluid Dynamics, these are various notes on what I found/learned when trying to learn a bit on the topic. Some of the notes lack sources as I wrote them up later often just remembering some StackExchange answer. Some things I might have misinterpreted.
- Computational Fluid Dynamics (in graphics mostly)
- General / Overview
- SPH (Lagragian)
- Hybrid methods (mostly Eulerian)
- Finite Difference/Volume/Element (Eulerian)
- Lattice Boltzmann methods (LBM)
- Rendering
- Important/big/famous/interesting simulation software packages
- Fluids in Games GDC 2010
- Bridson & Müller-Fischer, Fluid Simulation Siggraph 2007 Course Notes, derived from the standard reference book of the same author, Bridson, Fluid Simulation for Computer Graphics
- Youtube Channel: Fluid Mechanics 101 (focused on )
- Wikipedia: Computational fluid dynamics
- Density ρ: Mass per volume, m / V
- Pressure p: Force per area, F / A
- Viscosity: The more a fluid has the "thicker" it is
- Dynamic viscosity μ: Relation of viscous stresses to rate of change
- Kinematic viscosity ν: μ / ρ
- Reynolds Number Re: A measure for how turbulent a flow is (higher is more turbulent)
- Mach Number M: Ratio of fluid velocity to speed of sound in that fluid. (if low then can treat fluid as incompressible)
- Courant–Friedrichs–Lewy condition (CFL): Condition for convergence of a numerical solution for a partial differential equation. Wiki
- Poisson Equation: Differential equation on laplacian, ∇²p=f
- Navier Stokes explanation by COMSOL starts out with compressible flow
- most simulations only care about the much easier incompressible flow, but this article is nice to understand how it is connected
Solving Navier Stokes: Either Lagrangian or Eulerian point of view (wiki). Eulerian: Grid. Lagrangian: Particles
- Lagragian:
- Smoothed Particle Hydrodynamics (SPH): Particles moving around
- Eulerian:
- Finite volume method (FVM): Eularian
- Finite element method (FEM): Eularian
- FLIP / PIC (particle in cell): Particles but solve with eulerian grid
- Other:
- Lattice Boltzmann methods (LBM) do not operate on Navier-Stokes directly but on grid of particle distributions governed by Boltzmann equations
Pro/Con (pure) Lagragian:
- advection is fairly trivial
- incompressibility harder to enforce. Can have issues with nonuniform particle distribution
Pro/Con (pure) Eulerian:
- incompressibility condition relatively easy to enforce
- advection harder. Tecniques like vorticity confinement used to counter dissipation
Resources
- SPlisHSPlasH Open Source SPH implementation
- Wikipedia: Smoothed Particle Hydrodynamics
- Koschier et al. 2019, Smoothed Particle Hydrodynamics Techniques for the Physics Based Simulation of Fluids and Solids (Eurographics Tutorial)
- Lecture from Uni Heidelberg notes
- "SPH Survival Kit" practical notes (yay!!) supplementing these lecture slides
- "Computing null divergence field using smoothed particle hydrodynamics as referred by the "Survival Kit", this paper argues its way through some more robust kernel formulations, in particular a comparision of gradient approximations
Basic idea: Reconstruct continous signal with gaussians (== smoothed particles). This makes every quantity in every point a weighted sum of particles/kernel functions. Generally, first need to estimate the density in every particle. Then, compute total change of velocity caused by pressure gradient, viscosity and direct forces.
Kernel function used to be typically a cubic spline. But there are others (PySPH implements quite a bunch) Many simulations use different kernel functions for different parts of the velocity update for more stability.
Muller et al. 2003, Particle-Based Fluid Simulation for Interactive Applications seemingly introduced computer graphics community to the concept of SPH. Kernel functions defined in there (poly6, spiky, viscosity) are widespread.
Wikipedia write about accuracy for fluid mechanics:
One drawback over grid-based techniques is the need for large numbers of particles to produce simulations of equivalent resolution. [...] However, accuracy can be significantly higher with sophisticated grid-based techniques, especially those coupled with particle methods (such as particle level sets), since it is easier to enforce the incompressibility condition in these systems. SPH for fluid simulation is being used increasingly in real-time animation and games where accuracy is not as critical as interactivity.
Incompressible fluid keeps density constant <=> velocity field divergence free.
(compressible fluid allows for a certain amount of density change, so problem still similar)
Methods can generally be distinguished whether they ...
- use a state equation or use pressure poisson equations (PPE) Koschier et al. 2019, SPH Eurographics Tutorial, 02 Incompressiblity slide 11
- State equation: WCSPH 2007, PCISPH 2009, LPSPH 2013
- PPE: IISPH 2013, DFSPH 2015, Cornelis et al. 2019, Pressure Boundaries for Implicit Incompressible SPH
- support compressible fluids or not which may not be important when only dealing with incompressible fluids, i.e. most liquids.
Mentioning a few selected approaches selected here:
Solving with the standard approach, weakly compressible SPH (WCSPH), requires to allow some compressiblity, usually done by reducing speed of sound (-> lower pressure than there should actually be since this governs how pressure is derived from density), otherwise required timesteps get too small. Guidance on how to choose speed of sound and timestep slide 35 here
Modern paper typically cite Becker & Teschner 2007, Weakly compressible SPH for free surface flows which presents treatments on a full framework (including surface tension). See equation (9) and following on timestamp / speed of sound / compressibility relations.
Maklin & Muller 2013, Position Based Fluids
SPH technique with constraints as in a position based physics system (i.e. more or less all game physics - [citation needed]). Uses constraints between particles to enforce incompressibility. Constraints are solved iteratively.
Bender & Koschier 2015, Divergence-Free Smoothed Particle Hydrodynamicss
Bender & Koschier 2017, Divergence-Free SPH for Incompressible and Viscous Fluids
Does not only focus on constant density but also on divergence free velocity field. CFL condition for maximum timestep applies.
Physical viscosity formulations typically take dynamic viscosity μ parameter. Muller et al. 2003, Particle-Based Fluid Simulation for Interactive Applications formulates physical viscosity as: fi = μ sum_over_particles_j(m * velocity_difference / density_j laplacian_of_kernel_func)
Artificial approaches are used to dampen unphysical oscilations on shocks (or generally high Reynolds numbers). Mentioning a few selected approaches selected here:
Term refers in general to any non-physical viscosity formulation, usually refers though to a special term added in the computation for pressure related accelleration. Typical formulations set artificial viscosity to zero for particles that do not move towards each other. See also D.J. Price PHD thesis, 3.5 Shocks
By some classified as a kind of artificial viscosity.
Added on velocity integration. Instead of changing the position via r += v * dt
, neighbors are taken into account using the SPH Kernel:
r_a += (v + eps * ForAllParticlesB(m_b * (v_ba / ((ρ_a + ρ_b) * 0.5)) W_ab) )*dt
(see 1992 review by Monaghan)
Can replace physical viscosity treatment completely:
The goal of artificial viscosity is just to damp out non-physical oscillations that plague the undamped method: a full treatment of physical viscosity, with a nonphysical coefficient tuned to stabilize the discretization, is overkill." Ghost SPH for Animating Water, Schechter et al. (this paper also uses the XSPH viscosity on the velocity, which makes it easier to stick to the usual framework - SPlisHSPlasH impl takes this further and puts it onto the accelleration by dividing by dt)
Need to access particles in neighborhood a lot (bound by smoothing distance). All approaches are based on some kind of (sparse) grid binning (at the very least conceptually!). A few general ideas:
- spatial consistency
- all algorithms profit from spatial coherency. employ space filling curve!
- sorting doesn't need to be done every frame
- can be costly since there might be many attributes
- spatial hashing
- spatial hash into a bin which then contains particle indices
- Advisory to occasionally sort particles spatially for better cache access
- Compact Hashing by "Ihmsen et al, A Parallel SPH Implementation on Multi-Core CPUs" outlined in Eurographics SPH Tutorial slide 48
- Lecture slides promoting compact hashing but also giving good overview over other techniques, SPHNeighborhood Search (and Time Step), Matthias Teschner University of Freiburg
- sorting
- sort by bin and remember offsets per bin
- nice for GPUs since everything is in place
- tends to rewrite all the data every frame though
- GPU Tech Conference slides on solving this with counting sort on gpu
- cell linked lists (CLL approach)
- every particle has a linked list to its "true" neighbors
- during query no need to look at cell data structure, but for builtup cells are still important
- if particles are spatially (i.e. cell index) sorted then this linked list can be heavily compressed!
- For a modern approach see Compressed Neighbour Lists for SPH, Stefan Band et al.
- General approach:
- sort all particles by grid cell index
- keep a list of the first particle of all grid cells
- for each particle create linked list, sped up by grid cell search
- compress linked list and store it
- sort all particles by grid cell index
- every particle has a linked list to its "true" neighbors
Unified Spray, Foam and Bubbles for Particle-Based Fluids, Ihmsen et al 2012 (also talks a bit about rendering)
Approaches that combine eularian grid and lagrangian particles: Use particles to resolve transport, use grid to compute forces and collision response. (i.e. "fix" the neighborhood problem) Generally, transfer between representation creates error!
Important Methods:
- PIC: Particle in Cell.
- The "original"
- keep quantities like velocity completely in the grid
- leads to very strong damping effect, angular momentum not preserved
- FLIP: FLuid Implicit Particle. Brackbill et. al. 1986/88. Widely cited is Zhu & Bridson 2005, Animating Sand as a Fluid
- Very popular in visual effects - primary solution for fluids in Houdini, very popular Blender plugin exists
- Less dissipative than PIC but occasionally less stable
- transfer increments of velocity/displacement from grid to particles instead of interpolating from grid
- suffers from instabilities, preserves some angular momentum, sometimes mixed with PIC for more stability (which brings in drawbacks as well)
- APIC: Affine Particle In Cell. Jiang et al., 2015, video
- less noisy than FLIP and retains low dissipation
- still uses MAC grid like PIC/APIC but transfer happens from/to not only a velocity but also an locally affine 3x3 velocity matrix
MAC Grid (also staggered Grid): Marker and cell grid (named after how it's used originally). Instead of storing velocities at the grid cells, x/y/z components are offset which makes finite differences at the cells much easier and avoids skipping over mid point. Avoids pressure oscillations ("checkerboard pressure") caused by skipping mid cell in central differences. Makes boundary equations a bit harder. Another way of avoiding oscillations in a collocated(/uniform/cell-centered) grid is Rhie-Chow interpolation.
Excellent explanation for how to solve with MAC grids (but also very helpful for understanding grid based approaches in general): Bridson & Müller-Fischer, Fluid Simulation Siggraph 2007 Course Notes
Houdini docs:
The Splashy Kernel corresponds to the FLIP/PIC method of velocity transfer, while the Swirly Kernel is implemented with the newer APIC method.
Some old docs talk a bit about pro/con of SPH versus FLIP: Bottom line FLIP is more stable such less substepping required and easier to work with albeit bad for slow moving (-> APIC alleviates that).
Suffers typically from volume loss, recent approach aiming to fix this: Kugelstadt et al., Implicit Density Projection for VolumeConserving Liquids
- transfer velocity to grid
- apply forces to grid
- solve pressure equation & enforce boundary conditions
- transfer velocities back to particles
- for PIC: Replace
- for FLIP: Update particle velocities with difference on grid since transfer to grid
- advect particles
Unlike with SPH, solving equation as Ax=b (with x as pressure and b as divergence) problem is typical. A is a quite simple coefficient matrix that describes relationship between neighboring pressures. Note that the dimension of A for a 3D fluid problem is (width * height * depth)², but it is very sparse, symmetric and positive definite.
Most popular solver for this is Preconditioned Conjugate Gradient Method (PCG), but Jacobi iterations work well enough for getting started on a toy example. Implementing it requires only some vector math, understanding it is a bit harder. Jonathan Richard Shewchuk 1994, An Introduction to the Conjugate Gradient Method Without the Agonizing Pain Edition 1 1/4 explains it step by step and in detail. Conjugate Gradient Method, 2007, a handout for a lecture of theIowa State University, gives a shorter overview.
Chentanez & Müller 2011, A Multigrid Fluid Pressure SolverHandling Separating Solid Boundary Conditions describe a more complex multi-grid solver which also avoids the typical stickiness problems of the "standard" boundary condition.
Transfer Particles->Grid is surprisingly tricky! Can do either gather or scatter.
Gather particles per grid cell: Need to find relevant particles somehow
Scatter particles to grid: Read/write contention - there's atomic float addition is not widely available, and even when it is it's slow.
Some ideas for ideas for conflict resolution in Ming et al 2018, GPU Optimization of Material Point Methods
Doing staggered grids in particular can get very expensive since now particles scatter over an even wider area.
Some pressure solvers are not well suited for GPU impl: For example Preconditioned Conjugate Gradient Method with Incomplete Cholesky preconditioner is very effective and popular (see Bridson, Fluid Simulation for Computer Graphics), but different pre-conditioners are much better suited for a GPU impl see e.g. Austin Eng's WebGL FLIP implementation.
Generalization to wider range of physical phenomena: Material Point Method (MPM). Excellent overview and redirect to various resources, by Niall Tl.
State of the art (and easier and faster than previous!) is Moving Least Squares MPM (MLS-MPM) by SIGGRAPH 2018, Yahnming Hu et al..
In a way (MLS-)MPM is closer again to SPH as more computation is happening on per-particle basis than rather on the grid as is the case with "pure" APIC fluids. Most notably there is (typically) no pressure solver or similar applied to the grid (rather state equations like in WCSPH). This makes the implementation easier & faster but also requires lower time steps.
Note that due to the different gradient requirements the grid in (MLS-)MPM is not staggered!
From the MLS-MPM paper:
Interestingly, our derivation shows that MPM, although seemingly quite different from purely Lagrangian meshless methods, can be treated as a modified element-free Galerkin (EFG) method [Belytschko et al.1994], where the background Eulerian grid merely acts as a helper structure for accelerating MLS interpolation from particle neighbor regions.
- short explanation and comparision of these methods: Autodesk 2019, Finite Element vs Finite Volume
- points out that Finate Differences is not actually usable
- Ed Fontes, COMSOL Blog, 2018,FEM vs. FVM
- The Finite Volume Method in CFD, Lecture Video
Popular in structural analysis but not so much in fluid dynamics since it requires higher cell resolution wiki
In pure form simple to implement grid propagation scheme. Looks at fluid with Boltzmann equations instead of Navier Stokes -> probability distributions of particles. Simulates steps of particles moving to neighbor gridcells and colliding with statistical functions. Needs very very small time steps and high grid resolution for more macroscopic phenomena. Scales very well with GPUs since can operate on homogenous grid cells individiually.
TODO: https://softologyblog.wordpress.com/2017/03/28/more-fun-with-lattice-boltzman-method-lbm-fluid-simulations/ https://medium.com/swlh/create-your-own-lattice-boltzmann-simulation-with-python-8759e8b53b1c
SimScale has a GPU based LBM solver
Screen space splatting of fluid particles, described well in these GDC 2010 slides,
some improvements & paper here: Screen space fluid rendering with curvature flow
And even more improvements: Adding a foam layer that can also be underwater! A Layered Particle-Based Fluid Model for Real-Time Rendering of Water, Bagar et al 2010 adding handling of a foam layer.
Improved screen space filtering A Narrow-Range Filter for SCreen-Space Fluid Rendering, Truong et al. 2018
Screen Space Foam Reandering, Akinci et al. 2013
Real-Time Screen-Space Liquid Rendering with Complex Refractions, Imai et al. 2016 (Sounds at first like they do two layers each with two refactions, but that's only technically true since one of the layers consists entirely of splashes)
level sets? surface extraction?
- COMSOL Multiphysics
professional simulation, combines different simulations (thus the Multi) - SIMSCALE
- Altair
- nanoFluidX
a sph based simulation
- nanoFluidX
- OpenFOAM
A open source CFD toolbox - Houdini
VFX for movies and games - Fifty2 Industrial SPH simulation (heavy transfer from CG research at University Freiburg)
Hello, very nice post. As an engineering student, I used this article. With these shares, I used the Engineering Calculators of the Mechanicalland Site.
I was able to do my transactions online. Thank you.