Skip to content
MarcoSuttiPublic

About

SPHM: A MATLAB code for SPH simulations

Resources

Stars

15 stars

Watchers

1 watching

Forks

Repository files navigation

SPHM: A MATLAB code for SPH simulations

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:

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

I) Version History

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

II) Contents

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 .mat files generated by Driver_SPHM.
  • utilities: contains all the core functions for the SPH simulations.
  • videos: contains videos of the simulations.

III) Installation and Usage

No installation is required.

Quick start

To run the Sod shock-tube example:

  1. Set the desired parameters in examples/shock_tube_parameters.m.
  2. Run Driver_SPHM.m.
  3. Run Driver_shocktube_profiles.m to compare the SPH results with the exact solution.
  • Use Driver_SPHM to perform an SPH simulation. Simulation results are saved as MATLAB .mat files in the results folder.
  • The script Driver_Animation can be used to generate a video of the simulation.
  • The script Driver_shocktube_profiles generates the profile plots for the shock-tube example.
  • The script Driver_shear_cavity_steady_state generates the plots for the shear-driven cavity problem at steady state.
  • The script Driver_Sod_shocktube can be used to visualize the profiles of the exact solution to the classical Sod shock-tube problem.

IV) Acknowledgments

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.

V) License

SPHM is distributed under the GNU General Public License (GPL).

About

SPHM: A MATLAB code for SPH simulations

Resources

Stars

15 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages