Rigid Body Sampling and Individual Time Stepping for Rigid-Fluid Coupling of Fluid Simulation

In this paper, we propose an efficient and simple rigid-fluid coupling scheme with scientific programming algorithms for particlebased fluid simulation and three-dimensional visualization. Our approach samples the surface of rigid bodies with boundary particles that interact with fluids. It contains two procedures, that is, surface sampling and sampling relaxation, which insures uniform distribution of particles with less iterations. Furthermore, we present a rigid-fluid coupling scheme integrating individual time stepping to rigid-fluid coupling, which gains an obvious speedup compared to previous method. The experimental results demonstrate the effectiveness of our approach.


Introduction
Physically based fluid simulation is a popular issue in computer graphics and virtual reality while having a huge research and application demand in three-dimensional visualization and human-computer interactions.More realistic effects and higher simulation efficiency are the main goals; thus, reasonable, efficient, and scientific programming algorithms are needed to design and implement the animation.Two major schemes are employed for animating fluids: the gridbased Eulerian approach and particle-based Lagrangian approach.Eulerian method is particularly suited to simulate large volumes fluid, while being restricted by time step and computing time for small scale features.In contrast, Lagrangian method is suitable for capturing small scale effects such as spindrift and droplet.Among various particlebased approaches, Smoothed Particle Hydrodynamics (SPH) is the most popular method for simulating fluid due to computational simplicity and efficiency.
In reality, rigid-fluid interaction widely exists in many scenarios.As a result, the interesting fluid behaviors emerge once rigid objects are added to fluid simulation.While interaction between particle-based fluids and rigid objects seems to be straightforward, there are still several issues not well resolved.For one thing, rigid bodies must be sampled to particles in order to interact with particle-based fluids, but only a few rigid boundary sampling methods can be directly employed in rigid-fluid coupling simulation.For another thing, the computational expenses of rigid-fluid coupling are considerable.To deal with the increasing demands for more detailed fluids and high efficiency, we present rigid sampling and individual time stepping for rigid-fluid coupling and design a practical and easy rigid-fluid animation simulation scheme with our scientific programming algorithms.

