Вы находитесь на странице: 1из 36

Lattice-Boltzmann

. .
4 2007 .

1.

1.1. . . . . . . . . . . . . . . . . . . . . . . . . .
1.2.
. . . . . . . . . . . . . . . .
1.3. .
. . . . . . . . . . . . . . . . . . . . . . . . . . .
1.4. . . . . . . . . . . . .

2.

Lattice-Boltzmann

.
.

4
5
11

3.

15

4.

19

4.1. . . . . . . . . . . . . . . . . . . . 19
4.2.
. . . . . . . . . . . . . . . . . . 20
4.3. . . . . . . . . . . . . . . . . . . . . . . . 23

A.

24

B.

31

,
[1-3]. 90- 20-

. , ,
.
. (
,
),
(
,
).
.
.

Lattice-

Boltzmann

Processing Unit CPU

Central

Graphics Processing Unit GPU

1.
1.1.


 (, )
( ).
, , . ,
, , [4].

(. 1), .
, .
,
.
,
,
. .
,

. 1.
. ,
, . , .
1.2.

-.


[5-7].

p
u
+ (u )u =
+ 2 u,
t

u = 0,

(1.1)
(1.2)

u  , p  ,  ,  . ,
.
(, ),
.
3


. .
[8],
,
.

1.3.

, .
- .

. , f (r, c, t), , f (r, c, t)drdc t,
, r r + dr, c c + dc. ,
f . , , f
:

f (r + cdt, c +

f
dt, t + dt)drdc f (r, c, t)drdc = 0,
m

(1.3)

m  , dt  .
.
, , (1.3) (f )drdcdt.
drdcdt dt
,
:

f
f
f f
+
c+

= (f ).
t
r
c m

(1.4)

,

4

Z
(r, t) =

mf (r, c, t)dc,
Z

(r, t) u(r, t) =

mcf (r, c, t)dc,


Z
1
(r, t) e(r, t) =
mkc uk2 f (r, c, t)dc.
2

(1.5)
(1.6)
(1.7)

, :
3
kB T,
(1.8)
e=
2m
kB  , T  .
, , .

, (
). :

BGK

1
= (f (r, c, t) f (r, c, t)),

(1.9)

, f  ,
-:
"
#

3/2
m(c u)2

m
exp
f=
.
(1.10)
m 2kB T
2kB T

Chapman-Enskog expansion


, [2], , ,


.

1.4. .

20- .
, .
, .
, , ,
5

. , , ,
29 .
, .
.
,
, .
[9].

, 1970 . [10] Scientic American.
,
, . ,
, .
, .

, , ,
, , . [11].


[1],
,
(
).
, (. 2).
,
.
, .

.

FHP
Frisch-Hasslacher-Pomeau
FHP

FHP-I

. 2. FHP-I

FHP-I :

,
.
, , , :
 
  
i , sin
i , i = 0 . . . 5.
(1.11)
ci = cos
3
3
,
.

.
(
) .
:

,
.

. .
, . 3.
, .
7

p = 0.5

. 3.

FHP-I

,
. ,
. .
,
, . .
. ,
,
.

,

.

, ,
,
(. 4) .
.
, , ,
, . , ,
:

II FHP-III

FHP-I

FHP-II
FHP-III

FHP-I

FHP-

. 4.

FHP-III

,
. ,

. ,
,
.
,
. , .1

FHP

,
, [2]:

.
.
,
.
1

php

http://www.longnow.org/views/essays/articles/ArtFeynman.
We have noticed in nature that the behavior of a uid depends very little on
the nature of the individual particles in that uid. For example, the ow of
sand is very similar to the ow of water or the ow of a pile of ball bearings.
We have therefore taken advantage of this fact to invent a type of imaginary
particle that is especially simple for us to simulate. This particle is a perfect
ball bearing that can move at a single speed in one of six directions. The ow
of these particles on a large enough scale is very similar to the ow of natural
uids.

. , ,

,
.

.
,
.

10

2.

Lattice-Boltzmann

Lattice-Boltzmann

[1-3], 80-  90-


20- .
, , .


. , , .
,
, , . ,
. , ,

. , , ,
,
.
, , , , [15].


, . , ,
, .
, [14] ..

. , ,
, .
,

,
, . .

, 
,  ( ,
).

Lattice-Boltzmann

FHP

BGK

Lattice-Boltzmann

