Forward modeling of gravitational fields in spherical coordinates