Related Work
Desbrun and Gascuel introduced SPH to computer graphics for simulating deformable objects [1].SPH became popular in computer graphics for various fluid phenomena.Monaghan addressed simulating free surface flows with SPH [2] that serves as a basis for SPH fluid simulation.Muller et al. [3] proposed using gas state equation with surface tension and viscosity forces for fluid simulation, which also bring compressibility issue.Becker and Teschner [4] proposed WCSPH employing Tait equation to reduce compressibility.It significantly increased realistic effects but the efficiency is limited by time step.As incompressibility expenses computation time, many improved algorithms were addressed to enhance the efficiency.Solenthaler and Pajarola [5] presented PCISPH using a prediction-correction scheme to determine 2 Scientific Programming particle's pressure and large time steps which significantly improved efficiency comparing to WCSPH.Another similar method that ensures incompressibility by iterative process is LPSPH [6].Afterwards, Ihmsen et al. addressed a more efficient approach IISPH [7].It carefully constructed pressure Poisson equation and solved the linear system using Relaxed Jacobi, which has a great improvement in stability as well as convergence speed and is particularly suitable for large-scale scene.Recently, a promising approach for impressible SPH has been proposed by Bender and Koschier [8].It combines two pressure solvers which enforce low volume compression and a divergence-free velocity field and permits large time steps that yields a considerable performance gain.
Besides, adaptive method, either spatial resolution or time discretization, is another way to promote efficiency.They allot computing resources to regions with complex flow behavior.Space adaptive methods [9][10][11] adaptively sample particle and employ less particles to produce similar details.Large particles are divided into small particles if high resolution is needed, and vice versa.However, difficulties exist in reproducing quantity when refining particles, and neighbor searching is usually the bottleneck.As an alternate to adaptive spatial discretization, the time domain can be adaptively sampled as well.Globally adaptive time stepping methods [1,12,13] employ a single time step to adjust each step for all particles in consideration of CFL condition.Though each particle has the current smallest time step, it is not the most efficient way.Locally adaptive time stepping methods [9,14,15] use different time steps for particles.Desbrun and Cani proposed that each particle evaluates forces depending on its current individual time step [9].He et al. [16] adopt this idea and implement stable simulation of stiff fluids.It updates position, velocity, and density for active particles and interpolates for inactive particles.In this paper, we integrate it to rigid-fluid coupling to reduce the computational time.
For boundary handling in SPH fluid simulation, distancebased penalty methods were commonly employed [17][18][19].Nonetheless, these methods require large penalty forces which limit the time step and make particles stick to the boundary on account of lacking fluid neighbors.Frozen or ghost particles based models are used to solve the problem of sticking particles [20].In order to avoid penetration, more than one layer of frozen particles were used [21], or the positions of penetrating particles should be corrected [13].However, handling two-way interaction is troublesome since the elevated density near boundary in one phase affects particles in the other phase.For this reason and for the lack of fluid neighbors, Ghost SPH [22] solved those problem using a narrow layer of ghost particles and Akinci et al. employed boundary particles to correct the calculation of fluid density [23].Because Ghost SPH is more time consuming, we use Akinci's boundary handling method which is simple and easy to achieve in this paper.
For rigid-fluid coupling, several approaches were presented up to now.In [24], the fluid is represented as rigid spheres and switching impulses with rigid bodies.In [25,26], the pressure at the boundary is taken into consideration for two-way fluid-rigid coupling.Then, Oh et al. proposed an impulse-based scheme for two-way coupling of SPH fluids with rigid bodies [27].Becker et al. presented direct forcing for rigid-fluid coupling [28] which employs a predictioncorrection scheme to enforce particle positions and velocities to specific values.Akinci et al. presented a momentumconserving two-way coupling approach based on hydrodynamic forces that use boundary particles to sample the surface of rigid bodies [23].We present a rigid-fluid coupling scheme by integrating individual time stepping to Akinci's boundary handling method that gains an obvious speedup [29].
Rigid bodies sampling includes particle-based methods and polygonization-based methods.Turk repelled particles on surfaces to get a uniform sample [30] and also simplified a polygonization through reducing the number of polygons [31].Witkin and Heckbert employed local repulsion to make particles spread uniform [32].Nehab and Shilane [33] presented algorithm of stratified point sampling.Cook addressed stochastic sampling of Poisson disk distributions with blue noise [34].Blue sampling has the ability to generate random points and get uniform distribution of sampling points set.Therefore, the following sampling methods always have blue noise characteristics.Corsini et al. sampled triangular meshes with blue noise properties [35].Dunbar and Humphreys [36] modified Poisson disk sample using a spatial data structure.Bridson [37] simplified Dunbar's approach with rejection sampling and extending it to higher dimensions.Then, Schechter [22] modified Bridson's approach and employed it to Ghost SPH.Inspired by Schechter's approach, we address sampling method improved by SPH equation that is more efficient and easy to implement.

Particle-Based Fluid Simulation Framework
In particle-based fluid simulation, the forces acting on particles are derived from the Navier-Stokes equations.The conservation of mass and momentum are written as where k  is the velocity,   is the density,   is the pressure,  is the viscosity coefficient, and  is the external force field.SPH works by obtaining approximate numerical solutions of fluid dynamics equations by expressing fluids with particles.In SPH, the representation of a field variable  at location x  is defined as where   and   represent particle mass and density, respectively, (x  − x  , ℎ) is smoothing kernel, and ℎ is smoothing radius.
It can be easily derived from the basic SPH equation by substituting fluid density  into (2), that is,

Rigid body
Rigid body Rigid body

Boundary particle
Fluid particle Therefore, particles' pressure force f   and viscous force f V  can be written as In this paper, we use Tait equation [4] to calculate the pressure; that is, , where  0 = 1000 is the rest density of the fluid,  = 7 is stiffness parameter, and   is velocity of sound.We use the equation in [23] to compute viscous force.

