Dan s Morris s Notes on Stable Fluids (Jos Stam, SIGGRAPH 1999)

Similar documents
Modeling, Simulating and Rendering Fluids. Thanks to Ron Fediw et al, Jos Stam, Henrik Jensen, Ryan

Fluid Animation. Christopher Batty November 17, 2011

An Overview of Fluid Animation. Christopher Batty March 11, 2014

Math background. Physics. Simulation. Related phenomena. Frontiers in graphics. Rigid fluids

PDE Solvers for Fluid Flow

Physics-Based Animation

Diffusion / Parabolic Equations. PHY 688: Numerical Methods for (Astro)Physics

CS 542G: The Poisson Problem, Finite Differences

Soft Bodies. Good approximation for hard ones. approximation breaks when objects break, or deform. Generalization: soft (deformable) bodies

Advection / Hyperbolic PDEs. PHY 604: Computational Methods in Physics and Astrophysics II

Game Physics. Game and Media Technology Master Program - Utrecht University. Dr. Nicolas Pronost

Dynamics and Time Integration. Computer Graphics CMU /15-662, Fall 2016

( ) Notes. Fluid mechanics. Inviscid Euler model. Lagrangian viewpoint. " = " x,t,#, #

Chapter 9 Implicit integration, incompressible flows

Physically Based Simulations (on the GPU)

Pressure corrected SPH for fluid animation

Dynamics and Time Integration

What Every Programmer Should Know About Floating-Point Arithmetic DRAFT. Last updated: November 3, Abstract

Elliptic Problems / Multigrid. PHY 604: Computational Methods for Physics and Astrophysics II

Before we consider two canonical turbulent flows we need a general description of turbulence.

Finding Limits Graphically and Numerically

(Refer Slide Time: 03: 09)

Math (P)Review Part I:

N H 2 2 NH 3 and 2 NH 3 N H 2

Partial Differential Equations

Cranfield University, Cranfield, Bedfordshire, MK43 0AL, United Kingdom. Cranfield University, Cranfield, Bedfordshire, MK43 0AL, United Kingdom

Chapter 4. Nonlinear Hyperbolic Problems

Math (P)Review Part II:

OpenFOAM selected solver

Slope Fields: Graphing Solutions Without the Solutions

Physics Motion Math. (Read objectives on screen.)

Numerical Methods for Inverse Kinematics

Computational Techniques Prof. Sreenivas Jayanthi. Department of Chemical Engineering Indian institute of Technology, Madras

Improvement of Calculation Stability for Slow Fluid Flow Analysis Using Particle Method *

MITOCW watch?v=pqkyqu11eta

CSCI1950V Project 4 : Smoothed Particle Hydrodynamics

Lesson 21 Not So Dramatic Quadratics

Computational Fluid Dynamics Prof. Dr. Suman Chakraborty Department of Mechanical Engineering Indian Institute of Technology, Kharagpur

PHYSICS - CLUTCH CH 01: UNITS & VECTORS.

7.2 Steepest Descent and Preconditioning

Notes. Multi-Dimensional Plasticity. Yielding. Multi-Dimensional Yield criteria. (so rest state includes plastic strain): #=#(!

Part 1. The diffusion equation

Pressure-velocity correction method Finite Volume solution of Navier-Stokes equations Exercise: Finish solving the Navier Stokes equations

Open boundary conditions in numerical simulations of unsteady incompressible flow

How to work out really complicated motion. Iteration and Problem Solving Strategies. Let s go. Vertical spring-mass.

Difference Equations

Lab Slide Rules and Log Scales

Conservation of Mass. Computational Fluid Dynamics. The Equations Governing Fluid Motion

Scientific Computing I

Instructor (Brad Osgood)

Relativity. Transcript.

Lecture 13 An introduction to hydraulics

CHAPTER 6 VECTOR CALCULUS. We ve spent a lot of time so far just looking at all the different ways you can graph

Project 4: Navier-Stokes Solution to Driven Cavity and Channel Flow Conditions

Quadratic Equations Part I

