๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
ํ”„๋กœ๊ทธ๋ž˜๋ฐ

[tbd] Jos Stam, Stable Fluids (1999)

by ๐“ƒ๐’ถ๐“ƒ๐’ถ๏ฝก 2015. 3. 6.

semi-Lagrangian simulation method

Fourier transform technique only works given periodic boundaries.

sparse linear solver based simulation - work with any boundary conditions

 

assume: fuild is bounded by rectangle

 

 

http://www.dgp.toronto.edu/people/stam/reality/Talks/FluidsTalk/FluidsTalk_files/v3_document.htm

 

1. Navier-Stokes Equation

 

<Evolution of density>

 

<Evolution of velocity>

 

+ velocity should conserve mass

 

๋‘ ์‹์€ ๋น„์Šทํ•œ ํ˜•ํƒœ๋ฅผ ์ง€๋…”์ง€๋งŒ ๋‘๋ฒˆ์งธ ์‹์˜ ๊ฒฝ์šฐ, ๋น„์„ ํ˜•(non-linear) ํ•ญ์ด ์žˆ์–ด ํ’€๊ธฐ ์–ด๋ ต๋‹ค.

 

1) (assume velocity known)

์‹œ๊ฐ„์— ๋”ฐ๋ผ ๋ฐ€๋„(density)๊ฐ€ ์–ด๋–ป๊ฒŒ ๋ณ€ํ™”ํ•˜๋Š”์ง€ ๋‚˜ํƒ€๋‚ธ๋‹ค.

์šฐ๋ณ€์˜ ์„ธ ํ•ญ์ด ๊ฐ๊ฐ ์˜ํ–ฅ์„ ๋ฏธ์น˜๋Š” ์š”์ธ์ด ๋œ๋‹ค.

์ฒซ๋ฒˆ์งธ ํ•ญ์€ ๋ฐ€๋„๊ฐ€ ์†๋„์žฅ(velocity field)์„ ๋”ฐ๋ฅด๋Š” ๊ฒƒ์„ ๋‚˜ํƒ€๋‚ธ๋‹ค. (๋‹ด๋ฐฐ์—ฐ๊ธฐ๋ฅผ ๋ถˆ๋ฉด ์ž…๊น€ ๋ฐฉํ–ฅ์„ ๋”ฐ๋ฅด๋Š” ๊ฒƒ์ฒ˜๋Ÿผ)

๋‘๋ฒˆ์งธ ํ•ญ์€ ๋ฐ€๋„๊ฐ€ kappa์˜ ์†๋„๋กœ ํผ์ ธ๋‚˜๊ฐˆ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ๋‚˜ํƒ€๋‚ธ๋‹ค.

๋งˆ์ง€๋ง‰ ํ•ญ์ธ S๋Š” ์™ธ๋ถ€์˜ ์†Œ์Šค์— ์˜ํ•ด ์ฆ๊ฐ€ํ•ด์•ผ ํ•จ์„ ๋‚˜ํƒ€๋‚ธ๋‹ค. ์ด๋Š” user interface๋กœ๋ถ€ํ„ฐ ์ œ๊ณต๋œ๋‹ค.

 

 

2. Algorithm

 

discretize the entire space into identical voxels

์ „์ฒด ๊ณต๊ฐ„์„ ๋ณต์…€๋กœ ๋‚˜๋ˆˆ๋‹ค. (2D์—์„œ 3D๋กœ์˜ extend๋Š” another index / another for loop์œผ๋กœ ์‰ฝ๊ฒŒ ํ•ด๊ฒฐ ๊ฐ€๋Šฅ)

 

initial grid of density ๋นˆ ์ƒํƒœ๋กœ ์‹œ์ž‘ํ•จ

์„ธ ๋‹จ๊ณ„๋ฅผ ๊ฑฐ์ณ ๊ทธ๋ฆฌ๋“œ๋ฅผ ์—…๋ฐ์ดํŠธํ•จ (์„ธ ๊ฐœ์˜ ํ•ญ) : add source - diffuse - move

1) add the sources to the grid : multiply this grid by the time step and add them to the density grid

2) diffusing densities : D^n -> D^(n+1)

immediate neighbors (์ตœ์ธ์ ‘๋ณต์…€) ๋งŒ ๊ณ ๋ ค. adjacent faces๋ฅผ ํ†ตํ•ด density exchange

single face the exchange = density flux in - density flux out = kappa * timestep (neighbor - center) / h^2

ํ”Œ๋Ÿญ์Šค๊ฐ€ ๋†’๋‹ค = ํฐ time steps, large diffusion rate(kappa), small grid spacings(h)

Dn+1i,j = Dn i,j + k Dt (Dn i-1,j + Dn i+1,j + Dn i,j-1 + Dn i,j+1 - 4Dn i,j)/h2

-> ์ด์›ƒ ์…€๋ณด๋‹ค ๋” ๋จผ ๋ฒ”์œ„๋กœ ํ™•์‚ฐํ•  ๊ฒฝ์šฐ unstableํ•ด์ง€๊ธฐ ๋•Œ๋ฌธ์— ์„ฑ๋ฆฝํ•˜์ง€ ์•Š๋Š”๋‹ค.

