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 unnecessary queries to n_faces() #45

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions include/agglomeration_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,11 @@ class AgglomerationHandler : public Subscriptor
const auto &agglo_neigh =
agglomerated_neighbor(cell,
f); // returns the neighboring master
const unsigned int n_faces_agglomerated_neighbor =
n_faces(agglo_neigh);
// Loop over all cells of neighboring agglomerate
for (unsigned int f_out = 0; f_out < n_faces(agglo_neigh); ++f_out)
for (unsigned int f_out = 0; f_out < n_faces_agglomerated_neighbor;
++f_out)
{
if (agglomerated_neighbor(agglo_neigh, f_out).state() ==
IteratorState::valid &&
Expand Down Expand Up @@ -520,7 +523,7 @@ class AgglomerationHandler : public Subscriptor
* is as it can be equal to -1 (meaning that the cell is a master one).
*/
std::vector<typename Triangulation<dim, spacedim>::active_cell_iterator>
get_slaves_of_idx(const int idx) const;
get_slaves_of_idx(types::global_cell_index idx) const;



Expand Down Expand Up @@ -773,6 +776,12 @@ class AgglomerationHandler : public Subscriptor

Quadrature<dim - 1> agglomeration_face_quad;

// Associate the master cell to the slaves.
std::unordered_map<
types::global_cell_index,
std::vector<typename Triangulation<dim, spacedim>::active_cell_iterator>>
master2slaves;


/**
* Initialize connectivity informations
Expand Down
30 changes: 13 additions & 17 deletions src/agglomeration_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,19 @@ AgglomerationHandler<dim, spacedim>::agglomerate_cells(
cell; // set iterator to master cell
}

std::vector<typename Triangulation<dim, spacedim>::active_cell_iterator>
slaves;
slaves.reserve(vec_of_cells.size() - 1);
for (const auto &cell : vec_of_cells)
{
if (cell->active_cell_index() != master_idx)
master_slave_relationships_iterators[cell->active_cell_index()] =
master_slave_relationships_iterators[master_idx];
{
master_slave_relationships_iterators[cell->active_cell_index()] =
master_slave_relationships_iterators[master_idx];
slaves.push_back(cell);
}
}
master2slaves[master_idx] = slaves;

for (const types::global_cell_index idx : global_indices)
{
Expand All @@ -87,22 +94,11 @@ AgglomerationHandler<dim, spacedim>::agglomerate_cells(


template <int dim, int spacedim>
std::vector<typename Triangulation<dim, spacedim>::active_cell_iterator>
AgglomerationHandler<dim, spacedim>::get_slaves_of_idx(const int idx) const
inline std::vector<typename Triangulation<dim, spacedim>::active_cell_iterator>
AgglomerationHandler<dim, spacedim>::get_slaves_of_idx(
const types::global_cell_index idx) const
{
std::vector<typename Triangulation<dim, spacedim>::active_cell_iterator>
slaves;

// Loop over the tria, and check if a each cell is a slave of master cell
// idx If no slave is found, return an empty vector.
for (const auto &cell : tria->active_cell_iterators())
{
if (master_slave_relationships[cell->active_cell_index()] == idx)
{
slaves.push_back(cell);
}
}
return slaves;
return master2slaves.at(idx);
}


Expand Down
Loading
Loading