Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid memory allocation in CellIDTranslator #15857

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 5 additions & 9 deletions include/deal.II/grid/cell_id_translator.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ namespace internal
unsigned int child_level = 0;
unsigned int binary_entry = 2;

// path to the get to the cell
std::vector<unsigned int> cell_indices;
// compute new coarse-grid id: c_{i+1} = c_{i}*2^dim + q on path to cell
types::global_cell_index level_coarse_cell_id = coarse_cell_id;
while (child_level < n_child_indices)
{
Assert(binary_entry < binary_representation.size(), ExcInternalError());
Expand All @@ -280,20 +280,16 @@ namespace internal
unsigned int cell_index =
(((binary_representation[binary_entry] >> (j * dim))) &
(GeometryInfo<dim>::max_children_per_cell - 1));
cell_indices.push_back(cell_index);
level_coarse_cell_id =
level_coarse_cell_id * GeometryInfo<dim>::max_children_per_cell +
cell_index;
++child_level;
if (child_level == n_child_indices)
break;
}
++binary_entry;
}

// compute new coarse-grid id: c_{i+1} = c_{i}*2^dim + q;
types::global_cell_index level_coarse_cell_id = coarse_cell_id;
for (auto i : cell_indices)
level_coarse_cell_id =
level_coarse_cell_id * GeometryInfo<dim>::max_children_per_cell + i;

return level_coarse_cell_id;
}

Expand Down