DOLFIN-X
DOLFIN-X C++ interface
DofMap.h
1 // Copyright (C) 2007-2020 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 <cstdlib>
10 #include <dolfinx/common/MPI.h>
11 #include <dolfinx/graph/AdjacencyList.h>
12 #include <memory>
13 #include <utility>
14 #include <vector>
15 
16 namespace dolfinx::common
17 {
18 class IndexMap;
19 }
20 
21 namespace dolfinx::mesh
22 {
23 class Topology;
24 }
25 
26 namespace dolfinx::fem
27 {
28 class ElementDofLayout;
29 
53 graph::AdjacencyList<std::int32_t>
54 transpose_dofmap(const graph::AdjacencyList<std::int32_t>& dofmap,
55  std::int32_t num_cells);
56 
63 
64 class DofMap
65 {
66 public:
79  template <typename U,
80  typename = std::enable_if_t<std::is_same<
81  graph::AdjacencyList<std::int32_t>, std::decay_t<U>>::value>>
82  DofMap(std::shared_ptr<const ElementDofLayout> element,
83  std::shared_ptr<const common::IndexMap> index_map, int index_map_bs,
84  U&& dofmap, int bs)
86  _index_map_bs(index_map_bs), _dofmap(std::forward<U>(dofmap)), _bs(bs)
87  {
88  // Do nothing
89  }
90 
91  // Copy constructor
92  DofMap(const DofMap& dofmap) = delete;
93 
95  DofMap(DofMap&& dofmap) = default;
96 
98  virtual ~DofMap() = default;
99 
100  // Copy assignment
101  DofMap& operator=(const DofMap& dofmap) = delete;
102 
104  DofMap& operator=(DofMap&& dofmap) = default;
105 
110  tcb::span<const std::int32_t> cell_dofs(int cell) const
111  {
112  return _dofmap.links(cell);
113  }
114 
116  int bs() const noexcept;
117 
121  DofMap extract_sub_dofmap(const std::vector<int>& component) const;
122 
128  std::pair<std::unique_ptr<DofMap>, std::vector<std::int32_t>>
129  collapse(MPI_Comm comm, const mesh::Topology& topology) const;
130 
133  const graph::AdjacencyList<std::int32_t>& list() const;
134 
136  std::shared_ptr<const ElementDofLayout> element_dof_layout;
137 
139  std::shared_ptr<const common::IndexMap> index_map;
140 
142  int index_map_bs() const;
143 
144 private:
145  // Block size for the IndexMap
146  int _index_map_bs = -1;
147 
148  // Cell-local-to-dof map (dofs for cell dofmap[cell])
149  graph::AdjacencyList<std::int32_t> _dofmap;
150 
151  // Block size for the dofmap
152  int _bs = -1;
153 };
154 } // namespace dolfinx::fem
Degree-of-freedom map.
Definition: DofMap.h:65
std::shared_ptr< const ElementDofLayout > element_dof_layout
Layout of dofs on an element.
Definition: DofMap.h:136
int index_map_bs() const
Index map that described the parallel distribution of the dofmap.
Definition: DofMap.cpp:298
std::shared_ptr< const common::IndexMap > index_map
Index map that described the parallel distribution of the dofmap.
Definition: DofMap.h:139
DofMap(std::shared_ptr< const ElementDofLayout > element, std::shared_ptr< const common::IndexMap > index_map, int index_map_bs, U &&dofmap, int bs)
Create a DofMap from the layout of dofs on a reference element, an IndexMap defining the distribution...
Definition: DofMap.h:82
std::pair< std::unique_ptr< DofMap >, std::vector< std::int32_t > > collapse(MPI_Comm comm, const mesh::Topology &topology) const
Create a "collapsed" dofmap (collapses a sub-dofmap)
Definition: DofMap.cpp:232
DofMap & operator=(DofMap &&dofmap)=default
Move assignment.
const graph::AdjacencyList< std::int32_t > & list() const
Get dofmap data.
Definition: DofMap.cpp:293
virtual ~DofMap()=default
Destructor.
DofMap(DofMap &&dofmap)=default
Move constructor.
tcb::span< const std::int32_t > cell_dofs(int cell) const
Local-to-global mapping of dofs on a cell.
Definition: DofMap.h:110
int bs() const noexcept
Return the block size for the dofmap.
Definition: DofMap.cpp:192
DofMap extract_sub_dofmap(const std::vector< int > &component) const
Extract subdofmap component.
Definition: DofMap.cpp:194
The class represents the degree-of-freedom (dofs) for an element. Dofs are associated with a mesh ent...
Definition: ElementDofLayout.h:36
This class provides a static adjacency list data structure. It is commonly used to store directed gra...
Definition: AdjacencyList.h:68
Miscellaneous classes, functions and types.
Finite element method functionality.
Definition: assemble_matrix_impl.h:23
graph::AdjacencyList< std::int32_t > transpose_dofmap(const graph::AdjacencyList< std::int32_t > &dofmap, std::int32_t num_cells)
Create an adjacency list that maps a global index (process-wise) to the 'unassembled' cell-wise contr...
Definition: DofMap.cpp:150
Mesh data structures and algorithms on meshes.
Definition: DirichletBC.h:23