generalize grid2d to grid