ASTRO 114 Lecture Okay. What we re going to discuss today are what we call radiation laws. We ve

Grades 7 & 8, Math Circles 10/11/12 October, Series & Polygonal Numbers

A Study on Numerical Solution to the Incompressible Navier-Stokes Equation

TheFourierTransformAndItsApplications-Lecture28

Lecture 10: Powers of Matrices, Difference Equations

Particle Systems. CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Winter 2017

Homework 4 in 5C1212; Part A: Incompressible Navier- Stokes, Finite Volume Methods

Algebra. Here are a couple of warnings to my students who may be here to get a copy of what happened on a day that you missed.

SUPERCHARGED SCIENCE. Unit 2: Motion.

Computing a null divergence velocity field. using smoothed particle hydrodynamics

2.2. Methods for Obtaining FD Expressions. There are several methods, and we will look at a few:

Revision History Date Version Description Author 03/06/ Initial Version Sergio Miguel Martin. Table of Contents

Notes for CS542G (Iterative Solvers for Linear Systems)

CHAPTER 7: TECHNIQUES OF INTEGRATION

CALCULUS III. Paul Dawkins

Chapter 3 ALGEBRA. Overview. Algebra. 3.1 Linear Equations and Applications 3.2 More Linear Equations 3.3 Equations with Exponents. Section 3.

Getting Started with Communications Engineering

Physics Motivated Modeling of Volcanic Clouds as a Two Fluids Model

Math 3361-Modern Algebra Lecture 08 9/26/ Cardinality

Differential Equations

Instructor (Stephen Boyd)

1 Introduction. J.-L. GUERMOND and L. QUARTAPELLE 1 On incremental projection methods

Descriptive Statistics (And a little bit on rounding and significant digits)

Basics of Proofs. 1 The Basics. 2 Proof Strategies. 2.1 Understand What s Going On

Grade 7/8 Math Circles March 8 & Physics


Chapter 3. Finite Difference Methods for Hyperbolic Equations Introduction Linear convection 1-D wave equation

JMBC Computational Fluid Dynamics I Exercises by A.E.P. Veldman

Preptests 59 Answers and Explanations (By Ivy Global) Section 1 Analytical Reasoning

Problem Set Number 01, MIT (Winter-Spring 2018)

Chapter 5. Methods for Solving Elliptic Equations

Chemical Reaction Engineering Prof. Jayant Modak Department of Chemical Engineering Indian Institute of Science, Bangalore

Rotation and Angles. By torque and energy

Forces. Unit 2. Why are forces important? In this Unit, you will learn: Key words. Previously PHYSICS 219

Partial Differential Equations II

Lecture 15: Exploding and Vanishing Gradients

Physics 212E Spring 2004 Classical and Modern Physics. Computer Exercise #2

Modeling and Solving Constraints. Erin Catto Blizzard Entertainment

Ideas from Vector Calculus Kurt Bryan

Numerical Methods Lecture 2 Simultaneous Equations

The Derivative of a Function

Designing Information Devices and Systems II Fall 2018 Elad Alon and Miki Lustig Homework 8

Conservation of mass. Continuum Mechanics. Conservation of Momentum. Cauchy s Fundamental Postulate. # f body

MATH 308 COURSE SUMMARY

The Shallow Water Equations

Transcription:

