We present a computer code written in c that is designed to simulate struct
ure formation from collisionless matter. The code is purely grid-based and
uses a recursively refined Cartesian grid to solve Poisson's equation for t
he potential, rather than obtaining the potential from a Green's function.
Refinements can have arbitrary shapes and in practice closely follow the co
mplex morphology of the density field that evolves. The time-step shortens
by a factor of 2 with each successive refinement.
Competing approaches to N-body simulation are discussed from the point of v
iew of the basic theory of N-body simulation. It is argued that an appropri
ate choice of softening length epsilon is of great importance and that e sh
ould be at all points an appropriate multiple of the local interparticle se
paration. Unlike tree and (PM)-M-3 codes, multigrid codes automatically sat
isfy this requirement. We show that at early times and low densities in cos
mological simulations, epsilon needs to be significantly smaller relative t
o the interparticle separation than in virialized regions. Tests of the abi
lity of the code's Poisson solver to recover the gravitational fields of bo
th virialized haloes and Zel'dovich waves are presented, as are tests of th
e code's ability to reproduce analytic solutions for plane-wave evolution.
The times required to conduct a Lambda CDM cosmological simulation for vari
ous configurations are compared with the times required to complete the sam
e simulation with the ART, AP(3)M and GADGET codes. The power spectra, halo
mass functions and halo-halo correlation functions of simulations conducte
d with different codes are compared.
The code is available from http://www-thphys.physics.ox.ac.uk/users/MLAPM.