Page 1

i

FLUID SIMULATION IN TETRAHEDRAL MESH USING HYBRID METHOD

Dongsoo Han

A THESIS

in

Computer and Information Science

Presented to the Faculties of the University of Pennsylvania in Partial Fulfillment of the Requirements for the Degree of Master of Science in Engineering

2010

Norman I. Badler Supervisor of Thesis

Jianbo Shi Graduate Group Chairperson


Table of Contents List of figures ........................................................................................................................................... 3 List of symbols ......................................................................................................................................... 4 1

Introduction ..................................................................................................................................... 7

2

Background...................................................................................................................................... 9

3

2.1

Previous Work ......................................................................................................................... 9

2.2

Basics of Fluid Mechanics ........................................................................................................ 9

2.3

Basics of numerical simulation of fluids ................................................................................ 10

2.4

Particle-in-Cell Method ......................................................................................................... 15

2.5

Fluid-Implicit-Particle ............................................................................................................ 16

Fluid Simulation in Tetrahedral Mesh ........................................................................................... 17 3.1

Discretization ......................................................................................................................... 17

3.2

Boundary Condition............................................................................................................... 19

3.3

Interpolation.......................................................................................................................... 19

3.4

Transferring Velocity between Particles and Mesh .............................................................. 20

3.5

Body Force ............................................................................................................................. 21

3.6

Projection .............................................................................................................................. 22

3.7

Time step size and the CFL condition .................................................................................... 22

3.8

Implementation ..................................................................................................................... 22

3.9

Visualization .......................................................................................................................... 24

4

Results ........................................................................................................................................... 25

5

Conclusion and Future Work ......................................................................................................... 27 References ......................................................................................................................................... 28 Appendix............................................................................................................................................ 30

2


List of figures Figure 2-1 The MAC grid in 2D .............................................................................................................. 11 Figure 2-2 Semi-Lagrangian Advection .................................................................................................. 13 Figure 2-3 PIC Advection ....................................................................................................................... 16 Figure 3-1 Triangular mesh in two-dimension ...................................................................................... 17 Figure 3-2 Tetrahedral mesh in three-dimension ................................................................................. 17 Figure 3-3 Gradient of pressure ............................................................................................................ 18 Figure 3-4 Dual cell ................................................................................................................................ 20 Figure 3-5 Barycentric coordinates for convex polytope ...................................................................... 20 Figure 3-6 Getting velocity at the center of face from particles ........................................................... 21 Figure 3-7 Maya plug-in AnimOBJ ......................................................................................................... 24 Figure 4-1 Comparing typical tri-linear interpolation (A) and SPH kernel function interpolation (B) using FLIP method in regular grid.......................................................................................................... 25 Figure 4-2 2D fluid simulation in disc shaped irregular grid.................................................................. 25 Figure 4-3 3D fluid simulation in cylinder shaped irregular grid. .......................................................... 26 Figure 4-4 Simulation time analysis for PIC/FLIP method ..................................................................... 26 Figure 4-5 Rendered images.................................................................................................................. 26

3


List of symbols A

N x N sparse matrix of known values in the linear system Ax = b.

b

The column vector of known values in the linear system Ax = b.

u

The velocity.

n

The velocity at the beginning of a time step.

n+1

u

The final velocity at the end of a time step.

u

The x-component of the velocity u.

v

The y-component of the velocity u.

w

The z-component of the velocity u.

p

The pressure.

u

The density x

The column vector of unknown values in the linear system Ax = b.

f

The force. In the Navier-Stokes equations or Euler equations, it is a body force such as gravity or external force.

4


Acknowledgements

I would like to thank Prof. Badler, Prof. Lane and Prof. Safonova. I also thank my parents who gave me immeasurable love and support. To my wife, Eun Ae, I would like to specially thank her for inspiring and supporting me for such a long time. Without her, I wouldn’t be able to finish my degree. Lastly, to my lovely boys, Joon and Sol. They make me feel happy every day.

5


Abstract

This paper seeks to implement fluid simulation in tetrahedral mesh using hybrid method. Since Jos Stam introduced Stable Fluid in computer graphics community, FDM (finite difference method) in regular grid (hexahedral mesh) became widely used. The drawback of FDM in regular mesh has to do with the fact that treating curved boundary presents a challenge. To handle irregular boundary, tetrahedral mesh was used as a simulation domain. For advection, modified PIC/FLIP method was used to take advantage of low numerical dissipation. Unlike the traditional linear interpolation in PIC/FLIP, SPH kernel function based velocity interpolation method was experimented.

6


