About this Journal Submit a Manuscript Table of Contents
Mathematical Problems in Engineering
Volume 2012 (2012), Article ID 635631, 9 pages
http://dx.doi.org/10.1155/2012/635631
Research Article

Real-Time Simulation of Fluid Scenes by Smoothed Particle Hydrodynamics and Marching Cubes

1College of Computer Science, Zhejiang University of Technology, Hangzhou 310023, China
2State Key Laboratory of Software Development Environment, Beijing 100083, China

Received 2 August 2012; Accepted 26 September 2012

Academic Editor: Fei Kang

Copyright © 2012 Weihong Wang et al. This is an open access article distributed under the Creative Commons Attribution License, which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly cited.

Abstract

Simulating fluid scenes in 3DGIS is of great value in both theoretical research and practical applications. To achieve this goal, we present an algorithm for simulation of fluid scenes based on smoothed particle hydrodynamics. A 3D spatial grid partition algorithm is proposed to increase the speed for searching neighboring particles. We also propose a real-time interactive algorithm about particle and surface topography. We use Marching Cubes algorithm to extract the surface of free moving fluids from particles data. Experiments show that the algorithms improve the rate of rendering frame in realtime, reduce the computing time, and extract good real effects of fluid surface.

1. Introduction

Simulation of fluid scenes has a wide range of applications in the movie special effects, computer animation, game production, virtual reality, and many other fields [14]. At first, most studies of fluid simulation are based on the nonphysical procedural modeling method which generates scene by parameterized surface. Although the simulation is faster, these methods are not based on physical principles, thus lack of authenticity, and can’t simulate some detailed effects, such as the effect of wave overturning. At the same time these methods are based on random functions, it is difficult to achieve solid-liquid interaction. So most researchers focused on fluid simulation based on physical methods.

At present, physics-based fluid simulation methods are mainly divided into two types [5]: one is grid-based Euler method, the other is particle-based Lagrange method. Smoothed particle hydrodynamics (SPH) is a new method based on particle-based Lagrange method, which is mainly used in astrophysics at first. J. Monaghan is the first one to apply SPH into simulation of free surface flow. Stam and Fiume [6] brought in SPH method into fluid simulation to achieve the effect of gas and flame. And then, the researches on fluid simulation mainly adopt particle-based Lagrange method. Harada et al. [7] made the searching adjacent particle feasible by constructing uniform spatial grid. Under this circumstances, fluid particles are relatively dispersed and lots of idle grid units would appear. Therefore, Grahn [8] made the fast searching adjacent particle of arbitrary size scene possible by constructing the space uniform grids with Hash function through GPU. Kolb and Cuntz [9] made use of GPU to achieve the whole process of SPH. However, this method calculates in the grids and interpolates in the particles, which leads to physical discontinuousness and simulation results distorted. David Lopez et al. [10] made use of SPH to build the physical pressure modal on river basin of the Villar Del Rey Dam, and it simulated the fluid scene of discharge floodwater. The way to deal with boundary interaction is too simple. So it simplified the terrain boundary to regular area, but the terrain surface is rugged in 3DGIS.

Although there are many SPH methods to simulate fluid in literature, they can’t apply to simulate fluid in real-time and high efficiency in complex scene [1113], such as simulating debris flow and flood and other process of fluid evolution in the 3DGIS. This paper improves 3D spatial grid partition algorithm to increase speed of neighboring particles searching, and we also propose a real-time interactive algorithm on particle and terrain surface. The results show that this method can calculate in real-time and has a good rendering rate.

2. Smoothed Particle Hydrodynamics

The basic idea of SPH makes fluid as a series of discrete particles, through the role of the smooth, which has certain radius of kernel functions to a particle physics scalar (such as density, pressure, etc.) assigning to the adjacent particles, as shown in Figure 1. Physical scalar of any particle can be calculated by where is density of the particle , is quality of the particle , and is radius of smoothing kernel. If the distance from the particle to particle , that is, , the particles is in smooth domain of the particle , we can get the weight of particle by smoothing kernel function . Otherwise , the weight of the particles is zero. In the solution of fluid equations, we often need to take derivatives of the physical scalar, and this operation only affects smoothing kernel function in SPH method. Therefore gradient of physical scalar value A can be expressed as (2.2).

635631.fig.001
Figure 1: The basic principle of SPH.

3. Grid-Based Neighboring Particles Search

The existing neighboring particle search algorithms mostly adopt to traverse all particles directly, with time complexity of and stands for the number of fluid particles. Chen et al. [14] constructed an index table of two-dimensional array of particle and spatial grid by dividing the three-dimensional space grid with grid number being the primary key and the index table being radix sorted (algorithm complexity of radix sort is ). The index numbers of the first particle which corresponds to each grid are obtained so that each grid in the particle is identified.

