We present an implementation of smoothed particle hydrodynamics (SPH)
in an adaptive particle-particle-particle-mesh (AP(3)M) algorithm. The
code evolves a mixture of purely gravitational particles and gas part
icles. SPH gas forces are calculated in the standard way from near nei
ghbors. Gravitational forces are calculated using the mesh refinement
scheme described by Couchman (1991). The AP(3)M method used in the cod
e gives rise to highly accurate forces. The maximum pairwise force err
or is set by an input parameter, For a maximum pairwise force error of
7.7%, the rms error in a distribution of particles is approximate to
0.3%. The refined-mesh approach significantly increases the efficiency
with which the neighbor particles required for the SPH forces are loc
ated. The code, ''Hydra,'' retains the principal desirable properties
of previous P(3)M-SPH implementations; speed under light clustering, n
aturally periodic boundary conditions, and easy control of the accurac
y of the pairwise interparticle forces. Under heavy clustering the cyc
le time of the new code is only 2-3 times slower than for a uniform pa
rticle distribution, overcoming the principle disadvantage of previous
implementations-a dramatic loss of efficiency as clustering develops.
A 1000 step simulation with 65,536 particles (half dark, half gas) ru
ns in one day on a Sun Sparc10 workstation. The choice of time integra
tion scheme is investigated in detail. We find that a simple single-st
ep predictor-corrector type integrator, which is equivalent to Leapfro
g for velocity-independent forces, is the most efficient. A method for
generating an initial distribution of particles by allowing a uniform
temperature gas of SPH particles to relax within a periodic box is pr
esented. The average SPH density that results varies by approximate to
+/-1.3%, This is the fluctuation amplitude on roughly the Nyquist fre
quency; for smaller wavenumbers the fluctuations have lower amplitudes
. We present a modified form of the Layzer-Irvine equation which inclu
des the thermal contribution of the gas together with radiative coolin
g. The SPH and time integration schemes were tested and compared by ru
nning a series of tests of sound waves and shocks. These tests were al
so used to derive time-step constraints sufficient to ensure both ener
gy and entropy conservation. We have compared the results of simulatio
ns of spherical infall and collapse with varying numbers of particles,
We show that many thousands of particles are necessary in a halo to c
orrectly model the collapse. As a further test, the cluster simulation
of Thomas & Couchman (1992) has been rerun with the new code, which i
ncludes a number of improvements in the SPH implementation. We find cl
ose agreement except in the core properties of the cluster which are s
trongly affected by entropy scatter in the older simulation. This demo
nstrates the crucial importance of conserving entropy in SPH simulatio
ns.