Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

PBF Sig Preprint

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

To appear in ACM TOG 32(4).

Position Based Fluids


Miles Macklin ∗ Matthias Müller †

NVIDIA

Abstract
In fluid simulation, enforcing incompressibility is crucial for real-
ism; it is also computationally expensive. Recent work has im-
proved efficiency, but still requires time-steps that are impractical
for real-time applications. In this work we present an iterative den-
sity solver integrated into the Position Based Dynamics framework
(PBD). By formulating and solving a set of positional constraints
that enforce constant density, our method allows similar incom-
pressibility and convergence to modern smoothed particle hydro-
dynamic (SPH) solvers, but inherits the stability of the geometric,
position based dynamics method, allowing large time steps suit- (a) Real-time rendered fluid surface using ellipsoid splatting
able for real-time applications. We incorporate an artificial pressure
term that improves particle distribution, creates surface tension, and
lowers the neighborhood requirements of traditional SPH. Finally,
we address the issue of energy loss by applying vorticity confine-
ment as a velocity post process.

CR Categories: I.3.5 [Computer Graphics]: Computational


Geometry and Object Modeling—Physically based modeling I.3.7
[Computer Graphics]: Three-Dimensional Graphics and Realism—
Animation;

Keywords: fluid simulation, SPH, PCISPH, constraint fluids, po-


(b) Underlying simulation particles
sition based dynamics
Figure 1: Bunny taking a bath. 128k particles, 2 sub-steps, 3 den-
1 Introduction sity iterations per frame, average simulation time per frame 10ms.

Fluids, in particular liquids such as water, are responsible for many


visually rich phenomena, and simulating them has been an area of For interactive environments, robustness is a key issue: the simula-
long-standing interest and challenge in computer graphics. There tion must handle degenerate situations gracefully. SPH algorithms
are a variety of techniques available, but here we focus on particle often become unstable if particles do not have enough neighbors for
methods, which are popular for their simplicity and flexibility. accurate density estimates. The typical solution is to try to avoid
Smoothed Particle Hydrodynamics (SPH) [Monaghan 1992][1994] these situations by taking sufficiently small time steps, or by using
is a well known particle based method for fluid simulation. It sufficiently many particles, at the cost of increased computation.
has many attractive properties: mass-conservation, Lagrangian dis-
In this paper, we show how incompressible flow can be simulated
cretization (particularly useful in games where the simulation do-
inside the Position Based Dynamics (PBD) framework [Müller
main is not necessarily known in advance), and conceptual simplic-
et al. 2007]. We choose PBD for its unconditionally stable time
ity. However, SPH is sensitive to density fluctuations from neigh-
integration and robustness, which has made it popular with game
borhood deficiencies, and enforcing incompressibility is costly due
developers and film makers. By addressing the issue of particle
to the unstructured nature of the model. Recent work has im-
deficiency at free surfaces, and handling large density errors, our
proved efficiency by an order of magnitude [Solenthaler and Pa-
method allows users to trade incompressibility for performance,
jarola 2009], but small time steps remain a requirement, limiting
while remaining stable.
real-time applications.
∗ e-mail:mmacklin@nvidia.com
2 Related Work
† e-mail:matthiasm@nvidia.com

Müller [2003] showed that SPH can be used for interactive fluid
simulation with viscosity and surface tension, by using a low stiff-
ness equation of state (EOS). However to maintain incompressibil-
ity, standard SPH or weakly compressible SPH (WCSPH) [Becker
and Teschner 2007] require stiff equations, resulting in large forces
that limit the time-step size. Predictive-corrective incompressible
SPH (PCISPH) [Solenthaler and Pajarola 2009] relaxes this time-
step restriction by using an iterative Jacobi-style method that accu-
mulates pressure changes and applies forces until convergence. It
has the advantage of not requiring a user-specified stiffness value
and of amortizing the cost of neighbor finding over many density

1
To appear in ACM TOG 32(4).

corrections. Algorithm 1 Simulation Loop


Bodin et al [2012] achieve uniform density fluid by posing incom- 1: for all particles i do
pressibility as a system of velocity constraints. They construct a 2: apply forces vi ⇐ vi + ∆tfext (xi )
linear complementarity problem using linearized constraint func- 3: predict position x∗i ⇐ xi + ∆tvi
tions, which are solved using Gauss-Seidel iteration. In contrast, 4: end for
our method (and PCISPH) attempts to solve the non-linear problem 5: for all particles i do
by operating on particles directly, and re-evaluating constraint error 6: find neighboring particles Ni (x∗i )
and gradients each Jacobi iteration. 7: end for
8: while iter < solverIterations do
Hybrid methods, such as Fluid Implicit-Particle (FLIP) [Brackbill 9: for all particles i do
and Ruppel 1986] use a grid for the pressure solve and transfer ve- 10: calculate λi
locity changes back to particles. FLIP was later extended to in- 11: end for
compressible flow with free surfaces by Zhu and Bridson [2005]. 12: for all particles i do
Raveendran et al. [2011] use a coarse grid to solve for an approx- 13: calculate ∆pi
imately divergence free velocity field before an adaptive SPH up- 14: perform collision detection and response
date. 15: end for
16: for all particles i do
Clavet et al. [2005] also use a position based approach to simu- 17: update position x∗i ⇐ x∗i + ∆pi
late viscoelastic fluids. However, because the time step appears in 18: end for
various places of their position projections, their approach is only 19: end while
conditionally stable as in regular explicit integration. 20: for all particles i do
1
x∗i − xi

Position Based Dynamics [Müller et al. 2007] provides a method 21: update velocity vi ⇐ ∆t
for simulating dynamics in games based on Verlet integration. It 22: apply vorticity confinement and XSPH viscosity
solves a system of non-linear constraints using Gauss-Seidel itera- 23: update position xi ⇐ x∗i
tion by updating particle positions directly. By eschewing forces, 24: end for
and deriving momentum changes implicitly from the position up-
dates, the typical instabilities associated with explicit methods are
avoided. [Monaghan 1992] gives the SPH recipe for the gradient of a func-
tion defined on the particles. Applying this, the gradient of the
constraint function (1) with respect to a particle k is given by:
3 Enforcing Incompressibility
1
∇pk Ci = ∇pk W (pi − p j , h) (7)
To enforce constant density we solve a system of non-linear con- ρ0 ∑
j
straints, with one constraint per-particle. Each constraint is a func-
tion of the particle’s position and the positions of its neighbors, Which has two different cases based on whether k is a neighboring
which we refer to collectively as p1 , · · · , pn . Following [Bodin et al. particle or not:
2012] the density constraint on the ith particle is defined using an 
∇pk W (pi − p j , h) if k = i
equation of state: 1 ∑ j
∇pk Ci = (8)
ρ0 
ρi −∇pk W (pi − p j , h) if k = j
Ci (p1 , ..., pn ) = − 1, (1)
ρ0
Plugging this into (6) and solving for λ gives
where ρ0 is the rest density and ρi is given by the standard SPH
density estimator:
Ci (p1 , ..., pn )
λi = − 2
(9)
ρi = ∑ m jW (pi − p j , h). (2) ∑k ∇pk Ci
j
which is the same for all particles in the constraint.
We treat all particles as having equal mass and will drop this term
from subsequent equations. In our implementation we use the Because the constraint function (1) is non-linear, with a vanish-
Poly6 kernel for density estimation, and the Spiky kernel for gradi- ing gradient at the smoothing kernel boundary, the denominator in
ent calculation, as in [Müller et al. 2003]. equation (9) causes instability when particles are close to separat-
ing. As in PCISPH this can be solved by pre-computing a conser-
Now we give some background on the position based dynamics vative corrective scale based on a reference particle configuration
method and then show how to incorporate our density constraint. with a filled neighborhood.
PBD aims to find a particle position correction ∆p that satisfies the
constraint: Alternatively, constraint force mixing (CFM) [Smith 2006] can be
used to regularize the constraint. The idea behind CFM is to soften
C(p + ∆p) = 0 (3)
the constraint by mixing in some of the constraint force back into
the constraint function, in the case of PBD this changes (6) to
This is found by a series of Newton steps along the constraint gra-
dient: C(p + ∆p) ≈ C(p) + ∇CT ∇Cλ + ελ = 0. (10)
∆p ≈ ∇C(p)λ (4)
Where ε is a user specified relaxation parameter that is constant
over the simulation. The scaling factor is now
C(p + ∆p) ≈ C(p) + ∇CT ∆p = 0 (5)
Ci (p1 , ..., pn )
T
≈ C(p) + ∇C ∇Cλ = 0. (6) λi = − 2
, (11)
∑k ∇pk Ci + ε

2
To appear in ACM TOG 32(4).

and the total position update ∆pi including corrections from neigh- This purely repulsive term keeps particle density slightly lower than
bor particles density constraint (λ j ) is the rest density. Consequently, particles pull their neighbors in-
wards causing surface tension-like effects similar to the ones de-
1  scribed in [Clavet et al. 2005]. We note that this effect is a non-
∆pi = λi + λ j ∇W (pi − p j , h). (12)
ρ0 ∑
j physical artifact of the anti-clustering term and requires a trade off
between clustering errors and surface tension strength.
Without clustering problems our algorithm is free from the rule of
thumb that in SPH a particle must have 30-40 neighbors at all times,
improving efficiency.

5 Vorticity Confinement and Viscosity


Position based methods introduce additional damping which is of-
ten undesirable. Fedkiw et al. [2001] introduced vorticity confine-
ment to computer graphics to address numerical dissipation in the
simulation of smoke, which was later extended to energy conserv-
ing fluid simulation in [Lentine et al. 2011]. In Bubbles Alive, Hong
et al. [2008] show how vorticity confinement can be used in a hy-
brid setup where by vorticity is transferred from a grid to the SPH
particles to introduce turbulent motion.
We optionally use vorticity confinement to replace lost energy (Fig-
ure 5). This requires first calculating the vorticity at a particle’s lo-
cation, for which we use the estimator given in [Monaghan 1992]:

ω i = ∇ × v = ∑ vi j × ∇p j W (pi − p j , h) (15)
j

where vi j = v j − vi . Once we have the vorticity we calculate a


η
corrective force using the location vector N = |η| with η = ∇|ω|i

vorticity
fi = ε (N × ω i ) . (16)

Figure 2: Armadillo Splash, Top: particle clumping due to neigh-


bor deficiencies, Bottom: with artificial pressure term, note the im- Unlike [Hong et al. 2008] we do not use normalized ω as this would
proved particle distribution and surface tension. increase vorticity indiscriminately. Instead we use the unnormal-
ized value, which only adds vorticity where it already exists, as in
[Fedkiw et al. 2001].

4 Tensile Instability In addition, we apply XSPH viscosity [Schechter and Bridson


2012], which is important for coherent motion. The parameter c
A common problem in SPH simulations is particle clustering or is typically chosen to be 0.01 in our simulations:
clumping caused by negative pressures when a particle has only a
few neighbors and is unable to satisfy the rest density (Figure 2). vnew
i = vi + c ∑ vi j ·W (pi − p j , h) (17)
j
This may be avoided by clamping pressures to be non-negative, but
at the cost of reduced particle cohesion. Clavet et al. [2005] use
a second ’near pressure’ term, while Alduan and Otaduy [2011]
use discrete element (DEM) forces [Bell et al. 2005] to push apart 6 Algorithm
particles closer than half the smoothing kernel width. Schechter
and Bridson [2012] place ghost particles around the free surface to Our simulation loop is outlined in Algorithm 1. It is similar to
ensure consistent density estimates. the original Position Based Dynamics update except that each con-
straint is solved independently in a Jacobi fashion, rather than
We follow the approach of [Monaghan 2000] which adds an arti- through sequential Gauss-Seidel iteration. We perform collision de-
ficial pressure specified in terms of the smoothing kernel itself as tection against solids as part of the constraint solving loop.
W (pi − p j , h) n
 
We recompute particle neighborhoods once per-step and re-
scorr = −k , (13)
W (∆q, h) calculate distance and constraint values each solver iteration. This
optimization can lead to density underestimates, for example if a
where ∆q is a point some fixed distance inside the smoothing kernel particle separates from the initial set of neighbors. In PCISPH this
radius and k is a small positive constant. |∆q| = 0.1h · · · 0.3h, k = can cause serious problems, once a particle becomes isolated, each
0.1 and n = 4 work well. We then include this term in the particle iteration makes its pressure increasingly negative. If it then comes
position update as back into contact on a subsequent iteration, large erroneous pres-
sure forces are applied. Our algorithm considers only the current
1  particle positions (not accumulated pressure), so this does not oc-
∆pi = ∑ λi + λ j + scorr ∇W (pi − p j , h). (14)
ρ0 j cur.

3
To appear in ACM TOG 32(4).

Because we are interested in real-time applications with predictable


performance, we set the number of iterations to a fixed value (typ-
ically 2-4) rather than solving for a specific error threshold. How-
ever, we also show the convergence of our method over multiple
iterations in Figure 6.
We implemented our algorithm in CUDA and ran our simulations
on an NVIDIA GTX 680. Each stage of our algorithm is fully par-
allelizable so we are able to take advantage of parallel architec-
tures such as GPUs. For neighbor finding we use the method of
[Green 2008]. We also perform particle-solid collision detection on
the GPU where we use signed distance fields [Bridson et al. 2006]
stored as volume textures.

9 Limitations and Future Work


Figure 3: Dropping a liquid bunny into a pool of water (80k parti- Occasionally particle stacking along boundaries can occur due to
cles). incorrect density estimates when particles are in contact with solids.
Recent work by Akinci et al. [2012] would help address this issue.
Jacobi methods only propagate information (in our case position
corrections) between a particle’s immediate neighbors each itera-
tion. This can lead to slow convergence as the number of particles
increases. More sophisticated parallel solvers such as red-black or
multi-scale schemes such as [Solenthaler and Gross 2011] should
help improve convergence speed.
Because our artificial pressure term is dependent on the spatial res-
olution and time-step it can be difficult to adjust parameters inde-
pendently. Decoupling these parameters and making anti-clustering
independent from surface tension effects would be important future
(a) Average Density (b) Maximum Density work.

Figure 4: Density over the bunny drop simulation. Our algorithm Position based dynamics is popular for simulating deformable ob-
maintains compressibility similar to PCISPH at time-steps more jects such as cloth. We have prototyped two-way interaction be-
than twice as large. Color key: Blue, rest density. Red, PCISPH. tween position based cloth and fluid with promising results.
Green, our method.
Table 1: Performance results for several examples. A frame time of
16ms is used in all cases.
7 Rendering
Scene particles steps/frame iters/step time/step [ms]

