DOLFINx 0.10.0.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
63 md::mdspan<const std::int32_t, md::dextents<std::size_t, 2>> dofmap,
64 std::int32_t num_cells);
65
72class DofMap
73{
74public:
88 template <typename E, typename U>
89 requires std::is_convertible_v<std::remove_cvref_t<E>,
91 and std::is_convertible_v<std::remove_cvref_t<U>,
92 std::vector<std::int32_t>>
93 DofMap(E&& element, std::shared_ptr<const common::IndexMap> index_map,
94 int index_map_bs, U&& dofmap, int bs)
95 : index_map(index_map), _index_map_bs(index_map_bs),
96 _element_dof_layout(std::forward<E>(element)),
97 _dofmap(std::forward<U>(dofmap)), _bs(bs),
98 _shape1(_element_dof_layout.num_dofs()
99 * _element_dof_layout.block_size() / _bs)
100 {
101 // Do nothing
102 }
103
104 // Copy constructor
105 DofMap(const DofMap& dofmap) = delete;
106
108 DofMap(DofMap&& dofmap) = default;
109
110 // Destructor
111 ~DofMap() = default;
112
113 // Copy assignment
114 DofMap& operator=(const DofMap& dofmap) = delete;
115
117 DofMap& operator=(DofMap&& dofmap) = default;
118
121 bool operator==(const DofMap& map) const;
122
127 std::span<const std::int32_t> cell_dofs(std::int32_t c) const
128 {
129 return std::span<const std::int32_t>(_dofmap.data() + _shape1 * c, _shape1);
130 }
131
133 int bs() const noexcept;
134
138 DofMap extract_sub_dofmap(std::span<const int> component) const;
139
146 std::pair<DofMap, std::vector<std::int32_t>>
147 collapse(MPI_Comm comm, const mesh::Topology& topology,
148 std::function<std::vector<int>(
149 const graph::AdjacencyList<std::int32_t>&)>&& reorder_fn
150 = nullptr) const;
151
154 md::mdspan<const std::int32_t, md::dextents<std::size_t, 2>> map() const;
155
158 {
159 return _element_dof_layout;
160 }
161
164 std::shared_ptr<const common::IndexMap> index_map;
165
167 int index_map_bs() const;
168
169private:
170 // Block size for the IndexMap
171 int _index_map_bs = -1;
172
173 // Layout of dofs on a cell
174 ElementDofLayout _element_dof_layout;
175
176 // Cell local-to-dof map
177 std::vector<std::int32_t> _dofmap;
178
179 // Block size for the dofmap
180 int _bs = -1;
181
182 // Number of columns in _dofmap
183 int _shape1 = -1;
184};
185} // namespace dolfinx::fem
Definition IndexMap.h:94
Degree-of-freedom map.
Definition DofMap.h:73
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:164
DofMap extract_sub_dofmap(std::span< const int > component) const
Extract subdofmap component.
Definition DofMap.cpp:170
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:93
std::pair< DofMap, std::vector< std::int32_t > > collapse(MPI_Comm comm, const mesh::Topology &topology, std::function< std::vector< int >(const graph::AdjacencyList< std::int32_t > &)> &&reorder_fn=nullptr) const
Create a "collapsed" dofmap (collapses a sub-dofmap)
Definition DofMap.cpp:204
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:127
const ElementDofLayout & element_dof_layout() const
Layout of dofs on an element.
Definition DofMap.h:157
md::mdspan< const std::int32_t, md::dextents< std::size_t, 2 > > map() const
Get dofmap data.
Definition DofMap.cpp:270
int index_map_bs() const
Block size associated with the index_map.
Definition DofMap.cpp:276
bool operator==(const DofMap &map) const
Equality operator.
Definition DofMap.cpp:162
int bs() const noexcept
Return the block size for the dofmap.
Definition DofMap.cpp:168
Definition ElementDofLayout.h:30
Definition AdjacencyList.h:27
Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relat...
Definition Topology.h:46
Miscellaneous classes, functions and types.
Definition dolfinx_common.h:8
Finite element method functionality.
Definition assemble_expression_impl.h:23
graph::AdjacencyList< std::int32_t > transpose_dofmap(md::mdspan< const std::int32_t, md::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
Graph data structures and algorithms.
Definition dofmapbuilder.h:26
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32