DOLFINx 0.10.0.0
DOLFINx C++ interface
Loading...
Searching...
No Matches
Topology.h
1// Copyright (C) 2006-2022 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 <memory>
13#include <optional>
14#include <span>
15#include <tuple>
16#include <vector>
17
18namespace dolfinx::common
19{
20class IndexMap;
21}
22
23namespace dolfinx::graph
24{
25template <typename T>
26class AdjacencyList;
27}
28
29namespace dolfinx::mesh
30{
31enum class CellType;
32
45{
46public:
57 std::shared_ptr<const common::IndexMap> vertex_map,
58 std::shared_ptr<const common::IndexMap> cell_map,
59 std::shared_ptr<graph::AdjacencyList<std::int32_t>> cells,
60 const std::optional<std::vector<std::int64_t>>& original_index
61 = std::nullopt);
62
78 MPI_Comm comm, std::vector<CellType> cell_types,
79 std::shared_ptr<const common::IndexMap> vertex_map,
80 std::vector<std::shared_ptr<const common::IndexMap>> cell_maps,
81 std::vector<std::shared_ptr<graph::AdjacencyList<std::int32_t>>> cells,
82 const std::optional<std::vector<std::vector<std::int64_t>>>&
84 = std::nullopt);
85
87 Topology(const Topology& topology) = default;
88
90 Topology(Topology&& topology) = default;
91
93 ~Topology() = default;
94
96 Topology& operator=(const Topology& topology) = delete;
97
99 Topology& operator=(Topology&& topology) = default;
100
102 int dim() const noexcept;
103
108 void set_index_map(int dim, std::shared_ptr<const common::IndexMap> map);
109
118 void set_index_map(std::int8_t dim, std::int8_t i,
119 std::shared_ptr<const common::IndexMap> map);
120
127 std::shared_ptr<const common::IndexMap> index_map(int dim) const;
128
132 std::vector<std::shared_ptr<const common::IndexMap>>
133 index_maps(std::int8_t dim) const;
134
143 std::shared_ptr<const graph::AdjacencyList<std::int32_t>>
144 connectivity(int d0, int d1) const;
145
157 std::shared_ptr<const graph::AdjacencyList<std::int32_t>>
158 connectivity(std::pair<std::int8_t, std::int8_t> d0,
159 std::pair<std::int8_t, std::int8_t> d1) const;
160
163 void set_connectivity(std::shared_ptr<graph::AdjacencyList<std::int32_t>> c,
164 int d0, int d1);
165
176 void set_connectivity(std::shared_ptr<graph::AdjacencyList<std::int32_t>> c,
177 std::pair<std::int8_t, std::int8_t> d0,
178 std::pair<std::int8_t, std::int8_t> d1);
179
181 const std::vector<std::uint32_t>& get_cell_permutation_info() const;
182
197 const std::vector<std::uint8_t>& get_facet_permutations() const;
198
201 CellType cell_type() const;
202
206 std::vector<CellType> entity_types(std::int8_t dim) const;
207
212 std::int32_t create_entities(int dim);
213
218 void create_connectivity(int d0, int d1);
219
222
231 const std::vector<std::int32_t>& interprocess_facets() const;
232
237 const std::vector<std::int32_t>& interprocess_facets(std::int8_t index) const;
238
240 std::vector<std::vector<std::int64_t>> original_cell_index;
241
244 MPI_Comm comm() const;
245
246private:
247 // MPI communicator
248 dolfinx::MPI::Comm _comm;
249
250 // Cell types for entites in Topology, as follows:
251 // [CellType::point, edge_types..., facet_types..., cell_types...]
252 // Only one type is expected for vertices, (and usually edges), but facets
253 // and cells can be a list of multiple types, e.g. [quadrilateral, triangle]
254 // for facets.
255 // Offsets are position in the list for each entity dimension, in
256 // AdjacencyList style.
257 std::vector<CellType> _entity_types;
258 std::vector<std::int8_t> _entity_type_offsets;
259
260 // Parallel layout of entities for each dimension and cell type
261 // flattened in the same layout as _entity_types above.
262 std::vector<std::shared_ptr<const common::IndexMap>> _index_map;
263
264 // Connectivity between entity dimensions and cell types, arranged as
265 // a 2D array. The indexing follows the order in _entity_types, i.e.
266 // increasing in topological dimension. There may be multiple types in each
267 // dimension, e.g. triangle and quadrilateral facets.
268 // Connectivity between different entity types of same dimension will always
269 // be nullptr.
270 std::vector<std::vector<std::shared_ptr<graph::AdjacencyList<std::int32_t>>>>
271 _connectivity;
272
273 // The facet permutations (local facet, cell))
274 // [cell0_0, cell0_1, ,cell0_2, cell1_0, cell1_1, ,cell1_2, ...,
275 // celln_0, celln_1, ,celln_2,]
276 std::vector<std::uint8_t> _facet_permutations;
277
278 // Cell permutation info. See the documentation for
279 // get_cell_permutation_info for documentation of how this is encoded.
280 std::vector<std::uint32_t> _cell_permutations;
281
282 // List of facets that are on the inter-process boundary for each facet type
283 std::vector<std::vector<std::int32_t>> _interprocess_facets;
284};
285
309Topology create_topology(MPI_Comm comm, std::span<const std::int64_t> cells,
310 std::span<const std::int64_t> original_cell_index,
311 std::span<const int> ghost_owners, CellType cell_type,
312 std::span<const std::int64_t> boundary_vertices);
313
326create_topology(MPI_Comm comm, const std::vector<CellType>& cell_type,
327 std::vector<std::span<const std::int64_t>> cells,
328 std::vector<std::span<const std::int64_t>> original_cell_index,
329 std::vector<std::span<const int>> ghost_owners,
330 std::span<const std::int64_t> boundary_vertices);
331
343std::tuple<Topology, std::vector<int32_t>, std::vector<int32_t>>
344create_subtopology(const Topology& topology, int dim,
345 std::span<const std::int32_t> entities);
346
357std::vector<std::int32_t>
358entities_to_index(const Topology& topology, int dim,
359 std::span<const std::int32_t> entities);
360} // 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:45
Topology(MPI_Comm comm, CellType cell_type, std::shared_ptr< const common::IndexMap > vertex_map, std::shared_ptr< const common::IndexMap > cell_map, std::shared_ptr< graph::AdjacencyList< std::int32_t > > cells, const std::optional< std::vector< std::int64_t > > &original_index=std::nullopt)
Topology constructor.
Definition Topology.cpp:715
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:821
void create_connectivity(int d0, int d1)
Create connectivity between given pair of dimensions, d0 / -> d1.
Definition Topology.cpp:877
std::shared_ptr< const graph::AdjacencyList< std::int32_t > > connectivity(int d0, int d1) const
Return connectivity from entities of dimension d0 to entities of dimension d1. Assumes only one entit...
Definition Topology.cpp:937
void set_connectivity(std::shared_ptr< graph::AdjacencyList< std::int32_t > > c, int d0, int d1)
Set connectivity for given pair of topological dimensions.
Definition Topology.cpp:961
std::vector< std::vector< std::int64_t > > original_cell_index
Original cell index for each cell type.
Definition Topology.h:240
void create_entity_permutations()
Compute entity permutations and reflections.
Definition Topology.cpp:917
std::int32_t create_entities(int dim)
Create entities of given topological dimension.
Definition Topology.cpp:837
const std::vector< std::uint32_t > & get_cell_permutation_info() const
Returns the permutation information.
Definition Topology.cpp:986
const std::vector< std::int32_t > & interprocess_facets() const
List of inter-process facets.
Definition Topology.cpp:1015
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:1001
Topology(const Topology &topology)=default
Copy constructor.
~Topology()=default
Destructor.
std::vector< CellType > entity_types(std::int8_t dim) const
Get the entity types in the topology for a given dimension.
Definition Topology.cpp:1028
int dim() const noexcept
Return the topological dimension of the mesh.
Definition Topology.cpp:800
Topology(Topology &&topology)=default
Move constructor.
void set_index_map(int dim, std::shared_ptr< const common::IndexMap > map)
Set the IndexMap for dimension dim.
Definition Topology.cpp:802
Topology & operator=(const Topology &topology)=delete
Assignment.
MPI_Comm comm() const
Definition Topology.cpp:1036
std::vector< std::shared_ptr< const common::IndexMap > > index_maps(std::int8_t dim) const
Definition Topology.cpp:828
CellType cell_type() const
Cell type.
Definition Topology.cpp:1026
Topology & operator=(Topology &&topology)=default
Assignment.
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, std::span< const std::int64_t > cells, std::span< const std::int64_t > original_cell_index, std::span< const int > ghost_owners, CellType cell_type, std::span< const std::int64_t > boundary_vertices)
Create a mesh topology.
Definition Topology.cpp:1313
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:1324
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:1407
Top-level namespace.
Definition defines.h:12