Simulation - Smoothed-Particle Hydrodynamics
Path of the code: [06_sph]
The objective is to model a fluid simulation using SPH model. So far, only the gravity force is applied on the particles
The blue color around the particle comes from a field function set as \(f(p)=\sum_i exp\left(-\left(\|p-p_i\|/\sigma\right)^2\right)\) and displayed as a colored texture to give the visual impression of continuous fluid material. > Fill the function "update_density" that set the density at each particle position \(\rho_i\) using a smooth kernel
-
- \(\displaystyle W_h(p) = \frac{315}{64\,\pi\,h^ 3}\,\left(1-\left(\frac{\|p\|}{h}\right)^ 2\right)^ 3\), \(\|p\|\leq h\)
- Note that this kernel is already implemented in the function W_density.
src/simulation/simulation.cpp) to add the force component related to pressure and check that the solution seems reasonable (before adding viscosity forces).
- Note: Fill the function "W_gradient_pressure" to be the gradient of the spiky kernel and use it in the computation of the pressure force
Example obtained without viscosity using 20 integration steps for each frame (the initial code performs a single call to
simulate per frame)
- Note: Fill the function "W_laplacian_viscosity" to be the laplacian of the viscosity kernel and use it in the computation of the viscosity force.
-
Note: The viscosity value is the parameter
nuof the structuresph_parameters_structure(filesrc/simulation/simulation.hpp), stored in the variablesph_parametersof the scene.
Adding viscosity
Example with more samples
Extensions
- - Note that particles have been initialized in the \((x,y)\) plane and leads to a 2D simulation. But if you initialize particles in 3D (or add a small \(z\) component in their initial position), the simulation will adapt seamlessly to 3D.
- - If you have spare time: Implement an acceleration grid structure to avoid comparing all pairs of particles (ex. uniform grid).