diff --git a/python/dolfinx/io/gmshio.py b/python/dolfinx/io/gmshio.py index 47e783384e..bcfb6cdbc8 100644 --- a/python/dolfinx/io/gmshio.py +++ b/python/dolfinx/io/gmshio.py @@ -269,20 +269,21 @@ def model_to_mesh( # Check that all cells are tagged once _d = model.getDimension() - if _d not in topologies.keys(): - raise RuntimeError("All cells are expected to be tagged once; none found") _elementTypes, _elementTags, _nodeTags = model.mesh.getElements(dim=_d, tag=-1) # assert only one type of elements # assert len(_elementTypes) == 1 # NOTE: already checked in extract_topology_and_markers + _elementType_dim = _elementType[0] + if _elementType_dim not in topologies.keys(): + raise RuntimeError("All cells are expected to be tagged once; none found") nbcells = len(_elementTags[0]) - nbcells_tagged = len(topologies[_d]["entity_tags"]) + nbcells_tagged = len(topologies[_elementType_dim]["entity_tags"]) if nbcells != nbcells_tagged: e = ( "All cells are expected to be tagged once;" f"found: {nbcells_tagged}, expected: {nbcells}" ) raise RuntimeError(e) - nbcells_tagged_once = len(np.unique(topologies[_d]["entity_tags"])) + nbcells_tagged_once = len(np.unique(topologies[_elementType_dim]["entity_tags"])) if nbcells_tagged != nbcells_tagged_once: e = "All cells are expected to be tagged once; found duplicates" raise RuntimeError(e)