Skip to content

Realtime Fluid Simulation Using CUDA

Written by Alex Choi, Feb. 09, 2012.

This is one of our researches done in CJ POWERCAST, which is dedicated from the members of our team, T.J. Kwak and J.M. Park and G.Choi.


INTORUDUCTION

GPU (Graphics Process Unit) has been traditionally used only for display of graphical contents with graphics acceleration.

Because of the characteristics of display that represent pixels as a massive array, memory and processing architectures of GPU are structured in parallel in order to process the massive graphical data in a short period.

Some pioneers have used these features for parallel computation as well as displaying computer graphics. Consequently GPU manufacturers realized their needs of general purposes of GPU.


FIG 1. Comparsion of Processor Structures: CPU VS GPU

As shown in FIG 1., GPU has a huge number of ALUs, which are in charge of arithmetic operations, enabling massively parallel processing.

With this background, GPGPU (General Purpose Graphics Process Unit) comes into the world and aims to process massively parallel computations not only for computer graphics but for general fields such as prediction of stock, weather, science, etc.

Most of the simulations in computer graphics are based on natural phenomena and tend to need massive computations to mimic the real nature.

Our research team has expected that GPGPU technology would be used for wider fields of our related research works.


IMPLEMENTATION

The goal of this research is, as a preceding research, to apply the GPU technology to a realtime fluid simulation that needs to solve the natural phonomenon called "Navier-Stokes equation" with parallel processing.

To this end we adopted the algorhithms from the simplified version of Navier-Stokes equation(Jos Stam, Real-Time Fluid Dynamics for Games, 2003 Game Development Conference) and modified the processing structures in order for GPUs to perform the massive calculation in parallel.

The simplified Navier-Stokes equation for a realtime calculation used in this research looks like:

\[ \frac{\partial \mathrm{u}}{\partial t} = -(\mathrm{u} \cdot \nabla) \mathrm{u} + \nu \nabla^2 \mathrm{u} + \mathrm{f} \]
\[ \frac{\partial \rho}{\partial t} = -(\mathrm{u} \cdot \nabla) \rho + \kappa \nabla^2 \rho + S \]

The above equation describes that the state of fluid at a given instant of time is modeled as a velocity field: a function that assigns a velocity vector to every point in space. Following this equation we designed the processing structure from Jos Stam's algorithms.

FIG 2. Fluid Simulation Processing Flow of CPU Sequential Processing and GPU Parallel Processing


Since this simulation performs calculations on each point within a specific area, it is a good case to verify massively parallel computation performance by GPGPU. We implemented for two cases, one carries out computation by CPU and the other the same by GPU to compare between their performances. As a result the simulation from CPU shows a good performance if the resolution is less than 128 X 128. However, if not the case, the performance is very poor.


RESULTS

As you can see the results on the video below, the simulation on 512 x 512 resolution goes terribly slow since CPU does sequential computations while the GPU simulation shows a nice result on the same resolution. The performance table of frame rates by testing the same simulation between CPU and GPU is given. [TABLE 1. Comparison of results between from CPU and from GPU for realtime fluid simulation] | Resolution | 128 ×128 | 256×256 | 512×128 | |-------------------------------:|:--------:|:-------:|:-------:| | Framerates from CPU Processing | 60 fps | 30 fps | 0.7 fps | | Framerates from GPU Processing | - | - | 60 fps | The simulation on CPU is performed for three different resolutions while that on GPU only for one resolution, 512 × 512, which is sufficient to verify the performance since running on CPU is very slow on 512 × 512 resolution. The test is run with Intel Xeon CPU 3.07Ghz 12 cores, 12GB RAM and NVIDIA Quadro 5000. In conclusion this research inspires us with the potential of GPU usage for general computation purposes. By theses reasons we should keep up with GPGPU technology corresponding to real-time simulations with massive computation. Why? Because the technology world requires us more and more massive computations.