1 Introduction For more than a decade, fluid simulation has received enormous attention from computer graphics researchers and the motion picture industry. Research in the area of fluid simulation is important due to the fact that there is a strong demand among movie directors, animators and 3D content designers for naturally animated imagery. In Fluid Mechanics there are two types of fluid flow representations: Lagrangian and Eulerian. The Lagrangian perspective represents fluid as particles. On the other hands, Eulerian perspective utilizes a fixed grid. The most popular numerical simulation of Lagrangian is Smoothed Particle Hydrodynamics (SPH). Since SPH does not require any grid (mesh), it simplifies the process of approximating any shape of boundaries. All solid-fluid boundaries can be represented as particles. The drawback of SPH is that it is inherently difficult to enforce incompressibility because SPH allows particles to be compressed in the initial stages. Also, the computation time of Eulerian proves to be more time effective than SPH overall. The most popular Eulerian approach is a regular grid. A regular grid is usually composed of cells such as a square and a cube (hexahedron) in 2D and 3D respectively. The benefit of the regular grid is that it is straightforward to discretize various calculus operators such as divergence, gradient, or Laplacian. However, it is complicated to deal with curved boundaries using the regular grid, because they cannot be easily expressed with squares or cubes. Similar issues can be observed in an anti-alias problem with image rendering. Lines or curves can produce artifacts when they are not aligned with pixels. The most important aspect of this research involves discretizing computation domain using simplices such as the triangle (2D) or tetrahedron (3D) to enable the domain to conform to the specified boundaries without causing unnecessary artifacts. This type of discretized domain is called irregular grid, mesh, or sometimes unstructured grid or mesh. Another benefit of irregular mesh is that it is relatively easy to change cell sizes similar to LOD. It is advisable for the higher resolution cells to be placed near the solid boundary or free surface and the coarser resolution cells to be positioned at the central region of fluid domain. Compared to regular grid, applying calculus operators to irregular grid is not easy and requires more careful implementation. In this paper, we will use irregular grid and tetrahedral mesh as interchangeable. In addition to irregular mesh, numerical dissipation has been a popular topic amongst fluid simulation researchers in the computer graphics community. When Jos Stam introduced SemiLagrangian advection method, numerical dissipation proved to be a disadvantageous side effect. In this research, PIC/FLIP was used with the modified interpolation approach to reduce numerical dissipation and exploit the strengths of the Lagrangian method. For this reason, this approach may best be described as a hybrid method. The contribution of this research is to combine 7


PIC/FLIP, irregular grid, and SPH kernel function interpolation to develop fluid simulation superior at handling curved boundaries, producing less numerical dissipation, and time effectiveness with computation time.

8


2 Background 2.1 Previous Work Fluid simulation has a long history known as Computational Fluid Dynamics (CFD). In recent years, there are a lot of papers published from computer graphics community. Here I will mostly focus on the relevant papers from computer graphics field. In early computer graphics liquid surface could be simulated by a height field over 2D domain. This idea was first used by (Peachey, 1986) who used sinusoidal functions to describe waves. (Kass, et al., 1990) represented the fluid as 2D height field with a partial differential equation (PDE) approximating shallow water equation. The limitation of 2D liquid simulation was that it was not possible to create breaking waves. The paper “Stable Fluids� by Jos Stam (Stam, 1999) presented full 3D Navier-Stokes equation simulation with unconditionally stable Semi-Lagrangian advection in computer graphics community. Foster and Metaxas presented general liquid and gas simulation in (Foster, et al., 1996) and (Foster, et al., 1997). Their work showed important aspects of CFD based on (Harlow, et al., 1965). In (Fedkiw, et al., August 2001) and (Enright, et al., 2002), enhanced visual representations were showed along with several approaches to reduce numerical dissipation. To take advantage of adaptation, (Losasso, et al., 2004) presented octree structure. To handle curved boundary in regular grid, (Batty, et al., 2007) presented variational approach. Using tetrahedral mesh as a fluid simulation domain was introduced by (Feldman, et al., 2005), (Feldman, et al., 2005) (Klingner, et al., 2006) and (Chentanez, et al., 2007). As a hybrid approach, Particle-in-Cell (PIC) method was developed by Harlow (HARLOW, 1963). To overcome numerical dissipation problem of PIC, (BRACKBILL, et al., 1986) presented FLIP (FluidImplicit-Particle). Robert Bridson introduced PIC/FLIP method in computer graphics community in (Zhu, et al., 2005).

2.2 Basics of Fluid Mechanics Fluid mechanics deals with various physics related to fluids such as liquid, gas or plasma. Basically we are interested in incompressible flow of Newtonian fluids, so we will limit ourselves in general Navier-Stokes equations. Navier-Stokes equations Navier-Stokes equations are named after Claude-Louis Navier and George Gabriel Stokes who independently discovered equations (2.1) and (2.2).

9


(2.1) (2.2) u is the velocity of the fluid. u = u(u, v) in 2D and u = u(u, v, w) in 3D. fluid.

stands for pressure. stands for time.

is the density of the

stands for kinematic viscosity. stands for body force

2

