Lava Lamp

Wesley Miaw <josuah@uclink4.berkeley.edu>
Tobin Fricke <tobin@splorg.org>
Kalman Lau

Table of Contents
1. Description
2. Deliverables
2.1 First Deliverable
2.2 Second Deliverable
2.3 Final
3. Files
3.1 Source Code
3.2 BMRT Files
3.3 Supplemental Files
3.4 First Deliverable Files
3.5 Second Deliverable Files
4. Resources


1. Description

This is a Lava Lamp animation rendered in BMRT 2.6. The particle movement cacluations are done using smooth particle hydrodynamics based on code by Kevin Olson at NASA/Goddard. The majority of modifications to his code were done to switch from one dimension to three dimensions.


2. Deliverables

2.1 First Deliverable (Files)

Animated image of the lava lamp.

Our first deliverable was a relatively basic attempt at modelling the physical properties of a lava lamp using particles.

The volume of the lamp is filled with spherical particles representing both fluids in the lava lamp. State information (mass, temperature, velocity, position) is kept for each particle. At each time step, the forces on each particle are summed and integrated to find the new position and velocity of each particle. The forces consist of, firstly, a buoyant force, and secondly, an interaction force between particles. The buoyant force is proportional to the particle's temperature. The interaction force only comes into effect for particles whose centers of mass are closer than the sum of their radii. For unlike particles (wax and kerosene) the force is always repulsive: the different fluids are imiscible, and two bits of fluid can't occupy the same space. For like particles (eg, bits of lava), the force is attractive for a range of separations, in an attempt to cause some kind of cohesion/surface-tension.

The output was rendered in OpenGL and GLUT. An animated GIF of this lava lamp is shown to the left.

2.2 Second Deliverable (Files)

In completing the second deliverable, we discarded our original attempt at modelling the physical properties of a lava lamp which was presented in the first deliverable. Instead, we switched to a smooth particle hydrodynamics model at the suggestion of Dr. Louis Moresi, a Senior Research Scientist at the Solid Mechanics Research Group of CSIRO Exploration & Mining. To implement smooth particle hydrodynamics, we modified one-dimensional public domain code by Kevin Olson at NASA/Goddard to work in three dimensions. The original code is in Fortran 90, which we translated to C++. Fortran is best suited for the types of calculations involved, but we are more familiar with C/C++ and the BMRT library is written in C.

The original code is designed for one-dimensional calculations. To add the y and z dimensions, additional arrays were added to store y- and z-values. The existing subroutines were then modified to accept those additional arrays as parameters. For the most part, calculations involving relative position and changes in velocity or acceleration needed to be changed to account for the new dimensions. If it looked like certain calculations were linear functions, then these additional dimensions were simply added to the calculations. The one calculation that is not linear but requires looking at velocity values in all three dimensions in the computation of the next time step amount. For that calculation, we used the minimum value of the three dimensions since it appears that is what is wanted when performing the final computation.

One computation we require but which is not present when considering a one-dimensional model is bouyancy. Our bouyancy calculation compares a particle's density with the densities of the particle immediately above and immediately below and adjusts the vertical accleration appropriately. If the density above is more, then the particle will rise. If the density below is less, then the particle will sink. The particle will not be affected by a less dense particle above or a more dense particle below.

We also created glass and wax shaders for use when rendering the final animation. The glass and wax shaders are based on the glass.sl and plastic.sl files included with BMRT 2.6. Reflection and refraction was incorporated through ray tracing, which is a feature of BMRT 2.6 and available in PRMan as an external library.

The image to the right showcases our shaders. The glass cube illustrates refraction of both the tabletop and the wax spheres inside. The glass sphere illustrates both refraction and reflection (blue light reflected off the glass cube is subsequently reflected off the glass sphere).

Sample rendering of glass and wax shaders.
View full size TIFF image (1024x768 1M).

2.3 Final (Files)

