An adaptive multigrid code for computing gravitational forces