Smoothed Particle Hydrodynamics is a Lagrangian technique to perform Computational Fluid Dynamics. It is especially powerful to simulate free surface flows, like pouring a beer. This is a simple implementation in Python/NumPy. Here is the code: https://github.com/Ceyron/machine-learning-and-simulation/blob/main/english/simulation_scripts/smoothed_particle_hydrodynamics_simple_python.py
The particle algorithm we use here is based on a 2003 paper by Matthias Müller that you can find here: https://matthias-research.github.io/pages/publications/sca03.pdf
There you will also find more details on why we use our particular kernels.
Timestamps:
00:00 Introduction
00:59 Scenario
01:23 Idea of SPH
02:36 Solution Algorithm
04:21 Computational Aspects
05:23 Imports
05:51 Defining Constants
08:36 Boilerplate
08:50 Initializing Variables
09:53 Time iteration
10:03 Add new particles
13:33 Neighborhood Computation
15:53 Computing Density
18:57 Computing Pressure
19:17 Force Computation Preparation
20:57 Pressure Force
23:12 Viscous/Viscosity Force
24:48 Gravity Force
25:11 Time Integration
26:23 Enforce Boundary Conditions
28:45 Visualization
30:55 Bug Fixing
31:24 Discussing the Simulation
33:17 Outro