DOLFINx 0.10.0.0
DOLFINx C++ interface
Loading...
Searching...
No Matches
Topology.h
1// Copyright (C) 2006-2024 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 <map>
13#include <memory>
14#include <optional>
15#include <span>
16#include <tuple>
17#include <utility>
18#include <vector>
19
20namespace dolfinx::common
21{
22class IndexMap;
23}
24
25namespace dolfinx::graph
26{
27template <typename T>
28class AdjacencyList;
29}
30
31namespace dolfinx::mesh
32{
33enum class CellType;
34
46{
47public:
66 std::vector<CellType> cell_types,
67 std::shared_ptr<const common::IndexMap> vertex_map,
68 std::vector<std::shared_ptr<const common::IndexMap>> cell_maps,
69 std::vector<std::shared_ptr<graph::AdjacencyList<std::int32_t>>> cells,
70 const std::optional<std::vector<std::vector<std::int64_t>>>&
72 = std::nullopt);
73
75 Topology(const Topology& topology) = default;
76
78 Topology(Topology&& topology) = default;
79
81 ~Topology() = default;
82
84 Topology& operator=(const Topology& topology) = delete;
85
87 Topology& operator=(Topology&& topology) = default;
88
90 int dim() const noexcept;
91
95 const std::vector<CellType>& entity_types(int dim) const;
96
102 CellType cell_type() const;
103
109 std::vector<std::shared_ptr<const common::IndexMap>>
110 index_maps(int dim) const;
111
118 std::shared_ptr<const common::IndexMap> index_map(int dim) const;
119
133 std::shared_ptr<const graph::AdjacencyList<std::int32_t>>
134 connectivity(std::array<int, 2> d0, std::array<int, 2> d1) const;
135
145 std::shared_ptr<const graph::AdjacencyList<std::int32_t>>
146 connectivity(int d0, int d1) const;
147
149 const std::vector<std::uint32_t>& get_cell_permutation_info() const;
150
165 const std::vector<std::uint8_t>& get_facet_permutations() const;
166
179 const std::vector<std::int32_t>& interprocess_facets(int index) const;
180
189 const std::vector<std::int32_t>& interprocess_facets() const;
190
195 bool create_entities(int dim);
196
201 void create_connectivity(int d0, int d1);
202
205
207 std::vector<std::vector<std::int64_t>> original_cell_index;
208
211 MPI_Comm comm() const;
212
213private:
214 // Cell types for entities in Topology, where _entity_types_new[d][i]
215 // is the ith entity type of dimension d
216 std::vector<std::vector<CellType>> _entity_types;
217
218 // Parallel layout of entities for each dimension and cell type
219 // flattened in the same layout as _entity_types above.
220 // std::vector<std::shared_ptr<const common::IndexMap>> _index_map;
221
222 // _index_maps[(d, i) is the index map for the ith entity type of
223 // dimension d
224 std::map<std::array<int, 2>, std::shared_ptr<const common::IndexMap>>
225 _index_maps;
226
227 // Connectivity between cell types _connectivity_new[(dim0, i0),
228 // (dim1, i1)] is the connection from (dim0, i0) -> (dim1, i1),
229 // where dim0 and dim1 are topological dimensions and i0 and i1
230 // are the indices of cell types (following the order in _entity_types).
231 std::map<std::pair<std::array<int, 2>, std::array<int, 2>>,
232 std::shared_ptr<graph::AdjacencyList<std::int32_t>>>
233 _connectivity;
234
235 // The facet permutations (local facet, cell))
236 // [cell0_0, cell0_1, ,cell0_2, cell1_0, cell1_1, ,cell1_2, ...,
237 // celln_0, celln_1, ,celln_2,]
238 std::vector<std::uint8_t> _facet_permutations;
239
240 // Cell permutation info. See the documentation for
241 // get_cell_permutation_info for documentation of how this is encoded.
242 std::vector<std::uint32_t> _cell_permutations;
243
244 // List of facets that are on the inter-process boundary for each
245 // facet type. _interprocess_facets[i] is the inter-process facets of
246 // facet type i.
247 std::vector<std::vector<std::int32_t>> _interprocess_facets;
248};
249
278create_topology(MPI_Comm comm, const std::vector<CellType>& cell_types,
279 std::vector<std::span<const std::int64_t>> cells,
280 std::vector<std::span<const std::int64_t>> original_cell_index,
281 std::vector<std::span<const int>> ghost_owners,
282 std::span<const std::int64_t> boundary_vertices);
283
307Topology create_topology(MPI_Comm comm, std::span<const std::int64_t> cells,
308 std::span<const std::int64_t> original_cell_index,
309 std::span<const int> ghost_owners, CellType cell_type,
310 std::span<const std::int64_t> boundary_vertices);
311
324std::tuple<Topology, std::vector<int32_t>, std::vector<int32_t>>
325create_subtopology(const Topology& topology, int dim,
326 std::span<const std::int32_t> entities);
327
337std::vector<std::int32_t>
338entities_to_index(const Topology& topology, int dim,
339 std::span<const std::int32_t> entities);
340} // namespace dolfinx::mesh
Definition topologycomputation.h:24
Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relat...
Definition Topology.h:46
std::shared_ptr< const common::IndexMap > index_map(int dim) const
Get the IndexMap that described the parallel distribution of the mesh entities.
Definition Topology.cpp:787
void create_connectivity(int d0, int d1)
Create connectivity between given pair of dimensions, d0 / -> d1.
Definition Topology.cpp:908
std::vector< std::vector< std::int64_t > > original_cell_index
Original cell index for each cell type.
Definition Topology.h:207
void create_entity_permutations()
Compute entity permutations and reflections.
Definition Topology.cpp:948
const std::vector< std::uint32_t > & get_cell_permutation_info() const
Returns the permutation information.
Definition Topology.cpp:807
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:793
const std::vector< std::int32_t > & interprocess_facets() const
List of inter-process facets.
Definition Topology.cpp:843
const std::vector< std::uint8_t > & get_facet_permutations() const
Get the numbers that encode the number of permutations to apply to facets.
Definition Topology.cpp:822
Topology(const Topology &topology)=default
Copy constructor.
~Topology()=default
Destructor.
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)
Create a mesh topology.
Definition Topology.cpp:712
const std::vector< CellType > & entity_types(int dim) const
Entity types in the topology for a given dimension.
Definition Topology.cpp:764
int dim() const noexcept
Topological dimension of the mesh.
Definition Topology.cpp:759
Topology(Topology &&topology)=default
Move constructor.
Topology & operator=(const Topology &topology)=delete
Assignment.
MPI_Comm comm() const
Mesh MPI communicator.
Definition Topology.cpp:968
CellType cell_type() const
Cell type.
Definition Topology.cpp:769
bool create_entities(int dim)
Create entities of given topological dimension.
Definition Topology.cpp:848
Topology & operator=(Topology &&topology)=default
Assignment.
std::vector< std::shared_ptr< const common::IndexMap > > index_maps(int dim) const
Get the index maps that described the parallel distribution of the mesh entities of a given topologic...
Definition Topology.cpp:775
Miscellaneous classes, functions and types.
Definition dolfinx_common.h:8
Graph data structures and algorithms.
Definition dofmapbuilder.h:26
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32
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)
Create a mesh topology.
Definition Topology.cpp:975
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:1261
CellType
Cell type identifier.
Definition cell_types.h:22
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:1344