A Julia implementation of a basic Smoothed Particle Hydrodynamics (SPH) solver. The code is primarily written for educational purposes and contains several ready to run examples such as 2D and 3D dam breaks or wedge impacts. Custom particle setups can also be loaded from the input/ folder.
Please consider giving the project a β if it is useful in your work. Citation is appreciated for academic use and feel free to reach out with feedback or questions.
The code can produce a 2D dam break (@DamBreak2D-Video):
2D.Dam-break.based.on.SPH.Simulation_second_highest_resolution.mp4
Or, if you are really patient (1+ day to calculate), a 3D case (@DamBreak3D-Video):
3D.Dam-break.based.on.SPH.Simulation.mp4
The project demonstrates how to assemble a small SPH solver with Julia. It focuses on clarity rather than ultimate performance. Unofficial benchmarks suggest that for 2D cases the CPU runtime is comparable to DualSPHysics. Key features include:
- Weakly compressible formulation β density varies ~1Β % and pressure is a function of density.
- Multi-threaded execution β achieved by spawning the neighbour loop.
- Configurable task granularity β
ChunkMultipliercontrols load balancing across threads. - Dynamic boundary condition β inspired by DualSPHysics.
- Density diffusion β based on Fourtakas et al.Β 2019 to reduce pressure noise.
- Wendland quintic kernel β simple and stable without tensile corrections.
.
βββ example/ # Ready to run simulations
βββ input/ # Pre-generated particle layouts (.csv)
βββ src/ # Package source code
βββ images/ # Images used in this README
βββ Project.toml # Package dependencies
βββ Manifest.toml # Exact dependency versions
Example scripts live in example/ and read geometry from input/. The solver code itself is in src/:
src/
βββ AuxiliaryFunctions.jl # Small helper utilities
βββ OpenExternalPrograms.jl # Convenience wrappers for logs and ParaView
βββ PreProcess.jl # Load inputs and allocate arrays
βββ ProduceHDFVTK.jl # Write simulation data in HDF5/VTK format
βββ SPHCellList.jl # Custom neighbour search and time stepping
βββ SPHDensityDiffusionModels.jl # Density diffusion implementations
βββ SPHExample.jl # Glue module re-exporting all functions
βββ SPHKernels.jl # SPH kernel definitions
βββ SPHViscosityModels.jl # Viscosity models such as Laminar or SPS
βββ SimulationConstantsConfiguration.jl # User-facing solver parameters
βββ SimulationEquations.jl # Core SPH physics equations
βββ SimulationGeometry.jl # Domain and geometry definitions
βββ SimulationLoggerConfiguration.jl # Logging helpers for timer outputs
βββ SimulationMetaDataConfiguration.jl # Metadata such as run time and output path
βββ TimeStepping.jl # Controls for Ξt and CFL condition
The easiest way to experiment with the code is to clone the repository and activate it in Julia:
using Pkg
Pkg.activate("/path/to/SPHExample")
Pkg.instantiate()Alternatively, install it directly:
using Pkg
Pkg.add(url="https://github.com/AhmedSalih3d/SPHExample")Open one of the files in example/, for instance example/StillWedgeMDBC.jl, and adjust the simulation parameters or the ComputerInteractions! function. Run the script to start the simulation. Results are written in hdfvtk format which can be loaded with ParaView 5.12 or newer.
Questions or issues can be posted on the GitHub issue tracker. Response times may vary but all feedback is welcome.
Written by Ahmed Salih (AhmedSalih3d).
| Version | Description |
|---|---|
| 0.6.12 | Simulation code uses now multiple dispatch procedure in main simulation code instead of if coding statements, to increase run time performance |
| 0.6.11 | Added ChunkMultiplier for improved thread load balance and focus on code dependencies |
| 0.6.10 | Implemented concepts of tests, aim is to understand allocations and run time |
| 0.6.9 | Specify output times via OutputTimes (float or vector). |
| 0.6.8 | Select which variables are written to vtkhdf files. |
| 0.6.7 | Introduced mDBC boundary conditions and other improvements allowing particles to interact with boundaries. |
| 0.6.6 | Added neighbour grid visualisation in ParaView for debugging. |
| 0.6.5 | Linearised density diffusion, optional single-file output and performance improvements. |
| 0.6.4 | Revised geometry configuration interface and added time-step plot. |
| 0.6.3 | Added automatic log visualisation and CloseHDFVTKManually helper. |
| 0.6.2 | Added automatic ParaView visualisation support. |
| 0.6 | Major rewrite with solver setup changes and moving object support. |
| 0.5 | Logging and hdfvtk output added. |
| 0.4 | Complete rewrite focusing on custom cell lists. |
| 0.3 | Highly optimised CPU version with minimal allocations. |
| 0.2 | Cleanup of initial release. |
| 0.1 | Initial release. |
This project is licensed under the MIT License β see LICENSE.md for details.
- DualSPHysics for inspiration.
- Many thanks to the Julia community and especially Leandro MartΓnez for guidance on neighbour-list algorithms.
- Thanks to PharmCat for suggestions and code contributions.