In this paper, the improved neighboring particle search algorithm doesn’t need to create the index table of particle and grid but divide grids, which saves memory space. It also doesn’t need to sort the particles and the index table, so it reduces the complexity of algorithm. The algorithm steps are as follows.

Step 1. Divide the three-dimensional spatial grid. In this paper, bounding box of the three-dimensional terrain space is divided into cube grid with length of . stands for the radius of smoothing kernel. The Standard Template Library std::vector is used to store information of particles of each spatial grid. Particle is a class which stores density, velocity, spatial coordinates, and other physical information of fluid particle, and a Particle* pointer pointing to next particle.

Step 2. Put the fluid particles into three-dimensional spatial grid. Insert all the particles into the corresponding spatial grid number by (3.1). That is to insert the current particle pointer into the spatial grid: where stands for the particle in axis coordinate, respectively, min_int is the positive integer function that get the minimum value, and represents spatial grid number.

Step 3. Calculate the neighboring particles of each particle. In SPH method, particles are only affected by other particles in radius of smoothing kernel, so we will find the scope for particle located in the neighborhood of 27 spatial grids. Firstly, calculate the spatial grid number of particle by (3.1); then calculate index number of by GridWidth, GridDepth, and GridHeight, respectively, stand for the dimension on direction of spatial grid, then the contained particles of are stored in pointer array. Finally, visit all the particles in and calculate current particle of density and physical pressure and so on by using the equations derivated from (2.1) and (2.2).

4. Interaction between the Fluid Particles and the Boundary

The simplest algorithm is exhaustive algorithm on dealing with interaction between fluids and boundary. Assuming that there are geometric facets and fluid particles in the scene, its time complexity is . In the 3DGIS, the number of triangular patches of terrain mostly ranges from 105 to 107 and the number of fluid particles is generally between 103 and 106. If the exhaustive algorithm is adopted, the computation will be too huge to be accepted. In this regard, [14] proposed a boundary interaction algorithm based on spatial mesh, which inserts information of the terrain boundary and obstacle into the spatial grid, then judges whether the fluid particles are intersected with boundary geometry patches and obstacle in spatial grid when the fluid particles pass through. The algorithm requires geometry patches of boundaries to be small enough; if geometry patches are large, the number of grid number each grid space occupied will increase, which will lead to reduced efficiency of algorithm.

Because the number of triangular grids of terrain is huge in the 3DGIS, if the above algorithms are adopted for boundary interaction, the amount of calculation will be too huge and the efficiency of real-time rendering will be degenerated. Regarding this, this paper proposes a real-time interaction method of the boundary bounce particles, where the time complexity of algorithms is and is the number of fluid particles. Interaction between the fluid particles and the terrain is mainly used in interaction between the fluid particles and the terrain surface to prevent fluid particles from penetrating through the terrain surface, shown in Figure 2 The basic idea of algorithm is as follows.

635631.fig.002
Figure 2: Interaction between the fluid particles and the terrain surface.

Step 1. Calculate intersection of the ray and triangular grid of the terrain surface. The origin of the rays is and direction is straight down (). As DEM data is regular grid data, two-dimension array can be used for storage. Spatial coordinate of the triangle patches of terrain surface can be calculated by (4.1). is . In a similar way, coordinates of and can be calculated. The and axis’s coordinates of and are equal, if , then calculate the elevation of by bilinear interpolation of triangle 1. Otherwise, calculate the elevation of by bilinear interpolation of triangle 2, and are the coordinates of , and are coordinates of . , respectively, stands for the particle on axis coordinate. and , respectively, stands for space interval on axis coordinate of the terrain elevation. stands for the two-dimension array which stores the terrain data:

Step 2. Judge whether the particle is in the area that rebounded by the terrain. First, calculate the spatial distance from particles to . If , then the particle is not in rebound area, so go to Step 1, and deal with particle . Otherwise, , then enter Step 3, values for which is the radius of the smoothed particle.

Step 3. Calculate force of rebound boundary. When fluid particle is close to terrain, the particle will be rebounded by the terrain surface. The rebound force can be calculated by (4.2), where is speed of the particle, is the hardness parameters of the terrain, is deceleration parameter of terrain to the particle, and is the normal unit vector of the triangular patches that include the intersection . When the fluid particles gradually approach the terrain surface, the rebound force increases gradually until the velocity of the particle decreases to zero. At this time, the particle is still subjected to the effect of rebound which increases the velocity of the particle, thus preventing fluid particles to penetrate through the terrain. The direction of the rebound force is normal direction of the triangular mesh plane. Note that the rendering system only renders the clockwise triangular patches; we adopt clockwise triangles for the calculation of the normal unit vector of triangular patches that the particles locate in:

