Efficient generation of restriction matrices for exploiting partial or complete symmetries in 2D and 3D problems