such as gravity, usually (0, -9.81, 0) m/s . The first equation (2.1) describes conservation of momentum. The second equation shows conservation of mass. Since fluid mass is conserved and density remains the same, it is incompressible. Euler equations (fluid dynamics) If fluid is inviscid, the Euler equations correspond to the Navier-Stokes equations with zero viscosity. (2.3) (2.4) The Euler equations are normally used when water or smoke is simulated. Even though real water or air has non-zero viscosity, viscosity can be disregarded because numerical simulation brings numerical dissipation into the equation. This numerical dissipation is also called diffusion, damping or smoothing and can be observed in the various areas where advection is used such as level set or heat transfer.

2.3 Basics of Numerical Simulation of Fluids In order to simulation fluids, it is necessary to discretize fluid domain. The basic method is to use MAC grid.

10


Figure 2-1 The MAC grid in 2D

Harlow and Welch introduced marker-and-cell (MAC) method (Harlow, et al., 1965) for solving incompressible fluid in 1965. In their method, each velocity component is defined on the center of cell face as illustrated in Fig. 2.1. However, pressure is sampled at the center of cell, indicated by pi,j. Also quantities such as temperature or level set can be defined at the cell center. In three dimensions, the MAC grid is set up in the same way. Each velocity component is defined on the center of face and pressure is at the center of cube. Because velocity and pressure are not co-located, MAC grid is a staggered grid. Even it is possible to assign different lengths for x, y and z directions of cell size, usually cell is defined as square (2D) or cube (3D) and the edge length is denoted as h. The benefit of staggered arrangement is that we can use accurate central difference for the pressure gradient. Also calculating divergence of velocity in the cell becomes trivial. In this paper, discretization of continuum is based on finite differences, which can be explained using Taylor series. (2.5) through (2.15) show how divergence, gradient and Laplacian operators can be expressed in the discretized forms in 2D and 3D. ( )

(

)

(2.5)

( )

(

)

(2.6)

( )

(

)

(2.7)

(

)

( 11

(2.8)

)

(2.9)


( (

)

(

(

)

(

)

(2.10)

)

(

(

) )

(2.11)

(2.12)

)

(2.13)

(

) (2.14) (

(

)

)

( )

(2.15) (

)

Discretizing the Navier-Stokes Equations Now we are ready to discretize (2.1) and (2.2). Since (2.1) is complicated, we split it up as (2.16).

(advection) (body force) (viscosity)

(2.16)

(pressure) such that

(incompressibility)

In (2.16), the first equation is advection. Advection is a unique behaviour of fluid in Eulerian point of view. In Lagrangian point of view, each particle carries its velocity. Therefore advection term would not appear in Lagrangian representation. In the advection equation in (2.16), fluid velocity gets advected. It is also possible that any vector or scalar values can be advected such as level set or temperature. The second equation in (2.16) shows applying body force. In smoke or fire simulation, gravity does not matter much because all fluid cells get the same gravity and will be cancelled each

12


other. However buoyancy is important to simulate realistically rising smoke or fire. On the other hand gravity plays important role in liquid simulation. The third equation is viscosity and normally omitted for inviscid flow. The forth equation shows that fluid flows from high pressure to low pressure in the steepest direction. The last equation enforces incompressibility and will be applied to the forth equation when it is discretized. (

)

(2.17)

(2.17) Shows discretized version of (2.16). We will take a look at the advection equation more closed in the next section. un is the velocity at the beginning of time step. un+1 is the velocity at the end of time step. u* and u**are intermediate velocities. Advection If we discretize the advection equation in (2.16) using Taylor series, we will end up with explicit equation. Explicit method is notoriously known to be unstable and requires very small time step. In (Stam, 1999) Jos Stam introduced Semi-Lagrangian advection method which is unconditionally stable. Fig. 2-2 shows how Semi-Lagrangian advection traces backwards in the regular grid. (2.18) shows a first order accurate backwards Euler time step tracking. (2.19) is second order accurate. When we obtain

( ), linear interpolation such as bi-linear (2D) or tri-linear (3D) is used.

( )

( )

(

)

(2.18)

( ) (

( )

(

( )

)

q : scalar or vector value to advect p : position vector u(p) : velocity at point p n represents the current time step n-1 represents the previous time step Figure 2-2 Semi-Lagrangian Advection

13

)

(2.19)


Boundary Condition There are basically three types of boundary conditions: solid, free flow and free surface boundary. ̂

solid boundary free flow boundary

̂

̂

free surface boundary

where non-liquid region Table 2-1 Boundary conditions

Table 2-1 shows boundary conditions. Solid boundary condition enforces that normal component of fluid velocity should be equal to the normal component of solid boundary velocity. If the boundary is static,

̂

̂

. In other words, the normal component of velocity of