5. Visualization of the Fluid Surface

The fluid surface reconstruction is important for fluid simulation. Lighting and texture rendering of the fluid surface will improve the fidelity of fluid scene. Iwasaki et al. [15] proposed Point Splatting method to build the surface rendering, and this method has highly real-time rendering efficiency, but emptiness appears where fluid particles are relatively sparse [1620]. In this paper, Marching Cubes algorithm is proposed to be applied in constructing fluid surface of free moving, which has the advantages of simple operation and fast drawing. The process is as follows.

Step 1. The 3D space is evenly divided into spatial grids. Traverse all the particles in the fluid region, calculate minimum coordinates () and maximum coordinates () of the particles which are bounding box of fluid region, and divide the box into homogeneous spatial grids.

Step 2. Calculate the density of the vertices of each spatial grids. Then use the divided grids as the sampling points of fluid scenes to get fluid density field data. Calculate the density value of each grid of the 8 vertices by using (2.1) and SPH interpolation on particles of each grid.

Step 3. Determine the threshold value of density isosurface of the fluid surface. According to the fluid pressure equal to atmospheric pressure, and the state equation of an ideal atmosphere, threshold value of density isosurface of the fluid surface can be obtained as follows: where stands for the fluid surface density, for atmospheric pressure, and for gaseous constant.

Step 4. Compare each vertex density value of spatial grid with threshold value of isosurface. If the vertex density value is greater or equal to the isosurface value, vertex value is 1 and the vertex is in the isosurface; otherwise is 0 and the vertex is outside of isosurface. According to the result of the comparison, structure the grid state table.

Step 5. Calculate the vertex of density isosurface coordinates of each spatial grid. If a vertex of a side of a grid is in the isosurface, while the other vertex is out of the isosurface, then, this side inevitably intersects with the desired isosurface. Firstly, according to the grid state table, get the grid’s sides which intersect with the isosurface. Then calculate the intersection of grid’s side and isosurface by linear interpolation method.

Step 6. Draw density isosurface. By using the central difference method and the linear interpolation method, calculate vertex normal of each triangle. Finally according to the coordinate values of each triangle vertex and normal vector, draw density isosurface.

6. Experiment Results

In this paper, the experiment platform is Intel Core 2 Duo CPU T6670@2.2GHZ. Main memory is 2 G, and graphic card is NVIDIA GeForce 9300GS with memory of 256 M, and operating system is Windows XP, and the drawing SDK is OSG (OpenSceneGraph).

Figure 3 shows fluid outflowing from a topographic position in 3DGIS, and its dynamic process of evolution on the terrain surface. The fluid particle number is 30000. Figure 4 shows the Figure 3 Scene by Marching Cube algorithm to construct the effect of fluid surface of free moving.

635631.fig.003
Figure 3: Fluid in the dynamic evolution process of particle simulation (particle number 30000).
635631.fig.004
Figure 4: Effect of reconstruction of fluid surface mesh reconstruction (particle number 30000).

As this algorithm applies Marching Cube algorithm which is the same as [8] to construct the fluid surface and field particle search and complex boundary interaction algorithm which are used in this algorithm are different to [12], thus they are comparable. Table 1 shows the comparison of simulation speed of the algorithm and two other kinds of algorithm. Figure 5 shows comparison of computing time per frame. Table 1 and Figure 5 show that this algorithm reduces the computation time per frame.

tab1
Table 1: Comparison of the three algorithms on simulation rate.
635631.fig.005
Figure 5: Comparison of the three algorithms on simulation rate.

7. Conclusion

In order to simulate the fluid scene in 3DGIS, this paper proposed an SPH algorithm for fluid scene simulation. The experiment results show that this algorithm can calculate in real-time and has a good real-time rate of rendering frame, and achieve the desired goals. In near future we intend to further improve the algorithms of extracting fluid surface and enhance reconstruction speed and accuracy of the fluid surface mesh.

Acknowledgments

This paper is supported by the National Natural Science Foundation of China (60873033), the Natural Science Foundation of Zhejiang Province (R1090569), and the State Key Laboratory of Software Development Environment Open Fund (SKLSDE-2012KF-05).

