2.3 Simulations
2.3.1 Force computation: gravity
The most accurate way to evaluate the gravitational force acting on particle k
is direct summation: Fk = X j6=k Gmj rj−rk |rj−rk|3 , (2.6)
where the sum is on all the other particles in the system. However, this is not a viable way due to its prohibitive computational cost (≈N2 operations per timestep). Other techniques have been developed that allow a much faster evaluation of the gravitational interaction while maintaining an acceptable accuracy.
Hierarchical tree
This method reduces to direct summation for the contribution of nearby parti- cles, but involves a great simplification in the evaluation of long-range interactions. This result in a reduction in the number of operations per timestep from≈ N2 to
≈N logN.
In one of the most popular versions of the algorithm (Barnes and Hut, 1986), the computational domain is recursively partitioned in a sequence of cubes. Starting from the simulation box (the root node), each cube is split into eight child nodes of half the side length each; the procedure is repeated on each child node until one ends up with a cube containing one single particle (the leaf node). Once thishier- archical treeis built, the force computation on particlekproceeds starting from the
Figure 2.4: Computation of the gravitational force acting on one of 100 particles (marked as stars) in two dimensions. The left plot shows the case for direct summation; each red line represents one evaluation of the force. The right plot shows the hierarchical-tree method; each green line represents a particle-node interaction, whereas the red line a direct particle-particle interaction. Figure adapted from Dehnen and Read (2011).
root node, down to the branches and - in some cases - to the leaves. The following criterion decides how deep into the hierarchy it is necessary to go:
r > l
θ, (2.7)
where r is the particle-node distance, l is the size of the node and θ is the open- ing angle, a parameter controlling the accuracy of the force computation. If the inequality is satisfied, the node is considered distant enough for the following sim- plification to apply: the contribution of all the member particles to the gravitational force acting on particlekis reduced to the computation of one single force provided by a particle of mass equal to the sum of these particles and positioned in their centre of mass. Clearly, this method provides only an approximation to the true force, better or worse depending on the choice of the opening angle. In the limit
θ= 0, the method reduces to direct summation.
Fig. 2.4 gives a visual idea of the different effort required by direct and tree methods to compute the gravitational interaction on one target particle.
Particle-Mesh (PM) techniques
Another way to obtain the evolution of the system under the effect of gravity is to solve the Poisson equation:
∇2Φ = 4πGρ. (2.8)
This approach is at the basis of PM methods (Hockney and Eastwood, 1981). The first step is to compute the density ρ out of the position of the particles. This is done at a set of regularly spaced points - the nodes of a mesh. The process of esti- mating the density at each of the grid points is called mass assignment: the mass of each particle is assigned to one or more nearby nodes, via a number of possible techniques (nearest-grid-point - NGP, cloud-in-cell - CIC, triangular-shaped-cloud - TSC, etc.). Once the density information is available, Eq. 2.8 is solved to obtain the value of the gravitational potential at each grid point. This is done in Fourier space using the Fast Fourier Transform technique (FFT; Cooley and Tukey 1965); the transformed density field is multiplied by Green’s function for the potential (−4πG/k2) and the result is then inverse-transformed in real space. The resulting gravitational potential is differentiated to obtain the corresponding force at each grid point. These are finally interpolated to the particle position using the same technique as for the mass assignment. Note that the Fourier approach implicitly assumes periodic boundary conditions for the computational domain, exactly as desired for cosmological simulations of structure formation.
The PM method comes with a computational cost comparable to that of the tree (≈ N logN). It provides an exact evaluation of the gravitational force, modulo inac- curacies introduced by the interpolation techniques. Its main shortcoming lies in the resolution limit set by the grid size; in some cases this cannot be reduced down to the desired scale without incurring memory problems.
The hybrid, TreePM method
A very popular technique used in state-of-the-art cosmological simulation codes is the so-called “TreePM” (Xu, 1995; Bode et al., 2000; Bagla, 2002); as the name suggests, it consists of a hybrid between the tree and PM methods. The scheme is implemented such that small-range interactions are evaluated by means of a hierarchical tree, leaving the long-range part to the PM algorithm. This allows:
• a fast and accurate evaluation of the gravitational interaction between distant particles and the automatic inclusion of periodic boundaries;
• a greater flexibility in the desired accuracy for the evaluated force on small scales.
A final comment on the resolution of the force computation in N-body codes. By definition, the gravitational potential of a collisionless system is smooth - i.e. the dynamics is not influenced by particle-particle encounters. By representing the
system with a number of particles infinitely smaller than its actual building blocks, we are boosting its collisionality. There is nothing that can be done to limit this problem, other than increasing the number of particles. The enhanced collisionality on small scales can have additional, tedious effects; a close approach between two of the sampling particles can lead to divergences in the evaluation of Eq. 2.6. The traditional way to solve this problem is tosoften the gravitational interaction. This means evaluating, instead of Eq. 2.6, an expression of the kind:
Fk= X j6=k Gmj (|rj−rk|2+2)3/2 rj−rk |rj−rk| , (2.9)
where is called the softening length and sets the scale below which the gravita- tional force deviates from the classical form of Eq. 2.6. The effect of this softening procedure is to smoothen the potential on scales smaller than ; the spurious ef- fects due to particle-particle collisions are attenuated and less computational time is needed to integrate the encounters (see Sec. 2.3.3). Gravitational force softening is the subject of the next two chapters and more will be said on the topic. Note that an implicit form of softening is present in the PM method too, even though Eq. 2.9 is not computed directly. This is given by the presence of a finite grid spacing, below which the evaluation of the force is not reliable.