Lattice Boltzmann Method & CUDA

Student: Ahmad Kiswani

Supervisor: Joan Adler

27, January 2016

Motivation

  • Lattice Boltzmann Methods solves Navier-Stoke equation.
  • Local = Easy to parallelize.
  • Simple calculation steps = Easy to implement on GPUs.
  • Boundary conditions are simple to = Easy to realize for arbitrary geometry.

alt text

Navier Stokes equations

  • Continuity equation: $$ \partial_t(\rho) + \nabla (\rho u)=0 $$
  • Navier Stoke: $$ \partial_t(\rho u) + \nabla (\rho uu)=-\nabla p + \nabla \sigma $$ or $$ \partial_t(u) + u \nabla u = -\frac{\nabla p}{\rho} + v\nabla^2u $$
  • $\sigma$ is the viscous stress tensor: $$ \sigma = \eta [\nabla u + (\nabla u)^T]+v\nabla u_t $$
  • In CFD, We need to discretize the first and second derivatives, then integrate them (inefficient).

Lattice Boltzmann

  • LBM simulates the dynamic behavior of fluid flows without directly solving the equations of continuum fluid mechanics.
  • We imagine an ensemble of particles, whose motion and interactions are confined to a regular space-time lattice.
  • particle velocities are restricted to a handful of discrete values (particles can only move along a finite number of directions).
  • With sufficient symmetries to fulfill the basic conservation laws of mass, momentum and energy, LBE can be shown to reproduce the equations of motion of CFM.

Space-time Lattice

D2Q9 lattice: alt text

Space-time Lattice - Cont.

The choice is not arbitrary – Satisfy symmetry requirements (up to required orders):

Wrong: alt text Correct alt text

Lattice Boltzmann equation

$$ f_i(\vec{r}+\vec{c_i}\Delta t, t+\Delta t)=f_i( \vec{r},\Delta t)+\frac{1}{\tau}(f_i^{eq}(\vec{r}, t))-f_i^{eq}(\vec{r}, t)) $$

$f_i( \vec{r},\Delta t)$ is the probability of finding a particle at position $\vec{r}$ and time $t$ with velocity $\vec{v}=\vec{c}$.

fluid quantities obtained via: $$ \rho(\vec{r},t)=\Sigma f_i(\vec{r},t) $$ $$ u(\vec{r},t)=\frac{1}{\rho(\vec{r},t)}\Sigma \vec{c_i}f_i(\vec{r},t) $$ $$ P(\vec{r},t)=\Sigma \vec{c_i}\vec{c_i}f_i(\vec{r},t) $$

Lattice Boltzmann Algorithm

  • The LB equation can be divided into two steps: $$ \underbrace{f_i(\vec{r}+\vec{c_i}\Delta t, t+\Delta t)-f_i( \vec{r},\Delta t)}_{\text{ Streaming}}=\underbrace{\frac{1}{\tau}(f_i^{eq}(\vec{r}, t))-f_i^{eq}(\vec{r}, t))}_{\text{Collision}} $$

Collision step

$$ f_i^t(\vec{r}, t+\Delta t)=f_i( \vec{r},t)+\frac{1}{\tau}(f_i^{eq}(\vec{r}, t))-f_i(\vec{r}, t)) $$
  • $\tau$ - relaxation time towards local equilibrium.
  • $f_i^{eq}$ - equilibrium distribution.
  • equilibrium distribution is calculated using Bhatnagar-Gross-Krook (BGK) collision

BGK collision

$$ f_i^{eq}(\vec{r},t)=w_i\rho + \rho s_i (\vec{u}(\vec{r},t)) $$
  • where: $$ s_i=w_i[3\frac{\vec{e_i}\vec{u}}{c}+\frac{9}{2}\frac{(\vec{e_i}\vec{u})^2}{c^2}-\frac{3}{2}\frac{\vec{u}\vec{u}}{c^2}] $$ $$ w_i=\left\{\begin{matrix} \frac{4}{9} & i=0\\ \frac{1}{9} & i=1,2,3,4\\ \frac{1}{36} & i=5,6,7,8 \end{matrix}\right. $$ $\vec{e_i}$ is the direction vector.

Streaming step

$$ f_i^t(\vec{r},t)=f_i(\vec{r}+\vec{c_i}\Delta t,t + \Delta t) $$

alt text

Boundary conditions

  • Bounce back:
    • Half-way bounce back: alt text
    • Full-way bounce back: alt text

Equivalence of BB methods

  • Full way: alt text
  • Half way: alt text

Boundary conditions – cont.

  • Zou-He boundary condition:
    • Prescribed velocity or pressure at the boundary $$ f_1 = f_3 +\frac{2}{3}\rho u $$ $$ f_5 = f_7 -\frac{1}{2}(f_2-f_4)+\frac{1}{6}\rho u+\frac{1}{2}\rho u $$ $$ f_5 = f_7 +\frac{1}{2}(f_2-f_4)+\frac{1}{6}\rho u-\frac{1}{2}\rho u $$ alt text

Algorithm

alt text

Code

Requirements

  1. Nvidia GPU with compute capability >= 3.0.
  2. CMake >= 2.4.
  3. OpenGL, GLUT and GLEW.

Compilation.

$ mkdir build && cd build
$ cmake ..
$ make
$ ./latticeBoltzmann --help

note: Do not forget to disable V-Sync to get more than 60 FPS.

Usage

$ ./latticeBoltzmann --help
Usage: latticeBoltzmann [OPTION...] 


  -x[INT]                    size of x plane (default 300)
  -y[INT]                    size of y plane (default 300)
  -c, --cpu                  Use CPU for simulation (default=False)
  -f, --file[=FILE]          color map file (default=../cmap.data)
  -p, --porous[=FILE]        porus file

  -?, --help                 Give this help list
      --usage                Give a short usage message

Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.

Porous file should be a text file in the following format:
cols rows  
i i i ... i
i i i ... i
. .        
.  .       
.   .      
.    .     
.     .    
i i i ... i

where the matrix values are 0 for porous and non zero for empty space.
for examle:
4 3   
1 1 1 
1 0 1 
1 1 1 

Note: Don not forget to disable V-Sync to get more than 60fps.

Result

  • The program uses OpenGL to draw a color map of the fluid velocity in the medium.
  • OpenGL is a cross-platform API used to interact with the GPU to render graphics on the screen.

Screenshot

alt text

Performance

Size CPU[fps] GPU[fps] SpeedUp
300x300 125 1050 8.4
500x500 32 440 13.7
1000x1000 8 122 15.25
2000x2000 2 33 16.5

CPU=Intel i7 3930k

GPU=Nvidia Geforce GTX 670

Downloads

Code: Zip or tar

ipython notebook: Here

References

  1. Alexander J. Wagner. A Practical Introduction to the Lattice Boltzmann Method. Department of Physics, North Dakota State University, 2008.[pdf]
  2. Yuanxun and Justin. Lattice Boltzmann Method for Fluid Simulations. 2011. [pdf]
  3. Steven Orszag. Lattice Boltzmann Methods for Fluid Dynamics. Department of Mathematics, Yale University.[pdf]
  4. Dror Denneboom. Lattice Boltzmann simulation of fluid flow in porous media. Computational Physics, Technion. 2014 [project link]