Real-time fluid surfacing is performed using a GPU based ellipsoid Armadillo Splash 128k 2 3 4.2
splatting technique. Particle anisotropy is first computed using the Dam Break 100k 4 3 4.3
method of Yu and Turk [2013], and the surface is reconstructed Bunny Drop 80k 4 10 7.8
using a method based on the screen-space filtering presented in
[van der Laan et al. 2009].
Table 2: Breakdown of a frame (percentages) for two examples.
Constraint Solve includes collision handling with static objects, and
8 Results Velocity Update includes vorticity confinement and viscosity calcu-
lation.
We tested our algorithm by dropping a liquid bunny into a pool of
water (Figure 3) and compared our results with a PCISPH imple- Step Armadillo Splash Dam Break
mentation. For this scenario PCISPH is not stable with less than Integrate 1 1
10 sub-steps per frame (∆t = 0.0016s). In contrast our algorithm is Create Hash Grid 8 6
stable with a single step (∆t = 0.016s). Detect Neighbors 28 28
Constraint Solve 38 51
To compare compressibility we run PCISPH with 10 sub-steps and Velocity Update 25 14
4 pressure iterations, and our algorithm with 4 sub-steps and 10
iterations per sub-step, so that each performs 40 pressure iterations
per-frame in total. The point of this comparison is to show that
our method can achieve comparable results with larger time-steps, 10 Acknowledgments
allowing us to amortize the per-step costs of grid construction and
neighbor finding over more density iterations. The authors would like to thank NVIDIA for supporting our re-
search, especially Nuttapong Chentanez, Tae-Yong Kim and Simon
Our results are in good accordance, and a plot of density over the Schirm for their valuable feedback, Simon Green for his rendering
simulation confirms that the level of compression is similar despite work, and Adam Moravanszky and Christian Sigg for their encour-
the larger time-step for our method (Figure 4). Tables 1 and 2 sum- agement. We also wish to thank the anonymous reviewers for their
marize the performance of our algorithm in a selection of scenarios. generous comments and suggestions. The Bunny and Armadillo

4
To appear in ACM TOG 32(4).

