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

Function build_collapsed_dofmap

cpp/dolfinx/fem/DofMap.cpp:28–115  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Build a collapsed DofMap from a dofmap view. Extracts dofs and doesn't build a new re-ordered dofmap.

Source from the content-addressed store, hash-verified

26// Build a collapsed DofMap from a dofmap view. Extracts dofs and
27// doesn't build a new re-ordered dofmap.
28fem::DofMap build_collapsed_dofmap(const DofMap& dofmap_view)
29{
30 spdlog::info("Build collapsed DofMap");
31
32 if (dofmap_view.element_dof_layout().block_size() > 1)
33 {
34 throw std::runtime_error("Cannot collapse a dofmap view with "
35 "block size greater "
36 "than 1 when the parent has a block "
37 "size of 1. Create new dofmap "
38 "first.");
39 }
40
41 // Build set of dofs that are in the new dofmap (un-blocked)
42 auto dofs_view_md = dofmap_view.map();
43 std::vector<std::int32_t> dofs_view(dofs_view_md.data_handle(),
44 dofs_view_md.data_handle()
45 + dofs_view_md.size());
46 dolfinx::radix_sort(dofs_view);
47 auto [unique_end, range_end] = std::ranges::unique(dofs_view);
48 dofs_view.erase(unique_end, range_end);
49
50 // Get block size
51 int bs_view = dofmap_view.index_map_bs();
52
53 // Create sub-index map
54 std::shared_ptr<common::IndexMap> index_map;
55 // Map from indices in the sub-index map to indices in the original
56 // index map
57 std::vector<std::int32_t> sub_imap_to_imap;
58 spdlog::debug("bs_view={}", bs_view);
59 if (bs_view == 1)
60 {
61 auto [_index_map, _sub_imap_to_imap] = common::create_sub_index_map(
62 *dofmap_view.index_map, dofs_view, common::IndexMapOrder::preserve);
63 index_map = std::make_shared<common::IndexMap>(std::move(_index_map));
64 sub_imap_to_imap = std::move(_sub_imap_to_imap);
65 }
66 else
67 {
68 std::vector<std::int32_t> indices;
69 indices.reserve(dofs_view.size());
70 std::ranges::transform(dofs_view, std::back_inserter(indices),
71 [bs_view](auto idx) { return idx / bs_view; });
72 auto [_index_map, _sub_imap_to_imap] = common::create_sub_index_map(
73 *dofmap_view.index_map, indices, common::IndexMapOrder::preserve);
74 index_map = std::make_shared<common::IndexMap>(std::move(_index_map));
75 sub_imap_to_imap = std::move(_sub_imap_to_imap);
76 }
77
78 spdlog::debug("Map old to new dofs");
79 // Create a map from old dofs to new dofs
80 std::size_t array_size = dofs_view.empty() ? 0 : dofs_view.back() + bs_view;
81 std::vector<std::int32_t> old_to_new(array_size, -1);
82 for (std::size_t new_idx = 0; new_idx < sub_imap_to_imap.size(); ++new_idx)
83 {
84 for (int k = 0; k < bs_view; ++k)
85 {

Callers 1

collapseMethod · 0.85

Calls 9

radix_sortFunction · 0.85
transformFunction · 0.85
mapMethod · 0.80
num_dofsMethod · 0.80
DofMapClass · 0.70
block_sizeMethod · 0.45
sizeMethod · 0.45
index_map_bsMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected