DOLFINx 0.12.0.0
DOLFINx C++
Loading...
Searching...
No Matches
Topology.h
1// Copyright (C) 2006-2026 Anders Logg and Garth N. Wells
2//
3// This file is part of DOLFINx (https://www.fenicsproject.org)
4//
5// SPDX-License-Identifier: LGPL-3.0-or-later
6
7#pragma once
8
9#include <array>
10#include <cstdint>
11#include <dolfinx/common/MPI.h>
12#include <dolfinx/graph/AdjacencyList.h>
13#include <map>
14#include <memory>
15#include <optional>
16#include <ranges>
17#include <span>
18#include <tuple>
19#include <type_traits>
20#include <utility>
21#include <vector>
22
23namespace dolfinx::common
24{
25class IndexMap;
26}
27
28namespace dolfinx::mesh
29{
31template <typename R>
32concept CellRange = std::ranges::input_range<R> and std::ranges::sized_range<R>
33 and std::is_integral_v<
34 std::remove_const_t<std::ranges::range_value_t<R>>>;
35
36enum class CellType : std::int8_t;
37
49{
50public:
70 std::vector<CellType> cell_types,
71 std::shared_ptr<const common::IndexMap> vertex_map,
72 std::vector<std::shared_ptr<const common::IndexMap>> cell_maps,
73 std::vector<std::shared_ptr<graph::AdjacencyList<std::int32_t>>> cells,
74 const std::optional<std::vector<std::vector<std::int64_t>>>&
75 original_cell_index = std::nullopt,
76 int num_threads = 1);
77
79 Topology(const Topology& topology) = default;
80
82#ifdef _MSC_VER
85 Topology(Topology&& topology) noexcept = default;
86#else
87 Topology(Topology&& topology) = default;
88#endif
89
91 ~Topology() = default;
92
93 // Copy assignment (deleted)
94 Topology& operator=(const Topology& topology) = delete;
95
97 Topology& operator=(Topology&& topology) = default;
98
100 int dim() const noexcept;
101
105 const std::vector<CellType>& entity_types(int dim) const;
106
112 CellType cell_type() const;
113
122 std::vector<std::shared_ptr<const common::IndexMap>>
123 index_maps(int dim) const;
124
134 std::shared_ptr<const common::IndexMap> index_map(int dim) const;
135
149 std::shared_ptr<const graph::AdjacencyList<std::int32_t>>
150 connectivity(std::array<int, 2> d0, std::array<int, 2> d1) const;
151
161 std::shared_ptr<const graph::AdjacencyList<std::int32_t>>
162 connectivity(int d0, int d1) const;
163
169 const std::vector<std::uint32_t>& get_cell_permutation_info() const;
170
191 const std::vector<std::uint8_t>& get_entity_permutations(int dim) const;
192
195 std::vector<CellType> cell_types() const;
196
209 const std::vector<std::int32_t>& interprocess_facets(int index) const;
210
219 const std::vector<std::int32_t>& interprocess_facets() const;
220
229 bool create_entities(int dim, int num_threads = 1);
230
238 void create_connectivity(int d0, int d1);
239
263 void create_entity_permutations(int dim, int num_threads = 1);
264
284 void create_cell_permutations(int num_threads = 1);
285
287 std::vector<std::vector<std::int64_t>> original_cell_index;
288
291 MPI_Comm comm() const;
292
293private:
294 // Cell types for entities in Topology, where _entity_types[d][i]
295 // is the ith entity type of dimension d
296 std::vector<std::vector<CellType>> _entity_types;
297
298 // _index_maps[(d, i)] is the index map for the ith entity type of
299 // dimension d
300 std::map<std::array<int, 2>, std::shared_ptr<const common::IndexMap>>
301 _index_maps;
302
303 // Connectivity between cell types: _connectivity[(dim0, i0),
304 // (dim1, i1)] is the connection from (dim0, i0) -> (dim1, i1),
305 // where dim0 and dim1 are topological dimensions and i0 and i1
306 // are the indices of cell types (following the order in _entity_types).
307 std::map<std::pair<std::array<int, 2>, std::array<int, 2>>,
308 std::shared_ptr<graph::AdjacencyList<std::int32_t>>>
309 _connectivity;
310
311 // Entity permutations by entity dimension, each (local entity, cell)
312 // [cell0_0, cell0_1, cell0_2, cell1_0, cell1_1, cell1_2, ...,
313 // celln_0, celln_1, celln_2]. Only sub-entities of a cell are stored,
314 // so the dimension is at most 2. Unset until computed, which an empty
315 // permutation vector (vertices, or a rank with no cells) does not
316 // indicate.
317 std::array<std::optional<std::vector<std::uint8_t>>, 3> _entity_permutations;
318
319 // Cell permutation info. See the documentation for
320 // get_cell_permutation_info for documentation of how this is encoded.
321 std::vector<std::uint32_t> _cell_permutations;
322
323 // List of facets that are on the inter-process boundary for each
324 // facet type. _interprocess_facets[i] is the inter-process facets of
325 // facet type i.
326 std::vector<std::vector<std::int32_t>> _interprocess_facets;
327};
328
330namespace impl
331{
343std::pair<Topology, std::vector<std::int64_t>>
344create_topology(MPI_Comm comm, const std::vector<CellType>& cell_types,
345 std::vector<std::span<const std::int64_t>> cells,
346 std::vector<std::span<const std::int64_t>> original_cell_index,
347 std::vector<std::span<const int>> ghost_owners,
348 std::span<const std::int64_t> boundary_vertices,
349 int num_threads);
350} // namespace impl
352
384create_topology(MPI_Comm comm, const std::vector<CellType>& cell_types,
385 std::vector<std::span<const std::int64_t>> cells,
386 std::vector<std::span<const std::int64_t>> original_cell_index,
387 std::vector<std::span<const int>> ghost_owners,
388 std::span<const std::int64_t> boundary_vertices,
389 int num_threads);
390
417Topology create_topology(MPI_Comm comm, std::span<const std::int64_t> cells,
418 std::span<const std::int64_t> original_cell_index,
419 std::span<const int> ghost_owners, CellType cell_type,
420 std::span<const std::int64_t> boundary_vertices,
421 int num_threads);
422
437std::tuple<Topology, std::vector<int32_t>, std::vector<int32_t>>
438create_subtopology(const Topology& topology, int dim,
439 std::span<const std::int32_t> entities);
440
450std::vector<std::int32_t>
451entities_to_index(const Topology& topology, int dim,
452 std::span<const std::int32_t> entities);
453
471std::vector<std::vector<std::int32_t>>
472compute_mixed_cell_pairs(const Topology& topology, mesh::CellType facet_type);
473
474} // namespace dolfinx::mesh
Distribution of a global index range [0, N) across MPI ranks.
Definition IndexMap.h:114
This class provides a static adjacency list data structure.
Definition AdjacencyList.h:41
Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relat...
Definition Topology.h:49
std::shared_ptr< const common::IndexMap > index_map(int dim) const
Get the IndexMap that describes the parallel distribution of the mesh entities.
Definition Topology.cpp:918
void create_connectivity(int d0, int d1)
Create connectivity between given pair of dimensions, d0 -> d1.
Definition Topology.cpp:1058
Topology(std::vector< CellType > cell_types, std::shared_ptr< const common::IndexMap > vertex_map, std::vector< std::shared_ptr< const common::IndexMap > > cell_maps, std::vector< std::shared_ptr< graph::AdjacencyList< std::int32_t > > > cells, const std::optional< std::vector< std::vector< std::int64_t > > > &original_cell_index=std::nullopt, int num_threads=1)
Create a mesh topology.
Definition Topology.cpp:834
std::vector< std::vector< std::int64_t > > original_cell_index
Original cell index for each cell type.
Definition Topology.h:287
std::vector< CellType > cell_types() const
Get the types of cells in the topology.
Definition Topology.cpp:900
CellType cell_type() const
Cell type.
Definition Topology.cpp:888
const std::vector< std::uint32_t > & get_cell_permutation_info() const
Get the cell permutation information.
Definition Topology.cpp:959
void create_entity_permutations(int dim, int num_threads=1)
Compute entity permutations and reflections.
Definition Topology.cpp:1098
void create_cell_permutations(int num_threads=1)
Compute the packed per-cell permutation info.
Definition Topology.cpp:1144
std::shared_ptr< const graph::AdjacencyList< std::int32_t > > connectivity(std::array< int, 2 > d0, std::array< int, 2 > d1) const
Get the connectivity from entities of topological dimension d0 to dimension d1.
Definition Topology.cpp:939
Topology(const Topology &topology)=default
Copy constructor.
~Topology()=default
Destructor.
const std::vector< CellType > & entity_types(int dim) const
Entity types in the topology for a given dimension.
Definition Topology.cpp:883
int dim() const noexcept
Topological dimension of the mesh.
Definition Topology.cpp:878
const std::vector< std::int32_t > & interprocess_facets(int index) const
List of inter-process facets of a given type.
Definition Topology.cpp:993
Topology(Topology &&topology)=default
Move constructor.
bool create_entities(int dim, int num_threads=1)
Create entities of given topological dimension.
Definition Topology.cpp:1005
MPI_Comm comm() const
Mesh MPI communicator.
Definition Topology.cpp:1161
const std::vector< std::uint8_t > & get_entity_permutations(int dim) const
Get the numbers that encode the permutation to apply to each cell-local entity of a given dimension.
Definition Topology.cpp:973
Topology & operator=(Topology &&topology)=default
Move assignment.
std::vector< std::shared_ptr< const common::IndexMap > > index_maps(int dim) const
Get the index maps that describe the parallel distribution of the mesh entities of a given topologica...
Definition Topology.cpp:906
Requirement on range of cell indices.
Definition Topology.h:32
Miscellaneous classes, functions and types.
Definition dolfinx_common.h:8
Graph data structures and algorithms.
Definition AdjacencyList.h:23
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32
std::tuple< Topology, std::vector< int32_t >, std::vector< int32_t > > create_subtopology(const Topology &topology, int dim, std::span< const std::int32_t > entities)
Create a topology for a subset of entities of a given topological dimension.
Definition Topology.cpp:1599
CellType
Cell type identifier.
Definition cell_types.h:24
std::vector< std::vector< std::int32_t > > compute_mixed_cell_pairs(const Topology &topology, mesh::CellType facet_type)
Compute a list of cell-cell connections for each possible combination in the topology which have the ...
Definition Topology.cpp:1764
Topology create_topology(MPI_Comm comm, const std::vector< CellType > &cell_types, std::vector< std::span< const std::int64_t > > cells, std::vector< std::span< const std::int64_t > > original_cell_index, std::vector< std::span< const int > > ghost_owners, std::span< const std::int64_t > boundary_vertices, int num_threads)
Create a mesh topology.
Definition Topology.cpp:1168
std::vector< std::int32_t > entities_to_index(const Topology &topology, int dim, std::span< const std::int32_t > entities)
Get entity indices for entities defined by their vertices.
Definition Topology.cpp:1699