MCPcopy Create free account
hub / github.com/FEniCS/dolfinx / transpose_dofmap

Method transpose_dofmap

cpp/dolfinx/fem/DofMap.cpp:120–162  ·  view source on GitHub ↗

-----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

118
119//-----------------------------------------------------------------------------
120graph::AdjacencyList<std::int32_t> fem::transpose_dofmap(
121 md::mdspan<const std::int32_t, md::dextents<std::size_t, 2>> dofmap,
122 std::int32_t num_cells)
123{
124 // Count number of cell contributions to each global index
125 const std::int32_t max_index = *std::max_element(
126 dofmap.data_handle(),
127 std::next(dofmap.data_handle(), num_cells * dofmap.extent(1)));
128
129 std::vector<int> num_local_contributions(max_index + 1, 0);
130 for (std::int32_t c = 0; c < num_cells; ++c)
131 {
132 auto dofs = md::submdspan(dofmap, c, md::full_extent);
133 for (std::size_t d = 0; d < dofmap.extent(1); ++d)
134 num_local_contributions[dofs[d]]++;
135 }
136
137 // Compute offset for each global index
138 std::vector<int> index_offsets(num_local_contributions.size() + 1, 0);
139 std::partial_sum(num_local_contributions.begin(),
140 num_local_contributions.end(), index_offsets.begin() + 1);
141
142 std::vector<std::int32_t> data(index_offsets.back());
143 std::vector<int> pos = index_offsets;
144 int cell_offset = 0;
145 for (std::int32_t c = 0; c < num_cells; ++c)
146 {
147 auto dofs = md::submdspan(dofmap, c, md::full_extent);
148 for (std::size_t d = 0; d < dofmap.extent(1); ++d)
149 data[pos[dofs[d]]++] = cell_offset++;
150 }
151
152 // Sort the source indices for each global index
153 // This could improve linear memory access
154 // FIXME: needs profiling
155 for (int index = 0; index < max_index; ++index)
156 {
157 std::sort(data.begin() + index_offsets[index],
158 data.begin() + index_offsets[index + 1]);
159 }
160
161 return graph::AdjacencyList(std::move(data), std::move(index_offsets));
162}
163//-----------------------------------------------------------------------------
164bool DofMap::operator==(const DofMap& map) const
165{

Callers 1

test_transpose_dofmapFunction · 0.80

Calls 2

AdjacencyListClass · 0.50
sizeMethod · 0.45

Tested by 1

test_transpose_dofmapFunction · 0.64