Galaxy Simulations in Blender and Why They Are Awesome

'm an observational astronomer, which to some of my crueller theoretician friends means, "photographer". So be it, I like looking at the real sky more than playing video games with dodgy physics. But it wasn't always so. In fact, I only avoided the terrible fate of becoming a theoretician because of a pretty hydrogen GIF at Phd-recruitment day.

My fourth year undergraduate project was about using simulations to form a galaxy without dark matter (long story short : it didn't work, but mainly because of bugs in the code). For my PhD I moved into observational astronomy, but my stalwart friend Dr Rory Smith (now somewhere in Chile) remained loyal and true to simulations, for some reason. The tools used to visualise the results were pretty awful, so I wrote a script to import the data into Blender. You can try it out here, if you like (though there are surely better tools to do this). Some examples are shown below.

I began with the obvious and simplest approach of importing each data point as a seperate object and animating each one through keyframing. This turned out to be a really Dumb Thing To Do, because, as explained in "FITS in Blender", the software isn't optimised for it. But it's useful for certain things. Rory was simulating a whole cluster of galaxies, which each galaxy modelled as just simple points. That's super-easy to show in Blender. Showing their trajectories is fun, looks pretty, and conveys the whole "swarm of bees" essence of the thing quite nicely.



Animations are also easy and it's simple to show each galaxy with an image instead of a point. The size of the spheres represent the mass of each galaxy.

Importing a few hundred moving points in Blender is one thing, but a few thousand - which is what you need to simulate the stars and gas that make up a galaxy - is much harder. For that, in every frame of the animation, a mesh of vertices is imported which is moved so that it's only visible at the correct moment. It's a bit weird, but it works. And, like the galaxy cluster, it's also possible to display trajectories. When you have ~40,000 particles, things can look very interesting.

The above example shows a blob of gas (white) and stars (bright lines) with some dark matter (green) being hit by a hot wind. Such objects can be formed when galaxies move through a cluster, which contains very hot (but low density) gas. The example below illustrates the importance of this more clearly. Here, a dwarf galaxy falls through the hot gas (not shown) of a galaxy cluster. As it slams into the hot, thin cluster gas, its own much denser gas (white) gets pushed out. Because the dwarf has a lot of gas, the gravitational change of removing it also affects the stars (blue points). The thin rotating stellar disc gets transformed in a messy, spheroidal blob.

Just for fun, the next movie shows another type of galaxy transformation. In this one, a spiral galaxy gets hit in the face by an "elliptical" (basically a big red ball of stars, modelled here as a single point). The gravity of the elliptical causes the spiral to collapse, but once it's gone the spiral re-expands and produces a ring which looks very much like the famous Carthweel galaxy.  Rory later did a much more careful simulation that was able to reproduce another ring galaxy - Auriga's Wheel - pretty darn closely.

Another thing we tried purely for fun was to try and reproduce the appearance of a spiral galaxy. OK, sure, we could just manually tweak everything, but we wanted to see how closely the simulations resembled typical real galaxies. Most star formation happens in the spiral arms, and since young star clusters are dominated by bright blue stars (that don't live for very long), the arms are blue compared to the rest of the galaxy. So, knowing the age of the star particles in the simulation, we were able to calculate their colour. It sort of works, and at least looks pretty.

Finally, one problem with using Blender to visualise the simulations is that single vertex points can't be given any colour in the display - they have to be rendered, which take time. The method of importing all of the data at once also creates very large files. To illustrate the forces affecting a galaxy as it moves through a cluster, we rendered each particle as a cube to give it some colour. Instead of animating every single cube, another script updates their position as the frame is changed in Blender. This means a much smaller file with the forces visible in the realtime display. Changing frames is slightly slower than with the other method, but not unduly so.

I have a version of the main particle-viewing script that uses this update-each-frame method. I'll release it when I have the time to tidy up the code into a workable state.

rhysy.net | feedback@rhysy.net