Lattice-Boltzmann

FHP

DxQy

11

D2Q7  , , ;

D2Q9  , ,
;

D3Q19  , .
D2Q9.

. r
- . ci :

c0 =
c1,5 =
c3,7 =
c2,4,6,8 =

c4

c3

c2

@
I
@
@

c
5

0,
(1, 0),
(0, 1),
(1, 1),

@
@

-c1

@
@
@
@

c
6

?
c

@
@
Rc
@

. 5.

D2Q9


. i = 0 . . . 8 ,
ci . fi (r, t)
i r t.

12

X
=
fi (r, t),
(2.1)
i

1X
ci fi ((r), t).
u =
i

(2.2)

, (1.5) (1.6),
.

:
fi (r + ci , t + 1) fi (r, t) = i (f (r, t)),
(2.3)

Lattice-Boltzmann


.
i .
:

BGK


1
(2.4)
fi (r, t) fi (r, t) .

. [3] ,
,
: = ( 0.5)/3. fi .
:


9
3 2
2
fi = Wi 1 + 3 (ci u) + (ci u) u .
(2.5)
2
2
i =

Wi :

4
W0 = ,
9

1
W1,3,5,7 = ,
9

W2,4,6,8 =

1
.
36

(2.6)

,
. .

.
, . , [2], .
,

FHP

13

,
.

14

3.

(
,
) . . , , , ..

. , . , , , , ..


. 2

-
.

. . - ,
, . ,
, . , ,
.

(
),


.
.

. ,


, . 3. , -
,

GPU Graphics Processing Unit

GPU

HDR

GPU

GPU

GPGPU General-Purpose computation on GPU


GPU

GPU
API
API

2 High

dynamic range ( )

15

OpenGL
HLSL

Direct3D

) , , (
,
,
).
,
-,
,
, , ,
, .
3
4

.
, ,
5
6
.

,

.
,

.
,
, . (
). ,
, .
(
)
.


. , ,
, ,
.

GPUflow (. 6), ,
,
- .


.

. :
,

GLSL Cg

GPGPU

GPU

BrookGPU

RapidMind
GPGPU
CTM NVIDIA CUDA
API

ATI

IEEE 754 Single Precision

Floating Point
NVIDIA

CPU

GPU

Lattice-Boltzmann

GPU

CPU

GPU
C++
win32
NVIDIA
GeForce 6600 GeForce Go

3 http://graphics.stanford.edu/projects/brookgpu/
4 http://www.rapidmind.net
5 Close

To Metal
Unied Device Architecture

6 Compute

16

. 6.

7600, GeForce 8800. A CPU - . GPU - -

. 3.
4.
GPGPU- .
. (, )
[13],
.
,
GL_FLOAT_RGB32_NV. . ,
(x, y), , . 7. .
,
.
GL_EXT_framebuffer_object.
framebuffer' , ,
GL_ARB_draw_buffers,
.
-,
. B.

- , .

API OpenGL
NVIDIA

Cg

OpenGL

CPU

GPU

17

tex1

tex2

tex3

. 7.
, .

,
,
. [12]

.
: (hue), (saturation)
(lightness). h, s l. h
, , l
, , h  .
.
. 8 , .

HSL
OpenGL
HSL RGB

RGB

HSL

. 8.

18

4.
4.1.

, , ,
.
(
).
(. 9). , ,
.
, , ,
. y , x .

x
. 9.

. 1024x100. ,
, .
, , (2.5), = 1,

Lattice-Boltzmann

19

u = (0.01, 0).
(2.4).
, .
, . ,
.
. 10.

. 10.
Re = 10, Re = 1000

, Re = h u/ , h 
(
, 100), u  ,  .
, . ,
. ,

.

4.2.

, ,

(. 11). 
, .
40-

20

50.
Re = d u/ ,
d  , u  ( ),  .

. 11.

512x256. 0.05
. 20 .
.
,
. , Re = 30 (. 12)
. , , "".
,
, , . Re = 45 (. 13) .


(. 14).
,
, , , .
.
Re .
. ,
"".

21

. 12. , Re = 30

. 13. , Re = 45

. 14. , Re = 200
, , 22

.

[15], .

Lattice-Boltzmann

4.3.

.


(. 3). .
.

OpenGL API

Cg

1. ( )

CPU Intel Core 2 Duo 1.83 GHz (1 )


