From: Mathias Anselmann Date: Tue, 10 Nov 2020 23:24:22 +0000 (+0100) Subject: applied proposed changes by masterleinad X-Git-Tag: v9.3.0-rc1~910^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f5d6143bb2512537547f1af588d99290bab2efe;p=dealii.git applied proposed changes by masterleinad --- diff --git a/include/deal.II/dofs/dof_tools.h b/include/deal.II/dofs/dof_tools.h index fc30216f7f..380859bfa0 100644 --- a/include/deal.II/dofs/dof_tools.h +++ b/include/deal.II/dofs/dof_tools.h @@ -1658,11 +1658,10 @@ namespace DoFTools IndexSet & dof_set); /** - * Same function as above, but on a certain level in a multigrid scenarion. - * Strictly speaking we don't talk about active DoFs in such a multigrid - * scenario. Nevertheless this function returns all DoF indices that live on - * all locally owned cells (including on the interface to ghost cells) on a - * certain level, as the function above. + * Same function as above but for a certain (multigrid-)level. + * This function returns all DoF indices that live on + * all locally owned cells (including on the interface to ghost cells) on the + * given level. */ template void diff --git a/source/dofs/dof_renumbering.cc b/source/dofs/dof_renumbering.cc index d997f2dd08..03a4f8bd35 100644 --- a/source/dofs/dof_renumbering.cc +++ b/source/dofs/dof_renumbering.cc @@ -410,28 +410,29 @@ namespace DoFRenumbering // // note that if constraints are not requested, then the 'constraints' // object will be empty and using it has no effect - IndexSet locally_relevant_dofs; - IndexSet const *ptr_locally_owned_dofs; - if (reorder_level_dofs == false) - { - DoFTools::extract_locally_relevant_dofs(dof_handler, - locally_relevant_dofs); - ptr_locally_owned_dofs = &dof_handler.locally_owned_dofs(); - } - else - { - Assert(dof_handler.n_dofs(level) != numbers::invalid_dof_index, - ExcDoFHandlerNotInitialized()); - DoFTools::extract_locally_relevant_level_dofs(dof_handler, - level, - locally_relevant_dofs); - ptr_locally_owned_dofs = &dof_handler.locally_owned_mg_dofs(level); - } + IndexSet locally_relevant_dofs; + const IndexSet locally_owned_dofs = [&]() { + if (reorder_level_dofs == false) + { + DoFTools::extract_locally_relevant_dofs(dof_handler, + locally_relevant_dofs); + return dof_handler.locally_owned_dofs(); + } + else + { + Assert(dof_handler.n_dofs(level) != numbers::invalid_dof_index, + ExcDoFHandlerNotInitialized()); + DoFTools::extract_locally_relevant_level_dofs(dof_handler, + level, + locally_relevant_dofs); + return dof_handler.locally_owned_mg_dofs(level); + } + }(); AffineConstraints constraints; if (use_constraints) { - // regarding constraints is not yet implemented on a level basis + // reordering with constraints is not yet implemented on a level basis Assert(reorder_level_dofs == false, ExcNotImplemented()); constraints.reinit(locally_relevant_dofs); @@ -440,13 +441,12 @@ namespace DoFRenumbering constraints.close(); // see if we can get away with the sequential algorithm - if (ptr_locally_owned_dofs->n_elements() == ptr_locally_owned_dofs->size()) + if (locally_owned_dofs.n_elements() == locally_owned_dofs.size()) { - AssertDimension(new_indices.size(), - ptr_locally_owned_dofs->n_elements()); + AssertDimension(new_indices.size(), locally_owned_dofs.n_elements()); - DynamicSparsityPattern dsp(ptr_locally_owned_dofs->size(), - ptr_locally_owned_dofs->size()); + DynamicSparsityPattern dsp(locally_owned_dofs.size(), + locally_owned_dofs.size()); if (reorder_level_dofs == false) { DoFTools::make_sparsity_pattern(dof_handler, dsp, constraints); @@ -490,7 +490,7 @@ namespace DoFRenumbering { if ((needs_locally_active == /* previously already set to */ true) || - (ptr_locally_owned_dofs->is_element(starting_index) == false)) + (locally_owned_dofs.is_element(starting_index) == false)) { Assert( locally_active_dofs.is_element(starting_index), @@ -505,8 +505,7 @@ namespace DoFRenumbering } const IndexSet index_set_to_use = - (needs_locally_active ? locally_active_dofs : - *ptr_locally_owned_dofs); + (needs_locally_active ? locally_active_dofs : locally_owned_dofs); // if this process doesn't own any DoFs (on this level), there is // nothing to do @@ -557,8 +556,7 @@ namespace DoFRenumbering index_set_to_use.index_within_set(starting_indices[i]); // then do the renumbering on the locally owned portion - AssertDimension(new_indices.size(), - ptr_locally_owned_dofs->n_elements()); + AssertDimension(new_indices.size(), locally_owned_dofs.n_elements()); std::vector my_new_indices( index_set_to_use.n_elements()); SparsityTools::reorder_Cuthill_McKee(local_sparsity, @@ -577,7 +575,7 @@ namespace DoFRenumbering { // first step: figure out which DoF indices to eliminate IndexSet active_but_not_owned_dofs = locally_active_dofs; - active_but_not_owned_dofs.subtract_set(*ptr_locally_owned_dofs); + active_but_not_owned_dofs.subtract_set(locally_owned_dofs); std::set erase_these_indices; for (const auto p : active_but_not_owned_dofs) @@ -617,14 +615,14 @@ namespace DoFRenumbering translate_indices[i] = next_new_index; ++next_new_index; } - Assert(next_new_index == ptr_locally_owned_dofs->n_elements(), + Assert(next_new_index == locally_owned_dofs.n_elements(), ExcInternalError()); } // and then do the renumbering of the result of the // Cuthill-McKee algorithm above, right into the output array new_indices.clear(); - new_indices.reserve(ptr_locally_owned_dofs->n_elements()); + new_indices.reserve(locally_owned_dofs.n_elements()); for (const auto &p : my_new_indices) if (p != numbers::invalid_dof_index) { @@ -632,7 +630,7 @@ namespace DoFRenumbering ExcInternalError()); new_indices.push_back(translate_indices[p]); } - Assert(new_indices.size() == ptr_locally_owned_dofs->n_elements(), + Assert(new_indices.size() == locally_owned_dofs.n_elements(), ExcInternalError()); } else @@ -643,7 +641,7 @@ namespace DoFRenumbering // indices of the locally-owned DoFs. so that's where we get the // indices for (types::global_dof_index &new_index : new_indices) - new_index = ptr_locally_owned_dofs->nth_index_in_set(new_index); + new_index = locally_owned_dofs.nth_index_in_set(new_index); } } diff --git a/source/dofs/dof_tools.cc b/source/dofs/dof_tools.cc index c8ddae04b3..773eec8ed4 100644 --- a/source/dofs/dof_tools.cc +++ b/source/dofs/dof_tools.cc @@ -1149,19 +1149,18 @@ namespace DoFTools std::vector dof_indices; std::set global_dof_indices; - typename DoFHandler::level_cell_iterator - cell = dof_handler.begin_mg(level), - endc = dof_handler.end_mg(level); - for (; cell != endc; ++cell) - if (cell->is_locally_owned_on_level()) - { - dof_indices.resize(cell->get_fe().n_dofs_per_cell()); - cell->get_mg_dof_indices(dof_indices); + const auto filtered_iterators_range = + filter_iterators(dof_handler.cell_iterators_on_level(level), + dealii::IteratorFilters::LocallyOwnedLevelCell()); + for (const auto &cell : filtered_iterators_range) + { + dof_indices.resize(cell->get_fe().n_dofs_per_cell()); + cell->get_mg_dof_indices(dof_indices); - for (const types::global_dof_index dof_index : dof_indices) - if (!dof_set.is_element(dof_index)) - global_dof_indices.insert(dof_index); - } + for (const types::global_dof_index dof_index : dof_indices) + if (!dof_set.is_element(dof_index)) + global_dof_indices.insert(dof_index); + } dof_set.add_indices(global_dof_indices.begin(), global_dof_indices.end());