ProjectPhysX / FluidX3D

The fastest and most memory efficient lattice Boltzmann CFD software, running on all GPUs via OpenCL. Free for non-commercial use.
https://youtube.com/@ProjectPhysX
Other
3.88k stars 308 forks source link

Make revoxelization on GPU faster #28

Closed trparry closed 1 year ago

trparry commented 2 years ago

Hello Moritz, this is more of a feature enhancement than an issue. Due to your code's speed, I've realized that it may open doors into applications that have been under-researched.

Context: I am experimenting with getting a semi-real time (maybe 3-4s real time for every 1s simulation time) moving mesh simulation working on a Nvidia A100. This simulation involves fluid-solid interaction with the mid-grid bounce back boundaries you've implemented. During each timestep, FluidX3D sends forces and moments to my rigid body solver (with calculate_torque_on_object), and the rigid body solver calculates the resulting kinematics and sends rotation and translation matrices back to FluidX3d. I'm actually experimenting with the rigid body solver running on the same GPU using IPC. Right now I'm working on a single body pendulum to keep it simple. The end game is to do controller design on rigid body dynamics immersed in fluids. Multiphysics simulations have done similar things before, but combining control theory with fluid dynamics has been a challenge because controllers often involve trial and error. Trial and error on a simulation that takes many hours isn't practical, this is why I’m interested in LBM.

Now concerning the feature enhancement: I started with the tie fighter example where you detach a separate thread and revoxelize a new frame with the rotated mesh on CPU in parallel with LBM running on GPU. However in my scenario with fluid solid interaction we would need to solve the flow field before rotating/moving the mesh because the mesh movement is driven by the fluid and visa versa (in series). On large grids where we can't run close to real time, this isn't a big deal because LBM takes a lot longer than the revoxelization process anyways. However, if I were to try and get a simulation to run close to real time on a smaller grid (say only 4-5 million voxels), the revoxelization process on CPU could become a bottleneck and LBM would need to wait until the revoxelization process is complete in order to start on the next frame.

Do you have any thoughts on placing the revoxelization process onto the GPU as well? The two processes would still run in series with time, but each would be parallelized internally so that the overall process would be faster than doing it in series on CPU. I would appreciate your thoughts!

ProjectPhysX commented 1 year ago

Hi @trparry, thanks for the post! I am planning to replace the current slow voxelization, there is much faster algorithms on the internet. The two solutions I have currently implemented are not optimal:

Ideally the voxelization should be way faster than an LBM time step, so coupled fluid + rigid body simulations work much faster.

I'll leave this issue open as a reminder for myself to implement it some time :)

ProjectPhysX commented 1 year ago

Done! I found a quite ingenious solution that speeds up GPU voxelization by about 500x, reducing runtime from minutes to milliseconds. Details are in the v2.1 release notes.

trparry commented 1 year ago

This is awesome. Thank you!

Antotabo commented 1 year ago

Remesh in milliseconds 😱. This is great news ! Congrats on all this good work. My dream of creating a sandbox toy with rigid body/fluid interaction now seems more than feasible. Think Algodoo meets Powder Toy.