Dan s Morris s Notes on Stable Fluids (Jos Stam, SIGGRAPH 1999) This is intended to be a detailed by fairly-low-math explanation of Stam s Stable Fluids, one of the key papers in a recent series of advances in simulating fluids for computer graphics. Navier-Stokes Overview The goal of this whole field is to simulate realistic fluid motion; this paper is represents one step forward in that direction. So let s first talk about the basic Navier-Stokes equations, which are an accepted physical description of the things that affect fluid motion. These equations represent the truth, which 10 years of research have attempted to translate into algorithms. These formulations are taken from Stam s paper, although there are about one zillion different formulations of the Navier-Stokes equations. These equations describe the behavior of fluid at one point in a fluid volume. u is the vectorvalued velocity at that point, which is what we re trying to solve for over and over. t is time. ρ is density, p is pressure, υ is viscosity, and f is external force; these four values are basically assumed to be handed down from space, i.e. whoever is using this algorithm sets these values to model a particular fluid or a particular environment. Also, for right now, we assume a constant density, which is reasonable for an incompressible fluid like water. Equation (1) says that at any point, the velocity in and out of the point must sum to zero. For a constant density, this is the same as saying that mass is conserved, which seems important, since we re not simulating nuclear explosions or magic, so mass can t appear or disappear. Equation (2) lists the factors that govern the movement (partial derivative) of velocity: o The first term says that velocity moves along itself, and it moves faster at regions of high velocity. This is a known property of fluids; it s the reason that swirling regions of smoke or water continue to swirl. Because u appears twice in this term, this whole equation is non-linear. This is the advection term. o The second term says that velocity moves along a pressure gradient. This term will actually disappear later on because it creates divergence (velocity would always flow out of high-pressure cells), which is illegal in our constant-density universe, so Stam in fact omits this term entirely in his presentations. o The third term says that velocity tends to diffuse along the velocity gradient. The more velocity diffuses, the smoother the velocity field gets. How would you describe a fluid with a very smooth velocity field? It would be hella viscous. Hence v is viscosity. This term is the diffusion term.