-> implicit techniques: ์—ญ์œผ๋กœ ํ™•์‚ฐ๋˜๋Š” (-t) ์–‘์„ ์ฐพ์œผ๋ฉด ํ•ญ์ƒ ์„ฑ๋ฆฝ

Ax = b (A can be huge but is spase -> requires fast linear solver)

 

 

3) moving densities: ์†๋„๋Š” ์•ˆ๋‹ค๊ณ  ๊ฐ€์ •. ๊ฐ time step๋งˆ๋‹ค velocity field๋ฅผ ๋”ฐ๋ผ density๋ฅผ ์›€์ง์ธ๋‹ค.

transfer only between neighbors

์—ญ์‹œ๋‚˜ instability๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค. (ฮ”t|u| > h)

stable implicit method๋ฅผ ์‚ฌ์šฉํ•  ๊ฒฝ์šฐ linear system์€ non-symmetrical matrix๋ฅผ ๊ฐ€์ง„๋‹ค

KEY: particles + grids = density๋ฅผ ํŒŒํ‹ฐํด ์ƒ˜ํ”Œ๋ง ์‹œ์ผœ ํŒŒํ‹ฐํด์„ ์ด๋™์‹œํ‚จ ํ›„ ๊ฐ ํƒ€์ž„์Šคํ…๋งˆ๋‹ค ๋‹ค์‹œ ๊ทธ๋ฆฌ๋“œ ์„ผํ„ฐ๋กœ ์ด๋™ํ•œ๋‹ค.

trace particle backwards in time -> locate the four closest cells to the point -> interpolate the density from these cells -> 2๊ฐœ์˜ grid ํ•„์š” (previous time step / new interpolates values)

interpolation์„ ํ†ตํ•˜๊ธฐ ๋•Œ๋ฌธ์— density ๊ฐ’๋“ค์ด ํ•ญ์ƒ bounded๋˜์–ด์žˆ๋‹ค. -> unconditionally stable

 

----

 

Computing Velocities (Vector)

 

1st-term: non-linear "velocity should move along itself"

2nd-term: "diffusion" viscous-like fluids (์ ๋„ ํด์ˆ˜๋ก vel filed smooth) 'n' equations to solve for n-Dimension

3rd-term: force = sources in the density solver

 

1) Moving Velocity

์œ„์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋‘ ๊ฐœ์˜ grid ํ•„์š”. trace backwards

interpolate a new velocity at that location from the neighboring grid cells

"semi-Lagrangian technique"

 

 

์งˆ๋Ÿ‰๋ณด์กด Conservation of Mass = the fluid should conserve mass

Flow into cell = Flow out of the cell

Hodge decomposition : field = mass conserving + gradient field (slope function / height field / single scalar field)

๊ทธ๋ผ๋””์–ธํŠธ ํ•„๋“œ๋ฅผ ๊ตฌํ•˜๊ธฐ ์œ„ํ•ด Poisson equation์„ ํ’€์–ด์•ผ ํ•จ.

sparse symmetrical linear system (conjugate gradient, Jacobi)

 

 

3. Summary

 

UpdateVelocity(U1,U0,F,visc,dt)

AddForce(U1,U0,F,dt)

Diffuse(U0,U1,visc,dt)

Move(U1,U0,U0,dt)

ConserveMass(U1,dt)

 

Very easy to code. Only need:

Particle tracer + grid interpolator

Linear solver (FISHPAK or CG)


So in summary here is all you need to write a fluid solver: a linear solver for the diffusion and the mass conservation step and a good particle tracer and grid interpolator for the self-advection step.

 

 

Velocity field

add force

advect

diffuse due to viscous friction

force to mass

 

Scalar (density) field

add source

transport

diffuse

dissipate

 

 

 

 

 

Simple stable fluid solver

 

periodic boundaries

Fourier transform: ๊ฐ ํฌ์ธํŠธ์— ๋ฒกํ„ฐ๋ฅผ ์ง€์ •ํ•˜๋Š” ๋Œ€์‹ , ๊ฐ wave number (k,l) ์— ๋ฒกํ„ฐ๋ฅผ ์ง€์ •ํ•œ๋‹ค.

-N/2 < k, l < N/2 (N: resolution of the grid)

viscosity: low pass filter which dampens the higher frequencies. Fourier space์˜ ์ค‘์‹ฌ์—์„œ ๋ฉ€์–ด์งˆ์ˆ˜๋ก ํ™”์‚ดํ‘œ๋Š” ์ž‘์•„์ง.

velocity: wave number์— ํ•ญ์ƒ ์ˆ˜์ง. ๋”ฐ๋ผ์„œ ๋ชจ๋“  ๋ฒกํ„ฐ๊ฐ€ ์ค‘์‹ฌ์˜ ๋™์‹ฌ์›์— ์ˆ˜์งํ•œ๋‹ค.

"incompressibility equation"

 

60 lines of C code : vel (u, v) / forces (u0, v0) / visc / dt

add force : force grid * dt + vel field

self-advection : (move velocity) trace~~interpolation~

diffusion & mass conservation : transform our field to the Fourier domain