# Boundary SPH for Robust Particle-Mesh Interaction in Three Dimensions
## 2 Materials and Methods
### SPH Fluid Interaction  
For proper integration with any SPH scheme, this particle-triangle check must be extended to all particles \(p\in P\) and all mesh triangles \(t\in T\). The boundary condition must be accounted for the scenario where, for each single particle \(p\), its \(proj_{p,t}\) is within some radius \(r_{p}\) of the particle. Depending on the implementation, it is highly recommended to make \(r_{p}\) equivalent to the smoothing kernel of the particle in order to prevent kernel truncation. \(p\) is therefore intersecting with the boundary if the distance between \(p\) and \(proj_{p,t}\) is less than or equal to \(r_{p}\).  
The general operational flow from mesh pre-processing to simulation runtime is visualized in Figure 6. As a general rule of thumb, the mesh pre-processing step occurs prior to the first frame of the simulation. The global mesh vertices, edges, triangles, and obstacles arrays are buffered into the GPU and referenced during every simulation frame. During the simulation, SPH particles are compared with every obstacle to identify whether they are intersecting with any meshes in the scene.  
When a particle is detected to be intersecting with (or submerged in) the boundary manifold, the particle must be reflected away from the boundary to prevent truncation. The simplest approach is to (1) reposition the particle so that its smoothing kernel is just beyond the boundary manifold; and (2) adjust its velocity to reflect off of the boundary manifold (see Figure 7). We take inspiration from [PERSON]'s implementation of reflective boundary conditions to implement particle-boundary interactions with respect to the boundary manifold's friction and restitution coefficients [35]. Given the velocity \(V_{p}\) for particle \(p\), the reflected vector is the component of two orthogonal sub-vectors:  
\[V^{\prime}_{N_{b}}=N_{b}*|(V_{p}\cdot-N_{b})|*c_{rest} \tag{5}\]  
\[V^{\prime}_{T}=\left(V_{p}+[N_{b}*|(V_{p}\cdot-N_{b})|]\right)*\left(1.0-c_{ friction}\right) \tag{6}\]  
\[V^{\prime}_{p}=V^{\prime}_{N_{b}}+V^{\prime}_{T} \tag{7}\]  
where \(c_{rest}\) is the restitution coefficient that influences the strength of the reflection along the boundary normal and \(c_{friction}\) is the friction coefficient that influences the strength of the reflection along the tangent line of the boundary method at \(proj_{p,t}\).  
Figure 6: Overview of the general operational pipeline from the pre-processing to simulation step. In this visualization, three mesh obstacles are represented by blue, light green, and dark green. **(a)** Pre-processing occurs prior to the first simulation step. **(b)** During each simulation step, parallelization allows for each particle to be compared with each mesh obstacle and their vertices, edges, and triangles in thread groups on the GPU. The final determination of the closest mesh and its corresponding closest projection \(proj_{p,t}\) and boundary normal vector \(N_{b}\) is calculated for each particle.  
Figure 7: Calculation of the reflected velocity vector \(V_{p}^{\prime}\) based on the particle’s initial velocity \(V_{p}\), the projected point of \(p\) on the boundary manifold \(proj_{p,t}\), and the boundary normal vector \(N_{b}\). Particle \(p\) is represented by the light blue circle whose center is the darker, inner circle. \(V_{p}^{\prime}\) is derived from combining \(V_{T}^{\prime}\), the tangential component of the reflected velocity that is affected by the boundary’s friction coefficient, and \(V_{N_{b}}^{\prime}\), the normal component of the reflected velocity that is affected by the boundary’s restitution coefficient.