SPH Fluid Simulator Back
Fluid Dynamics

SPH Fluid Simulator

Real-time 2D fluid simulation using Smoothed Particle Hydrodynamics. Experience viscosity, turbulence, and fluid dynamics interactively.

Parameters
Particle Count 200
Viscosity 0.30
Gravity Strength 9.8
--
FPS
--
Particles
--
Avg. KE
Slow
Fast

SPH Kernel Functions

Density estimation (Poly6 kernel):

$$W_{poly6}(r,h) = \frac{315}{64\pi h^9}(h^2-r^2)^3$$

Pressure gradient (Spiky kernel):

$$\nabla W_{spiky}(r,h) = -\frac{45}{\pi h^6}(h-r)^2 \hat{r}$$

$h$: smoothing length, $r$: inter-particle distance

CAE Note: SPH is used industrially for large-deformation free-surface flows — landslides, concrete casting, and explosion fragmentation. Representative solvers include DualSPHysics and LS-DYNA SPH.

Click & drag on the canvas to add particles | The circular obstacle is placed at the center

What is Smoothed Particle Hydrodynamics (SPH)?

🧑‍🎓
What exactly is SPH? It looks like this simulator uses blobs instead of a grid to model the fluid.
🎓
Exactly! SPH, or Smoothed Particle Hydrodynamics, is a mesh-free method. Instead of calculating fluid properties on a fixed grid, we track individual "particles" that carry properties like density and velocity. In practice, it's fantastic for simulating splashing, breaking waves, and mixing—things that are tricky for grid-based methods. Try hitting the "Shake" button above; you'll see the particles mix chaotically, which SPH handles naturally.
🧑‍🎓
Wait, really? So each particle is like a tiny blob of fluid? How does it know what's happening around it?
🎓
Basically, yes. Each particle's properties are "smoothed" over a region using a special weighting function called a *kernel*. A particle's density, for instance, is estimated by summing up the contributions from all its neighbors within a certain distance, the "smoothing length" (h). This is the core idea. For instance, in this simulator, when you increase the "Particle Count," you're adding more neighbors, which makes the density calculation smoother but more computationally expensive.
🧑‍🎓
That makes sense. So what do the "Viscosity" and "Gravity Strength" sliders actually change in the particle math?
🎓
Great question! Those sliders directly control the forces on each particle. Gravity Strength is straightforward—it's the $g$ in $F = m g$ pulling particles down. Viscosity controls a force that resists relative motion between neighboring particles, like internal friction. A low viscosity (like water) lets particles slide past each other easily. Crank it up high, and you get a thick, honey-like behavior. Try it—set viscosity to max and hit "Pour"; you'll see the fluid blob hold together much more.

Physical Model & Key Equations

The foundation of SPH is estimating any quantity (like density $\rho$) at a particle's location by averaging contributions from its neighbors using a kernel function $W$.

$$ \rho_i = \sum_j m_j W( |\mathbf{r}_i - \mathbf{r}_j|, h ) $$

Here, $\rho_i$ is the density of particle $i$, $m_j$ is the mass of neighbor particle $j$, $\mathbf{r}$ are positions, and $h$ is the smoothing length defining the neighborhood radius.

The motion of particles is governed by the Navier-Stokes equations, discretized onto the particles. The acceleration of a particle comes from three main forces: pressure, viscosity, and gravity.

$$ \frac{d \mathbf{v}_i}{dt}= -\sum_j m_j \left( \frac{P_i}{\rho_i^2}+ \frac{P_j}{\rho_j^2}\right) \nabla W + \nu \sum_j m_j \frac{\mathbf{v}_j - \mathbf{v}_i}{\rho_j}\nabla^2 W + \mathbf{g}$$

$\mathbf{v}$ is velocity, $P$ is pressure (often from an equation of state like $P = k(\rho - \rho_0)$), $\nu$ is the viscosity coefficient (your slider!), and $\mathbf{g}$ is the gravity vector (your other slider!). The $\nabla W$ terms use a different kernel (like the Spiky kernel) to ensure stability.

Real-World Applications

Landslide & Debris Flow Simulation: SPH is ideal for modeling large, deformable masses of soil, rock, and water flowing down slopes. Engineers use it to predict runout distances and impact forces on structures, helping to design protective barriers and plan evacuation zones.

Concrete Casting & Manufacturing: Simulating the flow of highly viscous, non-Newtonian fluids like wet concrete is a classic SPH application. It helps optimize mold design to ensure the concrete fills all cavities without trapping air bubbles, which would weaken the final product.

