Table of Contents


nbody0, nbody00 - direct summation Aarseth N-body integrator


nbody0 in=snap_in out=snap_out [keyword=value ...]


nbody0 is the NEMO adaptation of version 0 (the Micky Mouse version) of Aarseth’s N-body integrator, as published in Appendix 4B of Binney & Tremaine (1987). It is a direct N-body integrator, i.e. for each particle it computes the force due to all other N-1 particles, hence the computational time grows approximately as N*N. Although also being referred to as a ’toy version’, it is a fully functional N-body integrator.

Each particle is followed with its own integration step - an essential feature when the dynamical times of different particles vary a lot. A complete description is given in: S.J. Aarseth, "Multiple Time Scales", ed. U.J. Brackhill & B.I. Cohen, pp377. Orlando: Academic Press. (1985).

An important input parameter to the program is the accuracy parameter eta (see also eta= below). The timestep, dt, chosen for a given particle is related to the force, F, and its time derivatives by dt = sqrt(eta * F / (d2Fdt2)), which is a slight modification of the criterion given by Aarseth in the above mentioned reference (but see also BUGS below on academic cases like the figure8 orbit).

A typical value of eta = 0.02 usually conserves the energy better than one part in 10000 over one crossing time, in the absence of close encounters.

nbody00 is the C version of nbody0, based on the f2c translated code (and hence will look odd and ugly in places). It has more debug output (debug=1 and higher) and also fixes problems with orbits like the Figure8 orbit (see BUGS below).


The following parameters are recognized in any order when the keyword is also given
Input file in snapshot(5NEMO) format. Depending on how nbody0 was compiled, other input formats are supported. [no default].
Output file in snapshot format [no default].
Accurracy parameter, which automatically determines the integration step. For small enough values of deltat the Heisenberg principle applies and the accuracy is determined by the integration step itself! [0.02].
Time interval of a major output. Although the timestep is determined from eta, the accurracy parameter, for small enough values of deltat= this parameter will determine the integration step, and hence accuracy. [Default: 0.25].
Final integration time [2.0].
Gravitational softening length [0.05].
Selects if the integration time of the next particle to be advanced be reset to the requested output time if that preceded the integration time (see deltat=). This is highly recommended, as for high output frequencies (small deltat= cf. the eta-derived timestep dt) [t].
Use higher order terms to determine the timestep from eta. In the determination of the timestep a simplified formulae using just F and F2DOT is used, which is what the original BT87 code uses. By setting this keyword higher order terms F3DOT (and also FDOT) are used, which mimic the behavior of nbody1(1NEMO) . This keyword was introduced to integrate nice orbits like the Figure8 orbit, in which both F and FDOT were 0 for the central particle. [f].
Miscellaneous control options, specified as a comma separated list of keywords. Currently implemented are: step, outputs the current timestep per particle in the Aux array of a snapshot(5NEMO) . Default: none.


The code has a hardcoded maximum number of particles in the fortran and C code (File: nmax.h), change the relevant PARAMETER statement to whatever is required. Using NEMO install the Makefile macro NMAX can also be used to do this automatically and hence easily generate a new version with a different value for NMAX, e.g. make nmax NMAX=256 nbody0. The NDIM parameter should not be changed, and remains at 3.

Close encounters are not treated in any special way. See any of the modified versions of the Aarseth code (nbody2(1NEMO) ) or in case regularization is needed (see also newton0_reg in: newton0(1NEMO) ).

Timesteps are not recomputed until the current timestep has expired.

A side-effect of the variable and particle-unique timesteps is that the final snapshot will not be exactly identical for two runs with different choices of deltat.

In order to save time, all calculations in the fortran code (nbody0.f) can be done in single precision. A different version of nbody0.f is needed in this case. See code comments labeled ‘‘SED’’.

A C version is also available, as nbody0.c, though the Makefile needs the target nbody00 to install it. The user interface is as that of nbody0, except the keyword f3dot= was added.


Starting time of initial conditions is (re)set to 0, even if the snapshot had another time.

nbody0 has a simple version of the time step criterion, which can fail in "academic" situations. For example, for the nice symmetric "figure8 orbit" (see $NEMODAT/figure8.dat), the integration will fail since the timestep for the 3rd particle blows up. Interestingly enough, some compilers (e.g. gnu) will happily work around this if optimization is turned on, but fail with pure debugging (OPT=-g) since only in this case the expression will compute as exactly 0.


A total of order 600.NMAX bytes is needed, for a given maximum of NMAX particles. This breaks down as follows:

The FORTRAN I/O code uses 10.NMAX double precision and 20.NMAX real storage units for a maximum compiled number of NMAX particles. On most machines this adds up to 160.NMAX bytes.

The C I/O code allocates space dynamically; and through limitations of the fortran code, a maximum of 100.NMAX double’s are needed, which means 400.NMAX bytes.


Sverre Aarseth (F77), Peter Teuben (C)


The nbody* series of NBODY integrators were all originally written by Sverre Aarseth, and exist in many forms throughout the scientific community. The list below is a mere zeroth order approximation to the current state of affairs:
nbody0        Binney & Tremaine’s toy version, with NEMO interface 
nbody1           variable timestep; runbody1
nbody2         with Ahmad-Cohen scheme - (see also Benz et al, 1997); runbody2
nbody3          XXX
nbody4        ... for HARP
nbody5        with regularization handling triples & binaries  
nbody6         ... for new parallel machine
nbody7        ... secret


NEMO/src/nbody/evolve/aarseth/nbody0    official source code within NEMO
NEMO/usr/aarseth/                          SJA’s other nbodyX versions (not
all exported)

See Also

hackcode1(1NEMO) , runbody2(1NEMO) , snapshot(5NEMO) , atos(1NEMO) , stoa(1NEMO)

Binney, J. & Tremaine, S. Galactic Dynamics. Princeton Unversity Press (1987), pp678.

S.J.Aarseth, 1972, p.373 in: "Gravitational N-Body Problem", IAU Colloquium #10, M.Lecar (Ed.), Reidel, Dordrecht.

S.J.Aarseth, 1985, p.377 in: "Multiple Time Scales", U.J. Brackbill & B.I. Cohen (Eds.), Academic Press, Orlando.

S.J. Aarseth, 2003, "Gravitational N-Body Simulations : Tools and Algorithms" (Cambridge Univ. Press).


30-jun-89    V1.0 created + NEMO interfaces to fortran source    PJT
3-jul-89    V1.1 mods to f2c interface, name of keywords           PJT
24-jan-90    V1.2 all in double precision                         PJT
15-nov-91    fixed up pure nbody0_ff version                     PJT
20-may-92    -- also made the C (f2c) version available                PJT
2-apr-97    documentation updated for NEMO 2.4                     PJT
6-aug-97    V1.3 added options=                                      PJT
11-feb-98    V1.3a fixed array index bug for higher order term    PJT
21-jan-00    V1.4 added reset= to fix small deltat problem/bug    PJT
24-feb-04    V1.5 documented the academic figure8 orbit problem, fixed in nbody00    PJT

Table of Contents