GPU NVIDIA Geforce 7600 Go

256x128
108
445

512x256
27
160

1024x512
7
47


.
.
GPU  32- . , 64-
,
, ,
, , .., ,
.

http://www.gpgpu.org.

GPU

GPU

23

A.

, .

Listing 1.
//

typedef float LBfloat ;


//
enum Site
{
SITE_C ,
SITE_R , SITE_U , SITE_L , SITE_D ,
SITE_UR , SITE_UL , SITE_DL , SITE_DR ,
SITE_NUM
};
//
struct D2Q9Cell
{
// Wi (2.5)
static const LBfloat weights [ SITE_NUM ];
// (2.1)
static const int c [ SITE_NUM ][2];
//
// (fi ), . 5
// 0 - center; 1..4 - R, U, L, D; 5..8 - UR, UL, DL, DR
LBfloat site [ SITE_NUM ];
//
.
LBfloat & operator [] ( int i )
{ return site [ i ]; }
const LBfloat & operator [] ( int i ) const
{ return site [ i ]; }
};
24

// Wi
const LBfloat D2Q9Cell :: weights [9] =
{
4.0 / 9.0 ,
1.0 / 9.0 , 1.0 / 9.0 , 1.0 / 9.0 , 1.0 / 9.0 ,
1.0 / 36.0 , 1.0 / 36.0 , 1.0 / 36.0 , 1.0 / 36.0
};
//
const int D2Q9Cell :: c [9][2] =
{
{ 0 , 0} ,
{ 1 , 0} , { 0 , 1} , { -1 , 0} , { 0 , -1} ,
{ 1 , 1} , { -1 , 1} , { -1 , -1} , { 1 , -1}
};

D2Q9Cell.

Listing 2. D2Q9Cell
// ,

(2.5)

