19

Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

Embed Size (px)

Citation preview

Page 1: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

Smoke Simulation using Smoothed Particle

Hydrodynamics (SPH)

Shruti Jain

MSc Computer Animation and Visual E�ects

Bournemouth University

21st November 2014

1

Page 2: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

Abstract

This report is based on the implementation of Smoothed particlehydrodynamics(SPH) method for smoke simulation. SPH is a meshfree Lagrangian method for free surface �uids, where the �uidis divided into discrete elements called particles. Particles beinga respresentation of mass, no extra calculations are needed forconservation of mass. Pressure and viscosity are derived usingthe Navier-Stokes equation. Radial symmetrical smoothing kernelsoperate on the particles which lie within the kernel range to de�nethe �eld quantity of a particle.

The overall motion is controlled using smooth �elds, and thesmall scale behaviour is governed by the statistical parameters andscale of turbulent wind �eld, which adds complexity to the motion(Stam 1995).

2

Page 3: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

Contents

1 Introduction 5

2 Related work 6

3 Technical background 7

3.1 Navier-Stokes equation . . . . . . . . . . . . . . . . . . . . . . . . 73.1.1 Equation terms . . . . . . . . . . . . . . . . . . . . . . . . 73.1.2 Equation operators . . . . . . . . . . . . . . . . . . . . . . 8

3.2 Euler equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.3 Vortex particle method . . . . . . . . . . . . . . . . . . . . . . . . 10

3.3.1 Equation terms . . . . . . . . . . . . . . . . . . . . . . . . 10

4 Implementation method 12

4.1 Gradient and Laplacian . . . . . . . . . . . . . . . . . . . . . . . 134.2 Density . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144.3 Pressure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144.4 Acceleration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154.5 Energy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154.6 Smoothing color . . . . . . . . . . . . . . . . . . . . . . . . . . . 154.7 External forces . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

5 Conclusion and future work 17

3

Page 4: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

List of Figures

1 Domain discretization and velocity components . . . . . . . . . . 92 Process �ow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Density of SPH particles . . . . . . . . . . . . . . . . . . . . . . . . 14

4

Page 5: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

1 Introduction

Realistic �uid simulation has been increasingly in demand in the Visual e�ectsindustry since decades. Fluid simulation which is based on principles of �uidmechanics, can be used for simulating e�ects like smoke, water, �re etc. Variousapproaches, ranging from usage of 2D particle-based systems to high qualityrendering systems based on complex algorithms, have been implemented toachieve realistic outcomes.

There has been a remarkable achievement in the techniques which werepreviously used for simulating e�ects in comparison to the currentadvancements. The modern techniques did not only overcome the shortcomingsof the earlier methods, but proved to be more e�cient and made simulationlook more realistic.

Various methods are used to approximate the behaviour of smoke, of whichthe basic and most popular method is based on Navier-Stokes equations. TheEulerian method is suitable for �uids con�ned within a rectilinear volume, whichis further divided into a grid of cubicle cells where each cell stores informationabout velocity, pressure, temperature etc. Lagrangian schemes (that is, schemeswhere the computational elements are not �xed in space) such as smoothedparticle hydrodynamics (Müller, Charypar & Gross 2003) are also popular for�uid animation. The method is based on interpolation of particles and it usesthem to directly render the �uid surface.

This assignment is based on the application of Smoothed ParticleHydrodynamics (SPH) method initially developed by Lucy (1977) and byMonaghan (1992). The calculations and implementation are mainly based onthe research by Müller, Charypar and Gross (2003) and Monaghan (2005).

5

Page 6: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

2 Related work

