Fluid Simulation Paper

5
Final Project: Smoothed Particle Hydrodynamics Fluids Simulation Andy Luong, Hassaan Markhiani Department of Computer Science University of Texas at Austin [email protected], [email protected] December 9, 2011 1 Introduction Our final project was focused on fluid simulation, in particular water. Typically there are two approaches in doing fluid simulation. The first is a grid based approach which are more accurate and better looking, but tend to more computationally expensive. The other approach is a particle-based approach which is much faster, but typically does not look as good as grid-based approaches. For our project, we decided to implement a Smoothed Particle Hydrodynamics (SPH) particle-based approach in 2D for simulation, and used a metaballs technique for rendering. 2 Problem and Approach 2.1 Equations Fluid Simulations are based on Navier-Stroke equations for fluid motions. The equations are as followers: ρ( ∂t u + u ·∇u)= -∇p + μ2 u + F (1) ∇· u =0 (2) where u is the velocity of the fluid at a point, is the del operator, p is the pressure, ρ is the density, μ is the viscosity of the fluid, Δ 2 is the Laplace operator, and F is the forces on the fluid. We transform the variables from these equations into forces and use Euler’s Method to simulate our particle movements. 2.2 Particle Simulation In SPH, fluids are represented by a set of particles in a space. However, not every point in the space will have a particle. Therefore, we must define a function given a point x, such that we estimate the effects of neighboring points (which may have particles) upon it. Using the forces described above, we will iteratively update the state or properties (position, velocity, density...) of the particles. Then, for a given point in space, we can interpolate any property A of particles by examining neighboring points. The formula: A(x)= N X i m i A i ρ i W (|x i - x|; h) (3) The value of A at a point x is determined by the sum of particles in neighboring regions around x weighted by the distance between them. The weight is determined using the kernel W such that: W (d; h)= ( 1-d h , if d<h 2 0, otherwise (4) To compute density of particle i: ρ i = X jN(i) (1 - |x j - x i | h ) 2 (5) 1

description

Fluid Simulation Paper

Transcript of Fluid Simulation Paper

Page 1: Fluid Simulation Paper

Final Project: Smoothed Particle Hydrodynamics Fluids Simulation

Andy Luong, Hassaan MarkhianiDepartment of Computer ScienceUniversity of Texas at Austin

[email protected], [email protected]

December 9, 2011

1 Introduction

Our final project was focused on fluid simulation, in particular water. Typically there are two approaches in doingfluid simulation. The first is a grid based approach which are more accurate and better looking, but tend to morecomputationally expensive. The other approach is a particle-based approach which is much faster, but typicallydoes not look as good as grid-based approaches. For our project, we decided to implement a Smoothed ParticleHydrodynamics (SPH) particle-based approach in 2D for simulation, and used a metaballs technique for rendering.

2 Problem and Approach

2.1 Equations

Fluid Simulations are based on Navier-Stroke equations for fluid motions. The equations are as followers:

ρ(∂

∂tu+ u · ∇u) = −∇p+ µ∇2u+ F (1)

∇ · u = 0 (2)

where u is the velocity of the fluid at a point, ∇ is the del operator, p is the pressure, ρ is the density, µ is theviscosity of the fluid, ∆2 is the Laplace operator, and F is the forces on the fluid. We transform the variables fromthese equations into forces and use Euler’s Method to simulate our particle movements.

2.2 Particle Simulation

In SPH, fluids are represented by a set of particles in a space. However, not every point in the space will havea particle. Therefore, we must define a function given a point x, such that we estimate the effects of neighboringpoints (which may have particles) upon it. Using the forces described above, we will iteratively update the state orproperties (position, velocity, density...) of the particles. Then, for a given point in space, we can interpolate anyproperty A of particles by examining neighboring points. The formula:

A(x) =

N∑i

miAi

ρiW (|xi − x|;h) (3)

The value of A at a point x is determined by the sum of particles in neighboring regions around x weighted bythe distance between them. The weight is determined using the kernel W such that:

W (d;h) =

{1−dh , if d < h2

0, otherwise(4)

To compute density of particle i:

ρi =∑

j∈N(i)

(1− |xj − xi|h

)2

(5)

1

Page 2: Fluid Simulation Paper

where N(i) is the set of neighboring particles i. This is determined from W .We then use density to compute the pressure of each particle puts on another as follows:

Pi,j = k(ρi − ρj) (6)

This is then turned into a pressure force for particle i:

Fpressure(i) =∑

j∈N(i)

(xi − xj) ·Pi,j

|xj − xi|(7)

Viscosity is essentially the fluids resistance to flow. Therefore, every particle affects each of its neighboringparticles velocity if there is a difference in velocity and position. For viscosity, we used a simplified equation toupdate a velocity (v) as follow:

u = dot((vi − vj), norm(xi, xj)) (8)

vi − =∑

j∈N(i)

(xi − xj)(1−|xj − xi|

h) · uσ + u2beta (9)

σ and β are parameters that we tweaked in our simulation. We used σ = β ≈ h10 . u is just the dot product of

the difference in velocity and the difference between position. In order to update the position and velocity of everyparticle, we simply add all the forces acting on the particle together and use Euler’s Method:

Fi = Fgravity + Fpressure + . . . (10)

vi + = dt · Fi (11)

xi + = dt · vi (12)

(13)

where dt is the change in time

2.3 Rendering

To better render our particle system, we used metaballs to present each particle. Implementing metaballs iscomputationally expensive, so the speed of our program suffered significantly. However, one benefit of using meta-balls, besides looking more like water, was that we needed much fewer particles to get a smooth simulation. Theimplementation was straightforward. We started with a naive approach, where we iterate over every pixel and sumeach metaballs value (equation 14) for that pixel. Then, if a pixels value is greater than an minimum threshold, wedraw that pixel.

M(x, y) =

N∑i

4 · size((x− xi)2 + (y − yi)2)2

(14)

Since the naive approach was very slow, we made a couple of improvements. The first improve was to skip overthe pixels we know will not receive a high enough value to draw. We did this by simply iterating over pixels that arewithin squares centered at the particles of height and width of 2 times the particles size. A second optimization wasto keep a buffer to hold each pixels value that we could keep reusing. We also kept a buffer to hold each pixels colorvalue, which varies based on the sum of the velocities of particles that touch the pixel. If the particles influencing apixel have no velocity, then the RGB color of the pixel is (0, 26, 179). We increase the value of blue depending onthe velocity to give faster moving particles a more light color.

3 Future Works

Currently, our simulation is in 2D space. Our obvious next step would be to translate our simulation to workin 3D space. This would not be difficult given that we have designed our code to use 3-dimensional vectors, wherethe last value is simply ignored. Our first 3D approach would simply use cubes or spheres to render our particles,similar to our square 2D implementation. Once our 3D simulation is working properly, we would attempt to renderour particles using metaballs, once again. However, rendering metaballs in 3D would be much more difficult than in2D.

2

Page 3: Fluid Simulation Paper

4 Results

Figure 1: Particle simulation.

Figure 2: Particle simulation with splash effect.

3

Page 4: Fluid Simulation Paper

Figure 3: Metaball simulation.

Figure 4: Metaball simulation with splash effect.

References

[1] Braley, C. and Sandu, A. Fluid Simulation For Computer Graphics: A Tutorial in Grid Based and Particle BasedMathods

[2] Harada, T. and Koshizuka, S. and Kawaguchi, Y. Smoothed particle hydrodynamics on GPUs

4

Page 5: Fluid Simulation Paper

[3] Pelfrey, B. An Informal Tutorial on Smoothed Particle Hydrodynamics for Interative Simulation, http://www.cs.clemson.edu/~bpelfre/sph_tutorial.pdf

[4] SPH Survival Kit http://www8.cs.umu.se/kurser/TDBD24/VT06/lectures/sphsurvivalkit.pdf

[5] Whitmore, S. Exploring Metaballs and Isosurfaces in 2D http://www.gamedev.net/page/resources/_/

technical/graphics-programming-and-theory/exploring-metaballs-and-isosurfaces-in-2d-r2556

5