inline void calcEquilibrium ( LBfloat p ,


LBfloat ux ,
LBfloat uy ,
D2Q9Cell & cell )
{
// (2.5)
const LBfloat C1 = ( LBfloat ) 1.0;
const LBfloat C2 = ( LBfloat ) 3.0;
const LBfloat C3 = ( LBfloat ) 9.0 / 2.0;
const LBfloat C4 = ( LBfloat ) -3.0 / 2.0;
LBfloat u2 = ux * ux + uy * uy ;
for ( int i = 0; i != SITE_NUM ; ++ i )
{
LBfloat eu = D2Q9Cell :: c[ i ][0] * ux
+ D2Q9Cell :: c [ i ][1] * uy ;
LBfloat eu2 = eu * eu ;
cell [ i ] = D2Q9Cell :: weights [ i ] * p
* ( C1 + C2 * eu + C3 * eu2 + C4 * u2 );
25

// , (2.1)
inline LBfloat calcDensity ( const D2Q9Cell & cell )
{
LBfloat res = 0;
for ( int i = 0; i != SITE_NUM ; ++ i )
res += cell . site [ i ];
return res ;
}
//
inline void calcMomentum ( const D2Q9Cell & cell ,
LBfloat & ux ,
LBfloat & uy )
{
ux = 0;
uy = 0;
for ( int i = 0; i != SITE_NUM ; ++ i )
{
ux += D2Q9Cell :: c [ i ][0] * cell . site [ i ];
uy += D2Q9Cell :: c [ i ][1] * cell . site [ i ];
}
}
//
// (2.1) (2.2)
inline void calcState ( const D2Q9Cell & cell ,
LBfloat & p ,
LBfloat & ux ,
LBfloat & uy )
{
calcMomentum ( cell , ux , uy );
p = calcDensity ( cell );
if (! cg :: eq_zero ( p ))
{
ux /= p ;
uy /= p ;
}
}
26

. ,
.
, .
CPUflow.

Listing 3. CPUow
class CPUflow
{
public :
// . width height
.
CPUflow ( int width , int height );
// count .
,
. ,
.
.
void Iterate ( int count );
// ,
(ux, uy)
1.0.
void FillGrid ( float ux , float uy );
// . ,
,
, (ux, uy) 1.0.
void SetBoundaryVelocity ( float ux , float uy );
//
.
void SetViscosity ( float viscosity );
// ,
.
private :
//
. Iterate.
void ProcessCell ( int cellId );
27

//
D2Q9Cell.
STL- std::vector. ,
(x,y)
m_width * y + x.
typedef std :: vector < D2Q9Cell > GridStorage ;
//
GridStorage m_buf1 , m_buf2 ;
// , ,
,
GridStorage * m_readBuf , * m_writeBuf ;
// .
, - .
std :: vector < int > m_walls ;
// 1/ (2.4).
.
LBfloat m_relaxCoef ;

};

//
int m_width , m_height ;

,
. , m_walls .
3.
CPUflow

Listing 4. CPUow
//
CPUflow :: CPUflow ( int width , int height )
: m_width ( width )
, m_height ( height )
, m_buf1 ( width * height )
//

, m_buf2 ( width * height )
//

, m_readBuf (& m_buf1 )
//

, m_writeBuf (& m_buf2 )


//

28

, m_walls ( width * height , 0) //

{
// ,
m_walls .
}
//
void CPUflow :: Iterate ( int count )
{
for ( int i = 0; i != count ; ++ i )
{
for ( int y = 1; y != m_height - 1; ++ y )
{
int curCell = y * m_width + 1;
for ( int x = 1; x != m_width - 1; ++ x )
ProcessCell ( curCell ++); //

}
swap ( m_readBuf , m_writeBuf ); //

}
}
//
, (2.3).
, .
.
void CPUflow :: ProcessCell ( int cellId )
{
D2Q9Cell cell ; //
// .
, .
for ( int i = 0; i != SITE_NUM ; ++ i )
{
// i-

int shift = - D2Q9Cell :: c [ i ][0]


- m_width * D2Q9Cell :: c [ i ][1];
cell [ i ] = (* m_readBuf )[ cellId + shift ][ i ];
}

29

// .
if ( m_walls [ cellId ] != 0)
{
// ,
,

swap ( cell [ SITE_R ], cell [ SITE_L ]);
swap ( cell [ SITE_U ], cell [ SITE_D ]);
swap ( cell [ SITE_UR ] , cell [ SITE_DL ]);
swap ( cell [ SITE_UL ] , cell [ SITE_DR ]);
}
else
{
// BGK (2.4)
D2Q9Cell eq ;
LBfloat p , ux , uy ;
calcState ( cell , p , ux , uy );
calcEquilibrium (p , ux , uy , eq ); //

// .
.
if ( cg :: eq_zero ( p ))
return ;

}
}

//
for ( int i = 0; i != SITE_NUM ; ++ i )
cell [ i ] += m_relaxCoef * ( eq [ i ] - cell [ i ]);

(* m_writeBuf )[ cellId ] = cell ;

30

B.

Listing 5.
//

struct pixelOutput
{
float3 row0 : COLOR0 ;
float3 row1 : COLOR1 ;
float3 row2 : COLOR2 ;
};
pixelOutput main (
float2 pos : TEXCOORD0 ,

//

//
, . 7
uniform samplerRECT bufRow0 : TEXUNIT0 ,
uniform samplerRECT bufRow1 : TEXUNIT1 ,
uniform samplerRECT bufRow2 : TEXUNIT2
)
{
pixelOutput pOut ;
//
//
//
//

r g b
UL U UR - row 0
L C R - row 1
DL D DR - row 2

//
float UL
float U
float UR


= texRECT ( bufRow0 , pos + float2 ( 1.0 , -1.0)). r ;
= texRECT ( bufRow0 , pos + float2 ( 0.0 , -1.0)). g ;
= texRECT ( bufRow0 , pos + float2 ( -1.0 , -1.0)). b ;

float L = texRECT ( bufRow1 , pos + float2 ( 1.0 , 0.0)). r ;


float C = texRECT ( bufRow1 , pos + float2 ( 0.0 , 0.0)). g ;
float R = texRECT ( bufRow1 , pos + float2 ( -1.0 , 0.0)). b ;
float DL = texRECT ( bufRow2 , pos + float2 ( 1.0 , 1.0)). r ;
31

float D = texRECT ( bufRow2 , pos + float2 ( 0.0 , 1.0)). g ;


float DR = texRECT ( bufRow2 , pos + float2 ( -1.0 , 1.0)). b ;
//
pOut . row0 = float3 ( UL , U , UR );
pOut . row1 = float3 (L , C , R );
pOut . row2 = float3 ( DL , D , DR );
}

return pOut ;

Listing 6.
//

struct pixelOutput
{
float3 row0 : COLOR0 ;
float3 row1 : COLOR1 ;
float3 row2 : COLOR2 ;
};
//
(2.5)
float3 calcEqRow ( float2 u , float u2 , float p , float cy )
{
const float3 cx = float3 ( -1.0 , 0.0 , 1.0);
const
const
const
const

float
float
float
float

C1
C2
C3
C4

=
=
=
=

1.0;
3.0;
9.0 / 2.0;
-3.0 / 2.0;

float3 eu = cx * u . x + cy * u .y ;
float3 eu2 = eu * eu ;
}

return p * ( C1 + C2 * eu + C3 * eu2 + C4 * u2 );

pixelOutput main (
float2 pos : TEXCOORD0 ,

//
32

// 1/ (2.4)
uniform float relaxCoef ,
//
, . 7
uniform samplerRECT bufRow0 : TEXUNIT0 ,
uniform samplerRECT bufRow1 : TEXUNIT1 ,
uniform samplerRECT bufRow2 : TEXUNIT2
)
{
pixelOutput pOut ;
//
//
//
//

r g b
UL U UR - row 0
L C R - row 1
DL D DR - row 2

//
float3 row0 = texRECT ( bufRow0 , pos ). rgb ;
float3 row1 = texRECT ( bufRow1 , pos ). rgb ;
float3 row2 = texRECT ( bufRow2 , pos ). rgb ;
// (2.1) (2.2)
float p = row0 . r + row0 . g + row0 . b
+ row1 . r + row1 . g + row1 . b
+ row2 . r + row2 . g + row2 . b ;
float2 u = float2 (0.0 , 0.0);
u . x += row0 . b + row1 . b + row2 . b ;
u . x -= row0 . r + row1 . r + row2 . r ;
u . y += row0 . r + row0 . g + row0 . b ;
u . y -= row2 . r + row2 . g + row2 . b ;
u /= p ;
float u2 = dot (u , u );
//
const float Wcorn = 1.0 / 36.0;
33

const float Wside = 1.0 / 9.0;


const float Wcent = 4.0 / 9.0;
pOut . row0 = row0 + relaxCoef * ( calcEqRow (u , u2 , p , 1.0)
* float3 ( Wcorn , Wside , Wcorn ) - row0 ) ;
pOut . row1 = row1 + relaxCoef * ( calcEqRow (u , u2 , p , 0.0)
* float3 ( Wside , Wcent , Wside ) - row1 );
pOut . row2 = row2 + relaxCoef * ( calcEqRow (u , u2 , p , -1.0)
* float3 ( Wcorn , Wside , Wcorn ) - row2 );
}

return pOut ;

34

[1]

[2]
[3]

Brian J. N. Wylie Application of two-dimensional cellular automaton

lattice-gas models to the simulation of hydrodynamics. University of


Edinburgh, 1990.

Maxwell J. B.

Lattice Boltzmann methods for interfacial wave modeling.


University of Edinburgh, 1997.

Wolf-Gladrow D. A.

Lattice-gas cellular automata and LatticeBoltzmann models. Springer, 2000.

- . . .: , 1986.
[5] . . . .:
[4]

- , 1950.

[6]

., ., . -

[7]

. ., . . . .: -

[8]

Ferziger J. H., Peric M. Computational methods for uid dynamics,

. 7. .
, 2006.

3ed. Springer, 2001.

[9]

Von Neumann J. Theory of self-reproducing automata. University of

[10]

Gardner M. Mathematical Games: The fantastic combinations of John

[11]

Chopard B., Luthi P., Masselot A.

Illinois Press, 1966.

Conway's new solitare game "Life". Scientic American 223, 1970.

Cellular automata and LatticeBoltzmann techniques: an approach to model and simulate complex
systems. University of Geneva, 1998.

[12] HSL Color Space. http://en.wikipedia.org/wiki/HSL_color_space


[13] Cg Toolkit User's Manual. NVIDIA Corporation, 2005.
[14]

Xiaowen S., Hudong C. Lattice-Boltzmann model for simulating ows

with multiple phases and components. Dartmouth College, Hanover,


1993.

35

[15]

Zhen-Hua C., Bao-Chang S., Lin Z. Simulating high Reynolds number


ow in two-dimensional lid-driven cavity by multi-relaxation-time
Lattice-Boltzmann method. Chin. Phys. Soc. and IOP Publishing Ltd,
2006.

36

Вам также может понравиться