2017 21st International Conference on Control Systems and Computer Science Comparison between incompressible SPH solvers Claudiu Baronea, Adrian Cojocaru, Mihai Francu, Anca Morar, Victor Asavei Computer Science and Engineering Department University POLITEHNICA of Bucharest Bucharest, Romania claudiu.baronea@gmail.com, adrian.cojocaru92@yahoo.com, mihai.francu@cs.pub.ro, anca.morar@cs.pub.ro, victor.asavei@cs.pub.ro Abstract In this paper, we present two high performing and efficient Smoothed Particle Hydrodynamics (SPH) methods used to physically simulate incompressible fluids: Implicit Incompressible SPH (IISPH) and Divergence-Free SPH (DFSPH). At the moment, the most stable SPH methods employ correctors that reduce the error of the fluid particles to achieve very low levels of compressibility. We analyze the performance of the correctors used for the methods previously mentioned. We also compare IISPH against DFSPH to study several characteristics such as the stability of the particles, the compressibility levels of the fluid achieved during the simulations, the execution speed of each corrector, the maximum possible increase of the time steps, etc. Keywords SPH, corrector, incompressibility, fluids, stability, time step I. INTRODUCTION The Smoothed Particle Hydrodynamics (SPH) method was developed by Monaghan and Gingold and Lucy in 1977 for astrophysics studies [5]. However, over the years, SPH has often been used to study and simulate other fields such as volcanology, oceanography, fluid dynamics, etc. SPH is based on the Navier-Stokes equations which best describe incompressible, isothermal fluids: the continuity equation (1) and the momentum equation (2). It is a mesh-, Lagrangian method that can be used to represent and discretize the fluid as a collection of particles. A. SPH Interpolation Each fluid particle has its own mass and can store various fluid quantities at certain points in the fluid, such as velocity,, pressure, viscosity, external forces, etc. In order to find such a quantity,, of a given particle at an arbitrary position,, SPH uses equation (3) to interpolate using the same type of quantities,, of all the neighboring particles. (1) B. Smoothing Kernels An important component of equation (3) and, at the same time, an essential aspect of every SPH method is the smoothing kernel W - a function that weights the quantities of the particles in the vicinity of the current particle based on position.. A neighboring particle that is close to the queried one contributes more to the evaluation compared to particles farther away. We can consider the general form of the kernel function given by equation (4), as presented in [2], where h represents the smoothing radius of the kernel and d represents the number of dimensions of the simulation domain. Most SPH implementations use a polynomial form for the kernel function as described in [5]. Although it is very efficiently computed, this kernel presents one important disadvantage. If used to obtain the pressure forces, the particles will tend to cluster together and produce sticking artifacts because the function s gradient nears zero when the particles get very close to each other, reducing the repulsion forces. To prevent this, [3] replaces the polynomial kernel with a spiky one when computing the pressure forces. However, both the polynomial and the spiky kernel have negative Laplacians that produce further repulsion forces when computing the viscosity forces, making the simulation unstable. To correct this, another kernel is used for the viscous terms, the viscosity kernel as presented in [3]. (2) (3) (4) 2379-0482/17 $31.00 2017 IEEE DOI 10.1109/CSCS.2017.44 271
C. Time Integration Usually, time integration schemes can be classified as either explicit or implicit. While implicit schemes that consider both the current state and the next state of the simulation use large time steps that are advantageous for real time rendering, they need, however, large execution times per simulation step. In contrast to implicit schemes, explicit integration schemes use only the current state of the simulation and require small execution times per simulation step but require smaller time steps for the integration. SPH methods usually employ explicit methods such as Verlet and Leap-Frog time integration schemes. In the case of Leap-Frog, the positions and velocities of the current state are forwarded in time using the time step and forces acting on particles in the current simulation step. In this paper, we compare two incompressible methods: IISPH and DFSPH. We present several implementation details and we show how each algorithm works. In addition, we study the correctors employed in each method. Also, we analyze and compare their performances: what level of compressibility can they reach, how fast and accurate the correctors are, etc. II. RELATED WORK Many SPH algorithms have been implemented to improve fluid simulations as much as possible, visual and computational wise. In [5], Monaghan uses state equations to weakly enforce incompressibility by penalizing errors using a user defined stiffness value relative to the speed of sound. The straightforward computation of pressure values makes Standard SPH (SSPH) well suited for efficient simulation of compressible fluids. For weakly compressible fluids, Weakly Compressible SPH (WCSPH) uses a stiff equation of state (EOS) that imposes a severe time step restriction that reduces the overall performance since lower compressibility requires smaller time steps, as per [7]. Some of the best performing SPH algorithms are those that aim to achieve a compressibility level as low as possible - these systems are often labeled as Incompressible SPH. These SPH methods first integrate the velocity field in time without enforcing incompressibility. Secondly, the resulting variation in particle or intermediate velocity field are projected onto a space to satisfy incompressibility through a pressure Poisson equation. This concept is known as splitting, as presented in [8], [9]. Some of the most notable incompressible SPH methods that are worth mentioned are: Predictive-Corrective Incompressible SPH (PCISPH) [3], Implicit Incompressible SPH (IISPH), Divergence-Free SPH (DFSPH). Predictor-corrector methods, Predictive-Corrective Incompressible SPH [3] and local Poisson SPH [10] model pressure forces as a constraint force that resolves compression generated by the non-pressure forces. This is done by iteratively predicting and correcting the particle positions based on an EOS. Implicit Incompressible SPH [2] employs a discretized form of the continuity equation (1) and computes symmetric pressure forces using Relaxed Jacobi in order to obtain a semi-implicit predictor. In addition, it considers velocity instead of positions to compute deviations. IISPH has proven to reduce the deviations down to 0.01%, at the same time allowing large time steps, making it a robust choice for real time fluid simulations. Divergence-Free SPH [1] combines two solvers to obtain volume compression below 0.01%, at the same time making it possible to use large time steps. First, it uses a solver to minimize the deviation, thus enforcing incompressibility on position level. The second solver enforces a - state of the fluid particles, enforcing incompressibility on velocity level and increasing particle stability. DFSPH can simulate complex scenes consisting of more than 5 million fluid particles and 40 million boundary particles. III. DIVERGENCE FREE SPH Incompressible SPH methods try to reduce fluid compression levels to acceptable values by correcting the pressure forces acting on the particles. This is equivalent to solving systems of equations resulted from the state of the particles. The algorithms that solve these systems of equations are called pressure solvers and are usually built around iterative methods (or relaxation methods) able to solve linear and nonlinear equation systems. One example of a relaxation method for SPH simulations is the Jacobi Iteration, useful in determining solutions for diagonally dominant systems of equations. Both SPH methods analyzed in this paper use Relaxed Jacobi pressure solvers. However, DFSPH combines two such Relaxed Jacobi based pressure solvers to correct both the variation and the error in the same simulation step. As such, a -field corrector maintains a small change rate, while the solver corrects the variations resulted from computational errors. This section further analyses the two pressure solvers used in [1], presenting the main implementation aspects and the advantages resulted from their approach. 272
A. Divergence Free Solver The first pressure solver ensures a near - velocity field by enforcing a velocity as close to zero as possible, meaning that the of the fluid does not change over time. If, for a certain particle, this condition is not fulfilled the solver computes a set of pressure forces using Jacobi iteration to change the velocities of the particle and its neighbors enough to ensure that [1]. The force created by the pressure of the ith particle is given by equation (5), where is the of the i th particle, is the gradient operator, represents the mass of the j th particle and is the fluid stiffness parameter. Also, the pressure forces exercised by the i th particle upon each of its neighboring particles are computed using equation (6). The change rate can be expressed using particle velocities (equation (7)) as described in [2]. (5) (6) (7) Keeping in mind that the pressure forces and cause velocity changes between two consecutive simulation steps, equation (7) can be rewritten to emphasize the contribution of the pressures. Furthermore, we can substitute the pressure force terms with equations (5) and (6), thus obtaining equation (8). (8) (9) According to [1], in order to compute the correct particle velocities to obtain a small change rate, the stiffness factor of each particle must be found. Using equation (9), the stiffness factor can be expressed with equation (10), where is a scalar factor computed using only particle positions as described in equation (11). Because depends solely on the positions of the particles, it is computed only at the beginning of each simulation step and used in both solvers. Using the stiffness from equation (10) we can compute the new pressure forces that fulfill the condition as per equation (12) [1]. (10) (11) (12) Below, we present our own implementation of the pressure solver used to correct the - error. At the beginning of each iteration, the average change rate is reinitialized to zero and recomputed at the end of the first loop. Each particle s change rate is computed and used to obtain the stiffness factors for all the parcels. The solvers iterate as long as the average change rate is above a certain, user defined threshold. Finally, the velocities of the particles are updated with regard to the total pressure forces that correct the error. In contrast to the solver algorithm presented in [1], we compute the stiffness factor for each particle at the same time as the change rate because the value of does not depend on the quantities of other particles. Second, because in our simulations all particles have the same mass, we moved the parameter outside of the summation as a minor optimization. DivergenceZeroSolver(particleList) i i B. Constant Density Solver Figure 3.1.0 Divergence solver The second solver used for the DFSPH algorithm is the solver which corrects the variation in relation to the rest. As with the - 273
solver, this solver also uses the scalar factor in its computations, conferring the advantage of speed. The algorithm is outlined in Fig 3.2.0 and is similar to the previous one; it runs until the average variation with respect to the rest lowers below a user defined threshold. Each iteration starts by computing the predicted for the i th particle, according to [1]. ConstantDensitySolver(particleList) i i Figure 3.2.0 Constant solver overall performance. Note that, similar to the error solver, the stiffness factor is computed at the same time with advected. IV. IMPLICIT INCOMPRESSIBLE SPH Standard SPH methods employ an equation of state (EOS) in order to compute pressure forces that lower the compression rate. An alternative solution to EOS based SPH algorithms, projection schemes are used to calculate intermediate velocities without prior extraction of pressure forces. Also, a Poisson Pressure Equation (PPE) is solved to compute the pressure forces necessary to correct the intermediate velocities to a state. However, projectionbased SPH schemes are considered impractical in the context of computer graphics, the main reason being that their performance does not scale well with the size of the simulation. The method proposed in [2] addresses this point, using a discretization of the PPE that significantly improves the convergence of the solver and the stability of the time integration scheme. The pressure of a particle is computed using the equation of state (15), where is the rest of the fluid, and control the stiffness. Moment preserving pressure forces are computed using equation (16). (15) Finally, the stiffness factor needed to compute the pressure forces that correct the error is calculated in a similar way as in the - solver (equation (13)), which leads to equation (14) for computing the stiffness factor. A. Derivation (16) (13) (14) As stated above, due to the fact that the scalar factor is precomputed at the beginning of each simulation step and then used in both the field corrector and the variation corrector without needing any other modifications or updates, both solvers are very cheap computational-wise, needing very small CPU time. Also, due to the usage of the - solver to correct the velocities of the particles, the solver doesn t need as many as other pressure solvers to obtain a satisfying error. This also means that the system becomes very stable, allowing larger time steps. This, in turn, means that the neighborhood query, one of the most expensive operations per simulation step, is done less frequently for each particle, giving an increase to the The IISPH method considers the change rate and the continuity equation presented in (1) to obtain a predictor that uses both the current and the next value for the particle, as described in (19). (19) This semi-implicit predictor uses, however, unknown velocities dependent on pressure forces at time t. To compute these unknown factors, IISPH updates the positions and velocities using a semi-implicit Euler scheme. The particle velocities can be thus obtained as in (20) using unknown pressure forces and known forces such as gravity, surface tension, viscosity (. In order to predict the in (22), IISPH uses the advected velocities obtained as in (21). 274
(20) (21) (22) (26) (27) (23) Equation (23) describes the deviation from the rest considering in (19). From (16) and (23) a linear system is obtained which uses one equation and one unknown pressure value for each particle. B. Relaxed Jacobi (24) IISPH uses a relaxed Jacobi to iteratively solve equation system (24) for each particle pressure as in (25). (25) where is the relaxation factor ([2] suggests an optimal convergence for value 0.5). In order to compute this, and are computed using (26), where the first term represents (displacement of i due to pressure) and the second (movement caused by the pressure of neighboring particles). Using (26), (23) and denoting the neighbors of j with k yields the equation (27). Note that are computed using equation (28) and pressures are evaluated using (29). Figures 4.1.0 and 4.2.0 present the pressure solver used in IISPH method to compute the advected densities and velocities of the fluid particles. The first module iterates through the fluid particles in order to compute the densities, the velocities and the displacement factors of each particle. A second loop is necessary to compute the advected. The second module computes the pressures corresponding to the next state of the equation by calculating the movement caused by the pressures to each particle,. (28) V. PERFORMANCE COMPARISON DFSPH vs IISPH (29) The following section analyzes the behavior of the two algorithms described so far - Divergence-Free SPH [1] and Implicit Incompressible SPH [2] - and presents the results obtained using our own sequential implementations, on two simulation scenarios: breaking dam and -fall cube. Both SPH implementations used 125k particles to discretize the fluid body in the breaking dam scenario (fig. 5.1.0). For rigid body approximations, we employed a twoway coupling method using boundary particles as described in [11]. Also, to ensure a good approximation of continuous surfaces, we oversampled the objects four times compared to the smoothing kernel radius. In this regard, the walls and floor that represent the dam used for the simulation were constructed using 18k boundary particles. Although these particles do not change positions between successive states, they are included in the neighborhood queries and in the solver. We first executed the simulation using DFSPH method. We used the spiky smoothing kernel [3] for the solvers and for the computation of the change rate. Although we did not go for the cubic spline as in [1], we did use the same kernel for both solvers to ensure the symmetry between - and solvers so that they behave well when executed sequentially. We used a lookup table to discretize the scalar and the gradient values of the kernel to optimize the computations of, forces and other required factors. To this extent, we used a resolution of 1000 samples for the discretization process. Although the algorithm presented in [1] uses warm 275
(ms) average solver DFSPH max solver max error average solver IISPH max solver max error 5 2.1 3.01 8 6 1.9909 0.008575 42.8 87 0.0498 2.5 1.2 2.07 5 3 1.2938 0.00265 15.1 52 0.0496 1 1 2 1 2 0.1114 0.000058 5.3 12 0.0491 0.5 1 2 1 2 0.0229 0.000011 3.002 4 0.0486 Table 5.1.0 Breaking Dam scenario. DFSPH vs IISPH Pressure Solve() i i Predict Advection() i i Figure 4.1.0 Advection Predictor Figure 4.2.0 IISPH pressure solver start-ups for both solvers in each simulation step to improve the computations and lower the number of, we did not use warm start-ups in our own scenarios. After executing the simulation, we obtained the data presented in Table 1.0. For large times steps (i.e. 2.5 ms, 5 ms) the solver has higher iteration spikes compared to the solver, but behaves better in average with fewer over the entire simulation, the corrector needing only 2 to converge compared to 3 for the solver, results similar to those illustrated in [1]. For smaller time steps, the average and the maximum number of per solver are very close in value because, for small time steps, the deviations are small enough that the solvers do not need to execute too much to converge. In such cases, the corrector generally needs only 1 iteration, while the corrector needs no more than 2 to obtain very good results. We can observe that the solver obtains very low variations, regardless of the size of the time step. We conclude, from the simulation results, that the DFSPH solvers need a small number of to converge to our thresholds and give very small variations. This means that the compressibility of our simulations is under 0.01%. Because the - solver is executed first and obtains a very small change rate, the solver doesn t need too many to converge and offers an acceptable error. As previously stated, we also ran the IISPH implementation on the breaking dam. For a time step of 5ms, the corrector used in IISPH needs an average of 42 to converge, with an iteration spike of 87. While, for the same time step, both DFSPH solvers need around 5-6 to converge, the IISPH solver needs 7 times more to obtain good variations to bring the compressibility below 0.01%. At the same time, the corrector used in DFSPH outclasses the one used in IISPH, the first one obtaining a variation of 0.008575, while the latter one resulted in a variation of 0.0498. 276
(ms) average solver DFSPH max solver max error average solver IISPH max solver max error 5 2.22 2.47 9 5 1.73 0.0061 40.5 80 0.0492 2.5 2.01 2.32 6 4 1.116 0.00056 14.8 45 0.0487 1 1 2 1 2 0.764 0.00101 4.9 10.1 0.0483 0.5 1 2 1 2 0.083 0.0006 2.9 3.5 0.0481 Table 5.2.0 Free Fall Cube. DFSPH vs IISPH For smaller times steps, the IISPH solver does indeed fare better, needing almost the same number of as DFSPH solvers. As the time step is decreased, the number of decrease as well, both the average and the maximum values. However, the error obtained after running the solver does not decrease too much compared to the results of DFSPH simulations. The error remains above 0.048 for all the time steps used in our simulations. Thus, for the breaking dam simulation scenario, it can be concluded that IISPH behaves poorly compared to DFSPH. The second simulation scenario analyzed is the fall cube. The scene configuration consisted of a cube of 27k fluid particles left to fall on a flat surface approximated by a number of 10k boundary particles. The results are showcased in Table 2.0. In the case of DFSPH, similar to the breaking dam scenario, the - solver has higher iteration spikes than the solver, but a smaller number of on average. Also, if smaller time steps are used, the number of for both solvers decrease, both on average and maximum values. As was the case for the previous scenario, the IISPH solver needs more to converge, both on average and during execution spikes. The error does not decrease too much when using smaller time steps, compared to the improvements DFSPH presents when changing the integration step. The solver are higher for IISPH solver than for DFSPH solvers, regardless of the time step used. The similarity between the results obtained from both scenarios further confirm our analysis and data. We can observe that, indeed, the solvers used for DFSPH are faster than the pressure solver used in IISPH. In both scenarios, the - solver finished in an average of 1 or 2 and the solver in an average of 2 or 3, while, for IISPH, the solver needed much more execution steps. While the error is, indeed, below our threshold using both algorithms, we can clearly see that the DFSPH error is smaller than the IISPH error by at least one order of magnitude for large time steps. Thus, our comparison concludes that, although, both algorithms can achieve very good compressibility levels, DFSPH solvers are, indeed, faster than IISPH s, while still obtaining better, smaller variations. A similar comparison between DFSPH and IISPH using several fixed time steps was also made in [1]. In the case of the first fixed time step of 4 milliseconds, DFSPH solvers finished in an average of 2.8 for the solver and 4.5 for the solver. The summed execution times of both solvers for a simulation of 60 seconds approximated to 45 seconds, while the entire execution time of the algorithm rounded to 51 seconds. However, the IISPH solver was much slower, reaching even 50 per simulation step. The solver execution times reached even 312.1 seconds, while the total duration of the algorithm was 318 seconds for 60 seconds of simulation. As such, for a time step of 4 ms, the solvers used for DFSPH combined were 6.9 times faster than the IISPH solver. For a fixed time step of 2 milliseconds, the number of for DFSPH solvers was lower, 1.3 for the - solver, and 2.1 for the solver. The execution time of both solvers, summed together, was 47.8 seconds. Even though slightly higher than the previous solver execution duration of 45.2 seconds, we must keep in mind that the time step is two times smaller than the previous one used. On the other hand, IISPH performance had improved compared to the previous tests. The solver needed an average of 21.4 to converge, as opposed to the previous number of 50.5, and a solver execution time of 256.4 seconds with a total execution time of 267.9 seconds. However, IISPH still behaved poorly compared to DFSPH for a time step of 2 milliseconds, the latter s solvers being 5.36 times faster and requiring fewer to converge. For small times steps (i.e. 0.25 milliseconds), both methods solvers required almost the same amount of, although the execution times of DFSPH solvers were just slightly lower, 288.3 seconds compared to 322.5 seconds. 277
Fig. 5.1.0 Breaking Dam - Initial state Fig 5.2.0 Breaking Dam - Intermediate state The comparison performed in [1] confirms our conclusion that DFSPH behaves very well even when large time steps are used. This gives the advantage of better performance since the neighborhood query is necessary less often. VI. CONCLUSIONS In this paper, we presented two, very efficient incompressible SPH methods: Divergence-Free SPH [1] and Implicit Incompressible SPH [2]. We analyzed how each of these methods work and what solvers they use. DFSPH uses two solvers to obtain low compressibility levels: a - solver that minimizes change rate and a solver which aims to lower the error as much as possible. In contrast to DFSPH, IISPH uses only one pressure solver and discretizes the Poisson Pressure Equation to significantly improve the convergence of the corrector and the stability of the time integration scheme. We have also shown how our implementations of both SPH methods behave in two scenarios: the breaking dam scenario and a simpler one, a -falling cube on a flat surface. We compared the results from DFSPH simulation against the IISPH results and concluded that DFSPH solvers behave better than the IISPH solver, they need much fewer to converge and also yield better, smaller errors. VII. ACKNOWLEDGEMENT This work has been funded by University Politehnica of Bucharest, through the Excellence Research Grants Program, UPB GEX. Identifier: UPB EXCELEN 2016 3Diafano Reconstructia si vizualizarea tesuturilor pe baza transiluminarii in NIR si a camerelor video 3D, Contract number 01/26.09.2016, code 514 (acronym: 3Diafano). REFERENCES [1] Bender, Jan, and Dan Koschier. 2015. Divergence-Free Smoothed Particle Hydrodynamics. In Proceedings of the 14th ACM SIGGRAPH / Eurographics Symposium on Computer Animation - SCA 15. [2] Ihmsen, Markus, Jens Cornelis, Barbara Solenthaler, Christopher Horvath, and Matthias Teschner. 2013. Implicit Incompressible SPH. IEEE Transactions on Visualization and Computer Graphics, July. [3] Solenthaler, B., and R. Pajarola. 2009. Predictive Corrective Incompressible SPH. In ACM SIGGRAPH 2009 [4] Ihmsen, M., Orthmann, J., Solenthaler, B., Kolb, A., and Teschner, M. 2014. SPH Fluids in Computer Graphics. Eurographics (State of the Art Reports), 21 42. [5] Monaghan, J. J. 1992. Smoothed particle hydrodynamics. Ann. Rev. of Astron. and Astrophys. 30, 543 574. [6] Muller, M., Charypar, D., and Gross, M. 2003. ParticleBased Fluid Simulation for Interactive Applications. In ACM SIGGRAPH / Eurographics Symposium on Computer Animation, 154 159. [7] Becker, M., and Teschner, M. 2007. Weakly compressible SPH for surface flows. In ACM SIGGRAPH / Eurographics Symposium on Computer Animation, 1 8 [8] Chorin, A. J. 1968. Numerical solution of the Navier-Stokes equations. Mathematics of Computation 22, 745 762. [9] Bridson, R. 2008. Fluid Simulation for Computer Graphics. A K Peters / CRC Press. [10] He, X., Liu, N., Li, S., Wang, H., and Wang, G., 2012. Local poisson SPH for viscous incompressible fluids. [11] Akinci, N., Ihmsen, M., Akinci, G., Solenthaler, B., and Teschner, M., 2012. Versatile rigid-fluid coupling for incompressible SPH. 278