This repository contains proof-of-concept C++ implementations of different fluid dynamics solvers in 2D.
The goal is to provide minimalistic and straightforward implementations, emphasizing ease of understanding.
I decided to keep simulation code mostly independent (single file), which means that routines and data-types are at times duplicated (e.g. SPH density estimation, eos, boundary particles, ...).
- Methods
- WCSPH: Weakly Compressible SPH
- PCISPH: Predictive-Corrective Incompressible SPH [Solenthaler 2009]
- PBF: Position Based Fluid [Macklin 2013]
- PF: Projective Fluids
- IISPH: Implicit Incompressible SPH [Ihmsen 2013]
- DFSPH: Divergence-Free SPH [Bender 2015]
- FLIP/PIC: Fluid-Implicit-Particle / Particle-In-Cell Blend
- APIC: Affine Particle-In-Cell Method
- Utility
- 2D-Viewer with OpenGL2 and ImGui/ImPlot (standalone repo)
- Minimal Performance Monitoring
- Hash-Grid Nearest Neighbor Search
- Uniform-Grid Nearest Neighbor Search
- Minimalistic Generic Scene Description
Scene setup is independent of the used simulator.
An instance of Scene provides an interface to construct geometry (Box, Circle) that can either be a boundary or fluid body (currently no dynamic boundaries).
The simulator (WCSPH, PCISPH, PBF, IISPH, DFSPH, etc.) initializes its data (e.g. fluid and ghost particles) from the description via void Simulation::create(const Scene&)
.
/* scene description */
Scene desc;
/*left, right, bottom boundary*/
desc.add(Scene::Box{ {-5.00f, -3.50f}, { 5.00f, -3.25f}, Scene::eType::BOUNDARY });
desc.add(Scene::Box{ {-5.00f, -3.25f}, {-4.75f, 8.00f}, Scene::eType::BOUNDARY });
desc.add(Scene::Box{ { 4.75f, -3.25f}, { 5.00f, 8.00f}, Scene::eType::BOUNDARY });
/* fluid */
desc.add(Scene::Box{ {-4.72f, -3.23f}, { 4.73f, 0.00f}, Scene::eType::FLUID_BODY });
desc.add(Scene::Circle{ {0.0f, 3.5f}, 0.75f, Scene::eType::FLUID_BODY});
/* simulation handler (Implicit Incompressible SPH) */
IISPH simulation;
simulation.timeStep = 1.0 / 240.0f;
simulation.stepPerFrame = 1;
/* load scene (initialize fluid and boundary particles) */
simulation.create(scene);
/* solve dynamics -> time += stepPerFrame*timeStep */
simulation.update();
iisph_waterdrop.mp4
Eurographics Tutorial - Koschier et al. 2019
SPH Fluids in Computer Graphics - Ihmsen et al. 2014
Fluid Engine Development - Doyub Kim
SPlisHSPlasH - Jan Bender