From d19d42932a4ab052a5267132ca7ae59deb4be609 Mon Sep 17 00:00:00 2001 From: jorgensd Date: Sun, 17 Aug 2025 11:33:02 +0000 Subject: [PATCH] Start handling mixed topology more properly --- cpp/dolfinx/mesh/Geometry.h | 5 +++-- cpp/dolfinx/mesh/Topology.cpp | 11 +++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cpp/dolfinx/mesh/Geometry.h b/cpp/dolfinx/mesh/Geometry.h index 6b9b5597a0a..5767bae2ebd 100644 --- a/cpp/dolfinx/mesh/Geometry.h +++ b/cpp/dolfinx/mesh/Geometry.h @@ -271,8 +271,9 @@ create_geometry(const Topology& topology, // If the mesh has higher order geometry, permute the dofmap if (elements.front().needs_dof_permutations()) { - const std::int32_t num_cells - = topology.connectivity(topology.dim(), 0)->num_nodes(); + std::int32_t num_cells = 0; + for (const auto& imap : topology.index_maps(topology.dim())) + num_cells += imap->size_local() + imap->num_ghosts(); const std::vector& cell_info = topology.get_cell_permutation_info(); int d = elements.front().dim(); diff --git a/cpp/dolfinx/mesh/Topology.cpp b/cpp/dolfinx/mesh/Topology.cpp index 0773aefbcfa..8c4117011ce 100644 --- a/cpp/dolfinx/mesh/Topology.cpp +++ b/cpp/dolfinx/mesh/Topology.cpp @@ -859,10 +859,13 @@ Topology::connectivity(int d0, int d1) const const std::vector& Topology::get_cell_permutation_info() const { // Check if this process owns or ghosts any cells - assert(this->index_map(this->dim())); - if (auto i_map = this->index_map(this->dim()); - _cell_permutations.empty() - and i_map->size_local() + i_map->num_ghosts() > 0) + if (auto im = this->index_maps(this->dim()); im.empty()) + throw std::runtime_error("Missing IndexMap in Topology."); + + const bool has_cells = std::ranges::any_of( + this->index_maps(this->dim()), [](const auto& imap) + { return imap->size_local() + imap->num_ghosts() > 0; }); + if (has_cells and _cell_permutations.empty()) { throw std::runtime_error( "create_entity_permutations must be called before using this data.");