SPH Fluid Simulation in Python

Опубликовано: 02 July 2026
на канале: Machine Learning & Simulation
23,081
431

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-lea...

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/p...
There you will also find more details on why we use our particular kernels.

-------

📝 : Check out the GitHub Repository of the channel, where I upload all the handwritten notes and source-code files (contributions are very welcome): https://github.com/Ceyron/machine-lea...

📢 : Follow me on LinkedIn or Twitter for updates on the channel and other cool Machine Learning & Simulation stuff:   / felix-koehler   and   / felix_m_koehler  

💸 : If you want to support my work on the channel, you can become a Patreon here:   / mlsim  

-------

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