My Fluid Simulation (SPH) Sample (1) – Rigid body model + N-S model

来源:互联网 发布:linux命令打开到文件夹 编辑:程序博客网 时间:2024/04/19 08:32

I keep a strong interest for fluid simulation (specifically water simulation) and this is my first implementation for SPH (Smoothed Particle Hydrodynamics).

This post is the first part of the whole application – SPH framework.

1) Rigid Body model

Rigid body model indicates that all particles, scene walls and barriers are not  elastic – it will repel other rigid objects away when they hit it. Navier-Stokes equation will be directly applied on rigid particles, just like the real world situation : molecules cannot converge.

Collisions with walls/barriers

There are no repulsion forces. Only velocity is ‘reflected’ by the hit point normal, as light ray reflection. This works well.

Collisions with other particles

The physical model among particles is from GPU Gem 3 Chapter 29:
http://http.developer.nvidia.com/GPUGems3/gpugems3_ch29.html

But how to get a proper spring coefficients and damping coefficients is not easy, and inappropriate configuration could make your particles crazy or sluggish.

(Rookie Hint - [Collision Detection] : |currPos – wall| < epsilon is not the correct solution that suffers from precision problem in ANY case bcz. you can never predict particle velocities. The right solution is to judge whether the predicted position in next frame is beyond the wall or not)

2) Navier-Stokes model

The basic idea is still from [Muller 2003] as mentioned before. Interestingly this paper doesn’t mention SPH is based on rigid particles and this may bring confusions to SPH beginners as me.
I refered to the following link for the maths part.
http://www.rchoetzlein.com/eng/graphics/fluids.htm

3) Grid Acceleration

I split the whole scene space by about 10*10*10 grid cells, and only particles in neighboring grid cells (27 cells) are considered when calculating pressure/viscosity kernels. This improves the performance by about 100% when particles number is about 700 on CPU.


[Screenshots]

Let me show you a sequence of screenshots here:

fl_0 fl_1 fl_2 fl_3 fl_4 fl_5 fl_6 fl_7 fl_8

You can see the splashing when particles hit the ball barrier and they are ‘flowing’ on the ground – see the small waves! I think it will look much better when we have more particles like 50000.

There are total 1600 particles with FPS averaged at about 1.3 fps – I haven’t done ANY code optimizations yet.

Yes the following work is:
- Fluid surface reconstruction (it is even harder man…)
- GPU acceleration

Just wait for me…

原创粉丝点击