Fluid Simulation banner

Fluid Simulation

8 devlogs
20h 38m 31s

Creating a interactive Fluid Simulation using C++ and OpenGL

Repository

Loading README...

Jahaan

Updates:

  • I tried to optimize code, and optimize as much as i could using CPU processing, however for further optimization and particle generation I experimented with GPU programming, however I feel as that is outside the scope of what I want to do with this project.
  • Added a GUI so that you can control variables like gravity, target density, etc. Added mouseLock so that if you press M it lock the mouse on the current camera orientation.
  • Also fixed up broken physics code and refactored tiny bits of code for optimization, honestly it didnt have much of a difference

Changelog

0
Jahaan

Updates:

  • Fixed broken code which was the Verlet integration function. Basically I was updated position and velocity before i even computed the fluid forces, so everything was delayed by a frame. So i had to move updateFluid down and remove Verlet integration and just hardcode updated velocity and position.
  • I also fixed my value problem, due to the wrong order for computing forces, the delay and lag resulted in current particles being affect by previous forces, which resulted in the particles phasing through each other under high pressure. After the fix they now dont phase and overlap each other.

Next Steps:

  1. Optimize code so that it can run above 50,000 particles (currently it runs around 15,000 decently smooth. The number mentioned in previous devlog was incorrect. I will do this by coding directly to the GPU instead of the cpu for faster calculations.
  2. Add interactive features, and rigid bodies to see the fluid behaviour against colliding bodies

Changelog

2

Comments

Jahaan
Jahaan 9 days ago

It didnt let me a longer video

dhruvil_patel
dhruvil_patel 9 days ago

Random guy your so cool, I want to be like you

Jahaan

Updates:

  • Added multithreading so that it can compute in parrallel, and also updated how its compiled by using -O2 for it to more efficiently and hastly compute vectors and arrays.
  • Optimized code by removing unesscary code that ran every frame such as drawParticle as a funciton, etc.
  • It can handle around 70,000 particles but only for a short while before my computer starts burning up
  • Added color interpolation for velcity, and most of the time was to tune the properties (restDensity, viscosity, stiffness, etc) Using claude I figured that we could just normalize it and I kept experimenting until i found decent values that worked.
  • Fixed the values so that it would simulate fluid behaviour properly, its still really broken, but I got it to work somewhat.

Changelog

0
Jahaan

Updates:

  • Optimized code so that it can handle thousands of particles using Spatial Hashing Grid
  • testes and fine tuned the values of the fluid properties (density, viscosity, stiffness, etc)
  • Added the spatialGrid class that basically only compares to neighboring particles to optimize for O(n). Previously it was O(n^2) because there could be a possibly that every other particle is in the influence of this particle, so it would check every particle.

Next Steps:

  1. Optimize it further so that it can run much more efficently and with even more particles
  2. Implement multi-threading so that I can calculate in parallel for faster computation and thus more particles can be simulated without crashing every second.

Changelog

0
Jahaan

Updates:

  • Implemented SPH (Smoothed Particle Hydrodynamics) which basically predicts behavior of fluid flow over time.

  • SPH help to discretize the continuity of fluids by sampling the values (density, velocity, etc) of a certain region into one particle location

  • Kernel Function: a smooth bell curve that shows how a physical property (like mass or velocity) is distributed in the particle’s region. This helps to keep the continuity of fluids without storing everything

  • Different types of Kernel for different fluid quantities (density, viscosity, pressure)

  1. Poly6 for density
  2. Spiky for pressure
  3. Laplacian for viscosity

Then we can compute for density, pressure, and finally the total force on the particle and add that value to the particles acceleration. These key features help to simulate fluids more effectively and realistically without needing to store millions of datapoints.

1

Comments

Diparsan Pathak
Diparsan Pathak 13 days ago

damn looks coolll

Jahaan

Updates:

  • Added 3D particles using a previous function I made for particle simulation.
  • Implemented zRange for grid so that it can make a 3D grid of particles
  • Fixed velocity verlet integration and added additional functions for 3D particle from previous project

Next Steps:

  • Learn about properties and characteristics of fluid and the governing laws behind them, and a possible implementation in code.
  • Going to add viscosity, density, cohesion, etc.
0
Jahaan

Updates:

  • implemented drawing multiple particles as a grid
  • implemented gravity as acceleration
  • added a boundary box with boundary collision
  • implemented particle collision
  • implemented camera lock where you have your camera permantly set

Next Steps:

  • I think I will aim to start from the ground up when building the fluid simulation, going from the quantum state all the way to the normal fluid simulation
  • Implement a quantum system
0
Jahaan

Added Camera System from my previous project
Created a draw particle/circle function
Initialized GLFW window for rendering
Setup OpenGL
Created Particle Class for fluid simulation

0