Simulation of particles in gravitational fields