Skip to content

Commit 974655a

Browse files
Warn about missing IndexMap in Topology (#3853)
* Add warning * Adjust Python layer
1 parent 8dade20 commit 974655a

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

cpp/dolfinx/mesh/Topology.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,14 @@ std::shared_ptr<const common::IndexMap> Topology::index_map(int dim) const
825825
if (_entity_types[dim].size() > 1)
826826
throw std::runtime_error(
827827
"Multiple index maps of this dimension. Call index_maps instead.");
828-
return this->index_maps(dim).at(0);
828+
auto im = index_maps(dim);
829+
if (im.empty())
830+
{
831+
throw std::runtime_error(std::format(
832+
"Missing IndexMap in Topology. Maybe you need to create_entities({}).",
833+
dim));
834+
}
835+
return im.at(0);
829836
}
830837
//-----------------------------------------------------------------------------
831838
std::shared_ptr<const graph::AdjacencyList<std::int32_t>>

python/dolfinx/mesh.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,7 @@ def index_map(self, dim: int) -> _cpp.common.IndexMap:
183183
Returns:
184184
Index map for the entities of dimension ``dim``.
185185
"""
186-
if (imap := self._cpp_object.index_map(dim)) is not None:
187-
return imap
188-
else:
189-
raise RuntimeError(
190-
f"Entities of dimension {dim} has not been computed."
191-
f"Call `dolfinx.mesh.Topology.create_entities({dim}) first."
192-
)
186+
return self._cpp_object.index_map(dim)
193187

194188
def index_maps(self, dim: int) -> list[_cpp.common.IndexMap]:
195189
"""Get the IndexMaps that describes the parallel distribution of
@@ -200,14 +194,9 @@ def index_maps(self, dim: int) -> list[_cpp.common.IndexMap]:
200194
201195
Returns:
202196
List of IndexMaps for the entities of dimension ``dim``.
197+
May be empty if not yet computed.
203198
"""
204-
if (imaps := self._cpp_object.index_maps(dim)) is not None:
205-
return imaps
206-
else:
207-
raise RuntimeError(
208-
f"Entities of dimension {dim} have not been computed."
209-
f"Call `dolfinx.mesh.Topology.create_entities({dim}) first."
210-
)
199+
return self._cpp_object.index_maps(dim)
211200

212201
def interprocess_facets(self) -> npt.NDArray[np.int32]:
213202
"""List of inter-process facets, if facet topology has been

0 commit comments

Comments
 (0)