Flow simulation with vortex elements Mark J. Stock Independent Artist Newton, Massachusetts, USA
[email protected]
Abstract While fluid flow is a ubiquitous phenomenon on both Earth’s surface and elsewhere in the cosmos, its existence, as a mathematical field quantity without discrete form, color, or shape, defies representation in the visual arts. Both physical biology and computational physics are, at their roots, very large systems of interacting agents. The field of computational fluid dynamics deals with solving the essential formulas of fluid dynamics over large numbers of interacting elements. This chapter presents a novel method for creating fluid-like forms and patterns via interacting elements. Realistic fluid-like motions are presented on a computer using a particle representation of the rotating portions of the flow. The straightforward method works in two or three dimensions and is amenable to instruction and easy application to a variety of visual media. Examples from digital flatwork and video art illustrate the method’s potential to bring space, shape, and form to an otherwise ephemeral medium. Though the rules are simple, the resulting behavior frequently exhibits emergent properties not anticipated by the original formulae. This makes both fluid simulations and related biological computations deep, interesting, and ready for exploration. Keywords: Computer science, visual art, computer art, scientific computing, fluid dynamics, emergent phenomena, computational physics, generative art
1
Introduction
The state of the Earth and of all of the life upon and within it are profoundly affected by flow. The convection in the mantle slowly transfers heat and pushes continents around; the currents and gyres in the ocean regulate and affect climate; the rain, ice melt, and surface runoff erode mountains into
1
plains; the wind spreads seeds across vast distances; and tiny vessels inside plants and animals transport life-giving nutrients between organs. Indeed, the shapes of many organisms have evolved to not only accommodate flow, but to thrive in a fluid environment. Birds’ wings and fish tails both flap to generate elongated vortex rings to provide thrust, seed pods are dispersed widely because they contain elements that make them fall very slowly, and the varying strengths of trees’ branches allow them to survive high winds by bending to reduce drag. If not an essential quality of life itself, flow clearly seems to support the variety and vitality of life on Earth. In the context of this chapter, flow means the ensemble motion of matter in which the individual elements are allowed to move relative to one another. A fluid can be a gas such as air, a liquid such as water, or a collection of solid particles such as sand. Seemingly solid materials can behave as fluids if one observes them over a long period of time; examples of this are ice (glaciers) and rock (mantle convection). How do we quantify a flow? Flowing matter is composed of disconnected, non-uniformly-spaced molecules, each with its own motion. But it is grossly inefficient to describe flows at human scales with such detail. One solution is to assume that the properties of nearby elements vary smoothly. With this continuum assumption, the ensemble motion can be written as a mathematical function. Still, most flows retain more complexity than a single function can easily describe. In these cases, the fluid volume is typically discretized: broken up into discrete volumes for which the flow properties in each volume are considered uniform. This turns out to be a useful approximation of the real flow, as it makes it amenable to description and prediction on digital computers. It is difficult to describe flow using the traditional elements of visual art (texture, form, space, line, color, value, shape). Flow doesn’t necessarily have a surface to support a texture, nor does it edges necessary for shape. It defies these categories because it fills space, is constantly moving, and even exists where it is not visible. In many situations, line, form, and texture appear in flow due to visible material being carried by the flow. A collection of clouds, for example, defines negative and positive space, while a thin cloud layer provides texture to the background. Further, the shape and position of foreground subjects can imply their presence in a flow field: hair or branches blown by a breeze, or boats being tossed about on the open ocean. As an alternative to relying on external elements affected by flow, the properties of flow itself may be used as visual elements. In the methods and artwork presented below, certain properties of the flow, such as volumes of quickly-rotating fluid, or numerical elements used to compute the flow, have been instantiated as solid objects, becoming fluid-like lines or forms within the volume. Flow then allows transformation of spatial entities such as points and lines, and in special cases, those entities themselves recursively define the
2
flow. The non-deterministic nature of this feedback makes fluid simulations powerful and often-surprising tools for visual art. In the following chapter, we will describe how points, lines, and surfaces can be made into elements which describe a flow, and how their positions and properties can evolve under their self-influence. This capability is described with a simple computer algorithm, but allows spontaneous generation of higher-level dynamics not suggested by the simple elemental rules.
2
Particle Simulations
Very simple systems of interacting elements can produce non-deterministic, emergent behavior. Conway created a set of rules governing the life cycle of a square pixel in a grid (a cellular automaton): it becomes alive if exactly three of its eight neighbors are alive, survives if two or three are alive, and dies otherwise [Gardner, 1970]. Despite the simplicity of these rules, this Game of Life generates a remarkable diversity of behaviors, such as the Gosper Glider Gun seen in Figure 1 [Britton, 2011], and is still the subject of active research forty years after its creation. A limitless number of cellular automata are possible, though most research focuses on emergent behavior of simple rule sets [Wolfram, 2002]. Other sets of rules are used to mimic the behavior of biological systems. For example, the flocking algorithm dictates the motion of independent agents, representing birds or insects, in space [Reynolds, 2011]. At every step, each bird will attempt to achieve three goals: move toward the average center of local flock mates, match the flight direction of those neighbors, and steer to reduce crowding. Note that all of these rules requires knowledge of the locations of only nearby birds in the flock, though global information is used to determine which birds are nearby. Applying any rule by itself would produce a stable and simple system, but together the algorithm allows much more complex behavior, as if the group were acting as a whole despite having no leader. A similar system, and one with connections to computational physics, is the gravitational n-body problem. Newton’s law of universal gravitation states that every mass attracts every other mass in the universe in direct relation to the product of the two masses and to the inverse square of the distance between them. The only other rules governing this system are also Newton’s: that an object at rest remains at rest, it maintains its velocity unless acted upon by another object, and it changes its velocity by an amount equal to the imposed forces divided by its mass. Simulations using rules like these are used by astrophysicists to study the formation and collision of galaxies [J.Dubinski, 2008], and helped demonstrate how the moon may have been formed by a large impact with the Earth [Ida et al., 1997]. Figure 1 illus-
3
c Figure 1: Left: Conway’s Game of Life. Right: Mark Stock, Gravtime ( 2005, M. Stock) trates a small n-body simulation in which the paths taken by particles/bodies as they progress upward are rendered as solid forms. From an even initial distribution, small clusters are born, and those in turn merge to generate larger and larger structures. It is not surprising that emergent phenomena like this exist in the universe, as many physical systems are composed of large numbers of simple elements with straightforward interaction rules.
3
Computational Fluid Dynamics
The field of computational physics is concerned with recreating the motions of physical phenomena on digital computers. Specifically, computational fluid dynamics (CFD) involves solving the fluid equations of motion on a system of discrete elements in order to generate an approximation of a real flow. CFD is used for many scientific and engineering purposes, such as industrial combustion, automobile and truck design, wind power optimization, and obviously aircraft and rocket design and analysis. Scientists, engineers, and now a few artists are using a wide variety of CFD methods, each with advantages and disadvantages relating to accuracy, ease of programming, and aesthetic potential. To represent field values on a digital computer, the domain of interest must be broken up into small volumes, each with its own unique set of values of the tracked properties. The most common type of CFD method discretizes the
4
domain into adjacent, non-overlapping, non-moving volumes, through which fluid and fluid properties move. In these methods, velocity is a property of the fluid, along with density, pressure, and temperature. The simulation progresses by updating these properties for each cell according to relationships among that cells’ neighbors. For example, if a cell sees a higher pressure on its left edge, it will initiate a velocity from the left to the right, and if that cell on the left is warmer, that velocity will carry some of the heat with it. This method appears and acts much like a complex cellular automata simulation. The rules used to update the cells originate with the Navier-Stokes equations— the primary governing equations of fluid dynamics. These consist of differential equations that relate the change of velocity, pressure, density and temperature in space and time. Terms in these equations represent convection and diffusion of momentum and internal energy, the influence of external forces and heat sources, and the effects of any body forces such as those caused by gravity or rotation. The complete Navier-Stokes equations can only be solved analytically for very specific and simple situations, such as the flow between two infinite flat plates or in a tube. For most applications, especially those for which the flow is turbulent, these equations cannot be solved, instead approximate solutions are created on a computer. To do this, the differential equations are discretized in space and time and expressed as difference equations—equations relating the difference between values in neighboring elements. These equations of fluid motion and their discretization are described in many undergraduate and graduate texts such as those from Hirsch [1988] and Wesseling [2000]. An example of imagery created using this type of method appears in Figure 2. In this work, millions of cells were initialized with horizontal rows of color and a density, but the flow began motionless. The simulation accounted for the density differences by allowing the lower-density (lighter-colored) fluid to rise while the darker/denser fluid fell. Fluid fills every space always—no voids are created during the evolution of the flow. The consequence of this is that vortices are generated at boundaries between light and heavy fluids, and these vortices jostle with each other and persist for quite a long time. There are several other popular discretization techniques, each leading to different solution methodologies. In spectral methods, the flow is described by its components in the frequency domain [Karniadakis and Sherwin, 1999]. Lattice-Boltzmann methods resolve collisions among macro-particles constrained to move in quantized directions on a grid and use local averages to resolve the fluid properties [Wolf-Gladrow, 2000]. Smoothed particle hydrodynamics (SPH) represents the flow as independently-moving spherical parcels of fluid with a location and velocity, and the evolution equations only contain summations over the local neighborhood of elements [Liu and Liu, 2003]. This makes SPH methods popular in computer graphics, where fast solutions are more important than accuracy. Finally, particle methods such
5
c Figure 2: Magma 19. ( 2010, M. Stock) as SPH are well-suited to visual art, as the motion of their computational elements is easily translated to basic drawing elements.
4
Vortex Methods
A novel way to solve the equations of fluid motion stems from taking a mathematical transformation of the Navier-Stokes equations. For flows that do not involve shock waves or other compressibility effects, this new formulation— based on a quantity called vorticity which represents the rate of rotation at a point in a flow field—is easy to program and solve. A vortex is a volume of rotating fluid; normally with decaying circumferential speed and no radial motion. Vorticity and vortices appear frequently in nature and human-made flows, and provide a rich source of dynamical forms for artist and scientist
6
alike [Lugt, 1983]. A vortex method is a numerical scheme for discretizing and tracking the motion of vorticity. For derivation of the equations of vortex methods in two and three dimensions, and detailed information on the numerical methods for their solution, consult Cottet and Koumoutsakos [1999]. In vortex methods, the fluid volume is broken up into moving particles called vortices or vortons, each with a position and strength. These are not physical particles, but simply spatial markers indicating the rotation of fluid in their vicinity. The rules governing the evolution of these positions and strengths can be expressed by a few simple equations, though the method will be presented below in the form of an algorithm. For each step of the simulation, the influence of every particle on every other particle must be calculated. This influence depends on the distance and direction between the particles and the strength of the influencing particle, very much like that for universal gravitation. Note that even though only part of space is ever occupied by vortex elements, their influence covers the entire space; there is a velocity that is computable everywhere. As the particles move relative to each other, these velocity influences will change, further changing both the future motion of the particles and the flow everywhere. Even with just three particles, the resulting motion will be chaotic. With hundreds or thousands, their motion is clearly fluid-like.
4.1
A simple 2-D solver
A vortex simulation can be created relatively easily, even by one with little programming experience. In fact, the combination of a straightforward algorithm and visually interesting results makes it an ideal exercise for novice programmers. What follows is technically a two-dimensional inviscid (no viscosity) vortex method with a non-singular kernel [Krasny, 1986] and first-order time stepping. The pseudo-code used in the examples below is not from any specific computer language; it is only meant to illustrate the general procedure. Those not familiar with software development should consider using Processing [Fry and Reas, 2001] to create these programs. The first task of any particle simulator is to define the initial conditions. In the case of a simple vortex method, these are the positions and strengths of the particles, the length of the time step, and in this case, the smoothing radius that stabilizes the simulation. Naturally, particles can be added or removed during the simulation, either arbitrarily or based either on physical rules; such capability can be added at the programmer’s discretion. In the following code fragment, the arrays containing position (x, y), velocity (xvel, yvel) and rotational direction and strength (strength) are defined, and the necessary values set to random numbers.
7
# the simulation will use n particles integer n = 100 # the following arrays store the properties of each particle float x[n], y[n], strength[n] float xvel[n], yvel[n] # these constants affect speed and smoothness float dt = 0.01 float rad_squared = 0.01 for each particle i in n # random is a function that selects a random real # number between the given bounds x[i] = random(-1,1) y[i] = random(-1,1) strength[i] = random(-1,1) end loop over i The remainder of the program must calculate the particle positions as they change over time and call some external routine to display the results. This consists of an outer loop, which never exits containing three major steps which repeat in order. The first step contains a doubly-nested loop that calculates the new velocities for every particle in the system. The second carries the particles forward a distance equal to their velocity times the time step size dt. Finally, the particles are drawn to the screen. In pseudo-code, the algorithm can be arranged as follows. while (forever) # find the velocities for each particle i in n # accumulate the velocity influences, start at zero xvel[i] = 0 yvel[i] = 0 for each particle j in n # first find the vector between the particles dx = x[i] - x[j] dy = y[i] - y[j] # find distance and add the smoothness parameter dist_squared = dx*dx + dy*dy + rad_squared # scale by strength of source particle j factor = strength[j] / dist_squared # add the result to the velocity vector xvel[i] -= dy * factor
8
c Figure 3: Left: Traces left by 2D vortex flow. ( 2011, M. Stock); Right: frame c from Rota 9 8.( 2009, M. Stock) yvel[i] += dx * factor end loop over j end loop over i # update for each x[i] y[i] end loop
the position of each particle particle i in n += dt * xvel[i] += dt * yvel[i] over i
# call a routine to draw the particles draw_particles(n,x,y) end while loop Though the first vortex simulations were performed by hand [Rosenhead, 1931], the advent of the digital computer allowed simulations with much larger numbers of particles. Running the above algorithm and rendering the particle paths as lines generates an image similar to that on the left of Figure 3. On the right is a frame from Rota 9 8 (2010), a vortex simulation with a slightly different influence formula. In either case, vortices tend to pair up, with those of similar sign spinning around one another, and those of opposite sign marching sideby-side along a curve. Their motion is graceful and seemingly unpredictable. The evolution equations for more than two particles are non-deterministic, so changing any one initial value will generate a completely different flow.
9
4.2
Into three dimensions
Things get more complicated in three dimensions. Most importantly, a rotation in three dimensions is described by a three-dimensional vector, where two dimensions requires just a single number. This adds a new set of variables for the strengths (xstr, ystr, zstr) and some new steps to the vortex particle velocity influence code, as seen below. for each particle i in n xvel[i] = 0 yvel[i] = 0 zvel[i] = 0 for each particle j in n # find vector between the particles dx = x[i] - x[j] dy = y[i] - y[j] dz = z[i] - z[j] # find the distance from that vector dist_squared = dx*dx + dy*dy + dz*dz # add the smoothness parameter dist_squared += rad_squared # next two lines find reciprocal of the cube # of the distance dist = sqrt(dist_squared) factor = 1.0 / (dist * dist_squared) # scale the results by that factor dx *= factor dy *= factor dz *= factor # compute cross product of strength of source # particle j and scaled distance vector xvel[i] += dz*ystr[j] - dy*zstr[j] yvel[i] += dx*zstr[j] - dz*xstr[j] zvel[i] += dy*xstr[j] - dx*ystr[j] end loop over j end loop over i An additional complication that will not be addressed in the present method is the treatment of the vortex stretching term. This is a term that results from converting the governing equations of fluid motion into those required for vortex motion, and is used to change the particle strengths with respect to the flow. Inclusion of this term is required for accurate simulations, but very flow-like results are possible without it.
10
c Figure 4: Red Streamlines. ( 2003, M. Stock) A straightforward application of the above algorithm can be seen in Figure 4 in a piece called Red Streamlines. In this scene, ten thousand random vortex particles were created inside a cube. Then, one thousand streamlines were created using the above algorithm. For each streamline, an initial point was created, the velocity at that point calculated, and a new point created a short distance downstream. A line was traced between those two points, and the process repeated. Each line was finally converted to three-dimensional geometry, while the background vortices were kept invisible. Even though the simulation does not represent a physically possible flow configuration, the resulting wispy forms and interrelated lines imply dynamic, volumetric flow.
11
c Figure 5: Turbulence Infinite. ( 2003, M. Stock)
4.3
Other vortex elements
The most common three-dimensional vortex methods use point particles as vortex elements (as above), but alternate vorticity discretization methods use elements that more easily translate to the visual arts. The earliest threedimensional vortex methods used closed, connected circuits of segments to represent vortex filaments [Leonard, 1975]. One nice property of vortex filaments is that their circulation is constant along the entire length of the filament [Saffman, 1992]. In the context of the above algorithm, the strength per unit length of the segments is constant, and the direction is always along the axis of the segment. This obviates the need to compute the vortex stretching term, and the resulting method is an accurate viscosity-free three-dimensional vortex method. Being composed of line segments themselves, vortex filament simulations need to carry no other property, nor affect any external object, to be rendered as artistic elements. Nevertheless, as these vortex filaments are still just numerical representations of flow properties, their instantiation is an attempt to make visible the normally-invisible. Figure 5 shows a simulation of the evolution of a vortex ring—a closed loop composed of one vortex filament. The ring was perturbed slightly, which was just enough to cause the motion to become chaotic. The resulting tangle of tubes represents the hidden details of fluid turbulence, made solid. If vortex filaments represent lines around which flow rotates, vortex sheets can be considered to be many small, parallel, and adjacent vortex lines. The
12
c Figure 6: Frame from Smoke Water Fire. ( 2008, M. Stock) result is that the vortex sheet separates flows with co-planar, but not parallel, fluid motions. Like the other vortex elements, a vortex sheet moves under its own self-influence, and the evolution of its form can be computed with similar algorithms. See Stock [2006] for a detailed description of the necessary steps to accurate simulation of three-dimensional vortex sheets. The sheet is normally composed of connected triangles forming a closed surface. The connectivity of these elements must be defined and adapted as the simulation progresses, which can require substantial effort. Figure 6 illustrates the contortions and complexity that this triangle mesh can exhibit. That frame is from a larger work called Smoke Water Fire that aims to decontextualize fluid flow and leave merely its constituent motions. By rendering only the essential computational elements of a flow, and removing any suggestion of physical material or appearance, the fluid stands ephemeral as motion alone. Vortex sheets can increase in area substantially during the course of a simulation. The repeated stretching, folding, and twisting generates forms in three-dimensional space unlike any other algorithm. Figure 7 shows a very convoluted form that emerged from the simulation of three vortex sheets. They began as separate spherical entities, but in the course of their motion collided with each other, causing rapid swirling and overlapping of their boundaries. The result is a sculptural form, but one that would not support
13
itself if physically constructed. Despite the fluid origins of this, and other images using these methods, observers seem quick to draw comparisons to forms with only loose connections to flow, such as octopus heads, or a woman in a flowing dress walking down stairs.
5
Conclusion
Many of the methods presented above for fluid simulation are applicable to other kinds of biologically-inspired computation. This is not surprising, as both physical biology and computational physics are, at their roots, very large systems of interacting agents. Because of the often very large number of highly non-linear equations, artwork formed by these systems is essentially different than other forms of digital algorithmic art such as those based on fractals, iterated function systems, or limited-order chaotic systems. When the rules governing the behavior of agents in a large simulation are known (or approximated), the systems can be simulated in a computer. While the rules are often simple, the resulting behavior frequently exhibits emergent properties not anticipated in the original rules. This makes both fluid simulations and other biological computations deep, interesting, and ready for exploration.
References S. Britton, April 2011. URL http://ironphoenix.org/tril/gtklife/. GtkLife version 5.1 (computer software). Georges-Henri Cottet and Petros Koumoutsakos. Vortex Methods: Theory and Practice. Cambridge Univ. Press, Cambridge, UK, 1999. B. Fry and C. Reas, 2001. URL http://processing.org/. Processing (computer software). M. Gardner. Mathematical Games: The fantastic combinations of John Conway’s new solitaire game “life”. Scientific American, 223:120–123, October 1970. Charles Hirsch. Numerical Computation of Internal and External Flows, volume 1: Fundamentals of Numerical Discretization. John Wiley & Sons, New York, NY, 1988. S. Ida, R. Canup, and G. Stewart. N-body simulation of moon accretion. In Interactions between Planets and Small Bodies, 23rd meeting of the IAU, August 1997.
14
c Figure 7: The Trouble With Algorithmic Art. ( 2009, M. Stock)
15
J.Dubinski, 2008. URL http://www.galaxydynamics.org/. Galaxy dynamics. G.E. Karniadakis and S.J. Sherwin. Spectral/hp Element Methods for CFD. Oxford University Press, New York, NY, 1999. Robert Krasny. Desingularization of periodic vortex sheet roll-up. J. Comput. Phys., 65:292–313, 1986. Anthony Leonard. Numerical simulation of interacting, three-dimensional vortex filaments. In Proceedings of the IV Intl. Conference on Numerical Methods of Fluid Dynamics, number 35 in Lecture Notes in Physics, pages 245–250. Springer-Verlag, 1975. G.R. Liu and M.B. Liu. Smoothed Particle Hydrodynamics: A Meshfree Particle Method. World Scientific Publishing Co. Pte. Ltd., Singapore, 2003. Hans J. Lugt. Vortex Flow in Nature and Technology. Krieger Publishing Company, Malabar, FL, USA, 1983. C. Reynolds, August 2011. URL http://www.red3d.com/cwr/boids/. Boids (Flocks, herds, and schools: A distributed behavioral model). L. Rosenhead. The formation of vorticies from a surface of discontinuity. Proc. Roy. Soc. London Ser. A, 134:170–192, 1931. P. G. Saffman. Vortex Dynamics. Cambridge Univ. Press, Cambridge, UK, 1992. Mark Joseph Stock. A Regularized Inviscid Vortex Sheet Method for Three Dimensional Flows With Density Interfaces. PhD thesis, University of Michigan, 2006. P. Wesseling. Principles of Computational Fluid Dynamics. Springer-Verlag, New York, NY, 2000. D. Wolf-Gladrow. Lattice-Gas Cellular Automata and Lattice Boltzmann Models. Springer-Verlag, New York, NY, 2000. Stephen Wolfram. A New Kind of Science. Wolfram Media, 2002.
16