From: Martin Kronbichler Date: Thu, 19 Sep 2019 11:03:50 +0000 (+0200) Subject: Speed up MGTools::make_boundary_list() X-Git-Tag: v9.2.0-rc1~1071^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7448f41dee24da466f54cdbb26e1d996a9500832;p=dealii.git Speed up MGTools::make_boundary_list() --- diff --git a/source/multigrid/mg_tools.cc b/source/multigrid/mg_tools.cc index f45b2f1c68..93a77e58df 100644 --- a/source/multigrid/mg_tools.cc +++ b/source/multigrid/mg_tools.cc @@ -1320,13 +1320,14 @@ namespace MGTools local_dofs.reserve(DoFTools::max_dofs_per_face(dof)); std::fill(local_dofs.begin(), local_dofs.end(), numbers::invalid_dof_index); + std::vector> dofs_by_level( + dof.get_triangulation().n_levels()); + // First, deal with the simpler case when we have to identify all boundary // dofs if (component_mask.n_selected_components(n_components) == n_components) { - typename DoFHandler::cell_iterator cell = dof.begin(), - endc = dof.end(); - for (; cell != endc; ++cell) + for (const auto &cell : dof.cell_iterators()) { if (dof.get_triangulation().locally_owned_subdomain() != numbers::invalid_subdomain_id && @@ -1348,8 +1349,9 @@ namespace MGTools if (boundary_ids.find(bi) != boundary_ids.end()) { face->get_mg_dof_indices(level, local_dofs); - boundary_indices[level].add_indices(local_dofs.begin(), - local_dofs.end()); + dofs_by_level[level].insert(dofs_by_level[level].end(), + local_dofs.begin(), + local_dofs.end()); } } } @@ -1360,9 +1362,7 @@ namespace MGTools ExcMessage( "It's probably worthwhile to select at least one component.")); - typename DoFHandler::cell_iterator cell = dof.begin(), - endc = dof.end(); - for (; cell != endc; ++cell) + for (const auto &cell : dof.cell_iterators()) if (dof.get_triangulation().locally_owned_subdomain() == numbers::invalid_subdomain_id || cell->level_subdomain_id() != numbers::artificial_subdomain_id) @@ -1439,15 +1439,25 @@ namespace MGTools Assert(component != numbers::invalid_unsigned_int, ExcInternalError()); if (component_mask[component] == true) - boundary_indices[level].add_index(local_dofs[i]); + dofs_by_level[level].push_back(local_dofs[i]); } } else - boundary_indices[level].add_indices(local_dofs.begin(), - local_dofs.end()); + dofs_by_level[level].insert(dofs_by_level[level].end(), + local_dofs.begin(), + local_dofs.end()); } } } + for (unsigned int level = 0; level < dof.get_triangulation().n_levels(); + ++level) + { + std::sort(dofs_by_level[level].begin(), dofs_by_level[level].end()); + boundary_indices[level].add_indices( + dofs_by_level[level].begin(), + std::unique(dofs_by_level[level].begin(), + dofs_by_level[level].end())); + } }