models are used courtesy of the Stanford Computer Graphics Lab- muller-fischer presenation videos are available from the citation
oratory. page. In ACM SIGGRAPH 2006 Courses, ACM, New York, NY,
USA, SIGGRAPH ’06, 1–87.
C LAVET, S., B EAUDOIN , P., AND P OULIN , P. 2005. Particle-
based viscoelastic fluid simulation. In Proceedings of the 2005
ACM SIGGRAPH/Eurographics symposium on Computer ani-
mation, ACM, New York, NY, USA, SCA ’05, 219–228.
F EDKIW, R., S TAM , J., AND J ENSEN , H. W. 2001. Visual sim-
ulation of smoke. In Proceedings of the 28th annual conference
on Computer graphics and interactive techniques, ACM, New
York, NY, USA, SIGGRAPH ’01, 15–22.
G REEN , S. 2008. Cuda particles. nVidia Whitepaper 2, 3.2, 1.
H ONG , J.-M., L EE , H.-Y., YOON , J.-C., AND K IM , C.-H. 2008.
Figure 5: Dam break scenario at t=6.0, Left: vorticity confine- Bubbles alive. In ACM SIGGRAPH 2008 papers, ACM, New
ment disabled. Right: vorticity confinement enabled, note the visi- York, NY, USA, SIGGRAPH ’08, 48:1–48:4.
bly higher splash.
L ENTINE , M., A ANJANEYA , M., AND F EDKIW, R. 2011. Mass
and momentum conservation for fluid simulation. In Proceed-
ings of the 2011 ACM SIGGRAPH/Eurographics Symposium on
Computer Animation, ACM, New York, NY, USA, SCA ’11, 91–
100.
M ONAGHAN , J. J. 1992. Smoothed particle hydrodynamics. An-
nual Review of Astronomy and Astrophysics 30, 1, 543–574.
M ONAGHAN , J. J. 1994. Simulating free surface flows with sph.
J. Comput. Phys. 110, 2 (Feb.), 399–406.
M ONAGHAN , J. J. 2000. Sph without a tensile instability. J.
Comput. Phys. 159, 2 (Apr.), 290–311.
M ÜLLER , M., C HARYPAR , D., AND G ROSS , M. 2003. Particle-
based fluid simulation for interactive applications. In Proceed-
Figure 6: Convergence of our method over multiple iterations at ings of the 2003 ACM SIGGRAPH/Eurographics symposium on
t = 1.0 in the dam break scenario. Computer animation, Eurographics Association, Aire-la-Ville,
Switzerland, Switzerland, SCA ’03, 154–159.
References M ÜLLER , M., H EIDELBERGER , B., H ENNIX , M., AND R AT-
CLIFF , J. 2007. Position based dynamics. J. Vis. Comun. Image
A KINCI , N., I HMSEN , M., A KINCI , G., S OLENTHALER , B., AND Represent. 18, 2 (Apr.), 109–118.
T ESCHNER , M. 2012. Versatile rigid-fluid coupling for incom- R AVEENDRAN , K., W OJTAN , C., AND T URK , G. 2011. Hybrid
pressible sph. ACM Trans. Graph. 31, 4 (July), 62:1–62:8. smoothed particle hydrodynamics. In Proceedings of the 2011
A LDU ÁN , I., AND OTADUY, M. A. 2011. Sph granular flow ACM SIGGRAPH/Eurographics Symposium on Computer Ani-
with friction and cohesion. In Proceedings of the 2011 ACM mation, ACM, New York, NY, USA, SCA ’11, 33–42.
SIGGRAPH/Eurographics Symposium on Computer Animation, S CHECHTER , H., AND B RIDSON , R. 2012. Ghost sph for animat-
ACM, New York, NY, USA, SCA ’11, 25–32. ing water. ACM Trans. Graph. 31, 4 (July), 61:1–61:8.
B ECKER , M., AND T ESCHNER , M. 2007. Weakly compressible S MITH , R. 2006. Open dynamics engine v0.5 user guide.
sph for free surface flows. In Proceedings of the 2007 ACM SIG-
GRAPH/Eurographics symposium on Computer animation, Eu- S OLENTHALER , B., AND G ROSS , M. 2011. Two-scale particle
rographics Association, Aire-la-Ville, Switzerland, Switzerland, simulation. ACM Trans. Graph. 30, 4 (July), 81:1–81:8.
SCA ’07, 209–217.
S OLENTHALER , B., AND PAJAROLA , R. 2009. Predictive-
B ELL , N., Y U , Y., AND M UCHA , P. J. 2005. Particle-based sim- corrective incompressible sph. In ACM SIGGRAPH 2009 pa-
ulation of granular materials. In Proceedings of the 2005 ACM pers, ACM, New York, NY, USA, SIGGRAPH ’09, 40:1–40:6.
SIGGRAPH/Eurographics symposium on Computer animation,
ACM, New York, NY, USA, SCA ’05, 77–86. VAN DER L AAN , W. J., G REEN , S., AND S AINZ , M. 2009. Screen
space fluid rendering with curvature flow. In Proceedings of the
B ODIN , K., L ACOURSIERE , C., AND S ERVIN , M. 2012. Con- 2009 symposium on Interactive 3D graphics and games, ACM,
straint fluids. IEEE Transactions on Visualization and Computer New York, NY, USA, I3D ’09, 91–98.
Graphics 18, 3 (Mar.), 516–526.
Y U , J., AND T URK , G. 2013. Reconstructing surfaces of particle-
B RACKBILL , J. U., AND RUPPEL , H. M. 1986. Flip: A method based fluids using anisotropic kernels. ACM Trans. Graph. 32, 1
for adaptively zoned, particle-in-cell calculations of fluid flows (Feb.), 5:1–5:12.
in two dimensions. J. Comput. Phys. 65, 2 (Aug.), 314–343.
Z HU , Y., AND B RIDSON , R. 2005. Animating sand as a fluid.
B RIDSON , R., F EDKIW, R., AND M ÜLLER -F ISCHER , M. 2006. In ACM SIGGRAPH 2005 Papers, ACM, New York, NY, USA,
Fluid simulation: Siggraph 2006 course notes fedkiw and SIGGRAPH ’05, 965–972.

You might also like