adjacent fluid becomes zero. Because a velocity value is directly assigned, this is Dirichlet boundary condition. In computer graphics, we usually allow free slip so tangential component of fluid velocity can be free from solid boundary. Free flow boundary condition is particularly convenient when smoke simulation grid size is limited and smoke should flow through grid boundary. In many cases, we do not want to see that the smoke fills up simulation grid. It would look like the smoke is bounded by a rectangular container. We usually want to see that smoke flows naturally and disappears when it passes through grid boundary. In order to do this, we make gradient of pressure zero. Adjacent fluid pressure can be copied and assigned to the solid cells across boundary. This is Neumann boundary condition. Free surface boundary condition is only for liquid. When we simulate liquid such as water, air is usually ignored because the density ratio is very large. Therefore we can assign any pressure value on the empty region. For the sake of simplicity, zero pressure is used but it can be atmospheric pressure. Numerical Dissipation Numerical dissipation is occurred when continuum flow is discretized spatially and temporally. Most of numerical dissipation is from advection in fluid simulation. The typical symptoms of numerical dissipation are viscous or sticky flow, less turbulence, losing small scale details. Also when smoke is advected, it diffuses into air too fast or nice sharp profiles or thin features vanish quickly. In case of water, if level set is used to trace free surface interface, thin water evaporates into air or loses total volume. Volume lose is specially an issue because it can be noticed easily. For example, if water is poured into a glass, thin layer of water smaller than a couple of cell sizes rapidly disappears. To understand numerical dissipation, we solve a simple advection problem in one dimension with a constant velocity u > 0 as below. 14


(

)

Using a first order finite difference and upwind scheme, we can discretize spatial derivate but let’s leave time derivate.

(2.20) Upwind scheme means that we take a quantity against flow direction when we calculate finite difference. In above discretization, velocity flows positive x direction. So when we discretize we have two choices,

or

. In upwind,

is chosen. Upwind scheme is particularly

important for level set because interface information propagates downwards away from zero level set. Upwind scheme shows superior accuracy over downwind when quantity flows in the constant direction. To compare (2.20) with higher order accuracy, we can use Taylor series as below.

( (

(

) (

(

) (

* By disregarding (

)

(

) )

)

(

) )+

), we can get (2.21). By comparing (2.20) and (2.21), the different term

looks like viscosity. It means that a first order finite difference of advection introduces viscosity. Please note that we just looked spatial discretization and temporal discretization would contribute to numerical dissipation as well.

(2.21)

2.4 Particle-in-Cell Method PIC (Particle-in-Cell) was developed by Harlow (HARLOW, 1963). The idea is to let particles handle advection and keep the background grid to enforce divergence free. Because PIC uses both particles and grid, it is hybrid of Lagrangian and Eulerian aspects. Compared to SPH, computation time to enforce incompressibility is independent to the number of particles. It only depends on grid size. Compared to Semi-Lagrangian advection, advection of PIC is fully Lagrangian. The advantages of using particles are that applying external force is trivial and small scale simulation can be possible even in the relatively coarse grid. 15


In terms of numerical dissipation, PIC does not show much superiority over Semi-Lagrangian. If we sample a quantity using linear interpolation and reassign the sampled quantity back to the grid without moving particles, the grid will get a less quantity than before. Due to the linear interpolation scheme in MAC grid, the quantity gets smaller. It means that if we advect velocity, momentum will be lost. If we advect level set, we will see the volume loss. (2.20) shows a first order PIC advection and (2.21) is second order. Higher order is possible but second order seems to be good enough.

(

)

(

) (

where (

)

where

)

(

)

(

)

(2.22)

(2.23)

( ) q : scalar or vector value to advect p : position vector u(p) : velocity at point p Figure 2-3 PIC Advection

n represents the current time step n+1 represents the next time step

2.5 Fluid-Implicit-Particle FLIP (Fluid-Implicit-Particle) was developed by Brackbill & Ruppel (BRACKBILL, et al., 1986). The main idea of FLIP is to break the accumulating dissipation by transferring the change of a quantity. If a quantity of grid has not changed, particle gets zero value. When particle transfers the zero value change back to the grid, the grid would not gain or lose. Therefore the quantity will remain the same. This simple idea provides dramatically reduced numerical dissipation. Even with this remarkable feature, FLIP tends to show noise and requires many particles. But still the required number of particles is smaller than SPH. Mixing PIC and FLIP like 20% and 80% seems to reduce noise and still gives a plausible result.

16


3 Fluid Simulation in Tetrahedral Mesh 3.1 Discretization Fig. 3-1 and 3-2 show triangular and tetrahedral meshes. In each cell (triangle or tetrahedron), pressure is defined at circumcenter. Barycenter is also possible. However circumcenter is convenient when gradient of pressure is calculated. Also it is easy to compute dual cells.

Figure 3-1 Triangular mesh in two-dimension

Figure 3-2 Tetrahedral mesh in three-dimension

