2.4 Crisis en el Ámbito Minero
2.4.1 Pautas para el manejo de crisis
The SPH fluid simulation implementation is different to the spring-mass model in two main ways:
• The usage of the fluid dynamics equations to calculate extra acting forces on the particles
• The calculation of pressure and viscosity requires a mass-density calculation onallpar-
ticles to be performed beforehand, as the total density must be summed for all neigh- bouring spatial grid cells before the pressure or viscosity on the actual particle can be calculated.
The first point is relatively straightforward - rather than a single spring-force calculation, the sum of all forces acting on the particle is comprised of both pressure and viscosity forces in the SPH simulation. The second point however, means that the SPH simulation requires the
spatial grid to be passed throughtwice. The first pass calculates the density for each particle,
and the second pass calculates the pressure and viscosity forces. Essentially, this means that the SPH method will effectively run slower, but this is not always the rule as will be explained shortly. Apart from these two aspects, the SPH implementation of a water simulation remains largely unchanged. Similar to the spring-mass model, Algorithm 12 shows a more in-depth look at the calculation of the forces in the SPH simulation.
There are several things to note in Algorithm 12. As with the spring-mass model, the mass of all particles is assumed to be the same as well as the fluid parameters. The algo- rithm performs two passes through the spatial grid, firstly calculating the density and pres- sure values for each particle in the fluid, and then doing a second pass through the grid and using those values to calculate the pressure and viscosity forces acting on the particles.
Pseudo Code Value
Particle Number n 524,288
Timestep t 0.0005
Particle Mass M 0.00005
Rest Density KrestD 1000.0
Rest Pressure KrestP r 0.0
Gas Stiffness KgasSt 1.5
Smoothing Kernel Length Klen 0.00641
Table 6.2: Table with simulation parameters of the SPH model for water simulation, with pseudo-code symbols.
Algorithm 12In-depth SPH model force calculation algorithm
Given array P ofnparticle positions
Given array V ofnparticle velocities
Given array D of particle densities Given array Pr of particle pressures
Given arrays F and L of sorted particle indices (First and Last)
Given simulation constants K - kernel length, length squared, rest density and pressure, gas stiffness, kernel coefficients
Given particle mass M
Accelerations (forces)Ap(pressure force),Av(viscosity force),Atotal= 0
foreach particle in PARALLEL, with thread indexido
Cell C = cellfunc(P[i]) //Find neighbours
for all-1≤x≤+1, -1≤y≤+1, -1≤z≤+1do Neighbour N = C + Vec(x, y, z)
cell index=cellfunc(N)
f= F[cell index];l= L[cell index] //Loop through all neighbouring particles forp=f;p≤l;p++do
D[i] =calc density(P[i], P[p],KlenSq,Ksm, M)
//For SPH, use the smoothing kernel constants to calculate density end for
end for
//Final density and pressure is calculated using SPH equations D[i] = max(1.0f, M *Kpoly6co* D[i])
Pr[i] =KrestP r+KgasSt*( D[i] -KrestD) end for
//Now use pressure and density to calculate forces
foreach particle in PARALLEL, with thread indexido
Cell C = cellfunc(P[i]) //Find neighbours
for all-1≤x≤+1, -1≤y≤+1, -1≤z≤+1do Neighbour N = C + Vec(x, y, z)
cell index= cellfunc(N)
f= F[cell index];l= L[cell index]
//Calculate pressure and viscosity forces using SPH equations forp=f;p≤l;p++do
Ap=calc pressure force(P[i], P[p], D[i], D[p], Pr[i], Pr[p],Klen,Ksm, M)
Av=calc viscosity force(P[i], P[p], D[i], D[p], V[i], V[p],Klen,Ksm, M) end for
end for
//Finalize SPH forces
Atotal[i] =Ap*KkernelP r +Av *KkernelV * M Add external force E where applicable
end for
SECTION 6.5: WATER IMPLEMENTATION 115 / / C a l c u l a t e t h e d e n s i t y o f p a r t i c l e A from B d e v i c e f l o a t c a l c d e n s i t y (f l o a t 3 posA , f l o a t 3 posB , f l o a t k l e n g t h s q , f l o a t s m o o t h i n g c o e f f , f l o a t p a r t i c l e m a s s ){ / / U s i n g t h e p o l y 6 s m o o t h i n g k e r n e l f l o a t 3 r e l p o s = posA − posB ; f l o a t d i s t = l e n g t h ( r e l p o s ) ; f l o a t d i s t s q = d i s t ∗ d i s t ; / / ( ( h ˆ 2 − r ˆ 2 ) ˆ 3 f l o a t d = k l e n g t h s q − d i s t s q ; d ∗= d ∗ d ; / / c o e f f : 3 1 5 / 6 4∗p i∗ h ˆ 9 r e t u r n p a r t i c l e m a s s ∗ s m o o t h i n g c o e f f ∗ d ; }
Listing 6.7: Calculating the particle mass-density. See previous equations in Section 4.3 for a more detailed explanation
Many constant simulation parameters are used in this method, many of which have been pre- calculated during the particle system initialization and put into constant memory. These pa- rameters are explained in more detail in Table 6.2. The interesting parts of the algorithm are
highlighted in bold. Three device kernels,calc_density,calc_pressure_forceand
calc_viscosity_forcecontain the bulk of the SPH functionality. Each of these device kernels are shown in detail in code listings 6.7, 6.8 and 6.9 respectively.
Table 6.2 shows the simulation parameters used for a SPH model to produce a standard water simulation. For reference, it contains the equivalent symbols used in the pseudo-code in Algorithm 12. These parameters can be easily changed to get vastly different behaviour from the fluid. Different smoothing kernel coefficients are calculated directly based on the
smoothing kernel lengthKlen.
Listing 6.7 shows the device kernel used to calculate the density of each particle in the
fluid. The square of the kernel smoothing lengthk_length_sqand the smoothing coefficient
are constant values which have been pre-calculated and stored in constant memory for fast
access. TheposAandposBare the positions of the current particle and neighbouring particle
respectively. Once the density has been calculated, the pressure of the particular particle can be calculated using Equation 4.11 (see Chapter 4).
The calculation of the force due to pressure is shown in Listing 6.8. It is using a conser- vation of momentum equation to make sure that the force is symmetrical - both particles will apply the same pressure force on each other. Taking the positions of the two particles as well as the pressure and density of these particles, it uses the first differential of the spiky smoothing kernel to calculate the final pressure force.
The viscosity component of the force is also calculated as shown in Listing 6.9. Taking the position and velocity of the two particles it uses the laplacian of the viscosity smoothing kernel to calculate the viscosity force.
/ / C a l c u l a t e t h e p r e s s u r e f o r c e o f p a r t i c l e B on A d e v i c e f l o a t 3 c a l c p r e s s u r e f o r c e (f l o a t 3 posA , f l o a t 3 posB , f l o a t p r e s s u r e A , f l o a t p r e s s u r e B , f l o a t d e n s i t y A , f l o a t d e n s i t y B , f l o a t k l e n g t h , f l o a t s m o o t h i n g c o e f f , f l o a t p a r t i c l e m a s s ){ / / U s i n g t h e f i r s t d i f f e r e n t i a l s p i k y s m o o t h i n g k e r n e l f l o a t 3 r e l p o s = posA − posB ; f l o a t d i s t = l e n g t h ( r e l p o s ) ; f l o a t p = ( p r e s s u r e A / ( d e n s i t y A ∗ d e n s i t y A ) ) + ( p r e s s u r e B / ( d e n s i t y B ∗ d e n s i t y B ) ) ; / / ( ( h − r ) ˆ 2 f l o a t s = k l e n g t h − d i s t ; s ∗= s ; / / c o e f f : −45/ p i∗ h ˆ 6 r e t u r n p ∗ s m o o t h i n g c o e f f ∗ ( r e l p o s / d i s t ) ∗ s ; }
Listing 6.8: Calculating the particle pressure force. See previous equations in Section 4.3 for a more detailed explanation. Smoothing kernel length, coefficient and mass are all pre-calculated and stored in constant memory for fast access.
/ / C a l c u l a t e t h e v i s c o s i t y f o r c e o f p a r t i c l e A from B d e v i c e f l o a t c a l c v i s c o s i t y f o r c e (f l o a t 3 posA , f l o a t 3 posB , f l o a t 3 velA , f l o a t 3 velB , f l o a t d e n s i t y A , f l o a t d e n s i t y B , f l o a t k l e n g t h , f l o a t s m o o t h i n g c o e f f , f l o a t p a r t i c l e m a s s ){ / / U s i n g t h e l a p l a c i a n v i s c o s i t y s m o o t h i n g k e r n e l f l o a t 3 r e l p o s = posA − posB ; f l o a t d i s t = l e n g t h ( r e l p o s ) ; f l o a t 3 v = ( v e l B − velA ) / ( d e n s i t y A ∗ d e n s i t y B ) ; / / h − r f l o a t s = k l e n g t h − d i s t ; / / c o e f f : 4 5 / p i∗ h ˆ 6 r e t u r n v ∗ s m o o t h i n g c o e f f ∗ s ; }
Listing 6.9: Calculating the particle viscosity force. Viscosity force is dependent upon the velocity of the particle - a faster velocity means a greater viscosity force, because fluid dynamics seeks to keep particles from escaping the fluid. Smoothing kernel length, coefficient and particle mass are all pre-calculated and stored in constant memory for fast access.
SECTION 6.5: WATER IMPLEMENTATION 117
Afterwards the total force is added up and multiplied by the assumed constant particle mass, as well as any external forces such as gravity and boundary forces. Once this final force has been calculated it is used in the integration method in calculating the movement of the particles. This completes the implementation of the SPH system for water. All that is left to do is render the system.