Smoothed Particle Hydrodynamics (SPH)wang.3602/courses/cse...Smoothed Particle Interpolation •...

Preview:

Citation preview

Smoothed Particle Hydrodynamics (SPH)

Huamin Wang

Fluid Representation• Fluid is represented using a set of particles.• Particle i has position xi, velocity vi, and mass mi.

Animation Example

• Using 10 million particles– http://www.youtube.com/watch?v=Q4_quqtGtM

A

Smoothed Particle Interpolation• Suppose each particle j has a physical quantity Aj.• The quantity can be: velocity, pressure, density, temperature….• How to estimate the quantity at a new location Xi?• A simple solution:

Ai?

A0

A4

A3

A2

A1

A5

A6

Aismooth = Aj

j∑ For |Xi – Xj| < r

Smoothed Particle Interpolation• Instead of assuming a particle is volumeless, let us assume

each one has a volume Vi.• So a better solution is:

Ai?

A0

A4

A3

A2

A1

A5

A6

Aismooth = Vj Aj

j∑ For |Xi – Xj| < r

Smoothed Particle Interpolation• One problem of this solution:

• Not smooth! (red 7 -> green 9!)

i

Aismooth = Vj Aj

j∑ For |Xi – Xj| < r

Smoothed Particle Interpolation

• Final solution:• Wij is called smoothing kernel.• When |Xi – Xj| is large, Wij is small. • When |Xi – Xj| is small, Wij is large.

i

For |Xi – Xj| < rAismooth = Vj AjWij

j∑

Particle Volume• But how do we get the volume of particle i?

ρi = Vjρ jWijj∑

m0

m4

m3

m2

m1

m5

m6

ρi = mjWijj∑

Vi =mi

ρi Vi =mi

mjWijj∑

Final Interpolation Solution• So the actual solution is:

Vj =mj

mkWjkk∑Ai

smooth = Vj AjWijj∑

Aismooth =

mj

mkWjkk∑

AjWijj∑

The advantage of This Interpolation

• We can easily compute its derivatives:– Gradient

– Laplacian

Aismooth = Vj AjWij

j∑ ∇Ai

smooth = Vj Aj∇Wijj∑

Aismooth = Vj AjWij

j∑ ∆Ai

smooth = Vj Aj∆Wijj∑

A Smoothing Kernel Example

Wij =3

2πh3

23− q2 +

12

q3 (0 ≤ q < 1)

16

(2 − q)3 (1 ≤ q < 2)

0 (2 ≤ q)

q =xi − x j

h

h is called smoothing length

Kernel Derivatives• Gradient at particle i (a vector)

∇iWij =

∂Wij

∂xi

∂Wij

∂yi

∂Wij

∂zi

=∂Wij

∂q∇iq =

∂Wij

∂qxi − x j

xi − x j h q =xi − x j

h

∂Wij

∂q=

32πh3

−2q + 32

q2 (0 ≤ q < 1)

−12

(2 − q)2 (1 ≤ q < 2)

0 (2 ≤ q)

Wij =3

2πh3

23− q2 +

12

q3 (0 ≤ q < 1)

16

(2 − q)3 (1 ≤ q < 2)

0 (2 ≤ q)

Kernel Derivatives

• Laplacian at particle i (a scalar)

∇iWij =∂2Wij

∂xi2 +

∂2Wij

∂yi2 +

∂2Wij

∂zi2 =

∂2Wij

∂q2

1h2 +

∂Wij

∂q2h q =

xi − x j

h

∂Wij

∂q=

32πh3

−2q + 32

q2 (0 ≤ q < 1)

−12

(2 − q)2 (1 ≤ q < 2)

0 (2 ≤ q)

∂2Wij

∂q2 =3

2πh3

−2 + 3q (0 ≤ q < 1)2 − q (1 ≤ q < 2)0 (2 ≤ q)

Fluid Dynamics• We model fluid dynamics by applying three

forces on particle i.– Gravity– Fluid Pressure– Fluid Viscosity

i

Gravity Force• Gravity Force is:

i

Figravity = mig

Pressure Force• Pressure is related to the density

– First compute the density of Particle i:

– Convert it into pressure (some empirical function):

High Pressure Low pressure

ρi = mjj∑ Wij

Pi = k ρi

ρconstant

7

−1

Pressure Force• Pressure force depends on the difference of

pressure:

i

High Pressure

High Pressure

High Pressure

High Pressure

High Pressure

No pressure force!

i

High Pressure

High Pressure

LowPressure

LowPressure

High Pressure

Pressure force!

Pressure Force• Mathematically, the difference of pressure =>

Gradient of pressure.

• To compute this pressure gradient, we assume that the pressure is also smoothly represented:

• So:

Fipressure = −Vi∇iP

smooth

Pismooth = VjPjWij

j∑

Fipressure = −Vi VjPj∇iWij

j∑

Viscosity Force• Viscosity effect means: particles should move together

in the same velocity.• In other words, minimize the difference between the

particle velocity and the velocities of its neighbors.

Before Ultimately

Viscosity Force• Mathematically, it means:

• To compute this Laplacian, we assume that the velocity is also smoothly represented:

• So:

Fivis cos ity = −νmi∆iv

smooth

v ismooth = Vjv jWij

j∑

Fivis cos ity = −νmi Vjv j∆iWij

j∑

Algorithm• For every particle i

– Compute its neighborhood set– Using the neighborhood, compute:

• Force = 0• Force + = The gravity force• Force + = The pressure force• Force + = The viscosity force

– Update vi = vi + t * Force / mi;– Update xi = xi + t *vi; What is the bottleneck of the

performance here?

Exhaustive Neighborhood Search• Search over every particle pair? O(N2)• 10M particles means: 100 Trillion pairs…

i

Solution: Spatial Partition– Separate the space into cells– Each cell stores the particles in it– To find the neighborhood of i, just look at the surrounding

cells

i

Spatial Partition

– What if particles are not uniformly distributed?– Solution: Octree, Binary Spatial Partitioning tree…

i

Fluid Display• Need to reconstruct the water surface from

particles!

Ongoing Research

• How to make the simulation more efficient?

• How to make fluids incompressible?

• When simulating water, only use water particles, no air particles. So particles are sparse on the water-air boundary. How to avoid artifacts there?

Recommended