DOLFINx 0.8.0
DOLFINx C++ interface
Loading...
Searching...
No Matches
DofMap.h
Go to the documentation of this file.
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
9
10#pragma once
11
12#include "ElementDofLayout.h"
13#include <basix/mdspan.hpp>
14#include <concepts>
15#include <cstdlib>
16#include <dolfinx/common/MPI.h>
17#include <dolfinx/graph/AdjacencyList.h>
18#include <dolfinx/graph/ordering.h>
19#include <functional>
20#include <memory>
21#include <mpi.h>
22#include <span>
23#include <utility>
24#include <vector>
25
26namespace dolfinx::common
27{
28class IndexMap;
29}
30
32{
33class Topology;
34}
35
36namespace dolfinx::fem
37{
38
63transpose_dofmap(MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
64 const std::int32_t,
65 MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 2>>
66 dofmap,
67 std::int32_t num_cells);
68
75class DofMap
76{
77public:
91 template <typename E, typename U>
92 requires std::is_convertible_v<std::remove_cvref_t<E>,
94 and std::is_convertible_v<std::remove_cvref_t<U>,
95 std::vector<std::int32_t>>
96 DofMap(E&& element, std::shared_ptr<const common::IndexMap> index_map,
97 int index_map_bs, U&& dofmap, int bs)
98 : index_map(index_map), _index_map_bs(index_map_bs),
99 _element_dof_layout(std::forward<E>(element)),
100 _dofmap(std::forward<U>(dofmap)), _bs(bs),
101 _shape1(_element_dof_layout.num_dofs()
102 * _element_dof_layout.block_size() / _bs)
103 {
104 // Do nothing
105 }
106
107 // Copy constructor
108 DofMap(const DofMap& dofmap) = delete;
109
111 DofMap(DofMap&& dofmap) = default;
112
113 // Destructor
114 ~DofMap() = default;
115
116 // Copy assignment
117 DofMap& operator=(const DofMap& dofmap) = delete;
118
120 DofMap& operator=(DofMap&& dofmap) = default;
121
124 bool operator==(const DofMap& map) const;
125
130 std::span<const std::int32_t> cell_dofs(std::int32_t c) const
131 {
132 return std::span<const std::int32_t>(_dofmap.data() + _shape1 * c, _shape1);
133 }
134
136 int bs() const noexcept;
137
141 DofMap extract_sub_dofmap(std::span<const int> component) const;
142
149 std::pair<DofMap, std::vector<std::int32_t>> collapse(
150 MPI_Comm comm, const mesh::Topology& topology,
151 const std::function<std::vector<int>(
152 const graph::AdjacencyList<std::int32_t>&)>& reorder_fn
153 = [](const graph::AdjacencyList<std::int32_t>& g)
154 { return graph::reorder_gps(g); }) const;
155
158 MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
159 const std::int32_t,
160 MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 2>>
161 map() const;
162
165 {
166 return _element_dof_layout;
167 }
168
171 std::shared_ptr<const common::IndexMap> index_map;
172
174 int index_map_bs() const;
175
176private:
177 // Block size for the IndexMap
178 int _index_map_bs = -1;
179
180 // Layout of dofs on a cell
181 ElementDofLayout _element_dof_layout;
182
183 // Cell local-to-dof map
184 std::vector<std::int32_t> _dofmap;
185
186 // Block size for the dofmap
187 int _bs = -1;
188
189 // Number of columns in _dofmap
190 int _shape1 = -1;
191};
192} // namespace dolfinx::fem
Degree-of-freedom map.
Definition DofMap.h:76
DofMap(DofMap &&dofmap)=default
Move constructor.
DofMap & operator=(DofMap &&dofmap)=default
Move assignment.
std::shared_ptr< const common::IndexMap > index_map
Index map that describes the parallel distribution of the dofmap.
Definition DofMap.h:171
DofMap extract_sub_dofmap(std::span< const int > component) const
Extract subdofmap component.
Definition DofMap.cpp:175
std::pair< DofMap, std::vector< std::int32_t > > collapse(MPI_Comm comm, const mesh::Topology &topology, const std::function< std::vector< int >(const graph::AdjacencyList< std::int32_t > &)> &reorder_fn=[](const graph::AdjacencyList< std::int32_t > &g) { return graph::reorder_gps(g);}) const
Create a "collapsed" dofmap (collapses a sub-dofmap)
Definition DofMap.cpp:209
DofMap(E &&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:96
MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan< const std::int32_t, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents< std::size_t, 2 > > map() const
Get dofmap data.
Definition DofMap.cpp:274
std::span< const std::int32_t > cell_dofs(std::int32_t c) const
Local-to-global mapping of dofs on a cell.
Definition DofMap.h:130
const ElementDofLayout & element_dof_layout() const
Layout of dofs on an element.
Definition DofMap.h:164
int index_map_bs() const
Block size associated with the index_map.
Definition DofMap.cpp:282
bool operator==(const DofMap &map) const
Equality operator.
Definition DofMap.cpp:167
int bs() const noexcept
Return the block size for the dofmap.
Definition DofMap.cpp:173
Definition ElementDofLayout.h:30
Definition AdjacencyList.h:28
Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relat...
Definition Topology.h:44
Miscellaneous classes, functions and types.
Definition dolfinx_common.h:8
Finite element method functionality.
Definition assemble_matrix_impl.h:26
graph::AdjacencyList< std::int32_t > transpose_dofmap(MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan< const std::int32_t, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents< std::size_t, 2 > > 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:118
std::vector< std::int32_t > reorder_gps(const graph::AdjacencyList< std::int32_t > &graph)
Re-order a graph using the Gibbs-Poole-Stockmeyer algorithm.
Definition ordering.cpp:360
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32