Open Source Computer Codes

The Art of Computational Science

At our web site The Art of Computational Science you will find a growing body of computer codes, grouped around a multi-volume series of text books that Jun Makino and I are currently writing.

At our web site you will find many pointers to software for simulations in stellar dynamics that is both `open source' and freely available.

Getting Started

If you want to do a quick N-body simulation, but you don't feel like installing a whole package (such as Starlab or Nemo, see below), you can pick up a stand-alone version of an N-body code, accurate though not terribly efficient. It can be used for small N-body systems where encounters between individual stars are important. It is a fourth-order

Tree Code

For an efficient code for large numbers of particles, where encounters between individual particles are not important, our tree code is the tool of choice. The algorithm was published in the article A Hierarchical O NlogN Force Calculation Algorithm, by Barnes, J. & Hut, P., 1986, Nature324, 446-449. Copies of the tree code, with a nicely detailed explanation, can be found at

Self-Scheduling Toy Code

Here is an example of a Ruby script for a self-scheduling N-body integrator that allows each particle to determine its own time step size, without any need for a master scheduler to oversee the whole operation. Instead, when the user asks the N-body system to print out its state at a future time, the first particle that would be printed out realizes that it is not there yet, and starts to integrate its orbit. This in turn forces all other particles to integrate their orbit as well, in order to provide the information needed by the first particle.

Each particle has a history mechanism that stores orbit information. Here is a short vector class include file, a test driver for the history mechanism, and finally the driver for the N-body calculations.

This toy model has, as yet, a minimal structure, and is extremely slow, since no effort was made, so far, to speed it up by adding C-models at time-critical places in the code, etc. Instead, it was developed over a few days as a matter of concept, together with Douglas Heggie, while both of us were visiting Christian Boily in Strasbourg Observatory. Douglas also wrote a Fortran version. He summarized our work during the Modest-4b meeting in Amsterdam, in June 2004 (Click here for his presentation in open office format)

Nemo environment

For a complete software environment in which to run the tree code, you can obtain a copy of the

There you will find a number of other tools for setting up, integrating, and analyzing N-body systems, mostly for `collisionless' situations, in which two-body relaxation effects are not important. The first version of NEMO was written in 1986 by Joshua Barnes and Piet Hut, at the Institute for Advanced Study. Soon Peter Teuben contributed several additions, and then took the lead in the maintenance of the package.

Kira code

Simulations of dense stellar systems pose very different requirements on a computer code. Close encounters between single stars, double stars, triples, and higher multiples have to be resolved on scales in space and time that are many orders of magnitude smaller than the global scales for the simulation as a whole. We have developed the kira code which uses a hierarchical nesting of separate local coordinate patches to resolve such close encounters, based on particle groupings in dynamically evolving binary trees. The code is available as part of the Starlab environment.

Starlab environment

To study systems where two-body relaxation is important (in stellar dynamics jargon called `collisional' systems, whether or not physical collisions play a role), you can obtain obtain a copy of the

The first version of Starlab was written in 1989 by Piet Hut, while on sabbatical at the University of Tokyo. Starting in 1992, Starlab was translated from C to C++ and developed further by Piet Hut, Steve McMillan and Jun Makino. Soon afterward, Simon Portegies Zwart added a stellar evolution extension (SeBa) to the main dynamical engine (the Kira code).


We are in the process of integrating Starlab with a plotting package, also freely available from our web site:

(for particle viewing), developed by Stuart Levy, at NCSA.

HOP: a group-finding algorithm

In large-scale N-body simulations, it is sometimes difficult to discern which particles belong to the same group or cluster. This is especially true for cosmological simulations aimed at following the evolution of large-scale structure, on the scale of clusters of galaxies and beyond. Several techniques have been developed to uncover physically meaningful groups. A few years ago, we developed a new group-finding algorithm that is completely coordinate-free and spatially adaptive, as described in HOP: A New Group-Finding Algorithm for N-body Simulations, by Eisenstein, D.J. & Hut, P. 1998, Astrophys. J.498, 137-142. A copy of the code can be obtained from

Core radius and Density Estimates

Stefano Casertano and I constructed a coordinate-independent scale-free algorithm to measure local densities, based on the kth nearest neighbor distance of a particle, and we used these estimates in turn to estimate the core radii of arbitrary distributions of stars in a cluster. The algorithms were introduced and analyzed in our paper Core Radius and Density Measurements in N-body Experiments: Connections with Theoretical and Observational Definitions, by Casertano, S. & Hut, P., 1985, Astrophys. J.298, 80-94. Implementations of the algorithms can be found in the Starlab package described above.