We attempted to complete the smooth particle hydrodynamics code from the second deliverable and create the lava lamp problem. However, although we were able to get the smooth particle hydrodynamics code to run very quickly, unidentifiable errors were introduced into the calcuations, most likely a result of failure to translate Fortran 90 code to C++. As a result, we went back to the code from our first deliverable and refined it to produce behavior very similar to that of a lava lamp.

Our final lava lamp simulation can draw to the screen using OpenGL or output RIB format files for use by a Renderman-compliant rendering program. If drawn using OpenGL, the temperature of a particle will be reflected by its color; hot particles are drawn in red and cold particles are drawn in blue. The image to the left shows what BMRT 2.6 renders for the first frame of the simulation. The animated GIF to the right shows how the particles are rendered in OpenGL.

Sample rendering of the lava lamp.
View full size TIFF image (1024x768 620K)
Animated GIF of the lava lamp.


3. Files

3.1 Source Code

These C++ files are what we used to create the final lava lamp simulation. A full-size image of the BMRT rendering is available in rendering.tif (620K). You can also view a full directory listing.

Makefile A GNU format Makefile.
lava.h
lava.c
The lava lamp simulation code. Once compiled, you can execute it with the flag -opengl to display an OpenGL rendering or pass as its only argument an integer which will tell it how many frames it should output in RIB format. e.g.
# ./lava -opengl
# ./lava 5 > lava.rib
grid.h
grid.c
A three-dimensional grid used to efficiently store and retrieve neighboring particles in the lava lamp.
vector.h
vector.c
A vector class.

3.2 BMRT Files

These BMRT and Renderman files are the shaders we used to create the lava lamp's glass and wax surfaces. A full-size image of these shaders in action is available in shaders.tif (1078K) and in lamp1.tif (985K) and lamp3.tif (954K). You can also view a full directory listing.

shaders.rib An example RIB file illustrating the use of our shaders.
myglass.sl Our glass surface shader.
myplastic.sl Our wax surface shader.
filterwidth.h
locillum.h
material.h
rayserver.h
raysphere.h
reflections.h
BMRT header files used to construct the surface shaders and incorporate reflection and refraction via ray tracing. BMRT has built-in ray tracing functionality; PRMan requires it to be implemented externally.
lamp1.cpp
lamp3.cpp
C++ programs for generating the lava lamp container. lamp1.cpp generates a single lamp. lamp3.cpp generates three lamps.
lamp1.rib
lamp3.rib
RIB format files for the lava lamp container.

3.3 Supplemental Files

Here are some supplemental files and documents that are related to our project.

lenardic0.txt
moresi0.txt
Our correspondence with Dr. Adrian Lenardic and subsequently Dr. Louis Moresi.
polygonizer.pdf An algorithm for the polygonization of implicit surfaces in C. Published in Graphics Gems IV chapter IV.8.

3.4 First Deliverable Files

These are the C++ files created for our first deliverable. You can also view a full directory listing.

Makefile A GNU format Makefile.
lava.cc The main program simulating the lava lamp.
vector.h
vector.cc
A vector class.

3.5 Second Deliverable Files

All of the files are available in either C++ or Fortran 90. Our code is in C++ and have the extension .cc. Kevin Olson's code is in Fortran 90 and have the extension .f. You can also view a full directory listing.

README Kevin Olson's original README describing his code and how to compile and run it. It has only been tested on the MasPar at NASA/Goddard.
Makefile A GNU format makefile for the C++ code.
sph.cc
sph.f
The main smooth particle hydrodynamics program.
sph_mods.h
sph_mods.cc
sph_mods.f
Supporting subroutines for calculating smooth particle hydrodyanmics.
r4_sort.h
r4_sort.cc
r4_sort.f
A bubble sort subroutine.
noh_int.f The shocks of Noh problem.
sod_const.f Sod's shock tube problem assuming a constant value for the smoothing length.
sod_int.h
sod_int.cc
sod_int.f
Sod's double shock tube problem.

4. Resources


Last updated: Saturday, 08-Dec-2001 18:28:49 PST