Skip to content

Proof of concept implementations of different fluid dynamic solvers in C++

License

Notifications You must be signed in to change notification settings

nikolausrauch/2D-fluids

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


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 are at times duplicated (e.g. SPH density estimation, eos, boundary particles, ...).

Features

  • 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
    • FLIP: Fluid Particle in Cell
    • Stable-Fluid: Eulerian based Fluid
  • 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

image

Minimal Example

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) 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_example

iisph_waterdrop.mp4

📚 Useful Resources

Eurographics Tutorial - Koschier et al. 2019
SPH Fluids in Computer Graphics - Ihmsen et al. 2014
Fluid Engine Development - Doyub Kim
SPlisHSPlasH - Jan Bender