Explosion & Fragmentation Analysis: For modeling the interaction of shock waves with fluids or the fragmentation of structures, SPH's mesh-free nature avoids the severe mesh distortion that grid-based methods suffer from. This is used in defense and safety engineering.

Marine & Offshore Engineering: SPH is used to simulate violent free-surface flows, such as green water loading on ship decks, sloshing in LNG tanks, and wave impact on offshore platforms. This helps in assessing structural loads and stability.

Common Misconceptions and Points to Note

When you first start working with SPH, there are a few common pitfalls. First is the misconception that "more particles always mean higher accuracy." While increasing particle count does reveal finer details, the computational cost can skyrocket, roughly proportional to the square of the particle number. For instance, doubling particles from 1000 to 2000 can make the neighbor search nearly four times heavier. For learning purposes, the trick is to start with a smaller number of particles (e.g., 2000–5000) to grasp the overall behavior before gradually increasing it.

Next is the pitfall of parameter settings. While viscosity and pressure coefficients can be changed independently, balancing them is crucial for realistically reproducing fluids. For example, to replicate the kinematic viscosity ($ν$) of something like water, you need to adjust not just the viscosity coefficient but also linked parameters like density and pressure coefficient. In practice, be mindful of "dimensionless numbers." If you increase gravity too much in this tool and particles scatter, try raising the pressure coefficient slightly to strengthen particle cohesion.

Finally, there's the overestimation that "SPH is a magical method that can compute anything." While SPH excels with free surfaces and large deformations, it has weaknesses. For instance, it's not well-suited for tiny turbulent structures or detailed boundary layer behavior. Also, while visualizing all particles as in this demo is intuitive, practical work often involves evaluating "statistical particle behavior" or "domain-averaged values." After experiencing phenomena with the tool, develop a habit of stepping back to ask, "How would I quantify this?"

Related Engineering Fields

The computational concepts handled by this simulator are actually applied to various continuum mechanics problems beyond fluids. First is "fracture analysis in solid mechanics." Modeling metal fatigue or concrete crack propagation as a process of breaking particle bonds—methods like the "bonded particle method"—are akin to relatives of SPH.

Another is "powder technology." The flow of powders like flour or sand grains is dominated by particle collisions and friction. By adding models that account for friction coefficients and rotation to SPH particles, you can simulate discharge from silos or mixing processes. For example, it's used to predict where blockages might occur in coffee bean bagging machines.

Furthermore, applications in "biomechanics" are interesting. Blood, a non-Newtonian fluid flowing within vessels, lacks a clear free surface. By endowing SPH particles with properties where viscosity changes with shear rate, research is advancing to simulate complex blood flow in aneurysms or the behavior of flexible particles like red blood cells. The feel of changing the viscosity coefficient in this tool connects to that foundational understanding.

For Further Learning

Once you're comfortable with this tool and think, "I want to understand more," the following three steps are recommended. First, Step 1: Understand the Governing Equations. Behind SPH lies the "Navier-Stokes equations," the fluid motion equations. Even if grasping it all at once is tough, just note that the right-hand side of $$ \rho \frac{D\boldsymbol{v}}{Dt} = -\nabla p + \mu \nabla^2 \boldsymbol{v} + \rho \boldsymbol{g} $$ corresponds to the "pressure," "viscosity," and "gravity" parameters in this tool. Your learning deepens by operating the tool while consciously thinking, "Right now, I'm adjusting this term."

Step 2: Distinguish and learn the key discretization concepts: "Kernel Approximation" and "Particle Approximation." The kernel function $W$ in existing texts is a "weighting function," but the next hurdle is understanding how to use it to express physical quantities with particle values. For example, try to imagine that the formula for density $\rho$ at a point from neighboring particles $j$ with mass $m_j$, $\rho(\boldsymbol{r}) \approx \sum_j m_j W(|\boldsymbol{r}-\boldsymbol{r}_j|, h)$, is being executed for each particle in this simulator.

Finally, Step 3: Tackle practical challenges. Set specific learning goals like, "Find a parameter set in this tool that reproduces the behavioral difference between honey and water," or "Change the obstacle angle and observe the conditions for flow separation." Through this process, you'll notice how parameters have nonlinear effects and the importance of initial conditions. This becomes the very first step toward the "calibration" work you'll eventually do in practice: using CAE software and reconciling experimental data with simulation.