As Fig. 3-1 and 3-2 illustrate, velocities are defined on the midpoint of edge in triangle or face circumcenter in tetrahedron. Unlike MAC grid, normal vector direction is arbitrary. It can point outwards or inwards. As long as normal direction is consistent throughout simulation, it is fine. Only velocity normal components are stored as one-dimensional index array. Since mesh is irregular, two or three dimensional array doesn’t apply here. Likewise, pressures are stored as one-dimensional array. We use i for cell index and j for edge (2D) or face (3D) index. For example, p i means pressure defined in i’th cell. Also uj means normal velocity component defined on the center of j’th edge or face. Divergence Defining divergence in irregular mesh is straightforward. Divergence of velocity means how much net fluid flows inwards or outwards in the closed cell (triangle or tetrahedron). (2.24) shows divergence theorem. By discretizing it, we can have (2.25). The first equation in (2.25) is in twodimensional.

is an area of triangle cell i and

in three-dimensional.

is a length of edge j. The second equation in (2.25) is is area of face j. ̂ is a normal vector

is a volume of tetrahedron cell i and

pointing outwards defined on edge or face.

∭(

)

∯( ̂

17

)

(2.24)


(

)

(

)

) (2.25)

(

)

(

)

)

In our mesh, normal vectors are arbitrary. To accommodate the arbitrary normal direction, we introduce a simple sign function

as (2.26). Please note that

is a velocity normal component

stored as scalar value. It can be positive or negative. To decide , we need to consider both direction of normal vector and sign of

.

(

)

| |

(

)

(

)

| |

(

)

(2.26)

{

Gradient We only need gradient of pressure to solve (2.17). (2.27) shows a discrete gradient of pressure.

(

)

̂)

