Skip to content

inonitz/compute-shader-fluid-2d

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers MIT


2D Incompressible Fluid Simulation

Implementation of
Chapter 38. Fast Fluid Dynamics Simulation on the GPU

About The Project

The following code simulates a 2D Incompressible Fluid using an:

  • Eulerian-Grid Scheme

  • Semi-lagrangian Advection Method [Unconditionally Stable]

  • System-of-Equations Jacobi Method Solver [Very easy to implement GPGPU]

  • Central Difference for Approximating Calculus Operators [O(x^2) Error]

  • Essentially All methods here are references to the original work of Stam1999 - stable fluids
    Here is a wikipedia article describing the method of solution


The currently most-updated revision 29cleanup3/ features the following:

  • Force/Dye/Force-Dye User-Simulation Interaction
  • Vorticity Confinement with variable coefficient
  • Variable Kinematic Viscosity, Delta Time & Poisson-Solver Iterations
  • Real-Time CFL/Reynolds Number Calculations (they're there to check solver correctness/stability)
  • Visualizations of Calculation Textures, in particular Velocity-Pressure/Dye/Curl/Absolute Curl/Velocity Error/Pressure Error/Velocity-X/Velocity-Y/Pressure/CFL
  • Real-Time Measurements of internal solver components - CPU & GPU Side:
    • A GPU Timer (gl-Begin/End-Query) essentially acts as a fence,
      waiting for all previous GPU commands to finish
      In Short: Using GPU Timers degrades Performance by a few milliseconds

    • When GPU Timers are not used, the calculations will be deferred until glfwSwapbuffers(), which by then will be dispatched & computed, updating glMemoryBarrier


Pretty Pictures

Tomorrow, Im Tired lol :)


Project Structure

The Underlying Project Structure uses my premake5-workspace-template repo,
You can expect the program/ folder to occupy all revisions of the fluid-solver,
culminating eventually with 29cleanup3/ as the currently best revision


Built With




GLFW v3.4                 ImGui                 Premake

Getting Started

Prerequisites - Instructions below work too, but you should follow premake5-workspace-template

Installation

Just Clone the repo


Usage

Build Process

premake5 --os=windows --arch=x86_64 --cc=clang gmake2
premake5 --os=windows --arch=x86_64 --cc=clang vs2022
premake5 --os=linux   --arch=x86_64 --cc=gcc   gmake2
premake5 --os=linux   --arch=x86_64 --cc=clang gmake2

You can also use this command to perform the whole build process,
if youre using gmake2 and a commandline:

premake5 --os=windows/linux --arch=x86_64 buildallrel

Dont forget to actually build using your favorite IDE/command-line utility


Execution

Static Library Builds: (premake5 gmake2, config=releaselib_amd64)

./build/bin/ReleaseLib_amd64_program/program

DLL/Shared Library Builds: (premake5 gmake2, config=releasedll_amd64)

./build/bin/ReleaseDll_amd64/program

Visual Studio 2022 - Just Run normally using Local Windows Debugger

Roadmap

  • Replacing Jacobi Method with the Multigrid Method for better performance & faster fluid convergence
  • Adding Arbitrary boundaries
  • Extending to 3D
  • MAC Staggered Grid
  • Different Simulation Schemes (FVM, etc...) for better simulation accuracy
  • Extending to compressible/Turbulent Models

Contributing

If you have a suggestion, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".

License

Distributed under the MIT License. See LICENSE file for more information.

Acknowledgements

References

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages