Black box multigrid for periodic and singular problems