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 
49 std::vector<bool> compute_boundary_facets(const Topology& topology);
50 
57 class Topology
58 {
59 public:
61  Topology(MPI_Comm comm, mesh::CellType type)
62  : _mpi_comm(comm), _cell_type(type),
63  _connectivity(mesh::cell_dim(type) + 1, mesh::cell_dim(type) + 1)
64  {
65  // Do nothing
66  }
67 
69  Topology(const Topology& topology) = default;
70 
72  Topology(Topology&& topology) = default;
73 
75  ~Topology() = default;
76 
78  Topology& operator=(const Topology& topology) = delete;
79 
81  Topology& operator=(Topology&& topology) = default;
82 
84  int dim() const;
85 
90  void set_index_map(int dim,
91  const std::shared_ptr<const common::IndexMap>& map);
92 
97  std::shared_ptr<const common::IndexMap> index_map(int dim) const;
98 
105  std::shared_ptr<const graph::AdjacencyList<std::int32_t>>
106  connectivity(int d0, int d1) const;
107 
110  void set_connectivity(std::shared_ptr<graph::AdjacencyList<std::int32_t>> c,
111  int d0, int d1);
112 
114  const Eigen::Array<std::uint32_t, Eigen::Dynamic, 1>&
115  get_cell_permutation_info() const;
116 
126  const Eigen::Array<std::uint8_t, Eigen::Dynamic, Eigen::Dynamic>&
127  get_facet_permutations() const;
128 
130  size_t hash() const;
131 
134  mesh::CellType cell_type() const;
135 
136  // TODO: Rework memory management and associated API
137  // Currently, there is no clear caching policy implemented and no way of
138  // discarding cached data.
139 
140  // creation of entities
145  std::int32_t create_entities(int dim);
146 
150  void create_connectivity(int d0, int d1);
151 
153  void create_entity_permutations();
154 
156  void create_connectivity_all();
157 
160  MPI_Comm mpi_comm() const;
161 
162 private:
163  // MPI communicator
164  dolfinx::MPI::Comm _mpi_comm;
165 
166  // Cell type
167  mesh::CellType _cell_type;
168 
169  // IndexMap to store ghosting for each entity dimension
170  std::array<std::shared_ptr<const common::IndexMap>, 4> _index_map;
171 
172  // AdjacencyList for pairs of topological dimensions
173  Eigen::Array<std::shared_ptr<graph::AdjacencyList<std::int32_t>>,
174  Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
175  _connectivity;
176 
177  // The facet permutations
178  Eigen::Array<std::uint8_t, Eigen::Dynamic, Eigen::Dynamic>
179  _facet_permutations;
180 
181  // Cell permutation info. See the documentation for
182  // get_cell_permutation_info for documentation of how this is encoded.
183  Eigen::Array<std::uint32_t, Eigen::Dynamic, 1> _cell_permutations;
184 };
185 
203 Topology create_topology(MPI_Comm comm,
205  const std::vector<std::int64_t>& original_cell_index,
206  const std::vector<int>& ghost_owners,
207  const CellType& cell_type, mesh::GhostMode ghost_mode);
208 } // namespace mesh
209 } // namespace dolfinx
A duplicate MPI communicator and manage lifetime of the communicator.
Definition: MPI.h:36
This class provides a static adjacency list data structure. It is commonly used to store directed gra...
Definition: AdjacencyList.h:28
Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relat...
Definition: Topology.h:58
Topology & operator=(const Topology &topology)=delete
Assignment.
Topology & operator=(Topology &&topology)=default
Assignment.
Topology(Topology &&topology)=default
Move constructor.
Topology(const Topology &topology)=default
Copy constructor.
Topology(MPI_Comm comm, mesh::CellType type)
Create empty mesh topology.
Definition: Topology.h:61
~Topology()=default
Destructor.
int cell_dim(CellType type)
Return topological dimension of cell type.
Definition: cell_types.cpp:359
std::vector< bool > compute_boundary_facets(const Topology &topology)
Compute marker for owned facets that are on the exterior of the domain, i.e. are connected to only on...
Definition: Topology.cpp:120
CellType
Cell type identifier.
Definition: cell_types.h:21
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:304
GhostMode
Enum for different partitioning ghost modes.
Definition: Mesh.h:37