Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
0Activity
0 of .
Results for:
No results containing your search query
P. 1
Real-Time Fluid Dynamics for Games

Real-Time Fluid Dynamics for Games

Ratings: (0)|Views: 1|Likes:
Published by jeroflat
In this paper we present a simple and rapid implementation of a fluid dynamics solver for game
engines. Our tools can greatly enhance games by providing realistic fluid-like effects such as
swirling smoke past a moving character. The potential applications are endless. Our algorithms
are based on the physical equations of fluid flow, namely the Navier-Stokes equations. These
equations are notoriously hard to solve when strict physical accuracy is of prime importance.
Our solvers on the other hand are geared towards visual quality. Our emphasis is on stability
and speed, which means that our simulations can be advanced with arbitrary time steps. We
also demonstrate that our solvers are easy to code by providing a complete C code
implementation in this paper. Our algorithms run in real-time for reasonable grid sizes in both
two and three dimensions on standard PC hardware, as demonstrated during the presentation
of this paper at the conference.
In this paper we present a simple and rapid implementation of a fluid dynamics solver for game
engines. Our tools can greatly enhance games by providing realistic fluid-like effects such as
swirling smoke past a moving character. The potential applications are endless. Our algorithms
are based on the physical equations of fluid flow, namely the Navier-Stokes equations. These
equations are notoriously hard to solve when strict physical accuracy is of prime importance.
Our solvers on the other hand are geared towards visual quality. Our emphasis is on stability
and speed, which means that our simulations can be advanced with arbitrary time steps. We
also demonstrate that our solvers are easy to code by providing a complete C code
implementation in this paper. Our algorithms run in real-time for reasonable grid sizes in both
two and three dimensions on standard PC hardware, as demonstrated during the presentation
of this paper at the conference.

More info:

Categories:Types, Presentations
Published by: jeroflat on Oct 11, 2013
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

10/11/2013

pdf

text

original

 
Real-Time Fluid Dynamics for Games
Jos Stam
 Alias | wavefront210 King Street EastToronto, Ontario, Canada M5A 1J7Email: jstam@aw.sgi.com,Url:http://www.dgp.toronto.edu/people/stam/reality/index.html.
Abstract
In this paper we present a simple and rapid implementation of a fluid dynamics solver for gameengines. Our tools can greatly enhance games by providing realistic fluid-like effects such asswirling smoke past a moving character. The potential applications are endless. Our algorithmsare based on the physical equations of fluid flow, namely the Navier-Stokes equations. Theseequations are notoriously hard to solve when strict physical accuracy is of prime importance.Our solvers on the other hand are geared towards visual quality. Our emphasis is on stabilityand speed, which means that our simulations can be advanced with arbitrary time steps. Wealso demonstrate that our solvers are easy to code by providing a complete C codeimplementation in this paper. Our algorithms run in real-time for reasonable grid sizes in bothtwo and three dimensions on standard PC hardware, as demonstrated during the presentationof this paper at the conference.
Introduction
Fluid flows are everywhere: from rising smoke, clouds and mist to the flow of rivers andoceans. Because one of the major goals of games is to immerse players into plausible virtualworlds, it is desirable to include fluid flows into game engines. There already exist many ad-hoc models that attempt to fake fluid-like effects, such as particles rendered as texturedsprites. However, animating them in a convincing manner is not easy.We believe that a better alternative is to use the physics of fluid flows which have beendeveloped since the time of Euler, Navier and Stokes (from the 1750’s to the 1850’s). Thesedevelopments have led to the so-called
Navier-Stokes Equations
, a precise mathematicalmodel for most fluid flows occurring in Nature. These equations, however, only admit analyticalsolutions in very simple cases. No progress was therefore made until the 1950’s whenresearchers started to use computers and develop numerical algorithms to solve theequations. In general, these algorithms strive for accuracy and are fairly complex and timeconsuming. This is because the applications that require these solvers have to be physicallyaccurate. It is obviously crucial that the stresses and drag on an airplane or a bridge arecalculated precisely.In computer graphics and in games on the other hand what matters most is that thesimulations both look convincing and are fast. In addition it is important that the solvers aren’t
 
