A classification of magnetic frustration and metamaterials from topology