Stam (1999) proposed an unconditionally stable model based on �nite di�erenceof Navier-Stokes equations. His method was based on Foster and Metaxas(1997) work which overcame the existing instabilities, by the use of much largertime-steps. Fedkiw, Stam and Jensen (2001) presented a numerical methodusing the inviscid Euler equations, that overcame the problem of numericaldissipation by introducing a forcing term called �vorticity con�nement� to addthe lost energy back into the �uid. Müller, Charypar and Gross (2003) basedtheir research on SPH method to simulate �uids with free surfaces than theusual grid-based techiniques. This method was earlier used by Stam andFiume (1995) for �re and other gaseous phenomena. Losasso, Gibou andFedkiw (2004) used the mesh re�nement semi-Lagrangian characteristic tracingtechnique on unrestricted octree data structure. Area weighted averaging wasused to calculate velocity and vorticity of the nodes. Mullen, Crane, Pavlov,Tong and Desbrun (2009), proposed fully Eulerian non-dissipative integrationschemes with no numerical viscosity, which would preserve energy over longtime scales for inviscid �uids. However, the approach did not eliminate di�usionsince vorticity di�usion is unavoidable in a purely Eulerian context (Mullen etal. 2009).

6

Page 7: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

3 Technical background

There are di�erent methods for simulating smoke and the popular ones aredescribed in this section. The implemented (SPH) method will be discussed indetail in section 4 and is not included in this section.

3.1 Navier-Stokes equation

There is a consensus among scientists that the Navier-Stokes equations are avery good model for �uid �ow (Stam 1999). When the velocity and pressureare known for initial state for some initial time t = 0, the Navier-Stokesequations are obtained by imposing that the �uid conserves both mass Eqn.(1)and momentum Eqn.(2) (Stam 1999).

Conservation of mass

The below equations shows that mass should always be conserved and that thevelocity �eld of an incompressible �ow should not have divergence.

∇.u =0 (1)

u = represents a velocity vector �eld∇= vector of spatial partial derivatives i.e (∂/∂x, ∂/∂y,∂/∂z)

Conservation of momentum

This equation couples the velocity and pressure �elds and relates them throughthe conservation of momentum (Foster & Fedkiw 2001). This equation describes�uid motion in terms of the local velocity u which is a function of position andtime.

∂u∂t

= −(u.∇)u− 1ρ∇p+ ν∇2u + f (2)

p = pressure �eldν = kinematic viscosity of the �uidρ = density of the �uid�.� = dot product between vectors∇2= ∇.∇

3.1.1 Equation terms

Advection

The term−(u.∇)u represents self-advection of the velocity �eld and is called theadvection term (Harris 2007). Advection shows the force exerted on a particleby the surrounding particles.

7

Page 8: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

Pressure

The term - 1ρ∇p is the pressure term and represents acceleration. When force isapplied to a �uid, it does not instantly propagate through the entire volume,instead the molecules close to the force push on those farther away, and pressurebuilds up (Harris 2007).

Di�usion

The term ν∇2u represents the viscosity, which is a measure of the resistancefor the �ow of the �uid. This factor indicates dampness and decides �uid'sviscosity. This resistance results in di�usion of the momentum (and thereforevelocity) (Harris 2007).

External forces

The term f represents acceleration due to external forces. These forces maybe either local forces or body forces (Harris 2007). Forces like pressure andviscosity act locally on the surface, the magnitude of this force will vary fromone region of the �uid to another. Gravity force can be considered as a bodyforce which will be evenly applied to the entire �uid.

3.1.2 Equation operators

Gradient

∇p = (∂p

∂x,∂p

∂y,∂p

∂z) (3)

Gradient is de�ned by the direction and rate at which the �uid moves fromhigh-pressure to low-pressure area. The gradient of a scalar �eld is a vector ofpartial derivatives of the scalar �eld (Harris 2007).

Divergence

∇.u =∂u

∂x+∂v

∂y+∂w

∂z(4)

Divergence is applied to the velocity of the �uid to measure net change in thevelocity. It represents the out�ow of volume density from an in�nitesimal volumesurrounding the point. In the equation for conservation of mass, also known asthe continuity equation, enforces the incompressibility assumption by ensuringthat the �uid always has zero divergence (Harris 2007).

Laplacian

∇2 =∂2

∂x2+

∂2

∂y2+

∂2

∂z2(5)

8

Page 9: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

Laplacian is a second order di�erential operator resulting from divergence beingapplied to the gradient. It represents the �uid density of the gradient �ow andresults into di�usion.

