From 7269fb25e6900e5582d4dd0840c777527955052c Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 19 Jul 2017 12:06:30 -0600 Subject: [PATCH] Simplify the implementation of an algorithm slightly. Also make it cheaper: We really only need to loop over ghost cells, but not locally owned cells. --- source/dofs/dof_handler_policy.cc | 39 +++++++++++++++++-------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/source/dofs/dof_handler_policy.cc b/source/dofs/dof_handler_policy.cc index 7327a3cb20..83ba8970fe 100644 --- a/source/dofs/dof_handler_policy.cc +++ b/source/dofs/dof_handler_policy.cc @@ -4010,31 +4010,34 @@ namespace internal ExcInternalError()); } - // mark not locally active DoFs as invalid + // delete all knowledge of DoF indices that are not locally + // owned. we do so by getting DoF indices on cells, checking + // whether they are locally owned, if not, setting them to + // an invalid value, and then setting them again on the current + // cell + // + // DoFs we (i) know about, and (ii) don't own locally must be located + // either on ghost cells, or on the interface between a locally + // owned cell and a ghost cell. In any case, it is sufficient + // to kill them only from the ghost side cell, so loop only over + // ghost cells { std::vector local_dof_indices; - typename DoFHandlerType::active_cell_iterator - cell = dof_handler->begin_active(), - endc = dof_handler->end(); - - for (; cell != endc; ++cell) - if (!cell->is_artificial()) + for (auto cell : dof_handler->active_cell_iterators()) + if (cell->is_ghost()) { local_dof_indices.resize (cell->get_fe().dofs_per_cell); cell->get_dof_indices (local_dof_indices); - for (unsigned int i=0; iget_fe().dofs_per_cell; ++i) - { - if (local_dof_indices[i] == numbers::invalid_dof_index) - continue; - if (!dof_handler->locally_owned_dofs().is_element(local_dof_indices[i])) - { - //this DoF is not owned by us, so set it to invalid. - local_dof_indices[i] - = numbers::invalid_dof_index; - } - } + for (unsigned int i=0; iget_fe().dofs_per_cell; ++i) + // delete a DoF index if it has not already been deleted + // (e.g., by visiting a neighboring cell, if it is on the + // boundary), and if we don't own it + if ((local_dof_indices[i] != numbers::invalid_dof_index) + && + (!dof_handler->locally_owned_dofs().is_element(local_dof_indices[i]))) + local_dof_indices[i] = numbers::invalid_dof_index; cell->set_dof_indices (local_dof_indices); } -- 2.39.5