All Projects → cgurps → 2DFluidSimulation

cgurps / 2DFluidSimulation

Licence: other
A simple eulerian fluid simulation using OpenGL compute shaders

Programming Languages

C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to 2DFluidSimulation

Ason
[DEPRECATED]: Prefer Moshi, Jackson, Gson, or LoganSquare
Stars: ✭ 777 (+2000%)
Mutual labels:  fluid
Vhs
TYPO3 extension VHS: Fluid ViewHelpers
Stars: ✭ 172 (+364.86%)
Mutual labels:  fluid
Hexo Theme Fluid
🌊 一款 Material Design 风格的 Hexo 主题 / An elegant Material-Design theme for Hexo
Stars: ✭ 3,700 (+9900%)
Mutual labels:  fluid
Blender Flip Fluids
FLIP Fluids is a powerful liquid simulation plugin that gives you the ability to create high quality fluid effects all within Blender, the free and open source 3D creation suite.
Stars: ✭ 983 (+2556.76%)
Mutual labels:  fluid
Oneflow
LargeScale Multiphysics Scientific Simulation Environment-OneFLOW CFD
Stars: ✭ 150 (+305.41%)
Mutual labels:  fluid
Fltkhs
Haskell bindings to FLTK GUI toolkit.
Stars: ✭ 187 (+405.41%)
Mutual labels:  fluid
Textblock
Continuously responsive typesetting — Demo:
Stars: ✭ 536 (+1348.65%)
Mutual labels:  fluid
canvas-fluid-solver
Real-time fluid simulation in Javascript.
Stars: ✭ 45 (+21.62%)
Mutual labels:  fluid
Aphros
Finite volume solver for incompressible multiphase flows with surface tension
Stars: ✭ 154 (+316.22%)
Mutual labels:  fluid
Fluid Interfaces
Natural gestures and animations inspired by Apple's WWDC18 talk "Designing Fluid Interfaces"
Stars: ✭ 2,487 (+6621.62%)
Mutual labels:  fluid
Fluidcontent
TYPO3 extension Fluidcontent: Fluid Content Element Engine
Stars: ✭ 82 (+121.62%)
Mutual labels:  fluid
Webgl Fluid Simulation
Play with fluids in your browser (works even on mobile)
Stars: ✭ 11,621 (+31308.11%)
Mutual labels:  fluid
Expressionevaluator
A Simple Math and Pseudo C# Expression Evaluator in One C# File. Can also execute small C# like scripts
Stars: ✭ 194 (+424.32%)
Mutual labels:  fluid
Fld Grd
Google Images/Flickr inspired fluid grid layouts
Stars: ✭ 37 (+0%)
Mutual labels:  fluid
Fluid
Modern, Stylish, Easier and Powerful Css framework for faster and hassle free web development
Stars: ✭ 24 (-35.14%)
Mutual labels:  fluid
Su2
SU2: An Open-Source Suite for Multiphysics Simulation and Design
Stars: ✭ 731 (+1875.68%)
Mutual labels:  fluid
Cape
Dynamically generates Capistrano recipes for Rake tasks
Stars: ✭ 178 (+381.08%)
Mutual labels:  fluid
fluid
🐙 Code-generated, Auto-versioned, & Smart Web APIs
Stars: ✭ 37 (+0%)
Mutual labels:  fluid
react-native-blobular
The Man in Blue's awesome Blobular, ported to React Native.
Stars: ✭ 53 (+43.24%)
Mutual labels:  fluid
Nek5000
our classic
Stars: ✭ 219 (+491.89%)
Mutual labels:  fluid

2D Fluid Simulator using OpenGL Build Status

This project is an implementation of an eulerian fluid simulation on GPU using OpenGL 4.3 compute shaders capabilities.

Getting Started

You will first need to clone the repository

git clone https://github.com/cgurps/2DFluidSimulation.git [PROJECT_FOLDER]

and then init the submodules

cd [PROJECT_FOLDER]
git submodule update --init

To compile the project, you will need OpenGL with a version above 4.3 in order to get compute shader capabilities. You will also need Boost installed on your machine. To project uses CMake to generate the Makefile needed for the compilation. You can use these commands to build the executable

mkdir build
cd build
cmake ..
make -j [YOUR_NUMBER_OF_CORES]

You can query the program options using -h.

Numerical Scheme

We solve the Navier-Stokes equation for incompressible fluids:

As every eulerian approaches, the quantites (velocties, pressure, divergence, curl and so on) are stored in a square grid. The advection step uses a semi-Lagragian approach. The advection combines a Maccormack numerical scheme with a Runge Kutta method of order 4. The new created extremas are clamped using values from the first advection. If the new extrama is too far from the original computed value, I remove the error correction term (which boils down to reverting to the 4th order Runge Kutta approach). The next step adds forces to the velocity field (note that vorticity is implemented, but not used as the advection scheme is accurate enough to conserve swirls in the field). After that, the intermediate field is made incompressible using a projection method based on the Helmholtz-Hodge decomposition. I solve the associated poisson equation using the Jacobi method. The time step is computed at each iteration with

The maximum of the velocity field is computed through a reduce method on the GPU.

Implementation

Each quantities is represented by a texture of 16bits floating points on the GPU. For exact texels query, I use the texelFetch method (which runs faster than using texture2D) and then handle the boundary cases by hand. The bilinear interpolation for the advection step is also computed by hand for better accuracy. The implementation contains three main classes:

  1. GLFWHandler is the GLFW wrapper that contains the OpenGL initilization and the main program loop
  2. SimulationBase which is a pure virtual function that gives the interface for the simulation. The main loop of the program accesses the shared_texture variable and display the associated texture on screen. This is where the various textures are created and stored.
  3. SimulationFactory which contains helpers for computing steps of the simulation (like advection, pressure projection, etc). This class does not allocate GPU memory, but is instead feeded by the simulation loop.

If you (ever) wish to play around this simulation, you should create a new class that inherits from SimulationBase and uses the SimulationFactory to compute whatever you need to compute. This new class must overload Init(), Update(), AddSplat(), AddSplat(const int) and RemoveSplat() for the simulation to work.

Note on the Jacobi method

I implemented a variation on the original Jacobi method described in Harris et al. called the Red-Black Jacobi method. The idea is to pack four values into a single texel. The packing is done both on the divergence and on the pressure values. The next figure (reproduced from the Figure 5 of Harris et al.) shows the process

The resulting texture has half the size of the original one. Then, the Jacobi iteration updates first the black values (which only depend on the red one) and second the red values (using the computed black values). This almost divides the number of texel fetches by two, hence we can obtain the same order of convergence in approximatively half the time! The actual tricky part is to pack the divergence into one texel. This is done in one shader pass by grabing numerous adjacent values of the current texel (see the file divRB.comp).

References

  1. @: a simple tutorial on fluid simulation
  2. @: this awesome books covers a lot of techniques for simulating fluids (classic!)
  3. @: 2D fluids from GPU gems 1
  4. @: 3D fluids from GPU gems 3
  5. @: the Maccormack method
  6. @: this article explains the reverse method to handle extremas generated by the Maccormack scheme
  7. @: The Runge Kutta method for the particle advection in the semi-Lagragian approach

Nice github projects

  1. tunabrain/gpu-fluid: 2D fluid simulation on the GPU using an hydrid approach (FLIP)
  2. PavelDoGreat/WebGL-Fluid-Simulation: online fluid simulation
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].