Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper...

57
{ Position Based Fluids How to simulate fluids

Transcript of Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper...

Page 1: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

{ Position Based Fluids

How to simulate fluids

Page 2: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Intro

Much bigger field than expected

Agenda:

- Background

- Smoothed Particle Hydrodynamics

- Navier-Stokes equations

- Position Based Dynamics

- Combining SPH and PBD (the paper)

- Video

- Questions?

Page 3: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Background

What is a fluid?

- Liquids (e. g. water)

- Gasses (e. g. air)

- Plasmas

Fluids continually deforms (flows) from high pressure to low pressure

Page 4: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Background

Lagrangian

(particles)

Eulerian

(grids)

Ways of representing fluids

Page 5: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Macklin and Müller’s approach (the paper):

”Combines Smoothed Particle Hydrodynamic (SPH) with Position Based Dynamics (PBD)”

Background

So, what is SPH and PBD?

Page 6: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Smoothed Particle Hydrodynamics (SPH)

Introduced by Monoghan 1992 using smoothing kernels and approximations to the Navier-Stokes equations

SPH is a computational method for simulating fluid flows. SPH uses the Lagrangian representation (particles)

Page 7: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Navier-Stokes equations

The Navier-Stokes equations were derived by Navier, Poisson, Saint-Venant, and Stokes between 1827 and 1845.

The Navier-Stokes equations describe how flows in fluids behave.

There are no analytical solutions, only numerical or simplified solutions. The Navier-Stokes equations is one of the Millennium Prize Problems

Page 8: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Navier-Stokes equations

The incompressible N-S equation:

ρ: density

g: gravity

μ: viscosity

p: pressure

v: velocity

Always solved together with the continuity

equation

Page 9: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Navier-Stokes equations

The incompressible N-S equation:

Inertial forces

Page 10: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Navier-Stokes equations

The incompressible N-S equation:

gravity

Page 11: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Navier-Stokes equations

The incompressible N-S equation:

pressure forces

Page 12: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Navier-Stokes equations

The incompressible N-S equation:

Viscous forces

Page 13: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Navier-Stokes equations

N-S equation for one particle:

The derivative of the velocity of particle i, with respect to time

(acceleration)

Page 14: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

From N-S to SPH

The SPH framework:

Evaluate a field anywhere by weighted sum

Page 15: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

From N-S to SPH

Examples of smoothing kernels:

Page 16: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

From N-S to SPH

Approximate the N-S equations using SPH framework

Page 17: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

From N-S to SPH

Plug the equations into the original equation

Page 18: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Updating SPH

Each time step:

- Compute acceleration a of each particle

- Update velocities: v = v + a dt

- Update positions: x = x + v dt Leapfrog integration

Page 19: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Position Based Dynamics

Introduced by Müller et al. (NVIDIA)

At the same time by Jos Stam (Maya)

Popular because of generality, simplicity, robustness and efficiency

Used in PhysX, Havok Cloth, Maya nCloth and Bullet

in 2006

Page 20: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Position Based Dynamics

Page 21: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Position Based Dynamics

Main idea:

- Instead of forces – constraints

- Instead of integration – constraint projection

Mass points:

mass mi, position xi, and velocity vi

Constraints:

E.g. distance constraint

Page 22: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Position Based Dynamics

A constraint consists of:

a cardinality nj

a function Cj

a set of indices {i1,...in}

a stiffness parameter kj

a type: equality or inequality

Example (distance constraint):

cardinality: 2

function: C(p1,p2) = ‖p1 − p2‖ − d2 = 0

set of indices: [1,... N]

stiffness parameter: range from 0-1

type: equality

Page 23: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Main PBD algorithm

(1)-(3)

initialize the state variables

(7)

estimates pi for new locations of the vertices. Computed using an explicit Euler integration step

(9)-(11)

Manipulates position estimates such that they satisfy the constraints using Gauss-Seidel

(13)-(14)

The positions of the vertices are moved to the optimized estimates and the velocities are updated accordingly

Page 24: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint

to satisfy the constraint, we project the particle in the valid position

Page 25: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint Approximate solution to a system of constraints using Gauss-Seidel method

Rest position

Page 26: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint Approximate solution to a system of constraints using Gauss-Seidel method

The particles are displaced by external forces

Page 27: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint Approximate solution to a system of constraints using Gauss-Seidel method

The constraints are solved sequentially

Page 28: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint Approximate solution to a system of constraints using Gauss-Seidel method

The constraints are solved sequentially

Page 29: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint Approximate solution to a system of constraints using Gauss-Seidel method

The constraints are solved sequentially

Page 30: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint Approximate solution to a system of constraints using Gauss-Seidel method

The constraints are solved sequentially

Page 31: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint Approximate solution to a system of constraints using Gauss-Seidel method

The constraints are solved sequentially

Page 32: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint Approximate solution to a system of constraints using Gauss-Seidel method

Iteration 1

Page 33: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint Approximate solution to a system of constraints using Gauss-Seidel method

Iteration 2

Page 34: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint Approximate solution to a system of constraints using Gauss-Seidel method

Iteration 3

Page 35: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint Approximate solution to a system of constraints using Gauss-Seidel method

Iteration 4

Page 36: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint Approximate solution to a system of constraints using Jacobi method

The particles are displaced by external forces

Page 37: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint Approximate solution to a system of constraints using Jacobi method

The constraints are solved in parallel

Page 38: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint Approximate solution to a system of constraints using Jacobi method

The constraints are solved in parallel

Page 39: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint Approximate solution to a system of constraints using Jacobi method

Iteration 1

Page 40: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint Approximate solution to a system of constraints using Jacobi method

Iteration 2

Page 41: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint Approximate solution to a system of constraints using Jacobi method

Iteration 3

Page 42: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Example: Distance constraint Approximate solution to a system of constraints using Jacobi method

Iteration 4

Page 43: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Gauss-Seidel vs Jacobi

- Gauss‐Seidel converges much faster than Jacobi

… but it is inherently serial

- Jacobi is trivially parallelizable

… but the convergence rate is slow

Page 44: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Position Based Fluids

Finally, we have reached the actual paper by Macklin and Müller.

We want to have the nice looking results of SPH, but with the robustness and efficiency of PBD. Macklin and Müller do this by combining the two methods.

Page 45: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Position Based Fluids

In the paper:

1. Modify the PBD algorithm

2. Postulate constraint using SPH definitions

3. (Apply surface tension)

4. (Apply vorticity)

5. (Apply viscosity)

6. Rendering

7. Result

Page 46: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Modify the algorithm

PBD algorithm PBF algorithm

Page 47: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Constraint projection

The density constraint on the ith particle:

Where ρ0 is the rest density and ρi is given by the SPH density:

Page 48: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Constraint projection

PBD tries to find a particle position correction ∆p that satisfy the constraint

Page 49: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Constraint projection

Doing some further math we end up with the position delta:

Where lambda is the contstraint force:

Page 50: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Constraint projection

Projection of the density constraint compared to the lenght constraint:

Page 51: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Artificial surface tension

Projection of the density constraint compared to the lenght constraint:

Where ∆q is a fixed constant inside the smoothing kernel

Page 52: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Vorticity and viscosity

Won’t go into details

- Vorticity:

PBD introduces damping which is unwanted. Macklin and Müller solves this by applying SPH vorticity.

- Viscosity:

Apply SPH viscosity parameter to make the speed of the particles more coherent.

Page 53: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Rendering

1: Anisotropic kernels

[Yu and Turk 2013]

2: Screen space curvature flow

[van der Laan et al. 2009]

Page 54: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Rendering

Page 55: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Result

Implemented using: - 10 CUDA kernels - GPU Hash Grid [Green 2008] - Parallel Jacobi iteration - 128k particles, 6 iterations, 10ms/frame on GTX680

Page 56: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Result

Page 57: Position Based Fluids - Chalmers...Position Based Fluids Finally, we have reached the actual paper by Macklin and Müller. We want to have the nice looking results of SPH, but with

Sources

Screen Space Fluid Rendering with Curvature Flow [van der Laan et al.]

A Survey on Position-Based Simulation Methods in Computer Graphics [Bender et al.]

Reconstructing Surfaces of Particle-Based Fluids Using Anisotropic Kernels [Yu and Turk]

Position Based Fluids [Macklin and Müller]

Smoothed Particle Hydrodynamics - Application Example [Alan Heirich]

Position-Based Simulation Methods in Computer Graphics [Bender et al.]

Fluids in Games [Jim Van Verth]

Papers:

Slides:

Introduction to liquid animation and rendering [Marco Fratarcangeli]

Position based dynamics [Marco Fratarcangeli]

Position Based Fluids [Macklin and Müller]