(

(2.27)

Because pressure is defined at the circumceter, a line between two adjacent two pressure points is perpendicular to the shared edge or face as illustrated in Fig 3-3. Like divergence, normal vector direction is arbitrary. Therefore when we choose pa and pb, the normal vector direction of shared edge or face should be considered. dba is a distance between two adjacent circumcenters.

Figure 3-3 Gradient of pressure

18


Laplacian Laplacian of pressure is defined as (2.28). Laplacian operator is a product of divergence operator and gradient operator. Because both divergence and gradient care of the direction of normal vector, we do not need to consider it for Laplacian. Simply divergence and gradient cancel it out.

(

)

(

)

(

∑

)

(

)

where b is a cell index adjacent to cell i sharing edge j

(

)

(

)

(

∑

)

(

)

(2.28)

where b is a cell index adjacent to cell i sharing face j If j is solid boundary,

, which results in decrementing the coefficient of

by 1.

If j is free surface boundary,

.

3.2 Boundary Condition Even In tetrahedral mesh, boundary condition has the same principal as described previously. However we do not create boundary cells around fluid domain. In hexahedral mesh, it is convenient to have boundary cells, even though it is not really necessary. In tetrahedral mesh, creating boundary cells does not give much benefit. When mesh is generated, we mark boundary edges or faces and take them into account when boundary condition is enforced.

3.3 Interpolation Interpolation is straightforward in MAC grid. Bi-linear or tri-linear interpolation schemes are typical in hexahedral mesh. Higher order interpolations (Fedkiw, et al., August 2001) are also well known. In triangular or tetrahedral mesh, only velocity normal component is stored at the center of edge or face. To get a velocity at any position, we need to interpolate within triangle or tetrahedron. Unlike MAC grid, normal vector direction can be arbitrary. We use two steps to interpolate developed in (Elcott, et al., 2005) . The first step is to find a velocity at cell circumcenter using . is a matrix whose rows are normal vectors of edge or face. In 2D, is 3x2 and in 3D, it is 4x3. is a column vector representing a velocity at cell circumcenter. is a column vector whose row is a normal component of velocity at the center of each edge or face. Because we know and , it is trivial to solve .

19


The second step is to create a dual cell and interpolate within a dual cell which is Voronoi cell. The interpolation method is based on (Warren, et al., 2005) which presents generalized interpolation method within a convex polytope. In Fig. 3-4, primary cells are simplex and dual cell is Voronoi cell.

Figure 3-5 Barycentric coordinates for convex polytope Figure 3-4 Dual cell

In (2.29), ( ) is a barycentric coordinate of vertex v for point x. (2.30) shows how to calculate weight function ( ) at a vertex v where ( )is the volume of the parallelepiped span by the normal vectors to the facets incident on v, expressed via a determinant as in Fig. 3-5. ( )

( )

( ) ( )

(2.29)

( ) ∏

(

( )(

where ( )

|

(

))

(2.30)

( ) )|

3.4 Transferring Velocity between Particles and Mesh Transferring velocity from mesh to particles can be done by interpolation explained in the previous section. Once particles move following fluid flow, we need to transfer the velocity from particles to mesh. This can be done in the reversed way of interpolation in regular or irregular grid. Because hybrid method uses Lagrangian fluid particles, SPH kernel function interpolation scheme was experimented as introduced by (MÜLLER, et al., 2004). (2.31) shows various SPH kernel functions. Normalized polynomial kernel function in 3D

̂ ( )

(

{

) (2.31)

Normalized polynomial kernel function in 2D

̂ ( )

{ 20

(

)


Normalized spiky kernel function in 3D Normalized spiky kernel function in 2D

Ě‚ ( )

{

(

)

Ě‚ ( )

{

(

)

Figure 3-6 Getting velocity at the center of face from particles

As illustrated in Fig. 3-6, neighbor particles are searched within kernel radius (h) at the center of each face. Because particles are unstructured, finding them within a range is expensive. This search operation can be efficiently computed using kd-tree or hash grid. In our search, hash grid with size of dh is used as in Fig. 3-6. Once neighbor particles are found, velocity is interpolated using (2.31). Only the normal component to the edge or face is eventually stored. Average edge length was used for dh.

3.5 Body Force Body force such as gravity or external forces can be directly assigned to each particle as . (Feldman, et al., 2005) suggested to find a normal acceleration across face j between cells a and b as (2.32). In this research, we tested both approaches. (Ě‚

)

(

21

)

(2.32)


3.6 Projection After advection and assigning body force, the vector field is not divergence-free any more. To satisfy incompressibility (2.2) or (2.4), we solve

. In the discretized domain, the

equation becomes Ax = b. A is a sparse matrix. x and b are column vectors and we solve for x. By Helmholtz decomposition (Stam, 2003), a smooth vector field can be decomposed into the sum of a curl-free vector field and a divergence-free vector field. After solving an equation (Ax = b), we can find a curl-free vector field. By subtracting the curl-free vector field will get a new divergence-free vector field

, we

.

Projection may sound confusing because it can be understood as projecting an object into a plane in 3D space. In vector field, we are trying to find a closest divergence-free vector field from the given vector field. Once we find it, if we apply the projection operation again, we will still get the same divergence-free vector field. So the projection operation has analogous properties to the one in 3D graphics world.

3.7 Time Step Size and the CFL Condition Semi-Lagrangian advection method is known to be unconditionally stable. However PIC/FLIP method can be unstable if we choose a very large time step. However PIC/FLIP shows good stability in the reasonable time step size practically. Even with the unconditional stability, we don’t choose too much large time step size because it will cause unpleasing visual artifacts. For numerical stability and visual quality, we limit the time step size as below. (

)

h : cell size

This means that the maximum traveling length cannot exceed five times of cell size in the computation domain. If the velocity exceeds it, we need to reduce the time step so that the CFL condition meets. In regular grid, h is a length of cell edge. In tetrahedral mesh, it is an average of tetrahedral edge lengths.

3.8 Implementation We used NETGEN1 to generate tetrahedral mesh from a given input mesh. Tetrahedral mesh is pre-calculated and saved as a text file. When the tetrahedral mesh is loaded, vertex, edge, face and cell indexes are stored as arrays. Mesh connection and neighbour information is created and dual cells are generated. In regular grid, fluid cells are initialized to contain particles. The number of particles per each cell is usually 8 (2D) and 32 (3D) in regular grid. In irregular grid, we try to maintain the same density per tetrahedron. In case of liquids, more particles are positioned near free surface area in order to 1

http://www.hpfem.jku.at/netgen/

22


generate a smooth and detailed free surface. It is convenient to use level set when we create initial water shapes such as water ball. Using level set, we can easily find interface and move particles close to it. At each simulation step, we need to compute (2.17). (2.33) shows pseudocode for one simulation step.

Add_Body_Force(); Advect_Particles(); Build_Hash_Grid(); Mark_Cell_Type(); Update_Grid_From_Particles(); Surface_Reconstruction(); Set_Boundary_Condition(); Project(); Update_Particles_From_Grid();

23

(2.33)


3.9 Visualization

Surface reconstruction is an important process for liquid. There are two steps. The first step is to create a distance field from particles. This process is similar to generate a density field because both use SPH kernel function. In this research, I followed the method explained in (Zhu, et al., 2005). The second step is to create surface triangle mesh from distance field using marching triangles (2D) or marching cubes (3D). Marching cubes method was developed by Lorensen and Cline (Lorensen, et al., 1987) and has been widely used to generate iso-surface. Maya2 and Mental Ray renderer were used to render liquid. At each simulation step, surface mesh is stored as obj file format with sequence number as a part of file name. I created Maya plug-in called AnimOBJ3 to load a sequence of obj files in Maya. I opened the source code to public.

Figure 3-7 Maya plug-in AnimOBJ

2 3

www.autodesk.com/Maya http://code.google.com/p/animobj/

24


4 Results Fig. 4-1 shows comparison between typical tri-linear interpolation and SPH kernel function interpolation using FLIP method in regular grid. SPH interpolation shows a slightly better simulation result in terms of numerical dissipation. However the simulation time of SPH interpolation takes much longer than tri-linear one.

(A)

(B)

Frame 0

24

31

55

Figure 4-1 Comparing typical tri-linear interpolation (A) and SPH kernel function interpolation (B) using FLIP method in regular grid. Grid size is 50 x 70 x50 and cell size is 0.1. Time step is 0.0417 seconds (24 fps). (A) takes 1.03 seconds and (B) takes 4.84 seconds per frame in Intel Xeon CPU 3.07 GHz, 10.0 GB of RAM. The time includes simulation and isosurface extraction.

Fig. 4-2 shows 2D fluid simulation in irregular grid. As it shows, irregular grid serves curved boundary very well and generates smooth fluid flow even near boundary. Fig. 4-2 shows 3D fluid simulation.

Frame 0

150

300

Figure 4-2 2D fluid simulation in disc shaped irregular grid. Number of cells is 820. A force is applied in the top portion of disc in order to create fluid flow. Each simulation step took 0.10 second in average in Intel Xeon CPU 3.07 GHz, 10.0 GB of RAM. Number of particles is 14760.

25


Figure 4-3 3D fluid simulation in cylinder shaped irregular grid.

60

Update particles from grid

50

Advect particles

40 30

Update grid from particles

20

Add body force

10 Project

0 simulation time (%)

Figure 4-4 Simulation time analysis for PIC/FLIP method

In Fig. 4-4, we can see that advecting particles takes more than 50% of total simulation time. The reason is because PIC/FLIP method depends on large number of particles. In contrast, project takes relatively small time. To utilize multi-core processor, OpenMP4 was used as much as possible.

Figure 4-5 Rendered images

4

http://openmp.org

26


5 Conclusion and Future Work Fluid simulation in tetrahedral mesh using modified PIC/FLIP method provides many benefits such as nice treating curved boundary, less numerical dissipation, variable cell sizes and easy way to add body force. In the meantime, the simulation time still take less than full Lagrangian method such as SPH. In addition to aforementioned advantages, hybrid method is naturally easy to be extended to parallel process. It is because most of operations are local and do not have a dependency to their neighborhoods. For example, advecting a particle is independent to its neighbour particles or grid cells and can be run in a parallel sense. This easy parallel process can open a new possibility for network based distributed simulation or GPU acceleration. In my early attempt, CUDA based acceleration shows huge performance gain. However bandwidth limit between CPU and GPU should be carefully taken into account. (Bell, et al., 2008) shows a good method to overcome bandwidth issue to perform sparse matrix-vector multiplication in GPU. In this paper, I did not show a direct performance comparison between irregular and regular grid. However throughout various testing, it was obvious that irregular grid takes more time than regular gird. In regular grid, mesh topology is quite simple and it severs as a hash grid naturally. Finding neighbour cells or searching neighbour particles can be accelerated by mash structure. However topology of irregular grid is complex and requires large memory storage. A constant lookup is necessary for each particle or cell. To speed up performance, hash grid or octree was used but still the speed cannot be close to regular grid. One of the possible solutions will be mixing hexahedral mesh with tetrahedral mesh. To handle boundary tetrahedral cells can be used. For inner cells, hexahedral mesh can be used. To connect these two types of cells, pyramid cells will be needed as transient cells. For liquid simulation, surface reconstruction is important. In traditional PIC/FLIP, particles are not necessarily stay close to solid boundary because velocity field in the boundary region is too weak to enforce particles. Therefore generated surface polygon can have a visible gap with solid mesh and produce artifacts. This issue occurs because particle interactions are done in the global level by grid. There is no local interaction among particles to reposition them so that all particles are equally separated. By taking an idea from SPH, particles can be repositioned in the cells close to boundary. This solution is different from moving particles close to boundary if they are within certain distance. Moving particles to boundary can cause artificial stickiness and artifacts. However the suggested solution would ensure that particles are equally distributed in the boundary region without any stickiness. In this paper, velocity extrapolation was completely removed. In regular mesh, velocity field should be extended across solid boundary and free surface because of staggered scheme. Also velocity extrapolation is necessary if Semi-Lagrangian advection is used in free surface. In tetrahedral mesh, it is possible to interpolate velocity without using information across boundary. In my implementation, barycentric interpolation was used in the boundary cells rather than dual cell interpolation. Locally it can create some discontinuity across cell faces but globally the vector field seems to be smooth and conform to boundary. Certainly there will be a better solution. 27


References Batty Christopher, Bertails F. und Bridson Robert A Fast Variational Framework for Accurate SolidFluid Coupling // ACM SIGGRAPH 2007. - 2007. BRACKBILL J. U. und RUPPEL H. M FLIP: a method for adaptively zoned, particle-in-cell calculuations of fluid flows in two dimentions. - 1986. Bridson and Müller-Fischer Fluid simulation // SIGGRAPH 2007 course notes. - 2007. Chentanez Nuttapong [et al.] Liquid simulation on lattice-based tetrahedral meshes// ACM SIGGRAPH 2007. - 2007. Elcott Sharif [et al.] Discrete, circulation-preserving, and stable simplicial fluids. - [s.l.] : Caltech, 2005. Enright Douglas P., Marschner Stephen R. und Fedkiw Ronald P. Animation and rendering of complex water surfaces // Special issue on Proceedings of SIGGRAPH 2002. - [s.l.] : ACM Transactions on Graphics, 2002. Fedkiw Ronald, Stam Jos und Wann Jensen Henrik Visual simulation of smoke // Special issue on Proceedings of SIGGRAPH 2001. - [s.l.] : ACM Transactions on Graphics, 20(3):15–22,, August 2001. Feldman Bryan E. [et al.] Fluids in deforming meshes// ACM SIGGRAPH/Eurographics Symposium on Computer Animation 2005. - 2005. Feldman Bryan E., O’Brien James F. und Klingner Bryan M. Animating gases with hybrid meshes // Special issue on Proceedings of SIGGRAPH 2005. - 2005. Feldman Bryan E., O’Brien James F. und Klingner Bryan M. Animating Gases with Hybrid Meshes // ACM SIGGRAPH 2005 Papers. - 2005. Foster Nick und Metaxas Dimitri Modeling the motion of a hot, turbulent gas // ACM SIGGRAPH 1997. - 1997. Foster Nick und Metaxas Dimitri Realistic animation of liquids. - [s.l.] : Graphics Interface, 1996. HARLOW F. H. The particle-in-cell method for numerical solution of problems in fluid dynamics. [s.l.] : Experimental arithmetic, high-speed computations and mathematics, 1963. Harlow F. und Welch J. Numerical calculation of time-dependent viscous incompressible. - [s.l.] : The Physics of Fluids, 1965. Kass Michael und Miller Gavin Rapid, stable fluid dynamics for computer graphics // ACM SIGGRAPH 90. - 1990. - S. 49–57. 28


Klingner Bryan M. [et al.] Fluid animation with dynamic meshes // Special issue on Proceedings of SIGGRAPH 2006. - [s.l.] : ACM Transactions on Graphics, 2006. Lorensen und Cline Marching cubes: A high resolution 3D surface construction algorithm // Proceedings of the 14th annual conference on Computer graphics and interactive techniques.. - 1987. Losasso Frank, Gibou Frederic und Fedkiw Ronald Simulating water and smoke with // Special issue on Proceedings of SIGGRAPH 2004. - [s.l.] : ACM Transactions on Graphics, 2004. MÜLLER M. [et al.] Point based animation of elastic, plastic and melting objects // Proceedings of 2004 ACM SIGGRAPH. - 2004. Peachey Darwyn R. Modeling waves and surf // SIGGRAPH ’86: Proceedings of the 13th annual conference on computer graphics and interactive techniques. - [s.l.] : ACM Press, 1986. - S. 65–74. Stam Jos Real-Time Fluid Dynamics for Games // Game Developer Conference. - [s.l.] : Alias|wavefront, 2003. Stam Jos Stable Fluids// SIGGRAPH 99 Conference Proceedings. - [s.l.] : Alia|wavefront, 1999. Warren Joe [et al.] Barycentric Coordinates for Convex Sets. - 2005. Zhu Yongning und Bridson Robert Animating Sand as a Fluid // ACM SIGGRAPH 2005. - 2005. Nathan Bell and Michael Garland Efficient Sparse Matrix-Vector Multiplication in, "NVIDIA Technical Report NVR-2008-004",, December 2008

29


Appendix To interpolate velocity at cell center, should be solved. Matrix N is non-squared and the linear equation is overconstrained. So it can be solved using least square method as below.

Ě…

(

)

Barycentric coordinates for circumcenter in triangle is below: (

)

(

)

(

)

a, b and c are edge lengths (BC, CA, AB respectively)

In liquid simulation, gravity plays an important role. With a presence of gravity in liquid simulation, divergence-free constraint should be applied more strict than one in smoke simulation. In my test, 10-6 worked fine as tolerance for Conjugate Gradient solver. If the value of tolerance becomes less, it will be observed that particles start moving downward in the still water.

30


31

FLUID SIMULATION IN TETRAHEDRAL MESH USING HYBRID METHOD  

This paper seeks to implement fluid simulation in tetrahedral mesh using hybrid method. Since Jos Stam introduced Stable Fluid in computer g...

Read more
Read more
Similar to
Popular now
Just for you