3.2 Euler equations

Smoke can be modeled as incompressible and inviscid. The e�ects of viscosityare negligible in gases especially on coarse grids where numerical dissipationdominates physical viscosity and molecular di�usion (Fedkiw, Stam & Jensen2001). The Eulerian method is based on dividing the volume into identicalvoxels as shown in Figure 1.

Figure 1: Discretization of domain into identical voxels (left). Velocity components de�nedon the faces of each voxel (right).

Euler equations correspond to the Navier-Stokes equations with zeroviscosity and no heat conduction. The inviscid incompressible Euler equationscan be represented as:

∇.u = 0 (6)

∂u∂t

= −(u.∇)u−∇p+ f (7)

The terms of these equations are similar to those for the Navier-Stokes equationsdescribed in section 2.1.

9

Page 10: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

Density and Temperature

The other factors that a�ect the velocity of the �uid particles are smoke's densityρ and temperature T. Temperature is inversely proportional to the density, andincrease in temperature will cause a decrease in the density and vice versa.The equations are based on the assumption that these two scalar quantities aresimply moved (advected) along the smoke's velocity (Foster & Fedkiw 2001).For velocity u = (u,v,w), the equations would be:

∂T

∂t= −(u · ∇)T (8)

∂ρ

∂t= −(u · ∇)ρ (9)

3.3 Vortex particle method

This hybrid technique is a combination of Lagrangian vortex particle methodand Eulerian grid based method. Vorticity con�nement reintroduces the smallscale detail lost when using e�cient semi-Lagrangian schemes for simulatingsmoke and �re (Selle 2005).

The Navier-Stokes equations can be put into vorticity form by taking the curlof equation (2) to obtain the equations below:

ωt + (u.∇)ω − (ω.∇)u = µ∇2ω +∇× f (10)

u = velocity,f = represents buoyancy, vorticity con�nement etc.ω= vorticity value at each vortex particle

The pressure term is not present for constant density �uids. Although theseequations can be solved on a grid, particle based methods have the distinctadvantage of avoiding grid based numerical dissipation that smears out the �owmaking it appear more viscous (Selle 2005).

3.3.1 Equation terms

Vorticity

The symbol ω represents vorticity value stored at each vortex particle, whichincludes both magnitude and direction. The vorticity con�nement force iscomputed by taking the curl of the velocity �eld to obtain the vorticity (Selle2005):

ω = ∇× u (11)

10

Page 11: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

For compressible �uids the magnitude of vorticity is higher. The vorticity at apoint is de�ned by summing the contributions from all nearby particles (Selle2005).

Vorticity advection

The term (u.∇)ω represents vorticity advection. This is the trilinearinterpolation used to de�ne a velocity of advecting each particle for a givenvelocity, u, determined via the grid based method (Selle 2005).

Vorticity stretching

The term (ω.∇)u represents vorticity stretching. This term represents theenhancement of vorticity by stretching and is the mechanism by which theturbulent energy is transferred to smaller scales.

Dissipation

The term µ∇2ω is responsible for strong dissipation of large velocity gradients.However, the goal in using particle based methods is to eliminate dissipation,so this term is ignored for solving the inviscid form of the the equations (Selle2005).

11

Page 12: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

4 Implementation method

SPH method is an approach based on particles where the properties are storedat particle level. The calculations are based on Lagrangian method whereasthe force density �eld is derived from the Navier-Stokes equation. Somecharacteristics, like pressure, mass and density, are tightly coupled to each otherthat highly impact the �uid's velocity and appearance.

The overall motion is controlled using smooth �elds, and the small scale behavioris governed by the statistical parameters and scale of turbulent wind �eld, whichadds complexity to the motion (Stam 1995).

According to SPH interpolation rule, a scalar quantity A is interpolated atlocation r by a weighted sum of contributions from all particles (Müller,Charypar & Gross 2003):

AS(r) =∑j

mjAjρjW (r − rj , h) (12)

j = iterator over all particlesmj= mass of the particlerj= Position of the particleρj= DensityAj= The �eld quantity at rj

