Particle Simulator.

A particle physics simulator written in Python using OpenGL.

Fall 2011:
CSCI 444 - Data Visualization - Dr. Jesse Johnson

What was the project assignment?

The project was to take some existing code that had equations for particle physics and create a visualization that demonstrated the Brazilian Nut Effect, otherwise known asGranular Convection. This is a phenomenon where granular material (in this case a jar full of different sized nuts) will exhibit behavior patterns similar to fluid convection dynamics, given ample agitation. In other words, if you shake a jar of nuts, the big ones (the Brazil nuts) will rise to the surface, while the other smaller nuts will fall to the bottom and remain there.

I demonstrated this phenomenon by creating a user-specified flow of randomly sized spherical particles to represent "nuts". I showed their x, y, and z velocities by coloring the spheres different shades of red, green, and blue, respectively. The molecules only had velocities roughly between -2 and 2, so I had to normalize the velocities to make each value 0-255 to correspond with the 256 bit RGB color spectrum. I also used the absolute value of the velocities, since negative RGB values don't make sense on the color spectrum. If a particle is moving quickly in the x-direction, for example, the particle will show up a bright red value. If it is moving in a x and y direction, it will be a mix of red and green RGB values and the color will show that representation. Once the particles come to a rest inside the box, the particles start to lose their color, with the exception of those that are continuously circulating due to the Brazilian Nut Effect.

What did you learn from the project?

I never really had a true understanding of how particles interacted until completing this project. It makes sense that things that are liquid should have some type of cirulation or flow, but I had given no thought to how solid things acted in a fluid-like environment. Because this is only a simulation where the spheres act as nuts and are not actually shaped like nuts, it isn't a perfect demonstration. However, it does show the dynamics of how smaller objects are able to fall between the "cracks" among larger objects and how they all move together. In my slower and larger demonstrations, we can see how the objects act in a fairly free-flow environment. In my fast and small demonstrations, we see the objects conjoin together much quicker and form a "full box of nuts" almost immediately.

I had previous experience with OpenGL, but only implemented in C++. I never realized how easily one can translate C++ OpenGL code to Python. In fact, the syntax is exactly the same, minus the semicolons and curly braces. I plan to use Python for any future OpenGL projects I might encounter. I especially like the idea of creating OpenGL pages dynamically with Python. I think this would be a great improvement over C++ for readability and writeability, but may suffer in terms of resource usage.

What are you most proud of?

I'm proud that I was able to deliver a reasonably high quality product by the end of the semester. There were a lot of pitfalls and trials in creating the visualization the way I wanted to and I missed a lot of my low priority goals, but visually you can't really tell that in the final deliverable. I was really surprised how well OpenGL works with Python, once you understand the OpenGL syntax. The graphics didn't seem choppy or difficult to render. The only major problems I ran into with the OpenGL/Python mix was memory. I was developing this project on my Mac OSX machine and had no troubles, but when I tried to test on my windows machine with only 2 GB of RAM the graphics slow or crash. This is normal behavior, however, because the simulation sends thousands of spheres per minute (drops a ball every .1 ms). The slower simulations worked better under the low resource condition. However, using a larger bounding box for the simulation seemed to have an equivelent resource issue.

What was your role in completing the project?

I was the sole designer of the driver for this product, but we were given the integration and particle physics calculations. My task was to create that driver for the product and add any alterations to the "default view" as necessary to prove my hypothesis. The hypothesis I chose was that denser fluids tend to have less motion than less dense fluids, which I think the simulation demonstrated quite nicely. If you could take a jar of nuts into space, the fewer nuts that were in the jar would allow the nuts to flow more freely, while a full jar would allow barely any movement at all. My final deliverable included abrief write-up and a few animations demonstrating the simulation.

Simulation Demonstration:

External Light Source:
Internal Light Source:

What would you do differently next time?

I would like to add a GUI to allow the control of lighting and camera zoom, as well as different modes for color materials and the alpha channel. I would also like to allow the user to control the "drip" flow rate and size of box without having to adjust source code.

This project is also found onGitHub