~ ωi,j,k = wi,j+1,k− wi,j−1,k 2∆x − vi,j,k+1− vi,j,k−1 2∆x , ui,j,k+1− ui,j,k−1 2∆x − wi+1,j,k− wi−1,j,k 2∆x , vi+1,j,k− vi−1,j,k 2∆x − ui,j+1,k− ui,j−1,k 2∆x (5.6)
The gradient of |~ω| is similarly estimated with central differences at the grid cell centers, for use in defining ~N : ∇|~ω|i,j,k = |~ω|i+1,j,k− |~ω|i−1,j,k 2∆x , |~ω|i,j+1,k− |~ω|i,j−1,k 2∆x , |~ω|i,j,k+1− |~ω|i,j,k−1 2∆x (5.7) When we normalize this to get N , we should of course guard against a divide-by-zero by using, for example:
~ Ni,j,k =
∇|~ω|i,j,k
k∇|~ω|i,j,kk + 10−20
(5.8) Finally, we take the cross-product to get fconfat the grid cell centers; we can take the appropriate averages to apply
this to the different components of velocity on the MAC grid.
We can simplify this to two dimensions by thinking of the two-dimensional velocity field as (u, v, 0). This gives a vorticity field ~ω = (0, 0, ω), which we can also interpret as just a scalar ω.
Vorticity is an extremely important fluid quantity, and by taking the curl of the momentum equation one can derive the “vorticity equation” which shows how vorticity evolves in time. In fact, many numerical methods for fluid flow have been devised based on this equation (especially in two dimensions, where the vorticity equation is particularly simple). Generally speaking, these vorticity methods accurately track the location, strength, and axis of vortices with vortex particles. Unfortunately, especially in three dimensions, it tends to be difficult to accurately model boundary interactions and other important physics with a pure vortex particle approach. However, we will point out the recent work of Selle et al. [SRF05] which demonstrates how to augment the fluid simulation approach in these notes by tracking vortex particles which feed into a more accurate version of vorticity confinement.
5.2
Sharper Interpolation
While vorticity confinement does wonders for countering numerical dissipation in the velocity field, it doesn’t apply to the temperature and smoke concentrations. Using the standard bilinear/trilinear interpolation in semi-Lagrangian advection quickly smears out sharp features in these fields, which for large scale smoke (where true physical diffusion is negligible) looks distinctly wrong.
One partial solution to this problem is to use more accurate interpolation. Fedkiw et al. [FSJ01] suggest a particular choice of cubic interpolant designed to be accurate yet stable, which we will go through in one dimension. This can be used to bootstrap up to two or three dimensions in the same way linear interpolation serves as the basis for
1Note: the null-space problem we discussed earlier isn’t particularly alarming here: we just will lack the ability to “see” and boost the
48 CHAPTER 5. SMOKE bilinear or trilinear interpolation: we interpolate in one dimension along one axis first, then interpolate between the interpolated values along the next axis, and so forth.
The underlying scheme is the Catmull-Rom spline. Given values qi−1, qi, qi+1, and qi+2, we want to estimate q
at a point x between xi and xi+1. To simplify life, we’ll conceptually translate and scale things so that xi = 0
and xi+1 = 1, i.e. so that the x here is the fraction along the interval we want. We estimate q(x) with a cubic
polynomial on the interval that passes through the points qiand qi+1, and whose slopes at the endpoints match the
central difference approximations from the data. That is, we want the slopes to be: di = qi+1− qi−1 2 (5.9) di+1= qi+2− qi 2 (5.10)
The Hermite cubic that satisfies these four conditions is:
q(x) ≈ qi+ dix + (3∆q − 2di− di+1)x2+ (−2∆q + di+ di+1)x3 (5.11)
where ∆q = qi+1− qi. (Note that the coefficients presented in [FSJ01] have a typo, a missing 2 in the cubic
term—which perhaps serves as a warning against blindly copying formulas from papers without first deriving them oneself!)
The danger with the Catmull-Rom interpolant is that it can over or undershoot the data. For example, if qi < qi+1
but the slope di+1 < 0, the maximum of the cubic occurs somewhere in the middle and is greater than qi+1. If our
semi-Lagrangian scheme happened to sample there, it could create a new value for q that was larger than any old value of q. If this keeps happening, q could blow up exponentially: not a good thing at all! To prevent this, we limit the cubic by restricting the slopes to agree with the sign of ∆q. That is, we set dior di+1to zero if it has sign
Chapter 6
Water and Level Sets
Our model for water is simply a fluid with a free surface that moves with the fluid velocity. We will include the vorticity confinement force from the previous chapter on smoke to counteract numerical dissipation in the velocity advection. What’s new is how to keep track of where the water is.
6.1
Marker Particles
The simplest approach, used for example in the original Marker-and-Cell paper [HW65], is to use “marker par- ticles”. Marker particles are simply particles used to mark where the fluid is: any grid cell containing a marker particle is marked fluid, and the empty cells are air.
We begin by sampling the fluid volume with several particles per grid cell. A fairly effective method is to create eight particles in a randomly jittered 2 × 2 × 2 arrangement (or four particles in 2 × 2 in two dimensions).
At the start of each time step we move the particles through the divergence-free velocity field, each following the simple motion
d~x
dt = ~u(~x) (6.1)
At least a second-order Runge-Kutta method, modified Euler, should be used as Forward Euler behaves miserably for rotational motion. (It can be instructive to try other schemes, such as leapfrog:
~
xn+1 = ~xn−1+ 2∆t~un(~xn) (6.2) which is guaranteed to trace rotational motion perfectly within its stability limit.) If large time steps in the fluid simulation are being used, then it may be preferable to subdivide the time interval and take multiple steps in moving the particles. In simulations involving solid objects, it is also advisable to detect whether particles have penetrated a solid object and move them out to the fluid region if so.
If you’re on your toes you might notice something odd here. These numerical integrators need to sample the fluid velocity along the trajectory of the particle. But if the water is splashing into a new region of space—i.e. the particles are moving outside of the current fluid volume—the fluid velocity might not be defined. The answer is to extrapolate the current fluid velocity out into the rest of the grid (air and solids) before moving marker particles. Indeed, this
50 CHAPTER 6. WATER AND LEVEL SETS will also be necessary for the semi-Lagrangian method to be able to work to determine new velocities in the new fluid regions. We’ll return to the question of exactly how to extrapolate velocity in section 6.3: in a nutshell, we’ll choose the velocity at a point outside the fluid volume to be the fluid velocity at the closest point on the fluid. After the particles have been moved, we label each grid cell that contains a marker particle as fluid and the rest as empty (or solid). This information is then used in the other steps of the fluid simulation, such as the pressure projection.
Marker particles are extremely simple and robust, but they do have one glaring flaw: it’s difficult to get accurate information about the water surface out of them. They can be rendered with a blobby implicit surface, but the result tends to be bumpy even for water that is supposed to be flat. Similarly if the accurate free surface boundary condition method from the last part of chapter 4 is to be used, we need good information about where the free surface cuts through grid lines: blobbies can give a possible answer again, but it is noisy. This motivates turning to an alternative method for capturing the location of the water: level sets.