To determine which
particles neighbor each other, we use a linked list/head-of-cell
method. First, we define both an integer vector with one entry for
every particle and a 3-dimensional integer grid around the matter,
whose size is set by the parameters NCMX, NCMY, and NCMZ
in the file nelist.f. The physical extent represented by each
grid cell in each direction is calculated by
taking the average smoothing length for all particles, and multiplying
by a factor of
(this just works faster). Once the grid
dimensions are defined, we run a loop over all the particles in the
simulation, calculating the grid cell in which each one lies. If the
particle is the first one to fall in its grid cell, we enter its
number into the grid. If there are already one or more particles in
the grid cell, we copy the old particle's number to the vector in the
new particle's slot, and enter the new particle's number in the grid
cell. When we are done, the algorithm to find every particle in a
given grid cell is simple: the number written in the grid cell,
,
is the highest-numbered particle which lies in the cell. The
th
element of the vector contains
, the next-highest numbered
particle in the cell. By making our way through the vector, we
recover all particles in the cell, until we reach an element in the
vector containing zero, indicating that the cell has been accounted
for completely.
Next, we go through the process of assembling the neighbor lists for
each particle. For each particle, we loop over all grid cells which
may lie within two smoothing lengths of the particle, and determine
for every particle in the cell whether this is the case. For each
particle meeting the criterion, we record its value in the array
``NNI''. Since all hydrodynamical interactions are parallelized
as described in Sec. 3.1.3,
we only record the neighbor lists spanning
particles with
on each processor.
We also keep track of the number of neighbors each particle has,
, but in a way such that every processor has access to the
complete list for all particles.