Fluid Simulation
for FX Artists
Wanho choi
wanochoi.com
Fluid Simulation for FX Artists
Physical Quantity
물리량 (物理量) 측정 가능한 물리적 속성 (physical property) Examples - 길이, 면적, 부피, 질량, 밀도, 온도, 압력, … - 힘, 속도, 가속도, 운동량, …wanochoi.com
Fluid Simulation for FX Artists
Scalar
vs
Vector
Scalar - 하나의 숫자로 표기가 가능한 물리량 - “크기”만을 가짐 Vector - N(=차원)개의 숫자로 표기가 가능한 물리량 - “크기”와 “방향”을 가짐wanochoi.com
Fluid Simulation for FX Artists
Scalar
vs
Vector
Scalar- 길이, 면적, 부피, 질량, 밀도, 온도, 압력, …
Vector
wanochoi.com
Fluid Simulation for FX Artists
Field (장,場)
모든 지점에서 어떠한 물리량이 존재하는 공간 Scalar field - Scalar 형식의 물리량이 정의되어 있는 공간 Vector field - Vector 형식의 물리량이 정의되어 있는 공간wanochoi.com
Fluid Simulation for FX Artists
Field (장,場)
모든 지점에서 어떠한 물리량이 존재하는 공간 Scalar field - 밀도장, 온도장, 압력장, … Vector field - 중력장, 자기장, 속도장, …wanochoi.com
Fluid Simulation for FX Artists
wanochoi.com
Fluid Simulation for FX Artists
Fields for Fluid Simulation
Gas (기체) - Velocity field - Divergence field - Pressure field - Density field - Temperature field Liquid (액체) - Velocity field - Divergence field - Pressure field
wanochoi.com
Fluid Simulation for FX Artists
Discrete Field
연속된 모든 지점에서 정의된 물리량을 이용하여 계산하는 것은 현실적으로 불가능함 - 저장공간의 한계 (memory, HDD) - 계산 시간의 한계 (computational time) 대안: 대표점들을 이용하여 sampling함wanochoi.com
Fluid Simulation for FX Artists
How to sample
Eulerian approach
(격자 기반 방식)
Lagrangian approach
(입자 기반 방식)
wanochoi.com
Fluid Simulation for FX Artists
How to sample
Eulerian approach
(격자 기반 방식)
Lagrangian approach (입자 기반 방식)
wanochoi.com
Fluid Simulation for FX Artists
Voxel, Grid (격자)
Our grid = Uniform (Cartesian regular) grid
Resolution (해상도)
Quality (accurary) vs Time & Memory
wanochoi.com
Fluid Simulation for FX Artists
Pixel
vs
Voxel
voxel = volumetrix pixel
: volume data
Greyscale image
= 2D상에 정의된 scalar field
RGB image
wanochoi.com
Fluid Simulation for FX Artists
For the Fluid Simulation
Voxelization
- Surface data → Volume data It looks like Lego.
wanochoi.com
Fluid Simulation for FX Artists
Memory Layout
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
2D scalar field defined @ node
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
wanochoi.com
Fluid Simulation for FX Artists
Memory Layout
2D vector field defined @ node
1.0 1.0 2.0 1.0 1.0 2.0 1.0 3.0 2.0 (1.0,1.0) (2.0,1.0) (1.0,2.0) (1.0,3.0) (2.0,3.0) (1.0,1.0) (1.0,1.0) (1.0,1.0) (1.0,1.0)
wanochoi.com
Fluid Simulation for FX Artists
How much memory?
2D scalar field @ cell : sizeof(float)×5×5
wanochoi.com
Fluid Simulation for FX Artists
How much memory?
2D scalar field @ cell : sizeof(float)×5×5
= 100 bytes
2D scalar field @ node : sizeof(float)×6×6
wanochoi.com
Fluid Simulation for FX Artists
How much memory?
Scalar Field(1003)
: sizeof(float)×100×100×100
wanochoi.com
Fluid Simulation for FX Artists
How much memory?
Scalar Field(1003) : sizeof(float)×100×100×100 = 4,000,000 bytes = 4 Mb Scalar Field(2563) : sizeof(float)×256×256×256 = 67,108,864 bytes = 67 Mb
wanochoi.com
Fluid Simulation for FX Artists
How much memory?
Scalar Field(1003) : sizeof(float)×100×100×100 = 4,000,000 bytes = 4 Mb Scalar Field(2563) : sizeof(float)×256×256×256 = 67,108,864 bytes = 67 Mb Scalar Field(5123) : sizeof(float)×512×512×512 = 536,870,912 bytes = 536 Mb
wanochoi.com
Fluid Simulation for FX Artists
How much memory?
Scalar Field(1003) : sizeof(float)×100×100×100 = 4,000,000 bytes = 4 Mb Scalar Field(2563) : sizeof(float)×256×256×256 = 67,108,864 bytes = 67 Mb Scalar Field(5123) : sizeof(float)×512×512×512 = 536,870,912 bytes = 536 Mb Vector Field(1003) : sizeof(float)×3×100×100×100 = 12,000,000 bytes = 12 Mb
wanochoi.com
Fluid Simulation for FX Artists
How much memory?
Scalar Field(1003) : sizeof(float)×100×100×100 = 4,000,000 bytes = 4 Mb Scalar Field(2563) : sizeof(float)×256×256×256 = 67,108,864 bytes = 67 Mb Scalar Field(5123) : sizeof(float)×512×512×512 = 536,870,912 bytes = 536 Mb Vector Field(1003) : sizeof(float)×3×100×100×100 = 12,000,000 bytes = 12 Mb Vector Field(2563) : sizeof(float)×3×256×256×256 = 201,326,592 bytes = 201 Mb
wanochoi.com
Fluid Simulation for FX Artists
How much memory?
Scalar Field(1003) : sizeof(float)×100×100×100 = 4,000,000 bytes = 4 Mb Scalar Field(2563) : sizeof(float)×256×256×256 = 67,108,864 bytes = 67 Mb Scalar Field(5123) : sizeof(float)×512×512×512 = 536,870,912 bytes = 536 Mb Vector Field(1003) : sizeof(float)×3×100×100×100 = 12,000,000 bytes = 12 Mb Vector Field(2563) : sizeof(float)×3×256×256×256 = 201,326,592 bytes = 201 Mb Vector Field(5123) : sizeof(float)×3×512×512×512 = 1,610,612,736 bytes = 1.6 Gb
wanochoi.com
Fluid Simulation for FX Artists
How to get a value
wanochoi.com
Fluid Simulation for FX Artists
How to get a value
Interpolation
wanochoi.com
Fluid Simulation for FX Artists
How to get a value
Interpolation
- 1D (linear): by length - 2D (bi-linear): by area
wanochoi.com
Fluid Simulation for FX Artists
How to get a value
Interpolation
- 1D (linear): by length - 2D (bi-linear): by area
wanochoi.com
Fluid Simulation for FX Artists
2D Density Field Visualization
0.0 0.0 0.0 0.0 0.5 0.5 0.5 0.5 1.0 1.0 1.0 1.0 0.0 0.0 0.0 1.0 0.0 1.0 0.0 1.0 0.5 0.5 0.0 0.0 A cell
wanochoi.com
Fluid Simulation for FX Artists
0.0 0.0 0.0 0.0 0.5 0.5 0.5 0.5 1.0 1.0 1.0 1.0 0.0 0.0 0.0 1.0 0.0 1.0 0.0 1.0 0.5 0.5 0.0 0.0 A cell
wanochoi.com
Fluid Simulation for FX Artists
All cells together
wanochoi.com
Fluid Simulation for FX Artists
??!?
from) http://physbam.stanford.edu/~fedkiw/
wanochoi.com
Fluid Simulation for FX Artists
Ray marching algorithm
wanochoi.com
Fluid Simulation for FX Artists
How to animate it
유체의 유동(fluid flow)에 의해서 - Velocity field
wanochoi.com
Fluid Simulation for FX Artists
How to animate it
유체의 유동(fluid flow)에 의해서 - Velocity field Advection - 어떠한 물리량이 유체의 속도장에 의해서 이동하는 현상 (밀도, 온도, 속도, …)wanochoi.com
Fluid Simulation for FX Artists
Density Field Advection의 예
wanochoi.com
Fluid Simulation for FX Artists
(n+1) frame
wanochoi.com
Fluid Simulation for FX Artists
(n+2) frame
wanochoi.com
Fluid Simulation for FX Artists
(n+3) frame
wanochoi.com
Fluid Simulation for FX Artists
(n+4) frame
wanochoi.com
Fluid Simulation for FX Artists
Lagrangian Advection
wanochoi.com
Fluid Simulation for FX Artists
Lagrangian Advection
0.5
wanochoi.com
Fluid Simulation for FX Artists
Lagrangian Advection
n frame
0.5
wanochoi.com
Fluid Simulation for FX Artists
Lagrangian Advection
0.5
Next frame
wanochoi.com
Fluid Simulation for FX Artists
Lagrangian Advection
0.5
And next frame
wanochoi.com
Fluid Simulation for FX Artists
Eulerian Advection
Velocity field @ n frame
△x = 6.0 △t = 2.0 (2,2) (2,2) (2,2) (2,2) (2,2) (2,2) (2,2) (2,2) (2,2)
wanochoi.com
Fluid Simulation for FX Artists
Eulerian Advection
0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 △x = 6.0 △t = 2.0wanochoi.com
Fluid Simulation for FX Artists
Eulerian Advection
? ? ? ? ? ? ? ? ? △x = 6.0 △t = 2.0wanochoi.com
Fluid Simulation for FX Artists
Eulerian Advection
0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 △x = 6.0 △t = 2.0wanochoi.com
Fluid Simulation for FX Artists
Eulerian Advection
0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 △x = 6.0 △t = 2.0Nodal velocity of (1,1) node @ n frame
wanochoi.com
Fluid Simulation for FX Artists
Eulerian Advection
0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 △x = 6.0 △t = 2.0 Streamline (2,2)wanochoi.com
Fluid Simulation for FX Artists
Eulerian Advection
0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 △x = 6.0 △t = 2.0 Back-tracking by △t (2,2)wanochoi.com
Fluid Simulation for FX Artists
Eulerian Advection
0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 △x = 6.0 △t = 2.0Get a value @ back-tracked position
wanochoi.com
Fluid Simulation for FX Artists
Eulerian Advection
0.0 0.0 0.0
0.0 0.0
1.0 0.0 0.0
Update nodal density of (1,1) node
wanochoi.com
Fluid Simulation for FX Artists
Eulerian Advection
△x = 6.0 △t = 2.0
Same procedure for the other nodes
1.0 0.444 0.0 0.0 0.0 0.0 0.0 0.667 0.667
wanochoi.com
Fluid Simulation for FX Artists
Eulerian Advection
△x = 6.0 △t = 2.0 Visualization (rendering) 1.0 0.444 0.0 0.0 0.0 0.0 0.0 0.667 0.667wanochoi.com
Fluid Simulation for FX Artists
Eulerian Advection
It’s animated!
(N+1) frame N frame
wanochoi.com
Fluid Simulation for FX Artists
Eulerian Advection
More plausible example
wanochoi.com
Fluid Simulation for FX Artists
Eulerian Advection
Field 당 2개의 저장 공간이 필요함
- Previous (=old) field - Current (=new) field
ρn+1 = Advect( Vn, ρn )
wanochoi.com
Fluid Simulation for FX Artists
Unconditionally stable Numerical diffusion
Eulerian Advection
wanochoi.com
Fluid Simulation for FX Artists
Semi-Lagrangian Advection
Actually,
wanochoi.com
Fluid Simulation for FX Artists
v
Semi-Lagrangian Advection
Actually,
wanochoi.com
Fluid Simulation for FX Artists
v
dt × v
Semi-Lagrangian Advection
Actually,
wanochoi.com
Fluid Simulation for FX Artists
v
dt × v
Semi-Lagrangian Advection
Actually,
wanochoi.com
Fluid Simulation for FX Artists
Semi-Lagrangian Advection
More accurate with sub-time step
v
wanochoi.com
Fluid Simulation for FX Artists
More accurate with sub-time step
v
dt/3 × v v1
wanochoi.com
Fluid Simulation for FX Artists
More accurate with sub-time step
v
dt/3 × v dt/3 × v1
wanochoi.com
Fluid Simulation for FX Artists
More accurate with sub-time step
v
dt/3 × v dt/3 × v1 v2
wanochoi.com
Fluid Simulation for FX Artists
More accurate with sub-time step
v
dt/3 × v dt/3 × v1
dt/3 × v2
wanochoi.com
Fluid Simulation for FX Artists
More accurate with sub-time step
v
dt/3 × v dt/3 × v1
dt/3 × v2
wanochoi.com
Fluid Simulation for FX Artists
Time Step Size
△t ↓
- Accuracy ↑, but Computations ↑
△t ↑
wanochoi.com
Fluid Simulation for FX Artists
CFL condition
Courant-Friedrichs-Lewy
(CFL>1) is unphysical.
wanochoi.com
Fluid Simulation for FX Artists
Adaptive Time Step
0 frame 4 sub-steps 0000.tif 1 frame 3 sub-steps 0001.tif 2 frame 2 sub-steps 0002.tif 3 frame 2 sub-steps 0003.tif 4 frame 3 sub-steps 0004.tif 5 frame 0005.tif 0000.den 0001.den 0002.den 0003.den 0004.den 0005.den
Cache
wanochoi.com
Fluid Simulation for FX Artists
Velocity Advection
wanochoi.com
Fluid Simulation for FX Artists
What makes fluid flows
Incompressibility (비압축성, 非壓縮性)
Conservation of mass (volume) : (input) = (output)
wanochoi.com
Fluid Simulation for FX Artists
What makes fluid flows
Incompressibility (비압축성, 非壓縮性)
Conservation of mass (volume) : (input) = (output)
wanochoi.com
Fluid Simulation for FX Artists
What makes fluid flows
Incompressibility (비압축성, 非壓縮性)
Conservation of mass (volume) : (input) = (output)
wanochoi.com
Fluid Simulation for FX Artists
What makes fluid flows
Incompressibility (비압축성, 非壓縮性)
Conservation of mass (volume) : (input) = (output)
- 모든 cell에서 입,출력 양의 합이 0이어야함!
wanochoi.com
Fluid Simulation for FX Artists
What makes fluid flows
Incompressibility (비압축성, 非壓縮性)
Conservation of mass (volume) : (input) = (output)
- 모든 cell에서 입,출력 양의 합이 0이어야함!
wanochoi.com
Fluid Simulation for FX Artists
What makes fluid flows
Incompressibility (비압축성, 非壓縮性)
Conservation of mass (volume) : (input) = (output)
- 모든 cell에서 입,출력 양의 합이 0이어야함!
wanochoi.com
Fluid Simulation for FX Artists
What makes fluid flows
Incompressibility (비압축성, 非壓縮性)
Conservation of mass (volume) : (input) = (output) - 모든 cell에서 입,출력 양의 합이 0이어야함! 2D 0.5 0.5 1.1 2.1
wanochoi.com
Fluid Simulation for FX Artists
What makes fluid flows
Incompressibility (비압축성, 非壓縮性)
Conservation of mass (volume) : (input) = (output)
wanochoi.com
Fluid Simulation for FX Artists
What makes fluid flows
Incompressibility (비압축성, 非壓縮性)
Conservation of mass (volume) : (input) = (output)
wanochoi.com
Fluid Simulation for FX Artists
What makes fluid flows
Incompressibility (비압축성, 非壓縮性)
Conservation of mass (volume) : (input) = (output)
wanochoi.com
Fluid Simulation for FX Artists
Pressure Projection
A velocity field decomposition
wanochoi.com
Fluid Simulation for FX Artists
Pressure Projection
Helmholtz-Hodge decomposition
from) Real-Time Fluid Dynamics for Games (by Jos Stam)
divergence-free vel. field (unknown) divergence-free vel. field (unknown) messed-up vel. field (given) messed-up vel. field (given)
wanochoi.com
Fluid Simulation for FX Artists
Simulation Update
messed-upwanochoi.com
Fluid Simulation for FX Artists
Simulation Update
messed-upvel. field
pressure projection
wanochoi.com
Fluid Simulation for FX Artists
Simulation Update
divergence-free vel. field messed-up vel. field pressure projectionwanochoi.com
Fluid Simulation for FX Artists
Simulation Update
divergence-free vel. field messed-up vel. field pressure projection advectionwanochoi.com
Fluid Simulation for FX Artists
Simulation Update
divergence-free vel. field messed-up vel. field pressure projection advection adding external forceswanochoi.com
Fluid Simulation for FX Artists
Simulation Update
divergence-free vel. field messed-up vel. field pressure projection advection adding external forcesone step
wanochoi.com
Fluid Simulation for FX Artists
Forces Swirls
wanochoi.com
Fluid Simulation for FX Artists
Forces Swirls
wanochoi.com
Fluid Simulation for FX Artists
Swirly Motion
wanochoi.com
Fluid Simulation for FX Artists
Swirly Motion
wanochoi.com
Fluid Simulation for FX Artists
Swirly Motion
wanochoi.com
Fluid Simulation for FX Artists
Smoke Simulation
Add external forces
wanochoi.com
Fluid Simulation for FX Artists
Smoke Simulation
Add external forces
- Gravity, buoyancy, …
Make incompressible flow
wanochoi.com
Fluid Simulation for FX Artists
Smoke Simulation
Add external forces
- Gravity, buoyancy, …
Make incompressible flow
- Very heavy computation
Advect
wanochoi.com
Fluid Simulation for FX Artists
Smoke Simulation
Diffusion(확산,擴散)이 필요할 때도 있음 - 분자간의 운동에서 기인함
- Viscosity(점성,粘性)에 비례함
wanochoi.com
Fluid Simulation for FX Artists
Now, can you make it?
http://users.skynet.be/fquake/
wanochoi.com
Fluid Simulation for FX Artists