Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid...
Transcript of Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid...
![Page 1: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/1.jpg)
Fluid Simulation on the GPU
GPGP Course PresentationHuai-Ping Lee
![Page 2: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/2.jpg)
Outline
Navier-Stokes based methodsLattice Boltzmann methodSummary and Comparison
![Page 3: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/3.jpg)
Navier-Stokes Equations for Fluid Simulation on the GPU
![Page 4: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/4.jpg)
Navier-Stokes Equations
Macroscopic behaviors of incompressible fluids
{ {
cases; 2Dfor where,),(),(
field)(vector force external :),( field);(scalar pressure:),( ;(constant) fluid ofdensity :
field);(vector fluid of velocity :),(
1)(
0
forceexternaldiffuse
2
pressureadvection
⎥⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡=
⎪⎪⎩
⎪⎪⎨
⎧
+∇+∇−∇⋅−=∂∂
=⋅∇
yx
tvtu
ttp
t
pt
xxx
u
xfx
xu
fuuuuu
ρ
νρ 321
43421
(1)
(2)
![Page 5: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/5.jpg)
Notation—Vector Calculus
![Page 6: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/6.jpg)
Derivation of Navier-Stokes Equations
Eq. 1: conserve massThe integral over the mass of the fluid = constant, and the density is constantSo the amount of flux = 0, therefore the flux in each small area = 0By divergence theorem, flux density is div(u)
xxunxu dtdivdsttt
∫∫ΩΩ∂
=⋅ )),((),(
![Page 7: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/7.jpg)
Derivation of Navier-Stokes Equations
Eq. 2: conserve momentum
Newton’s second law:
xxuxm dtttt
),(),()( ⋅= ∫Ω
ρ
∑= forcesactingtdtd )(m
![Page 8: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/8.jpg)
Derivation of Navier-Stokes Equations
There are two kinds of acting forcesBody force: given by the force density per unit volume f(x, t)
Surface force (e.g. pressure): represented by stress tensor σ
xxfxF dttt
b ),(),( ⋅= ∫Ω
ρ
cases. 3Dfor normal; surface: where
,)(),(
333231
232221
131211
⎥⎥⎥
⎦
⎤
⎢⎢⎢
⎣
⎡=
=⋅= ∫∫ΩΩ∂
σσσσσσσσσ
σn
xσnxσF ddivdsttt
s
![Page 9: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/9.jpg)
Derivation of Navier-Stokes Equations
Transport theorem
So Newton’s second law says (here f=ρu)
∫∫ΩΩ
⎟⎠⎞
⎜⎝⎛ ⋅+∂∂
=
ℜ→×Ω
tt
dtfdivtft
dtfdtd
tf endt
xuxxxx )),((),(),(
,],0[: fieldscalar abledifferenti aFor
{
{force externaladvection
0
)(1)(
0)()()()(
fσuuu
σfuuuuu
++∇⋅−=∂∂
diffuse pressure,
∴
=−−⋅∇+∇⋅+∂∂
4342143421
divt
divt
ρ
ρρρρ
![Page 10: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/10.jpg)
Derivation of Navier-Stokes Equations
So the equation depends on the stress tensorFor viscous fluids, σdepends on pressure and internal friction
Some applications also include boyancy in σFor more detail, see [Griebel et al. 98]Finally we have
{ {
forceexternaldiffuse
2
pressureadvection
1)( fuuuu+∇+∇−∇⋅−=
∂∂ ν
ρ 32143421
pt
The velocity of the fluid carries
itself along
Pressure in the fluid leads to acceleration
Internal friction results in diffusion in the momentum
![Page 11: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/11.jpg)
Helmholtz-Hodge Decomposition
2
0 where,∇=⋅∇
=⋅∇∇+=
wuuw
Decomposes a vector field w into a divergence-free vector field u and another gradient fieldDefine an operator P such that P(w) = u
Project any vector field to its divergence-free partP(gradient field) = 0
q∇−== wwu )P( (3)
![Page 12: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/12.jpg)
Helmholtz-Hodge Decomposition
Apply P() to both sides of (2), we get
Since P(u) = u and P(del(p)) = 0
))(P( 2 fuuuu+∇+∇⋅−=
∂∂ ν
t(4)
![Page 13: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/13.jpg)
Outline of Solution
Start from the solution of previous time step (t) and add each term on the right hand side of Eq.4, and them perform the projection to satisfy Eq.1
w can be stored in one RGBA texture2D case: 2D texture using 2 channels3D case: 3D texture using 3 channels
)()()()()(
where,),(),(
),()(
4project
3diffuse
2advect
1force add
0
0
xwxwxwxwxw
xxx
xuxw
⎯⎯ →⎯⎯⎯ →⎯⎯⎯ →⎯⎯⎯⎯ →⎯
⎥⎦
⎤⎢⎣
⎡=⎥
⎦
⎤⎢⎣
⎡==
yx
tvtu
t
![Page 14: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/14.jpg)
Storage
2D example:
![Page 15: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/15.jpg)
3D Textures vs. Flat 3D Textures
According to [Harris 03], flat 3D textures have performance advantage over true 3D textures on current graphics hardware
![Page 16: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/16.jpg)
External Force
),()()( 01 ttt
xfxwxw
fu
Δ+=
=∂∂
An approximation over the time step ∆tEasy to implement on GPU once we have w0 and fas input texture
For each cell (fragment), lookup textures w0 and f and add them.
![Page 17: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/17.jpg)
Advection [Stam 99]
uuu )( ∇⋅−=∂∂
tSolve the PDE by method of characteristics, we can find that the value of u does not change along the “streamlines” of the velocity field, therefore
field velocity the toaccording ago, Δ timea oflocation the:),(
)),(()( 12
ttt
xxpxpwxw
Δ−Δ−=
![Page 18: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/18.jpg)
Advection
When p(x, ∆t) is between the grids, interpolate itCan also be easily done on GPU, for each cell,
w1 as input textureCompute p(x, ∆t) in fragment shaderPerform 4 texture look-ups on w1 and interpolate
Use built-in function in Cg, f4texRECTbilerp()
![Page 19: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/19.jpg)
Diffusion [Stam 99]
)()()( 232
3223
323
xwxwI
www
ww
=∇Δ−
∇≈Δ−
∇=∂∂
tt
t
ν
ν
ν
It involves solving a Poisson equation (details later)
∇⋅∇=∇
=∇−2
2
where),(xfv
![Page 20: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/20.jpg)
Projection to Divergence-Free Vectors
Solve for q and subtract it from w3
∇−=⋅∇=∇
34
32
www
Also a Poisson equation
![Page 21: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/21.jpg)
Poisson Equation as Linear System
So the key to solving N-S equation is solving the Poisson equationsFor example, one-dimensional version:
Discretize the space into N+1 grids
{
.0
0
21001
00121
0012
and ,2 Therefore
.; ).(let ,1
1
)1(,)0( ,10 ),()(
1
2
1
211
2
2
11
1
2
2
⎥⎥⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢⎢⎢
⎣
⎡
≈
⎥⎥⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢⎢⎢
⎣
⎡
−
⎥⎥⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢⎢⎢
⎣
⎡
⎥⎥⎥⎥⎥⎥
⎦
⎤
⎢⎢⎢⎢⎢⎢
⎣
⎡
−−
−−−
++−≈
∂∂
−≈
∂∂−
≈∂∂
=+
=
==≤≤=∂
∂−
+−
++
−
Nb
a
N
iiii
iii
iiin
ba
f
f
h
v
v
v
v
hvvvv
x
hvvv
xhvvv
xnhvv
Nh
vvvvxxfx
xv
N
MMM
4444 34444 21L
OOOM
OOO
MO
L
vT
va v1 … vN vb0 11/(N+1) N/(N+1)…
![Page 22: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/22.jpg)
Poisson Equation Solvers
It can be extended to 2D or 3DTN, TNxN, TNxNxN are symmetric banded matricesDirect methods to solve linear systems: O(N3) time
impossible for 2D or 3D cases
Need iterative methodsPlease refer to previous lectures on linear algebra and banded matrices [Sashi, Suddha]Conjugate gradient [Krüger and Westermann 03], [Boltz et al. 03]Multigrid [Boltz et al. 03]: O(N) time for N samples
![Page 23: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/23.jpg)
Poisson Equation as Linear System
It can be shown that [Demmel 97]
Truncation error approaches zero proportional to h2
But the condition number of TN is [Demmel 97]
Larger N makes the system more sensitive to FP errorsRemember: only 32-bit floating point numbers on GPUN should be large enough, but not too large
)(ˆ 4
42
2∞
≤−dx
vdhOvv
2
2)1(4)(π
κ +≈
NTN
![Page 24: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/24.jpg)
Boundary Conditions
To solve the Poisson equation, we still need boundary values that satisfy boundary conditions
No-slip condition: velocity goes to zero at the boundaries
Resolution of boundary is limited by the size of grids
![Page 25: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/25.jpg)
Boundary Conditions
The boundary lies on the edge between the boundary cell and its nearest interior cell
Assign imaginary velocity value to boundary cells so that the average of itself and its nearest interior cell should satisfy the conditionFor example, on the left side,
jj
jj
,1,0
,1,0 02uu
uu
−=
=+
![Page 26: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/26.jpg)
Boundary Conditions
To update the boundary cells after solved the velocity field:
Draw lines on the boundaryIn the shader: lookup texture u at the coordinate of nearest interior cell and return the negative of the value.
Arbitrary boundaries is complicatedFor each boundary cell, need to determine the direction of the faceMore computation in the shader, more lines
![Page 27: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/27.jpg)
Results [Krüger and Westermann 03]
1024x1024, 13 fps
1024x1024, 9 fps
![Page 28: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/28.jpg)
Performance
The performance should be governed by the Poisson solver since other parts require little effort[Krüger and Westermann 03] reported a 2D N-S equation solver has 9 fps on a 10242 grid
using P4 2.8GHz with ATI 9800 graphics cardbut did not compare with performance on CPU
![Page 29: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/29.jpg)
Results [Harris et al. 2003]
128x128 grid, 30 fps
![Page 30: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/30.jpg)
Performance [Harris et al. 2003]
[Harris et al. 2003] reported 3D cloud simulation results on Geforce FX Ultra
32x32x32: 27 iterations per second64x64x64: 3.6 iterations per second
(I’m not sure if they include rendering time)Not compared to CPU
![Page 31: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/31.jpg)
Reference—Navier-Stokes Equations
Stam, J. Stable Fluids. In Proceedings of SIGGRAPH 1999.Griebel, M., Dornseifer, T., Neunhoeffer, T. Numerical Simulation in Fluid Dynamics. Society for Industrial and Applied Mathematics. 1998.Demmel, J. W. Applied Numerical Linear Algebra. Society for Industrial and Applied Mathematics. 1997.Harris, M. Fast Fluid Dynamics Simulation on the GPU. In GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time Graphics. 2004.Krüger, J. and Westermann, R. Linear Algebra Operators for GPU Implementation of Numerical Algorithms. SIGGRAPH 2003.Bolz, Farmer, Grinspun and Schröder, Sparse Matrix Solvers on the GPU: Conjugate Gradients and Multigrid. SIGGRAPH 2003.Harris, M., Baxter, W. V., Scheuermann, T., and Lastra, A. Simulation of Cloud Dynamics on Graphics Hardware. Graphics Hardware 2003.
![Page 32: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/32.jpg)
Lattice Boltzmann Method for Fluid Simulation on the GPU
![Page 33: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/33.jpg)
Two Different Strategies
Top-down: solving differential equations by discretizing the space
Be aware of truncation error when using finite difference!Navier-Stokes equations
Bottom-up: start from a discretizedmicroscopic model that conserves desired quantities
Lattice Gas Automata, Lattice Boltzmann Model
![Page 34: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/34.jpg)
Lattice Boltzmann Model
Simulate microscopic behaviors of particlesStreaming: each particle moves to the nearest node in the direction of its velocityCollision: particles arriving at a node interact and change their velocity directions
Averaged microscopic properties obey the desired macroscopic properties (conservation of mass and momentum)
![Page 35: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/35.jpg)
Lattice Geometry—D3Q19
![Page 36: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/36.jpg)
Lattice Gas Automata
The space is divided into a lattice of nodes with particles resides on themEach node has a set of directions of velocity
ei, i = 0, 1, …, MEach velocity vector is coupled with a boolean variable
ni(x, t), i = 0, 1, …, Mx: location of the node; t: timetrue iff there is a particle moving in this direction
![Page 37: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/37.jpg)
Lattice Gas Automata
At each time step, evolve each node with
Streaming: each particle moves to the nearest node in the direction of its velocityCollision: particles arriving at a node interact and change their velocity directions
No more than one particle is allowed in a node with a given velocity
43421321collisionstreaming
)),((),(),( tntntn iiii xxex Ω+=+
![Page 38: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/38.jpg)
Lattice Boltzmann Method (LBM)
Now replace the particle occupation variables ni with single-particle distribution functions
fi = <ni>The density of particles that have a given velocity
![Page 39: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/39.jpg)
Lattice Boltzmann Equations (LBE)
increments space and time: and collision from resulting of change
of rate therepresentshich operator wcollision :)),((directionth thealongfunction on distributi velocity particle :
..., ,1 ,0 ,)),((),(),(collisionstreaming
xtf
tfif
Mitftfttxf
i
ii
i
iiii
ΔΔ
Ω=Ω
=Ω+=Δ+Δ+
x
xxex43421321
Discretized space is consistent with the equationThe nearest neighbors of x are x + ei, i = 0, 1, …, M
![Page 40: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/40.jpg)
Lattice Boltzmann Equations (LBE)
The density and momentum density of a node are
So we can compute velocity field uΩi is required to satisfy conservation of total mass and total momentum at each node
∑∑==
==M
iii
M
ii ff
11
, euρρ
0 ,01
i1
=Ω=Ω ∑∑==
M
ii
M
ii e
![Page 41: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/41.jpg)
Two-Step Update of LBE
How to compute the collision term?
),()1,(:streaming
),(),(:collision
tftf
tftfnew
iii
iinew
i
xex
xx
=++
Ω+=
![Page 42: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/42.jpg)
Collision
The distribution function fi can be expanded about the local equilibrium distribution function fieq, which satisfies
fieq only depend on ρ and uEquilibrium means that forces in all directions are balanced
{ {
∑∑
∑∑
==
==
==
==
+=
M
ii
neqi
M
i
neqi
M
ii
eqi
M
i
eqi
negi
eqii
ff
ff
fff
11
11
riumnonequilibmequilibriu
0 ,0
,
e
euρρ
![Page 43: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/43.jpg)
Collision
The nonequilibrium (“unbalanced”) part is resulted from collision
How to find fieq?
viscosity thedetermineshat constant t:functionon distributi mequilibriu local:),(
)),(),((1
τρ
ρτu
ux
eqi
eqiii
f
ftf −−=Ω
![Page 44: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/44.jpg)
Equilibrium Distribution Function
Bhatnager, Gross, Krook (BGK) model [Wolf-Gladrow 2000]
geometry lattice chosen the tospecific tscoefficienconstant :,,,))()()((),( 2
DCBADCBAf ii
eqi uuueueu ⋅+⋅+⋅+= ρρ
![Page 45: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/45.jpg)
Boundary Condition
For simple boundary (box aligned with axes), the “bounce-back” method we mentioned before is enoughFor arbitrary boundary, LBM becomes easier than N-S based methods since the vectors are fixed to a certain directions
f for boundary nodes can be interpolated
![Page 46: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/46.jpg)
Arbitrary Boundary [Mei et al. 2000]
Boundary nodes are given a imaginary fvalue so that the interpolated value at the boundary satisfies the no-slip condition
bf
wf
xx
xx
−
−=Δ
The packet distribution at xf is streamed from xb, so we need to define an imaginary distribution for xb
![Page 47: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/47.jpg)
Arbitrary Boundary [Mei et al. 2000]
Post-collision value of fi(xb, t) isVelocity of
the wall
Constant determining
viscosity
![Page 48: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/48.jpg)
GPU Implementation [Li et al. 2003]
Flow chart
![Page 49: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/49.jpg)
GPU Implementation—Storage
Group the distribution functions into arrays according to their velocity vectors
Also density, velocity, and equilibrium distribution
![Page 50: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/50.jpg)
GPU Implementation—Storage
To exploit 4 channels, pack four arrays into one textureFor 3D case, the volume is treated as slices of 2D textures
Flat volume, [Harris et al. 2003]
![Page 51: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/51.jpg)
GPU Implementation—Collision & Streaming
Collision term is computed from texture uρand added to textures f0-f4Streaming: fetch neighboring texels and copy the corresponding f
finew (x)= fi(x-ei)
For example, f new(1, -1, 0)(x) = f(1, -1, 0)(x-(1, -1, 0))
![Page 52: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/52.jpg)
GPU Implementation—Boundary
To handle the complex boundary, we need to compute the intersections of boundary surface with all the lattice links
For moving or deformable boundary, the intersection changes dynamically
Create voxelization for boundaries by rendering the scene several times with different near and far clipping planes
Boundary is sparse in the entire scene, thus does not need too many passes
Clipping plane
![Page 53: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/53.jpg)
GPU Implementation—Boundary
When rendering the boundary voxels, apply the fragment shader to compute boundary conditions
We still need
Each boundary distribution will have the velocity vector crossing the boundary surface
bf
wf
xx
xx
−
−=Δ
![Page 54: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/54.jpg)
Boundary
Suppose the boundary surface is defined by Ax + By + Cz + D = 0 [(A, B, C) is normalized]
Define
Each ei has its own flagsNeed to make sure that each boundary node is covered by a fragment, so that boundary condition is computed for all boundary nodes
voxel theof coordinate 3D theis ),,() and normalbetween (angle ),,(
surface)boundary the to(distance ),,,()1,,,(
2
1
zyx
ii
zyx
posposposCBAflag
DCBAposposposflag
ee⋅=
⋅−=
![Page 55: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/55.jpg)
Boundary
Three passes to cover boundary cellsFirst pass—just render the voxelsSecond pass—only R and G channels are updated, ei is the vector corresponding to R channel, translate all voxels and render, with translation offsets decided by the rule:
⎪⎩
⎪⎨
⎧
=<−
>
0* if:00* if:
0* if:
21
21
21
flagflagflagflag
flagflag
i
i
ee
![Page 56: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/56.jpg)
Boundary
Third pass—similar to second pass, but only B and A channels are updated, and ei is the vector corresponding to the blue channelAll boundary nodes will be covered by the voxels
Note that each pass will check for all four textures f0~f4During the passes, compute in the fragment shader
If 1>=∆>=0, the voxel is a boundary node, and the boundary condition is computed for the voxel
2
11flagflag
−=Δ
![Page 57: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/57.jpg)
Boundary
•The vectors in R and B channels are perpendicular
•Vectors in R is opposite to vectors in G;
•Vectors in B is opposite to vectors in A
ei
ei
ejAx+By+Cz+D=0
(A, B, C)
Flag1 < 0
Flag2 > 0
Flag1 < 0
Flag2 < 0
Flag1 > 0
Flag2 > 0
Flag1 > 0
Flag2 < 0
Outside voxels moves inward in passes 2 & 3
Inside voxels moves outward in passes 2 & 3
ej
![Page 58: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/58.jpg)
Boundary
2
1
2
1
11
,' eIn triangl
flagflag
flagflag
bf
bw
bf
bw
wb
−=−
−−=Δ
=−
−
xxxx
xxxx
xxxDirection of (A, B, C)
Ax+By+Cz+D=0
flag1
flag2
xw
xf
xb
x’
![Page 59: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/59.jpg)
Results [Li et al. 2003]
![Page 60: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/60.jpg)
Performance—2D [Li et al. 2003]
•0.16 seconds per frame on 1024x1024 cell, including simulation and visualization
•[Kruger and Westermann 03] claimed 0.11 seconds per frame, but they did not deal with complex boundary
•Hardware used: P4 2.53 GHz, 1GB PC800 RDRAM with GeForce FX 5900 Ultra (256MB DDR RAM)
![Page 61: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/61.jpg)
Performance—3D [Li et al. 2003]
•[Harris et al. 2003] reported 0.28 sec/iteration on 64x64x64 grids
![Page 62: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/62.jpg)
Reference—Lattice Boltzmann Method
Li, W., Fan, Z., Wei, X., and Kaufman, A. GPU-Based Flow Simulation with Complex Boundaries. Technical Report 031105, Computer Science Department, SUNY at Stony Brook. Nov 2003.Chen, S. and Doolean, G. D. Lattice Boltzmann Method for Fluid Flows. Annu. Rev. Fluid Mech. 30, 329-364. 1998.Wolf-Gladrow, D. A. Lattice-Gas Cellular Automata and Lattice Boltzmann Models: An Introduction. Springer-Verlag. 2000.Mei, R., Shyy, W., Yu, D., and Luo, L.-S. Lattice Boltzmann Method for 3-D Flows with Curved Boundary. Journal of Comp. Phys. 161, 680-699. 2000.
![Page 63: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/63.jpg)
Summary and Comparison
Navier-Stokes and LBM can be used to simulate fluids, and they are both parallelizable
Solving Poisson equations can be a bottle neck for N-S based methods (need more passes for iterative refinement)N-S based method relies on numerical accuracy more than bottom-up methods
Sensitivity of linear systems can be criticalNo double precision on current GPUs may become a major problem for large scale simulation
![Page 64: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/64.jpg)
Summary and Comparison
Current work using N-S on GPUs only deal with simple boundary, while LBM on GPUscan deal with complex boundary
LBM is easier for this because each node only have a set of vector directions
LBM has advantage of complex boundary and numerical sensitivity
![Page 65: Fluid Simulation on the GPU - Computer Sciencelhp/courses/COMP790_058/GPU_Fluid.pdf · Fluid Simulation on the GPU GPGP Course Presentation Huai-Ping Lee](https://reader031.fdocuments.in/reader031/viewer/2022020303/5af421ae7f8b9a74448c762e/html5/thumbnails/65.jpg)
Future Work
Simulation and visualization of liquid surface are still not solved on GPUs
Can we solve for isocontour of liquid grids on the GPU??