Skip to content

Commit

Permalink
Use Cache::get_vertex_to_cell_map() in GT::find_all_locally_owned_act…
Browse files Browse the repository at this point in the history
…ive_cells_around_point()
  • Loading branch information
peterrum committed Jul 31, 2023
1 parent f6b833b commit c73268e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 25 deletions.
5 changes: 4 additions & 1 deletion include/deal.II/grid/grid_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,10 @@ namespace GridTools
const Point<spacedim> & p,
const double tolerance,
const std::pair<typename MeshType<dim, spacedim>::active_cell_iterator,
Point<dim>> & first_cell);
Point<dim>> & first_cell,
const std::vector<
std::set<typename MeshType<dim, spacedim>::active_cell_iterator>>
*vertex_to_cells = nullptr);

/**
* A variant of the previous function that internally calls one of the
Expand Down
3 changes: 2 additions & 1 deletion source/grid/grid_tools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6073,7 +6073,8 @@ namespace GridTools
cache.get_triangulation(),
point,
tolerance,
first_cell);
first_cell,
&cache.get_vertex_to_cell_map());

if (enforce_unique_mapping)
{
Expand Down
59 changes: 37 additions & 22 deletions source/grid/grid_tools_dof_handlers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,10 @@ namespace GridTools
const Point<spacedim> & p,
const double tolerance,
const std::pair<typename MeshType<dim, spacedim>::active_cell_iterator,
Point<dim>> & first_cell)
Point<dim>> & first_cell,
const std::vector<
std::set<typename MeshType<dim, spacedim>::active_cell_iterator>>
*vertex_to_cells)
{
std::vector<
std::pair<typename MeshType<dim, spacedim>::active_cell_iterator,
Expand Down Expand Up @@ -671,14 +674,19 @@ namespace GridTools
unsigned int local_vertex_index = 0;
for (unsigned int d = 0; d < dim; ++d)
local_vertex_index += (unit_point[d] > 0.5 ? 1 : 0) << d;
std::vector<typename MeshType<dim, spacedim>::active_cell_iterator>
cells = find_cells_adjacent_to_vertex(
mesh, my_cell->vertex_index(local_vertex_index));
for (const auto &cell : cells)
{

const auto fu = [&](const auto &tentative_cells) {
for (const auto &cell : tentative_cells)
if (cell != my_cell)
cells_to_add.push_back(cell);
}
};

const auto vertex_index = my_cell->vertex_index(local_vertex_index);

if (vertex_to_cells != nullptr)
fu((*vertex_to_cells)[vertex_index]);
else
fu(find_cells_adjacent_to_vertex(mesh, vertex_index));
}
// point on line in 3d: We cannot simply take the intersection between
// the two vertices of cells because of hanging nodes. So instead we
Expand Down Expand Up @@ -712,21 +720,28 @@ namespace GridTools
(vertex_indices[1].second << vertex_indices[1].first);
for (unsigned int d = 0; d < 2; ++d)
{
auto tentative_cells = find_cells_adjacent_to_vertex(
mesh,
my_cell->vertex_index(first_vertex + (d << free_direction)));
for (const auto &cell : tentative_cells)
{
bool cell_not_yet_present = true;
for (const auto &other_cell : cells_to_add)
if (cell == other_cell)
{
cell_not_yet_present = false;
break;
}
if (cell_not_yet_present)
cells_to_add.push_back(cell);
}
const auto fu = [&](const auto &tentative_cells) {
for (const auto &cell : tentative_cells)
{
bool cell_not_yet_present = true;
for (const auto &other_cell : cells_to_add)
if (cell == other_cell)
{
cell_not_yet_present = false;
break;
}
if (cell_not_yet_present)
cells_to_add.push_back(cell);
}
};

const auto vertex_index =
my_cell->vertex_index(first_vertex + (d << free_direction));

if (vertex_to_cells != nullptr)
fu((*vertex_to_cells)[vertex_index]);
else
fu(find_cells_adjacent_to_vertex(mesh, vertex_index));
}
}

Expand Down
3 changes: 2 additions & 1 deletion source/grid/grid_tools_dof_handlers.inst.in
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ for (X : TRIANGULATION_AND_DOFHANDLERS; deal_II_dimension : DIMENSIONS;
const Point<deal_II_space_dimension> &,
const double,
const std::pair<typename X::active_cell_iterator,
Point<deal_II_dimension>> &);
Point<deal_II_dimension>> &,
const std::vector<std::set<typename X::active_cell_iterator>> *);

template std::vector<
std::pair<dealii::internal::ActiveCellIterator<deal_II_dimension,
Expand Down

0 comments on commit c73268e

Please sign in to comment.