SPHM is a MATLAB implementation of the Smoothed Particle Hydrodynamics (SPH) method, including benchmark problems such as the 1D Sod shock tube and the 2D lid-driven cavity.
For documentation, please refer to the comments in the code and to the preprint:
- SPHM: a MATLAB package for Smoothed Particle Hydrodynamics simulations, M. Sutti, Tech. report, September 2022.
Note: The Sod shock-tube results reported in the 2022 preprint were affected by a bug in the internal-energy time integration. This issue has been corrected in the current version of the code.
The code is mainly based on the corresponding Fortran code contained in:
- Liu, G. R. and Liu, M. B. Smoothed particle hydrodynamics: a meshfree particle method. World Scientific, Singapore, 2003.
If there are any issues or bugs, feel free to email me at msutti (at) ncts.tw
- Sep 12, 2026: fixed a bug in the internal-energy time integration affecting the Sod shock-tube test.
- Feb 22, 2024: minor updates.
- Ver 2, Sep 12, 2022.
- Ver 1, Jul 11, 2021: initial release.
The code is organized in the following folders:
eos: contains the equations of state for ideal gas and artificial water.examples: contains parameters and data for the 1D shock tube and the 2D shear cavity problems.plots: contains the plots generated from the simulation data.postprocessing: contains utilities for plotting and visualizing data.results: contains the MATLAB.matfiles generated byDriver_SPHM.utilities: contains all the core functions for the SPH simulations.videos: contains videos of the simulations.
No installation is required.
To run the Sod shock-tube example:
- Set the desired parameters in
examples/shock_tube_parameters.m. - Run
Driver_SPHM.m. - Run
Driver_shocktube_profiles.mto compare the SPH results with the exact solution.
- Use
Driver_SPHMto perform an SPH simulation. Simulation results are saved as MATLAB.matfiles in theresultsfolder. - The script
Driver_Animationcan be used to generate a video of the simulation. - The script
Driver_shocktube_profilesgenerates the profile plots for the shock-tube example. - The script
Driver_shear_cavity_steady_stategenerates the plots for the shear-driven cavity problem at steady state. - The script
Driver_Sod_shocktubecan be used to visualize the profiles of the exact solution to the classical Sod shock-tube problem.
We gratefully acknowledge Navaneet Villodi for drawing our attention to an issue in the energy-equation implementation based on the Sod shock-tube results reported in the preprint, and for suggesting that the discrepancy could originate from the energy update.
Following his suggestion, we inspected the time-integration routine and found that the internal-energy derivative stored in tip.dedt was not assigned to the dedt variable used to advance the internal energy. The missing assignment dedt = tip.dedt; was added after the call to single_step(...). This correction substantially improves the agreement between the SPH solution and the exact Sod shock-tube solution.
SPHM is distributed under the GNU General Public License (GPL).