Create Your Own Smoothed-Particle Hydrodynamics Simulation (With Python)

Philip Mocz
6 min readSep 19, 2020

For today’s recreational coding exercise, we will simulate a star with smoothed-particle hydrodynamics (SPH). We will start with some initial condition and relax it into a stable stellar structure and measure the star’s density as a function of radius. The SPH method has many applications in astrophysics and elsewhere, and is in fact a general one to simulate all types of fluids.

You may find the accompanying Python code on github.

--

--

Philip Mocz

Computational Physicist. Sharing intro tutorials on creating your own computer simulations! Harvard ’12 (A.B), ’17 (PhD). Connect with me @PMocz