o The last term allows external forces. Since we assume a constant density, we call this term force. The left side of this equation is basically acceleration (derivative of velocity), and we know that all equations in physics have to look basically like f=ma, which in this case works because m (density in our case) is assumed to be constant. Now for completeness, I m going to bring in an equation that s not shown explicitly in the Stam paper. Very often density is not constant (e.g. in any smoke simulation), and we want density to move around too. There is a new equation that we add to our system to simulate density movement, and it looks so much like equation (2) that I won t really even explain it. Stam adds this equation in his presentations, and basically any implementation of this system uses this equation. (3) Using what we ve already discussed, this equation says that (a) density moves along the velocity field, (b) density tends to diffuse according to some constant κ, and (c) the user can add or remove density anywhere he wants (S). Solving Navier-Stokes Okay, now we have useful equations that describe how fluids behave. Now it s time to write my fluid simulation code void main { float time=0.0; while(1) { // oh shit I can t paste the equations into my code time += delta; Now we need a way to actually solve these equations, i.e. if the velocity and density look like some particular set of values at time t, what will they look like at the next timestep? This is the one-line summary of the entire field of computational fluid dynamics. In 1996, Foster and Metaxas started the modern wave of research in fluid simulation for graphics. They showed everyone the Navier-Stokes equations, and presented their approach to solving them: o They discretized the fluid volume into cubes, i.e. they use an Eulerian (fixed) grid for their simulation. Particles don t move around there is a fixed grid, and the velocity

of the fluid at each grid cell changes over time. This seems standard now, but if you asked me to write a fluid simulation before reading any of this literature, I would have headed straight for the particles and written a Lagrangian simulation. So this is a big deal. o They use explicit timestepping; i.e. at each timestep, they grab density and velocity from each cell and move it along the velocity field to neighboring cells. o Sometimes this violates incompressibility, so to enforce incompressibility, they iteratively move tiny bits of mass around neighboring cells until everyone has the same mass that he started with. This is a relaxation technique. The Foster and Metaxas system works nicely, but the explicit timestepping scheme leads to instability (long timesteps make the velocity field go crazy) and prevents interactivity, and the relaxation technique is slow and somewhat inaccurate. Stable Fluids Enter Jos Stam, 1999. Stam takes the F/M approach and moves it forward tremendously, presenting a semi-lagrangian/implicit method for solving the Navier-Stokes equations that is unconditionally stable for any timestep. In this paper he focuses on moving velocity around (not density), but I ll discuss density at the end of the summary, because it s much simpler than moving velocity around, and he covers it in other places online. He starts with a very clean summary of the N-S equations, which I ve paraphrased above Now he presents a magic tidbit of math that he ll use later: the Helmholtz-Hodge decomposition. This says that every vector field can be decomposed into a gradient field (of a scalar function) and a divergence-free vector field. I ll treat this math as a black box. As you might expect, he ll use this property to make illegal divergence disappear, instead of the relaxation scheme used by Foster and Metaxas. Next he presents a very clear set of steps that one needs to do to solve the N-S equations (which, as a reminder, means update the velocity field ). The steps here should remind you of the individual terms in the Navier-Stokes equations. Note that we ll re-use most of these steps when we talk about moving density around, but for now we re talking about velocity. o Add external force: just add Δt*f(x,t) to each cell x where f is an external force o Advect: move the velocity field along itself Foster and Metaxas did this using explicit simulation if I m a grid cell and my neighbor has some velocity that points toward me, take some of his velocity. Do this for all of my neighbors.

As I mentioned earlier, this makes the velocity field freak out for large timesteps. So Stam s biggest contribution is an unconditionally-stable, semiimplicit advection scheme. He uses the method of characteristics, which basically says that if I want to know the velocity at point x, I can trace a line backwards along the current velocity field at point x to see what my new velocity should be. More specifically, we imagine we have a particle sitting at point x (the center of a grid cell), and whatever the velocity u is at that cell, we move our imaginary particle by -uδt. I.e., it walks backwards along the velocity field. It won t necessarily land in the middle of a grid cell, so wherever it lands, we grab the nearest velocity values and interpolate. This is the new velocity at cell x. Very stable. Because we sort of used a particle, we call this a semi-lagrangian scheme. Stam s figure 2 illustrates this process note that the particle is created at grid cell x, and moved backwards along the velocity field to get the corresponding value at Δt seconds ago. o Diffuse: let the velocity field spread out to represent viscosity You could just diffuse any scalar field by taking each pair of neighbors and moving stuff (in this case velocity) from the higher-valued neighbor to the lower-valued neighbor. This would be a simple explicit scheme. Unfortunately it s really sensitive to grid size and timestep, so it s really unstable. What you really want is to look at the whole grid at once and find the new velocity field that best represents diffusion according to our diffusion constant. So Stam uses an implicit technique, i.e. he asks the question: what velocity field would give us the current velocity field if we ran the diffusion process backwards? This is a classic implicit system, and it leads to a linear equation, which they plug into a black-box linear system solver (choose your favorite from the web), which gives them a new, nicely-diffused velocity field. o Project: get rid of all the divergence Remember we want to enforce conservation of mass, but the previous steps didn t necessarily do this; we could have created or lost a little mass at individual cells. This is where Stam uses the magic Helmholtz decomposition, which basically finds the best divergence-free field to match a vector field, and lets you throw out the leftover junk.

This decomposition yields a Poisson equation (a second-order PDE), which they also feed to their favorite black-box solver (FISHPAK) to get a divergence-free field These steps let you update the velocity field given the previous velocity field. Now what about density? The density equation (3) is virtually identical to its velocity-oriented cousin (2). The first term depends on velocity, which we have now computed. So we use nearly the same steps for moving density around: Add source: if the user wants more density at some places, do it Convect: move the density field along the velocity field The same semi-lagrangian method works great here Diffuse: spread the density out according to a user-defined diffusion constant The same implicit method works great here No need to project, since our grid of density is a scalar field, not a vector field Now, we can put all this together to fill in our pseudocode: void main { // velocity field (vectors) float v[size][size][3]; // density field (scalars) Float d[size][size]; float time=0.0; while(1) { // solve for velocity addexternalforces(v); advect(v); diffuse(v); project(v); // solve for density addexternalsources(d); convect(d); diffuse(d); // uses particle-tracing technique // uses linear system solver // uses linear system solver // uses particle-tracing technique // uses linear system solver // do whatever I want to do with my fluids, e.g. rendering them... time += delta; These are the main contributions of this paper, although he also notes that if you assume a wrap-around boundary condition (practical only for texture synthesis), you can transform the whole problem into frequency space and use a pretty albeit slower FFT-based solver

A really clear 2D java implementation of this paper is available at: http://www.multires.caltech.edu/teaching/demos/