12

Page 13: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

Figure 2: Process �ow diagram

The high-level steps for implementation of the approach is given by Figure 2.

4.1 Gradient and Laplacian

With the SPH approach, the derivatives gradient and Laplacian will only a�ectsmoothing kernel (Müller, Charypar & Gross 2003).

The gradient of A can be denoted as:

∇AS(r) =∑j

mjAjρj∇W (r − rj , h) (13)

13

Page 14: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

The Laplacian of A can be evaluated as:

∇2AS(r) =∑j

mjAjρj∇2W (r − rj , h) (14)

4.2 Density

Considering the mass mi is constant and same for all the particles, the densityρi varies which needs to be evaluated for every time step. Substituting intoEqn.(12), the density at location r can be evaluated (Müller, Charypar & Gross2003).

ρS(r) =∑j

mjρjρjW (r − rj , h) =

∑j

mjW (r − rj , h) (15)

Figure 3: Density of SPH particles: Left frame shows placement according to a constantprobability density. Middle frame shows the positions of equal mass particles settled downin a Toy star potential starting with particle positions in the left frame. Right frame showsvariable mass SPH particles settled down in Toy star potential where cubic spline kernel wasused. (Monaghan 2005)

The density distribution for di�erent compositions is shown in Figure 3.

4.3 Pressure

The pressure p on the particle is calculated by the surrounding particles. Byapplying the SPH rule of Eqn.(12) to the pressure term −∇p from Navier-StokesEqn.(2) yields (Müller, Charypar & Gross 2003):

fpressurei = −∇p(ri) = −∑j

mjpjρj∇W (ri − rj , h) (16)

Pressure force is the pressure applied to one particle by another. Since, thepressure at di�erent locations will be di�erent, the pressure force for eachparticle will be di�erent This force is asymmetric and to calculate symmetric

14

Page 15: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

pressure force for particles i and j, the arithmetic mean of the pressures ofinteracting particles is used (Müller, Charypar & Gross 2003).

fpressurei = −∑j

mjpi + pj

2ρj∇W (ri − rj , h) (17)

4.4 Acceleration

The acceleration is used to calculate the velocity and position of the particle.The acceleration equation which conserves linear and angular momentum canbe de�ned as (Monaghan 2005):

∇pρ

= ∇(p

ρ

)+

p

ρ2∇ρ (18)

The above equation can be re-de�ned by using the SPH interpolation ruleEqn.(12) (Monaghan 2005):

dvadt

= −∑j

mj

(pjρ2j

+piρ2i

)∇iW (ri − rj , h)

4.5 Energy

The thermal energy can be de�ned per particle, and can be correlated with thetemperature and heat within the system. The time rate of change of thermalenergy is (Monaghan 2005):

du

dt=

p

ρ2

dt= − p

ρ2∇ · v

By using the SPH form Eqn. (12) , the equation can be de�ned as (Monaghan2005):

duidt

=piρ2i

∑j

mjv(ri − rj , h) · ∇iW (ri − rj , h)

4.6 Smoothing color

The color �eld of the particle should be correctly de�ned, a color value between0 and 1 can be used to de�ne the intensity of the particle. The color needs to beproperly adjusted in accordance with the surrounding particles, as there cannotbe a particle with color value 1 with an adjacent particle of 0 value for color.Color should gradually fade out. The equation for the smoothed color is givenby (Müller, Charypar & Gross 2003):

cs(r) =∑j

mj1ρjW (r − rj , h) (19)

15

Page 16: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

fsurface = σκn = −σ∇2csn

|n|(20)

n = ∇cs, gradient of the smoothed color �eld represents the surface normal

κ = −σ∇2cs

|n| , divergence of n measures surface curvature

4.7 External forces

External forces such as gravity and collision forces are directly applied to theparticles.

16

Page 17: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

5 Conclusion and future work

