Your Federal Quarterly Tax Payments are due April 15th Get Help Now >>

Fluid_Simulation_using_CUDA by babbian


									Fluid Simulation using CUDA

         Thomas Wambold

      CS680: GPU Program Optimization

             August 31, 2011

• Looking at 2D and 3D fluid
  simulation techniques.
• Simulate fluid interactions with
  itself and its environment.
• I'm mostly looking at it for visual
   o Video games, movies, etc.          From GPUGems 3

• More accurate simulations could
  be used for more scientific

• Field-based systems
   o Volume is represented by a grid.
   o Each block in the gird contains properties such as
     velocity, density, temperature, and pressure.
   o Blocks do not move.
   o An Eulerian view.
   o I looked more at this system.
• Particle-based systems
   o Fluid is represented by large quantities of particles.
   o Each particle has the same properties as before, but also
   o Particles can move.
   o A Lagrangian view.
From Intel Article. (a) Field-based (b) Particle-based

• Navier-Stokes equations for incompressable flow
   o Assumes incompressable, homogeneous
   o Invompressable - volume of any subregion is constant.
   o Homogeneous - density of any subregion is constant.
• Represents velocity field, pressure field.
• Use numerical integration techniques to solve incrementally.
• For each iteration of the simulation:
   o Update velocity with forces in the system.
   o Transfer velocity between grid cells (advection).
   o Diffuse velocity based on viscosity.
   o Update velocity for incompressible fluids.
       So velocity field is non-divergent.
2D Fluid Simulator

• Sample code from nVidia CUDA SDK.
• Uses field-based system.
• Currently 512x512 grid, split grid into 64x64 tiles.
• Each tile has 64 threads, each processing 64x16 cells.
• Uses texture memory.
• Iterations:
   o Velocities are updated based on mouse movements
   o Grabs values stored in neighboring cells for advection
   o Diffusion uses a Fourier Transform (CUFFT)
• Uses CUDA/OpenGL integration to avoid memory copies.
Sequential Fluid Simulator

• Modified example to not use CUDA
• Computations are done on the CPU, copied to Vertex Buffer
  Object to display via OpenGL.
• Attempted to replace cuFFT library with GSL FFT, but did
  not get far.
• Was able to get particles to display on the screen, and they
  do move around, but very oddly. Still many problems, but it
  doesn't crash.
• Some of this could probably be blamed on the memory
  copies between the CPU and GPU, but not this much.
CPU vs CUDA Fluid Simulations

• Tested on my home machine (didn't want to forward X11 or
   o Intel Core 2 Quad @ 2.8GHz
   o nVidia GeForce GTX 460
       Compute Capability: 2.1
       CUDA Cores: 7 multiprocessors X 48 cores = 336
• CUDA version never went below 300 FPS
• CPU version barely got above 5 FPS
   o This is without doing any FFT for force diffusion.
   o Slowness could probably be partially blamed on memory
2D Fluid Simulator
Next Steps/Conclusions

• Next steps:
   o Modify nVidia's sample to just use CPU (DONE)
   o Implement my own 2D simulator.
   o Explore 3D simulators.
• Difficulties:
   o Probably was a bit too ambitious for the time constraints.
   o I don't have much experience in this, a lot to try to absorb.
   o Have to worry about rendering, example uses CUDA
     OpenGL integration.
• Examples from various conferences show very impressive
  real-time simulations using the GPU.

• In-depth article from Intel with lots of math (both particle, and field-
• Good article explaining equations about field-based
• 3D simulations:
• Documentation for SDK example:
• SDK Example:

To top