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

Speed up computation of cell vertex indices cache #13930

Merged
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
49 changes: 46 additions & 3 deletions source/grid/tria.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14561,9 +14561,52 @@ Triangulation<dim, spacedim>::reset_cell_vertex_indices_cache()
for (const auto &cell : cell_iterators_on_level(l))
{
const unsigned int my_index = cell->index() * max_vertices_per_cell;
for (const unsigned int i : cell->vertex_indices())
cache[my_index + i] = internal::TriaAccessorImplementation::
Implementation::vertex_index(*cell, i);

// to reduce the cost of this function when passing down into quads,
// then lines, then vertices, we use a more low-level access method
// for hexahedral cells, where we can streamline most of the logic
const ReferenceCell ref_cell = cell->reference_cell();
if (ref_cell == ReferenceCells::Hexahedron)
for (unsigned int face = 4; face < 6; ++face)
{
const auto face_iter = cell->face(face);
const std::array<bool, 2> line_orientations{
{face_iter->line_orientation(0),
face_iter->line_orientation(1)}};
std::array<unsigned int, 4> raw_vertex_indices{
{face_iter->line(0)->vertex_index(1 - line_orientations[0]),
face_iter->line(1)->vertex_index(1 - line_orientations[1]),
face_iter->line(0)->vertex_index(line_orientations[0]),
face_iter->line(1)->vertex_index(line_orientations[1])}};

const unsigned char orientate =
levels[l]->face_orientations[cell->index() * 6 + face];
std::array<unsigned int, 4> vertex_order{
{ref_cell.standard_to_real_face_vertex(0, face, orientate),
ref_cell.standard_to_real_face_vertex(1, face, orientate),
ref_cell.standard_to_real_face_vertex(2, face, orientate),
ref_cell.standard_to_real_face_vertex(3, face, orientate)}};

const unsigned int index = my_index + 4 * (face - 4);
for (unsigned int i = 0; i < 4; ++i)
cache[index + i] = raw_vertex_indices[vertex_order[i]];
}
else if (ref_cell == ReferenceCells::Quadrilateral)
{
const std::array<bool, 2> line_orientations{
{cell->line_orientation(0), cell->line_orientation(1)}};
std::array<unsigned int, 4> raw_vertex_indices{
{cell->line(0)->vertex_index(1 - line_orientations[0]),
cell->line(1)->vertex_index(1 - line_orientations[1]),
cell->line(0)->vertex_index(line_orientations[0]),
cell->line(1)->vertex_index(line_orientations[1])}};
for (unsigned int i = 0; i < 4; ++i)
cache[my_index + i] = raw_vertex_indices[i];
}
else
for (const unsigned int i : cell->vertex_indices())
cache[my_index + i] = internal::TriaAccessorImplementation::
Implementation::vertex_index(*cell, i);
}
}
}
Expand Down