The mentioned approach will be implemented and is expected to yield areasonable accurate outcome. The advantages of using the SPH approach arethat preserving energy and linear momentum are easily achievable. Whereasthe Eulerian method does not conserve angular momentum, SPH does. SPHapproach guarantees conservation of the total energy when combined withself-gravity, which is not the case in mesh-based approaches. The majordisadvantage of SPH approach is the lack of accuracy for multi-dimensional�ow. As the impact of noise on particles is calculated by the particles closelysurrounding it, the repulsive forces may not get settled in all dimensions, whichmay cause jitter. As a further improvement, SPH method can be combinedwith other methods to overcome the problem of multi-dimensional �ow. Also,the SPH method can be implemented on the GPU to make the simulation fasterand provide a real-time high quality render.

17

Page 18: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

References

A. Selle, N. Rasmussen, and R. Fedkiw, �A vortex particle method for smoke,water and explosions,� in ACM SIGGRAPH 2005 Papers, SIGGRAPH '05,(New York, NY, USA), pp. 910-914, ACM, 2005.

F. Losasso, F. Gibou, and R. Fedkiw, �Simulating water and smoke with anoctree data structure,� in ACM SIGGRAPH 2004 Papers, SIGGRAPH '04,(New York, NY, USA), pp. 457-462, ACM, 2004.

J. J. Monaghan, �Smoothed particle hydrodynamics,� Annual review ofastronomy and astrophysics, vol. 30, pp. 543-574, 1992.

J. J. Monaghan, �Smoothed particle hydrodynamics,� Reports on progress inphysics, vol. 68, pp. 1703-1759, Jul. 2005.

J. Stam, �Stable �uids,� in Proceedings of the 26th annual conference onComputer graphics and interactive techniques, SIGGRAPH '99, (New York,NY, USA), pp. 121-128, ACM Press/Addison-Wesley Publishing Co., 1999.

J. Stam and E. Fiume, �Depicting �re and other gaseous phenomena usingdi�usion processes,� in Proceedings of the 22nd annual conference on Computergraphics and interactive techniques, SIGGRAPH '95, (New York, NY, USA),pp. 129-136, ACM, 1995.

L. B. Lucy, �A numerical approach to the testing of the �ssion hypothesis,�Astronomical Journal, vol. 82, pp. 1013-1024, Dec. 1977.

M. J. Harris. (2007, Sep). Chapter 38. Fast Fluid DynamicsSimulation on the GPU (5th ed.) [Online]. Available:http://http.developer.nvidia.com/GPUGems/gpugems_ch38.html

M. Müller, D. Charypar, and M. Gross, �Particle-based �uid simulationfor interactive applications,� in Proceedings of the 2003 ACMSIGGRAPH/Eurographics symposium on Computer animation, SCA'03, (Switzerland, Switzerland), pp. 154-159, Eurographics AssociationAire-la-Ville, 2003.

N. Foster and D. Metaxas, �Modeling the motion of a hot, turbulent gas,� inProceedings of the 24th annual conference on Computer graphics and interactivetechniques, SIGGRAPH' 97, (New York, NY, USA), pp. 181-188, ACMPress/Addison-Wesley Publishing Co., 1997.

18

Page 19: Smoke Simulation using Smoothed Particle Hydrodynamics (SPH) · PDF fileSmoke Simulation using Smoothed Particle Hydrodynamics (SPH) ... for free surface uids, where the uid is divided

N. Foster, and R. Fedkiw, �Practical animation of liquids,� in Proceedings ofthe 28th annual conference on Computer graphics and interactive techniques,SIGGRAPH' 01, (New York, NY, USA), pp. 23-30, ACM, 2001.

P. Mullen, K. Crane, D. Pavlov, Y. Tong, and M. Desbrun, �Energy-preservingintegrators for �uid animation,� in ACM SIGGRAPH 2009 Papers,SIGGRAPH' 09, (New York, NY, USA), ACM, 2009.

R. Fedkiw, J. Stam, and H. W. Jensen, �Visual simulation of smoke,� inProceedings of the 28th annual conference on Computer graphics and interactivetechniques, SIGGRAPH' 01, (New York, NY, USA), pp. 15-22, ACM, 2001.

19