Boundary Handling for Particle-Based Fluids
In rigid-fluid interaction, there are three types of forces among particles: the forces between fluid particles and boundary particles Force rigid-fluid , the forces between fluid particles Force fluid-fluid , the forces between boundary particles Force rigid-rigid , which is shown in Figure 1.In our simulation, we sample rigid body to obtain boundary particles which is described in Section 5.Moreover, for the boundary handling way of rigid-fluid interaction, we implement our simulation based on the work of [23].The following will briefly introduce boundary handling in this section.Considering influence of boundary particles, density formula of fluid particles in (3) needs to introduce weighted summation influence of boundary particle [23], that is, where   and   denote fluid particle  and boundary particle , respectively.The first summation calculates the affection of adjacent fluid particles, while the second summation computes the influence of adjacent boundary particles.This formula can overcome the problem of boundary defects in SPH fluid simulation to some extent.Due to the use of boundary particle mass in (5), the density of fluid particles is incorrect or unstable when the boundary particle density is set unreasonably or unevenly distributed.Hence, consider the contribution of boundary particles to fluid particle by the volume of boundary particles is where  0 denotes the remaining density of fluid and    is the estimation value of boundary area volume of corresponding boundary particles.Applying Ψ   ( 0 ) to replace the boundary particle mass can guarantee the stability.Thus, ( 5) can be rewritten as The most important interaction between fluid particles and boundary particles is the pressure.The pressure acceleration generated by boundary particles to fluid particles can be computed as where    > 0 takes  = 2.When    < 0, boundary particles and fluid particles attract each other; then, we can adjust parameter  (0 ≤  ≤ 2) to realize different adsorption effects, and we choose  = 1 in our experiment.
To simulate the friction between fluid and container wall or the interaction of rigid body and fluid, we have to compute the friction of boundary particles with fluid particles.The friction is calculated by the artificial viscosity; that is, where ), ] = 2ℎ  /(  +   ).On account of ( 8) and ( 9) that listed the forces for fluid particles, we can get the forces of boundary particles using Newton's third law.The forces generated by fluid particles to boundary particles are where  denotes the fluid neighbors of boundary particle .It is the counteracting force of ( 8) and (9).For a rigid body, the total force and torque need to be calculated.This can be separately written as   10) while new samples are found do (11) Generate random tangential direction d of surface at p (12) q ← p + d ⋅  ⋅  (13) Project q to surface of  (14) if q satisfies the Poisson Disk criterion in  then (15)  ←  ∪ {q} (16) p ← q Algorithm 1: Surface sampling.
where x  is the location of boundary particle  and x cm rigid denotes the mass center of a rigid body.The total force and torque will be transmitted to the physics engine to handle the motion of rigid bodies.

