DOLFIN-X
DOLFIN-X C++ interface
Topology.h
1 // Copyright (C) 2006-2019 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 "cell_types.h"
10 #include <Eigen/Dense>
11 #include <array>
12 #include <cstdint>
13 #include <dolfinx/common/MPI.h>
14 #include <memory>
15 #include <vector>
16 
17 namespace dolfinx
18 {
19 namespace common
20 {
21 class IndexMap;
22 }
23 
24 namespace fem
25 {
26 class ElementDofLayout;
27 }
28 
29 namespace graph
30 {
31 template <typename T>
32 class AdjacencyList;
33 }
34 
35 namespace mesh
36 {
37 enum class GhostMode : int;
38 
39 enum class CellType;
40 class Topology;
41 
48 std::vector<bool> compute_interior_facets(const Topology& topology);
49 
58 class Topology
59 {
60 public:
62  Topology(MPI_Comm comm, mesh::CellType type)
63  : _mpi_comm(comm), _cell_type(type),
64  _connectivity(mesh::cell_dim(type) + 1, mesh::cell_dim(type) + 1)
65  {
66  // Do nothing
67  }
68 
70  Topology(const Topology& topology) = default;
71 
73  Topology(Topology&& topology) = default;
74 
76  ~Topology() = default;
77 
79  Topology& operator=(const Topology& topology) = delete;
80 
82  Topology& operator=(Topology&& topology) = default;
83 
85  int dim() const;
86 
91  void set_index_map(int dim,
92  std::shared_ptr<const common::IndexMap> index_map);
93 
98  std::shared_ptr<const common::IndexMap> index_map(int dim) const;
99 
107  std::vector<bool> on_boundary(int dim) const;
108 
115  std::shared_ptr<const graph::AdjacencyList<std::int32_t>>
116  connectivity(int d0, int d1) const;
117 
120  void set_connectivity(std::shared_ptr<graph::AdjacencyList<std::int32_t>> c,
121  int d0, int d1);
122 
124  const Eigen::Array<std::uint32_t, Eigen::Dynamic, 1>&
125  get_cell_permutation_info() const;
126 
136  const Eigen::Array<std::uint8_t, Eigen::Dynamic, Eigen::Dynamic>&
137  get_facet_permutations() const;
138 
144  const std::vector<bool>& interior_facets() const;
145 
148  void set_interior_facets(const std::vector<bool>& interior_facets);
149 
151  size_t hash() const;
152 
155  mesh::CellType cell_type() const;
156 
157  // TODO: Rework memory management and associated API
158  // Currently, there is no clear caching policy implemented and no way of
159  // discarding cached data.
160 
161  // creation of entities
166  std::int32_t create_entities(int dim);
167 
171  void create_connectivity(int d0, int d1);
172 
174  void create_entity_permutations();
175 
177  void create_connectivity_all();
178 
181  MPI_Comm mpi_comm() const;
182 
183 private:
184 
185  // MPI communicator
186  dolfinx::MPI::Comm _mpi_comm;
187 
188  // Cell type
189  mesh::CellType _cell_type;
190 
191  // IndexMap to store ghosting for each entity dimension
192  std::array<std::shared_ptr<const common::IndexMap>, 4> _index_map;
193 
194  // AdjacencyList for pairs of topological dimensions
195  Eigen::Array<std::shared_ptr<graph::AdjacencyList<std::int32_t>>,
196  Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
197  _connectivity;
198 
199  // The facet permutations
200  Eigen::Array<std::uint8_t, Eigen::Dynamic, Eigen::Dynamic>
201  _facet_permutations;
202 
203  // Cell permutation info. See the documentation for
204  // get_cell_permutation_info for documentation of how this is encoded.
205  Eigen::Array<std::uint32_t, Eigen::Dynamic, 1> _cell_permutations;
206 
207  // Marker for owned facets, which evaluates to True for facets that
208  // are interior to the domain
209  std::shared_ptr<const std::vector<bool>> _interior_facets;
210 };
211 
226 Topology create_topology(MPI_Comm comm,
228  const std::vector<std::int64_t>& original_cell_index,
229  const std::vector<int>& ghost_owners,
230  const CellType& cell_type, mesh::GhostMode ghost_mode);
231 } // namespace mesh
232 } // namespace dolfinx
dolfinx::mesh::Topology::Topology
Topology(MPI_Comm comm, mesh::CellType type)
Create empty mesh topology.
Definition: Topology.h:62
dolfinx::mesh::compute_interior_facets
std::vector< bool > compute_interior_facets(const Topology &topology)
Compute marker for owned facets that are interior, i.e. are connected to two cells,...
Definition: Topology.cpp:123
dolfinx::mesh::CellType
CellType
Cell type identifier.
Definition: cell_types.h:22
dolfinx::mesh::cell_dim
int cell_dim(CellType type)
Return topological dimension of cell type.
Definition: cell_types.cpp:363
dolfinx::graph::AdjacencyList
This class provides a static adjacency list data structure. It is commonly used to store directed gra...
Definition: assemble_matrix_impl.h:26
dolfinx::mesh::GhostMode
GhostMode
Enum for different partitioning ghost modes.
Definition: Mesh.h:36
dolfinx::MPI::Comm
A duplicate MPI communicator and manage lifetime of the communicator.
Definition: MPI.h:34
dolfinx::mesh::Topology
Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relat...
Definition: Topology.h:58
dolfinx::mesh::create_topology
Topology create_topology(MPI_Comm comm, const graph::AdjacencyList< std::int64_t > &cells, const std::vector< std::int64_t > &original_cell_index, const std::vector< int > &ghost_owners, const CellType &cell_type, mesh::GhostMode ghost_mode)
Create distributed topology.
Definition: Topology.cpp:414