References

  1. M. Carlini and S. Castellucci, “Modelling and simulation for energy production parametric dependence in greenhouses,” Mathematical Problems in Engineering, vol. 2010, Article ID 590943, 28 pages, 2010. View at Publisher · View at Google Scholar · View at Scopus
  2. M. Li, C. Cattani, and S. Y. Chen, “Viewing sea level by a one-dimensional random function with long memory,” Mathematical Problems in Engineering, vol. 2011, Article ID 654284, 13 pages, 2011. View at Publisher · View at Google Scholar · View at Scopus
  3. Carlo Cattani, Shengyong Chen, and Gani Aldashev, “Information and Modeling in Complexity,” Mathematical Problems in Engineering, vol. 2012, Article ID 868413, 4 pages, 2012. View at Publisher · View at Google Scholar
  4. S. Chen, H. Tong, and C. Cattani, “Markov models for image labeling,” Mathematical Problems in Engineering, vol. 2012, Article ID 814356, 18 pages, 2012. View at Publisher · View at Google Scholar
  5. Y. Liu, X. Liu, H. Zhu, and E. Wu, “Physically based fluid simulation in computer animation,” Journal of Computer-Aided Design and Computer Graphics, vol. 17, no. 12, pp. 2581–2589, 2005. View at Scopus
  6. J. Stam and E. Fiume, “Depicting fire and other gaseous phenomena using diffusion processes,” in Proceedings of the 22nd Annual ACM Conference on Computer Graphics and Interactive Techniques, pp. 129–135, Los Angeles, Calif, USA, August 1995. View at Scopus
  7. T. Harada, S. Koshizuka, and Y. Kawaguchi, “Smoothed particle hydrodynamics on GPU,” in Proceedings of The Computer Graphics International, pp. 63–70, Rio de Janeiro, Brazil, 2007.
  8. A. Grahn, “Interactive simulation of contrast fluid using smoothed particle,” Hydrodynamics, pp. 1–69, 2008.
  9. A. Kolb and N. Cuntz, “Dynamic particle coupling for GPU based fluid simulation,” in Proceedings of the 18th Symposium on Simulation Technique, pp. 722–727, Erlangen, Germany, 2005.
  10. D. Lopez, R. Marivela, and F. Aranda, “SPH model calibration using data from pressure of the prototype still basin of Villar Del Rey Dam, Spain,” in Proceedings of the 33rd IAHR Congress, Water Engineering for a Sustainable Environment, pp. 187–198, 2009.
  11. S. Y. Chen, “Kalman filter for robot vision: a survey,” IEEE Transactions on Industrial Electronics, vol. 59, no. 11, pp. 4409–4420, 2012. View at Publisher · View at Google Scholar
  12. P. Kipfer and R. Westermann, “Realistic and interactive simulation of rivers,” in Proceedings of the 32nd Annual Conference on Computer Graphics (SIGGRAPH '06), pp. 1–8, New York, NY, USA, June 2006. View at Scopus
  13. S. Chen, Y. Wang, and C. Cattani, “Key issues in modeling of complex 3D structures from video sequences,” Mathematical Problems in Engineering, vol. 2012, Article ID 856523, 17 pages, 2012. View at Publisher · View at Google Scholar
  14. X. Chen, Z. Wang, J. He, H. Yan, and Q. Peng, “An integrated algorithm of real-time fluid simulation on GPU,” Journal of Computer-Aided Design and Computer Graphics, vol. 22, no. 3, pp. 396–405, 2010. View at Scopus
  15. K. Iwasaki, Y. Dobashi, F. Yoshimoto, and T. Nishita, “Real-time rendering of point based water surfaces,” Advances in Computer Graphics, vol. 4035, pp. 102–114, 2006. View at Publisher · View at Google Scholar · View at Scopus
  16. C. Cattani, “Shannon wavelets for the solution of integro-differential equations,” Mathematical Problems in Engineering, vol. 2010, Article ID 408418, 22 pages, 2010. View at Publisher · View at Google Scholar
  17. E. G. Bakhoum and C. Toma, “Specific mathematical aspects of dynamics generated by coherence functions,” Mathematical Problems in Engineering, vol. 2011, Article ID 436198, 10 pages, 2011. View at Publisher · View at Google Scholar · View at Scopus
  18. S. Y. Chen and Z. J. Wang, “Acceleration strategies in generalized belief propagation,” IEEE Transactions on Industrial Informatics, vol. 8, no. 1, pp. 41–48, 2012. View at Publisher · View at Google Scholar
  19. N. M. Kwok, X. Jia, et al., “Visual impact enhancement via image histogram smoothing and continuous intensity relocation,” Computers & Electrical Engineering, vol. 37, no. 5, pp. 681–694, 2011. View at Publisher · View at Google Scholar
  20. S. C. Lim, C. H. Eab, K. H. Mak, M. Li, and S. Y. Chen, “Solving linear coupled fractional differential equations by direct operational method and some applications,” Mathematical Problems in Engineering, vol. 2012, Article ID 653939, 28 pages, 2012. View at Publisher · View at Google Scholar