Академический Документы
Профессиональный Документы
Культура Документы
. .
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
Central
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) =
(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
. , , ,
,
.
, , , , [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
HDR
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
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.
. 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. ( )
256x128
108
445
512x256
27
160
1024x512
7
47
.
.
GPU 32- . , 64-
,
, ,
, , .., ,
.
http://www.gpgpu.org.
GPU
GPU
23
A.
, .
Listing 1.
//
// 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)
// , (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 )
//
28
{
// ,
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-
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 ]);
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 ;
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
return pOut ;
34
[1]
[2]
[3]
Maxwell J. B.
Wolf-Gladrow D. A.
- . . .: , 1986.
[5] . . . .:
[4]
- , 1950.
[6]
., ., . -
[7]
. ., . . . .: -
[8]
. 7. .
, 2006.
[9]
[10]
[11]
Cellular automata and LatticeBoltzmann techniques: an approach to model and simulate complex
systems. University of Geneva, 1998.
35
[15]
36