too complex so that they can be implemented on standard PCs, game consoles or PDAs. Inthis paper we present a set of algorithms which meet these requirements. To achieve thesegoals we depart from conventional wisdom in computational physics and develop algorithmscustom tailored for creating visual effects. Unlike physically accurate solvers which have strictbounds on their time steps, our algorithms are
stable
, and never “blow up.”
The Physics of FluidsFigure 1:
The Navier-Stokes Equations for the velocity in a compact vector notation (top) andthe equation for a density moving through the velocity field (bottom).Mathematically, the state of a fluid at a given instant of time is modeled as a velocity vector field: a function that assigns a velocity vector to every point in space. Imagine the air thatoccupies a room, its velocity will vary due to the presence of heat sources, air drafts, etc. For example, the velocity of the air near a radiator will predominantly be pointing in the upwarddirection due to heat rising. The distribution of velocities within a room is also quite complex asis evident when watching the smoke rising from a cigarette or the motion of dust particles inthe air.The Navier-Stokes Equations are a precise description of the evolution of a velocity fieldover time. Given the current state of the velocity and a current set of forces, the equations tellus precisely how the velocity will change over an infinitesimal time step. Figure 1 (top) depictsthese equations in a compact vector-like notation. Very roughly the equation states that thechange in velocity is due to the three terms on the right hand side of the equal sign. A velocity field on its own isn’t really visually interesting until it starts moving objects such assmoke particles, dust or leaves. The motion of these objects is computed by converting thevelocities surrounding the object into body forces. Light objects such as dust are usually justcarried along with the velocity field: they simply follow the velocity. In the case of smoke, it isprohibitively expensive to model every particle. Hence in this case the smoke particles arereplaced by a smoke density: a continuous function which for every point in space tells us theamount of dust particles present. The density usually takes values between zero and one:where there is no smoke the density is zero, and elsewhere it indicates the amount of particlespresent. The evolution of the density field through the velocity field of the fluid can also bedescribed by a precise mathematical equation, which is depicted at the bottom of Figure 1. Thereader is not expected to fully understand these equations. However, it should be evident toanyone that the two equations in Figure 1 look very much alike. In fact, this resemblance was
 
instrumental in the development of our algorithms. The equation for the density (bottom) is infact simpler than the one for the velocity (top). The technical reason is that the former is linear while the latter is non-linear. We first developed an algorithm for the density moving through afixed velocity field and then realized we could apply it to compute the evolution of the velocityfield as well. In this paper we will follow this historical development. First we will show how tosolve the density equation. This will familiarize the reader with the different components of our solver. The concepts involved are also easier to explain and visualize. Subsequently we willtransfer these ideas to the harder problem of simulating velocity fields.
A Fluid in a Box
N+1NN-12100 1 2 N-1 N N+1
 Figure 2:
Computational grids considered in this paper. Both the density and the velocity aredefined at the cell centers. The grid contains an extra layer of cells to account for the boundaryconditions.Mathematical equations for fluids are useful when thinking about fluids in general. However, inpractice we need a finite representation for our fluids. The usual approach is to dice up a finiteregion of space into identical cells and sample the fluid at each cell’s center. In this paper for the sake of clarity we will only describe a fluid living in two dimensions. However, extensions tothree dimensions of everything stated in this paper are straightforward. Nothing in this paper isrestricted to two dimensions. Therefore, our fluid will be modeled on a square grid like the oneshown in Figure 2. We allocate an additional layer of grid cells around the fluid’s domain tosimplify the treatment of the boundaries. Both the velocity and the density are assumed to beconstant in each grid cell and we usually display their values at the cell center. In practice weallocate two arrays for both the density and the velocity of size,
size=(N+2)*(N+2)
:
static u[size], v[size], u_prev[size], v_prev[size];static dens[size], dens_prev[size];
We prefer to use single dimensional arrays over double ones for efficiency purposes. Thearray elements are referenced using the following macro:
#define IX(i,j) ((i)+(N+2)*(j))

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->