Rigid Boundary Sampling
Rigid body sampling is the first issue in rigid-fluid coupling which we have to handle.We propose a rigid body sampling algorithm which is an extension of Poisson disk method and sampling method in [22] for rigid-fluid coupling.
For rigid objects sampling, boundary particles are used to sample the surface of rigid bodies that has several merits.For one thing, using particles permits us to get a rigid model that can handle different shapes even with complex geometry structure.For another thing, the use of boundary particles successfully alleviates sticking artifacts and makes sampling uniform.
There are two components in our sampling: surface sampling and surface relaxation.As shown in Figure 2, it first samples the surface of rigid object image, and then it improves initial sampling with surface relaxation.In order to realize the first procedure, it needs fast projection of points to the surface.Hence, level set method is employed to express surface geometry with  > 0 and  < 0 denoting exterior and interior of rigid objects, respectively, while  = 0 denotes surface of rigid objects.
After obtaining the surface geometry of signed distance function, we use surface sampling method proposed in [22] (as shown in Algorithm 1), first, searching seed points on the surface by checking each grid cell intersecting with the surface; the details are as follows: projecting random points from the cell to the surface and stopping when the point satisfies the Poisson disk criterion, which operates  attempts in a cell; when obtaining a seed sample, continuing to sample it and taking a step of size  ⋅  from the previous samples along a random tangential direction d; then projecting to the surface and checking the Poisson disk criterion again.Parameters were chosen as  = 30 and  = 1.085.In order to optimize the position of sample points, reduce noises, and get a uniform distribution set of sampling points, we need to further improve sampling set with a surface relaxation step.Inspired by the relaxation algorithm proposed in [22] and SPH interpolation method, surface relaxation algorithm is presented in Algorithm 2. Unlike employing random testing way in [22], we compel particles to move according to the density gradient.This ensures that the particles move to sparse place, so as to insure uniform distribution of particles.
It starts with the initial particles seed in Algorithm 1 and attempts to reposition each sample through density gradient.Next it computes density   () and density gradient ∇  () of each surface particles and employs deviation of density   () and average density   () as a coefficient to tune distance .Then, it employs  ⋅ ∇  () to adjust particle locations.Surface sample candidates are projected to the surface once again and are reserved which satisfies the Poisson disk criterion.Parameter t is iterations and f is distance coefficient.According to SPH gradient formula, particle's density gradient can be written as On the basis of signed distance field , it is fairly convenient for calculation of steps (7) and (8).If ( new ) ̸ = 0, it means  new is not on the surface.While for projecting particles to surface, we compute signed distance field gradient ∇( new ).Projection formula is We have done the experiment in 2 dimensions contrast to the relaxation algorithm in [22].We randomly generate 100 points in a 0.1 × 0.1 square shown in Figure 3.The red points represent that it does not meet the conditions of Poisson disk. Figure 4 shows the relaxation results of Figure 3; the first row is our method and the second row is the method in [22].The column (a) reveals the distribution of points after relaxation of two algorithms and the red points mean it does not satisfy Poisson disk condition.Each algorithm iterates 100 times, respectively, while column (b) illustrates the number of points that do not satisfy Poisson disk conditions for each iteration.It is obvious that our method can get a better effect with a slight concussion.Compared to the method in [22], the optimization effect is basically the same after 30 times' iteration using our method while it is the optimal results of fast Poisson disk method.In addition, our method is more efficient.In MATLAB environment, all parameters are the same as mentioned in [22]; our method takes 2.44691 s while relaxation method in [22] costs 56.44153 s for 100 iterations.

Individual Time Stepping for Rigid-Fluid Coupling
In this section, we propose a rigid-fluid coupling method employing individual time stepping.As a result, larger time steps can be used comparing to previous methods and the overall computation time is reduced.In particle-based fluids, particles only interact with their neighbors.So permitting particles to have different time steps is more efficient than using a global time step for all particles.The individual time stepping computes time step for each particle and updates time step asynchronously.6.1.Time Steps.For particle-based fluids, the time step must satisfies Courant-Friedrich-Levy (CFL) condition for numerical stability, that is, where V max = max  ‖k  ‖ is the maximum velocity of particles and coefficient  V < 1.In addition, it also has to consider particles' maximum acceleration.Thus, the time step must also meet the condition where  max = max  ‖k  /‖ denotes the maximum force per unit mass of particles and   < 1.In [13],  V = 0.4 and   = 0.25 are used for PCISPH, while we use  V = 0.1 and   = 0.05 for WCSPH.Instead of using a constant time step, we adjust time step dynamically as Thus, the time step for each particle  is where  denotes that it iterates all the neighbors.However, the presented algorithm demands small coefficients for asynchrony, so we choose  V = 0.05 and   = 0.025.6.2.Asynchronism.Since each particle has individual time step, we enforce asynchronous time integration for the update.To save computing resources, the system time step is chosen as the minimized individual time step: where Δ  is computed by (17).
Semi-implicit Euler integration is generally used in SPH simulation.To accommodate for asynchronism, the semiimplicit Euler integrations can be expressed as where Δ  is an independent integral time step which is different from the global time step Δ.For inactive particles, ( 20) is equivalent to interpolation, while, for active particles, they are semi-implicit Euler integration equations.In order to analyse the proposed algorithm, we implement the breaking dam with obstacles experiment.The setting of this experiment is shown in Table 1.We compare individual stepping method to adaptive stepping and constant stepping method in breaking dam with obstacles scene.The rending results are shown in Figure 5 and the time statistics are listed in Table 2. From Figure 5, the fluid simulation results are almost not different using three methods, while in Table 2, we can find that our method gains 1.5 and 6.4 times speedup comparing to globally adaptive stepping method and constant stepping method, respectively.In addition, the average active particles percent of individual stepping method is 31%.

