Computatonal Flud Dynamcs If you want to learn a bt more of the math behnd flud dynamcs, read my prevous post about the Naver- Stokes equatons and Newtonan fluds. The equatons derved n the post are the equatons whch govern moton of common fluds such as water, honey, and so on. If you just want to see runnng code, t s on GtHub. Smulatons Due to the complex nature of the Naver-Stokes equatons, analytcal solutons range from dffcult to practcally mpossble, so the most common way to make use of the Naver-Stokes equatons s through smulaton and approxmaton. A number of smulaton methods exst, and n the next secton, we wll examne one of the algorthms often used n computer graphcs and nteractve applcatons. Smoothed Partcle Hydrodynamcs One of the most researched and most used methods for flud smulatons, especally n nteractve applcatons, s a partcle-based approach known as Smoothed Partcle Hydrodynamcs (SPH). SPH s, at the most basc level, an attempt to dscretze the Naver-Stokes equatons. In addton to the flud partcles themselves, a smoothng functon (called the smoothng kernel) s used whch spreads the propertes of each partcle over a contnuum. In fact, SPH s often called an nterpolaton method for partcle systems. We wll now derve and demonstrate the use of SPH for modelng a smple ncompressble Newtonan flud. Smoothng Kernels and Bass of SPH Snce SPH s essentally an nterpolaton method for partcle systems, one of the key deas behnd t s the ablty to evaluate a scalar quantty n any pont n space, even though the quantty only truly has a value at the dscrete partcles. In order to evaluate a quantty A at a pont r, we use the followng equaton: A( r) = j W ( r r j, h). Ths s a weghted summaton of all the partcles around the pont. s the value of A at the partcle, s the mass of the partcle, s the densty of the partcle, and W ( r r j, h) s the weghtng factor, and h s the maxmum dstance. The functon W s also called the smoothng kernel, because t smoothes the partcle values throughout contnuous space. The smoothng functon W has a few notable propertes. Frst of all, the functon should decrease as the dstance ncreases; ths s only logcal, snce the ponts nearby should have more nfluence than those far away. Second of all, the kernel should evaluate to 0 at dstances equal to or greater than h. Fnally, the smoothng kernel should be normalzed. A normalzed smoothng kernel satsfes the equaton W ( r, h)dr = 1. Dervatves of Quanttes The Naver-Stokes equatons often requre calculatng the frst or second dervatves of varous quanttes. Ths s partcularly easy n SPH, because the dervatve of a quantty s r A( r) = r j W ( r r j, h). Equvalently, Thus, r A( r) = j A( r) = j r W ( r r j, h). W ( r r j, h) 1
and 2 A( r) = j 2 W ( r r j, h). Calculatng Densty As you may have notced, the equaton for the SPH value of a scalar quantty ncludes both a mass and a densty term. Ths s because each partcle represents a small volume V = m ρ. The Naver-Stokes equatons for an ncompressble flud (such as water) requre that the densty term s constant; however, due to the nature of SPH, mantanng a constant densty s very dffcult. Snce n many applcatons accuracy s less mportant than realsm and speed, we gnore the requrement that densty s constant. We can later compensate for that by makng the densty restorng force (pressure) very strong. Snce densty ρ s non-constant, we may need to calculate densty at a gven poston. Snce densty s yet another ntensve property, we can apply the SPH equaton above to get = j W ( r r j, h) = j W ( r r j, h). The problem of densty s one of the bggest reasons not to use SPH for models whch requre precson or accuracy. SPH s meant to provde a realstc-lookng flud smulaton, at the cost of gnorng certan requrements, such as symmetry, conservaton of momentum, or constant densty. Smulaton The Naver-Stokes equatons can now be appled to the SPH partcles. We have two man equatons. The frst s the conservaton of mass equaton, v = 0. The second equaton stems from the conservaton of momentum, and states that ρ Dv Dt = p + µ 2 v + f. The frst equaton s guaranteed for partcle systems, because we have a constant amount of partcles, each wth a constant mass. Therefore, the total mass remans constant, and we can gnore the frst equaton. The second equaton dctates the moton of the partcles. The left hand term s the change n momentum. Therefore, we can express the acceleraton of each partcle as a = f ρ where f s the sum of all the force terms on the rght hand sde. In order to be able to smulate the partcle moton, we must express each of the force terms through a dscrete summaton. Force Terms: Pressure If we apply our SPH equaton to pressure, we arrve at the equaton f pressure = p( r) = p j W ( r r j, h). However, ths sn t symmetrc. Pressure should be symmetrc, snce every acton should have an equal and opposte reacton; however, f we examne a 2-partcle system, the pressure of partcle depends on the pressure of partcle j and vce versa, so symmetry s not guaranteed n the general case. In order to rectfy ths, we can use a dfferent pressure equaton, whch uses an average of partcle pressures to ensure symmetry: f pressure = p( r) = p + p j W ( r r j, h). 2 We must also remember that the only state a partcle keeps around s ts mass, densty, and velocty. Thus, we cannot just use pressure, we must calculate t. Usng the deal gas state equaton, we can say that p = kρ. 2
In order to make the smulaton more numercally stable, we can make pressure smaller by usng the dfference. Snce the equaton uses the gradent of pressure, the math s unchanged f we use the equaton p = k(ρ ρ o ) where ρ o s the rest densty. By dong ths substtuton, we reduce the value of p, and thus decrease the effects of floatng pont roundng errors ntroduced by the computatons. Force Terms: Vscosty Applyng SPH prncples to vscosty, we arrve at the equaton f vscosty = µ 2 v( r ) = µ v j 2 W ( r r j, h). However, we encounter the same problem as before, namely that the vscosty force s non-symmetrc. We can resolve t n a smlar manner, usng the dfference n veloctes nstead. The resultng equaton takes the form of f vscosty = µ v j v 2 W ( r r j, h). In physcal terms, ths equaton states that a partcle s accelerated n the drecton that ts envronment s movng. Thnkng about a floatng partcle n a stream of lqud, ths makes sense. Force Terms: Surface Tenson In a flud, molecules experence ntramolecular attracton forces. For a partcle embedded nsde the flud, the force s evened out; however, for partcles on the edge of the flud, the force does cause an acceleraton, and thus s non-neglgble. Snce each partcle s the cause of the ntramolecular attracton, we defne another quantty (called color for convenence) such that c s equal to 1 at every partcle and 0 otherwse. Therefore, the equaton that descrbes the SPH quantty for c would be c( r) = c j W ( r r j, h). Snce c s 1 at all partcle locatons, we can smplfy ths to say that c( r) = 1 W ( r r j, h). For physcal reasons that are beyond the scope of ths analyss, the surface tenson force s equal to f surface = σκ n = σ 2 c n n. We try to avod calculatng the force when n s small, because that causes problems because we are dvdng by a small floatng pont number. We only calculate the surface tenson force when n s greater than a gven preset. The fnal equaton for the surface tenson force (when we calculate t) would be Force Terms: External Forces f surface = σ 2 c c c. External forces are smply appled to every partcle as they would be to a normal mass. If a partcle touches (or goes nto) a sold object, t s reflected (pushed out wth t s velocty vector reflected over the object normal vector). Smoothng Kernels The smoothng kernel functons are requred to do the actual computatons for smulaton. The qualty of smulaton, as well as the speed and accuracy, hghly depend on the choce of smoothng kernels. In the orgnal SPH publcaton that nvestgated smulatng fluds n real-tme [2], the authors suggested the use of three dfferent kernels for dfferent thngs. Note that the smoothng kernels are pece-wse functons; the functons presented subsequently defne the values of W for 0 r h. In other cases, W = 0. Note that the followng smoothng kernels are not normalzed, and should be pror to use. 3
General Smoothng Kernel The general smoothng kernel, used n all but two cases, s a sxth-degree polynomal wth the equaton W g (r, h) = 315 64πh 9 ( h 2 r 2) 3. One of the benefts of ths emprcally desgned kernel s that t uses r 2, whch means that we never need to calculate r. Calculatng r would be an expensve operaton, because t nvolves a square root; calculatng r 2, however, nvolves only multplcaton, and s thus much faster. Pressure Kernel For calculatons nvolvng pressure, the general kernel becomes zero when partcles are very close together. Ths s not what fluds actually act lke - n fact, as partcles come closer together, they should repel more due to pressure nstead of less. Thus, Desbrun [6] suggests a dfferent smoothng kernel of the form Vscosty Kernel W p (r, h) = 15 πh 6 (h r)3. The fnal smoothng kernel we are usng s specfc to the vscosty term. If we were to use the general smoothng term for vscosty, two partcles whch are very close to each other could possbly ncrease n speed. Ths s ncorrect, snce vscosty s a frcton force, whch should not be ncreasng the energy n the system. Thus, the authors of the orgnal flud smulaton SPH paper suggest usng the kernel of Ongong Research W v (r, h) = r3 2h 3 + r2 h 2 + h 2r 1. Although the Naver-Stokes equatons were orgnally formulated nearly 200 years ago, flud mechancs s a rapdly evolvng feld. The advent of computer technology has allowed physcsts to accurately model the behavour of fluds through teratve approxmatons of ther behavour, makng the study of the Naver-Stokes equatons stll more mportant. Current research can be subdvded nto two categores: one form of research s theoretcal, seekng mathematcal proof of the exstence and smoothness of the soluton to Naver-Stokes; the other branch of ongong research s more focused on practcal applcaton of Naver-Stokes to real-world problems. Though n some cases the dstncton s purely artfcal, t s nonetheless useful n dscussng the varous topcs currently beng nvestgated. Theoretcal Research The fundamental theoretcal problem of Naver-Stokes s one of the seven Mllenum Prze Problems. The Mllenum Prze Problems are seven mathematcal problems put forth by the Clay Mathematcs Insttute n the year 2000; the frst person to offer a vald soluton to any of the problems s promsed a mllon-dollar reward. The problem of Naver-Stokes, as stated by the Clay Mathematcs Insttute, s as follows: Prove or gve a counter-example of the followng statement: In three space dmensons and tme, gven an ntal velocty feld, there exsts a vector velocty and a scalar pressure feld, whch are both smooth and globally defned, that solve the Naver-Stokes equatons. Though ths statement tself has not been proven or ndcated false, attempts at proof have come close. It s known that for Naver-Stokes n two dmensons, the solutons exst and are smooth. In addton, t s known that for low ntal veloctes, smooth solutons to 3-dmensonal Naver-Stokes exst; however, for hgher ntal veloctes, the exstence of smooth solutons has not been proven. Practcal Research Though the mathematcal problem posed by Naver-Stokes has not yet been resolved, computer-aded approxmatons are sutable for many purposes. From the desgn of aerodynamc arcraft to smulaton of water for Pxar flms, flud smulatons are hghly used n ndustry. Much current research n the feld of computatonal 4
flud dynamcs (CFD) attempts to fnd faster or more-accurate approxmaton algorthms n order to make these smulatons more useful stll. The methods used n CFD can be broken down nto two categores: dscretzaton models and turbulence models. Dscretzaton models attempt to break the flud nto a dscrete set of elements, and teratvely smulate the moton of the flud through tme usng the Naver-Stokes equatons. Turbulence models deal wth turbulence, a chaotc type of flud flow, whch s nearly mpossble to smulate as wth the dscretzaton models; nstead, turbulence models attempt to track or obtan the value of specfc propertes of a flud over tme. Though the basc equatons used are the same, approxmaton methods often take dfferent approaches, dependng on ther objectve. Some methods, especally ones amed towards very fast or nteractve flud smulaton, use partcle based modelng. A volume of flud s subdvded nto a fnte number of partcles, and each partcle s subject to the velocty felds dctated by the Naver-Stokes equatons as well as external forces. Ths model typcally smplfes computaton and mplementaton, and s commonly used n computer graphcs and computer games. The partcle nature s usually hdden by nterpolatng partcle postons through a process called pont splattng. Smoothed Partcle Hydrodynamcs, the method nvestgated n the prevous secton, falls under that category. Other methods, however, use a three-dmensonal grd (a mesh ) to model the flud. The nternals and boundares are tracked through teratve Naver-Stokes approxmatons; the beneft of ths method s a hgher precson and hgher flexblty n terms of nteracton wth other bodes, at the cost of computatonal speed. 5