Computational Fluid Dynamics
Real-time animation of low-Reynolds-number flowusing Smoothed Particle Hydrodynamics
presentation by薛德明
Dominik SeifertB97902122
Visualization of my resultshttp://csie.ntu.edu.tw/~b97122/archive/fluid_dynamics/capture.mp4
My codehttp://csie.ntu.edu.tw/~b97122/archive/fluid_dynamics/OpenTissue_backup.rar
My motivation: From Dusthttp://www.youtube.com/watch?v=CfKQCAxizrA
The frameworkOpenTissueOpenTissue is an open source simulation
framework with a simple, working SPH implementation
I added some features to their implementation
Their original implementation is described in this 88 page document:“Lagrangian Fluid Dynamics Using Smoothed
Particle Hydrodynamics”
Smoothed Particle HydrodynamicsQuick reviewNote: SPH particles are not actual particles!
They are really fluid samples of constant massParticles are placed inside a container to
represent a fluidEvery particle is then assigned a set of initial
propertiesAfter every time step (a few milliseconds),
update the properties of all particlesUse interpolation methods to solve the Navier-
Stokes equation to find force contributions, then integrate to find new velocity and position
SPHParticle PropertiesSupport Radius (constant)
Minimum interaction distance between particlesMass (constant; ensures Conservation of Mass
explicitly)Position (varying)Surface normal (varying)Velocity (varying)Acceleration (varying)Sum of external forces (varying)Density (varying due to constant mass and varying
volume)Pressure (varying)Viscosity (constant)
Smoothed Particle HydrodynamicsSolver pseudocode
Smoothed Particle HydrodynamicsThe pressure problemFluids cannot be accurately incompressiblePressure value approximated by Ideal Gas Law:
k called “gas-stiffness”Entails assumptions of gas in steady stateDoes not consider weight pressureCauses “pulsing” because of lagging interplay between
gravity and pressure forceLarge gas-stiffness can reduce/eliminate the lag and the
pulsingAlternatively, take density to the power of heat capacity
ratioBut high pressure requires a smaller time-step and thus
makes the simulation more expensive
pV = nRT ⇒ p=( k ' )V = k ρ
My contributions IFluid-fluid interactionsIn OpenTissue, a system can be comprised of only a
single fluidI changed the code to support more than one fluid at a
timeThe math and physics are mostly the same, except for:
ViscosityKernel support radius
Still missing:Surface tension interfaces between fluids of different polarity
But I still spent three days on changing the framework due to heavily templated C++ code
My contributions IIFluid-solid interactionsIn OpenTissue only supports static (immovable)
objectsI wanted to add the ability to add objects that
interact with the fluid, objects that can float, sink etc.
Solid dynamics are very complicated! What are…Tensile Strength? Compressive Strength? Young’s modulus?
I came up with an intuitive but not quite correct approach
My contributions IIRestoring forcePlace an invisible spring between every
two particles that are close to each other initially
Store the initial distance between every two “neighboring” particles
Add a new spring force component that contributes:
k * abs(current_distance – original_distance)
Works for very few particles, but not for many
My contributions IIIControl Volumes - OverviewControl volumes are used in the analysis of
fluid flow phenomenaThey are used to represent the conservation
laws in integral form Conservation of mass over a given (control)
volume c.v. with surface area c.s.:
= density; u = velocity; n = surface normal
0= ddt ∫c.v.
ρ dV + ∮c.s.
ρ(u⋅n̂ )dA
My contributions IIIControl Volumes in SPHVolume integrators are easy: Simply
accumulate all contributions of all particles in volume
Area integrators are trickierTime derivative can be obtained via difference
quotients: for any property Fluid properties at some point in the field
can be obtained by interpolation
d ηd t
≈Δ ηΔ t
=ηT0+ 1−ηT0
Δ tη
My contributions IIIField evaluator function
ValueType evaluate(vector pos, real radius, ParticleProperty A): ParticleContainer particles; search(pos, radius, particles);
ValueType res = ValueType(0); foreach particle p in particles: real W = DefaultKernel.evaluate(pos - p.position); res += (p.*A)() * p.mass/p.density * W;
return res;
This required me to change the spatial partioning grid to support queries at arbitrary locations
After that, I only had to implement the famous SPH field evaluation template for some property A:
Translates to:
A( x)=∑j∈ΩA jV jW (x− x j , h)=∑
j∈ΩA jm j
ρ j
W (x−x j , h)
My contributions IIIArea Integrator
Goal: Find average of property at discretely sampled points
I went for an evenly distributing samplerAliasing is not an issue, don’t need random
sampling# of samples ns should be proportional to # of
particles that can fit into the surface:
So we get:
D f̄ =∫D
f (A)dA
∮c.s.
ρ(u⋅n̂)dA≈ AC1ns
∑j
ns
q j=ACns
∑j
ns
ρ j(u j⋅n̂ j)
ns=ceil(ACA p)
My contributions IIIDisk Integrator
real integrateDiskXZ(real ns, vector2 p_center, real r, field_evalutor f):real q_total = 0real ds = sqrt(PI / ns) * r //int samples_in_diameter = sqrt(ns * 4/PI) //vector2 min = p_center – rfor (int i = 0; i < samples_in_diameter; i++)for (int j = 0; j < samples_in_diameter; j++)vector2 pos = (min.x + i * ds, min.z + j * ds)if (length(pos - p_center) > r) continueq_total += f(pos)
return q_total / ns
In this approach, every kind of surface needs their own integrator
I only have to consider disks in my pipe flow exampleThe disk integrator iterates over the cells of an
imaginary grid that we lay over the disk to find the average of fluid property f
AC=π4
(2 r )2= ns⋅ds2⇒ 2 rds
=√4π ns
My contributions IIIArea Integrator - ConsiderationsNo need to sample over an already sampled set
Can use spatial selection instead:Find all particles in distance d from the surfaceUse scaled smoothing kernel to add up contributions
I was not quite sure how to mathematically scale the kernel, so I went for the sampling approach
I also used the integrator to place the cylindrically-shaped fluid inside the pipe
My contributions IIIConservation of mass
M T0+ 1−M T0
Δ t+ACns
∑j
ns
ρ j(u j⋅n̂ j)
0= ddt ∫c.v.
ρ dV + ∮c.s.
ρ(u⋅n̂ )dAThe integral form:
Becomes:
The first term is the time derivative of Mass inside the c.v.
The second term is the mass flux through the c.v.’s surface area
Particle boundary deficiency,Holes in the fluid andControl Volume - CorrectnessBoundary deficiency:
Since atmosphere and structure are not represented in this model, computations have to cope with a pseudo-vacuum (真空 )
Governing equations are adjusted to cope with the deficiencye.g. Level set function for surface tension considers:
Inside fluid = 1 Outside fluid = 0
C.v.’s must always be completely filled!Fluid volume is never correct which causes “holes” in
the fluid Think: What is the space between the particles/samples? C.v. computations can also never be 100% correct!
Bibliography[1] OpenTissue @ http://www.opentissue.org/
“OpenTissue is a collection of generic algorithms and data structures for rapid development of interactive modeling and simulation.”
[2] Smoothed Particle Hydrodynamics – A Meshfree Particle Method (book)
[3] Lagrangian Fluid Dynamics Using Smoothed Particle Hydrodynamics
[4] Particle-Based Fluid-Fluid Interaction
SummaryGiven high enough gas stiffness, SPH model is OK to
simulate visually appealing real-time flow but is quite inaccurate
OpenTissue SPH implementation is not very mature, lacks a lot of features
I really miss:Accurate pressure valuesCorrect fluid-solid interactionArbitrary geometry
I still cannot create real-time interactive applications involving fluid flow but it was still an insightful endeavour.
What’s next?Surface rendering until next weekThen choose one from the list…
Improve SPH implementation Add generic surfaces (currently only supports implicit primitives) Make it adaptive (choose sample size dynamically) Learn solid dynamics and work on Fluid-Structure interaction
More work on surface rendering Optimized OpenGL/DX/XNA implementation that runs on the GPU
Work on Computational Galactic Dynamics (計算星系動力學 ) with professor 闕志鴻 from the Institute of Astronomy (天文所 ) Simulation of dark matter & fluid during galaxy formation
Work on level sets and the level set method in CFD with professor Yi-Ju 周 from the Institute of Applied Mechanics (應力所 )