Implementation and Results
All the experiments in this paper are implemented on Intel 3.50 GHz CPU with 4 cores.The simulation algorithms (Algorithms 1, 2, and 3) and surface reconstruction [38,39] are actualized with C++ language and multithreading technology.Bullet is used to simulate rigid objects while OpenMP served as parallelization.Images were rendered with Blender.
To implement fluid-rigid coupling animation efficiently and scientifically, we design a fluid-rigid coupling programming simulation scheme shown in Figure 6.We firstly initialize rigid and fluid particles configuration.Then, we do neighbor search using spatial hashing algorithm for each particle.Next, the governing equations of fluid, rigid boundary sampling, and boundary handling are solved as described in the previous sections.Then, total force and torque of rigid are calculated and provided to Bullet.After total force acting on particles is computed, particles are integrated to next time step using asynchronous update scheme introduced in Section 6.
In order to demonstrate the validity of the entire fluidrigid coupling simulation system, we designed a scene of dropping multiple small squares into water.The setting and statistics are shown in Table 3, and the experimental results  are displayed in Figure 7.It can be seen from the diagram that small squares fall into water and splash water while they are rotated and inclined by water.Finally, small squares are force balance and floating on the water.
We realize another fluid-rigid coupling experiment displayed in Figure 8. Figure 8(a) is the results in particle view while Figure 8(b) is the rendering results.The setting and statistics are illustrated in Table 3.In this scenario, the breaking dam of water hits the sculpture which is knocked down and pushed for some distances due to kinetic energy of water.The motions of sculpture are in line with expectations which proved that the simulation and calculation of fluidrigid coupling system accord with physics laws.
This experiment further proved that our method can implement vivid fluid-rigid coupling animation simulation system with high realistic effects.It can be expected that this animation system can be used in virtual reality domain and special effects in film and game.

Conclusion
We proposed an efficient and simple rigid-fluid coupling scheme for particle-based fluid simulation.It samples rigid surface with boundary particles which are used to interact with fluids.It insures uniform distribution of particles which requires less iterations.In addition, we present an efficient rigid-fluid coupling approach combining individual time stepping with rigid-fluid coupling.Neighbors and forces of   10 Scientific Programming particles are updated only when needed, while computing resources are allocated to complex regions.It obtains an obvious speedup compared to previous methods.Besides, this scheme was integrated with rigid body coupling simulation with several scenes which has a good sense of visual reality.Overall, our method is efficient to compute while the sampling and coupling algorithm can be applied to other particle-based simulation or relevant approaches.Future work would be extending the proposed method to IISPH [7] or DFSPH [8] as well as large-scale scenarios.

Figure 1 :
Figure 1: Forces between boundary particles and fluid particles.

Figure 2 :
Figure 2: Surface sampling and relaxation.(a) Surface sampling.(b) Surface relaxation.Black points: newly added sample.Gray points: surface sampling points.White points: exterior points before being projected to the surface.

Figure 4 :
Figure 4: Relaxation results comparison of our method with fast Poisson disk.(a) Relaxation results.(b) The relationship between iteration times and points not conforming to the conditions.

Figure 5 :
Figure 5: Rendering results of breaking dam with obstacles.(a) Individual stepping method.(b) Globally adaptive stepping method.(c) Constant stepping method.

Figure 6 :
Figure 6: Flowchart of the programming scheme.
. Black points: newly added sample.Gray points: surface sampling points.White points: exterior points before being projected to the surface.
Input: Level set , radius , count , constant  Output: Sample set  (1) for all grid cells  that  changes sign do (2) for each  do Input: sample set , Level set , radius , count , constant is the system time and Δ is system update time step.Particle is active if  last + Δ  < .

Table 1 :
The setting of breaking dam with obstacles.

Table 2 :
Comparison of experimental results of breaking dam with obstacles.

Table 3 :
The setting and statistics of fluid-rigid coupling.Item Cubes fall into water Water shock sculpture Simulation domain size 12 m × 12 m × 12 m 10 m × 8 m × 5 m