From: Marc Fehling Date: Thu, 29 Nov 2018 12:21:55 +0000 (+0100) Subject: Applied suggestions. To be squashed. X-Git-Tag: v9.1.0-rc1~519^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c1ec84a50d8cbe6bf98dbc775f1754c3b50de09b;p=dealii.git Applied suggestions. To be squashed. --- diff --git a/include/deal.II/hp/dof_handler.h b/include/deal.II/hp/dof_handler.h index 6f8b91ac5e..bd39addf13 100644 --- a/include/deal.II/hp/dof_handler.h +++ b/include/deal.II/hp/dof_handler.h @@ -31,8 +31,6 @@ #include #include -#include - #include #include #include @@ -126,7 +124,13 @@ namespace hp * the parent. * - When coarsening cells, the (now active) parent cell will be assigned * an active FE index that is determined from its (no longer active) - * children, following the FiniteElementDomination logic. + * children, following the FiniteElementDomination logic: We choose the + * least dominant among all elements that dominate all of those used on the + * children. See FECollection::find_least_dominating_fe_in_collection() for + * further information on this topic. + * + * @note Finite elements need to be assigned to each cell by calling + * distribute_dofs() first to make this functionality available. * * *

Active FE indices and parallel meshes

@@ -1106,16 +1110,16 @@ namespace hp std::vector vertex_dof_offsets; /** - * Container to temporarily store the CellID and active FE index of + * Container to temporarily store the iterator and active FE index of * cells that will be refined. */ - std::vector> refined_cells_fe_index; + std::map refined_cells_fe_index; /** - * Container to temporarily store the CellID and active FE index of - * cells that will be coarsened. + * Container to temporarily store the iterator and active FE index of + * parent cells that will remain after coarsening. */ - std::vector> coarsened_cells_fe_index; + std::map coarsened_cells_fe_index; /** * A list of connections with which this object connects to the diff --git a/source/hp/dof_handler.cc b/source/hp/dof_handler.cc index 0dd1cf0790..28ffcf3ac1 100644 --- a/source/hp/dof_handler.cc +++ b/source/hp/dof_handler.cc @@ -1731,6 +1731,8 @@ namespace hp void DoFHandler::pre_refinement_fe_index_update() { + // Finite elements need to be assigned to each cell by calling + // distribute_dofs() first to make this functionality available. if (fe_collection.size() > 0) { Assert(refined_cells_fe_index.empty(), ExcInternalError()); @@ -1745,29 +1747,25 @@ namespace hp &(*tria))); std::vector saved_subdomain_ids; - if (shared_tria != nullptr) - if (shared_tria->with_artificial_cells()) - { - saved_subdomain_ids.resize(shared_tria->n_active_cells()); - - typename parallel::shared::Triangulation:: - active_cell_iterator cell = shared_tria->begin_active(), - endc = shared_tria->end(); + if (shared_tria != nullptr && shared_tria->with_artificial_cells()) + { + saved_subdomain_ids.resize(shared_tria->n_active_cells()); - const std::vector &true_subdomain_ids = - shared_tria->get_true_subdomain_ids_of_cells(); + const std::vector &true_subdomain_ids = + shared_tria->get_true_subdomain_ids_of_cells(); - for (unsigned int index = 0; cell != endc; ++cell, ++index) - { - saved_subdomain_ids[index] = cell->subdomain_id(); - cell->set_subdomain_id(true_subdomain_ids[index]); - } + for (auto &cell : active_cell_iterators()) + { + const unsigned int index = cell->active_cell_index(); + saved_subdomain_ids[index] = cell->subdomain_id(); + cell->set_subdomain_id(true_subdomain_ids[index]); + } - // Make sure every processor knows the active_fe_indices - // on both its own cells and all ghost cells. - dealii::internal::hp::DoFHandlerImplementation::Implementation:: - communicate_active_fe_indices(*this); - } + // Make sure every processor knows the active_fe_indices + // on both its own cells and all ghost cells. + dealii::internal::hp::DoFHandlerImplementation::Implementation:: + communicate_active_fe_indices(*this); + } // Store active_fe_index information for all cells that will be // affected by refinement/coarsening. @@ -1777,28 +1775,24 @@ namespace hp { // Store the active_fe_index of each cell that will be refined // to and distribute it later on its children. - refined_cells_fe_index.push_back( - {cell->id(), cell->active_fe_index()}); + refined_cells_fe_index.insert({cell, cell->active_fe_index()}); } else if (cell->coarsen_flag_set()) { // From all cells that will be coarsened, determine their parent // and calculate its proper active_fe_index, so that it can be // set after refinement. + // But first, check if that particular cell has a parent at all. + Assert(cell->level() > 0, ExcInternalError()); const auto &parent = cell->parent(); // Check if the active_fe_index for the current cell has been // determined already. - if (std::find_if( - coarsened_cells_fe_index.cbegin(), - coarsened_cells_fe_index.cend(), - [&parent]( - const std::pair &element) { - return element.first == parent->id(); - }) == coarsened_cells_fe_index.cend()) + if (coarsened_cells_fe_index.find(parent) == + coarsened_cells_fe_index.end()) { std::set fe_indices_children; for (unsigned int child_index = 0; - child_index < GeometryInfo::max_children_per_cell; + child_index < parent->n_children(); ++child_index) fe_indices_children.insert( parent->child(child_index)->active_fe_index()); @@ -1814,22 +1808,20 @@ namespace hp "that dominates all children of a cell you are trying " "to coarsen!")); - coarsened_cells_fe_index.push_back( - {parent->id(), fe_index}); + coarsened_cells_fe_index.insert({parent, fe_index}); } } } // Finally, restore current subdomain_ids. - if (shared_tria != nullptr) - if (shared_tria->with_artificial_cells()) + if (shared_tria != nullptr && shared_tria->with_artificial_cells()) + for (auto &cell : active_cell_iterators()) { - typename parallel::shared::Triangulation:: - active_cell_iterator cell = shared_tria->begin_active(), - endc = shared_tria->end(); - - for (unsigned int index = 0; cell != endc; ++cell, ++index) - cell->set_subdomain_id(saved_subdomain_ids[index]); + if (cell->is_artificial()) + cell->set_subdomain_id(numbers::invalid_subdomain_id); + else + cell->set_subdomain_id( + saved_subdomain_ids[cell->active_cell_index()]); } } } @@ -1839,21 +1831,21 @@ namespace hp void DoFHandler::post_refinement_fe_index_update() { + // Finite elements need to be assigned to each cell by calling + // distribute_dofs() first to make this functionality available. if (fe_collection.size() > 0) { // Distribute active_fe_indices from all refined cells on their // respective children. - for (auto &pair : refined_cells_fe_index) + for (const auto &pair : refined_cells_fe_index) { - typename hp::DoFHandler::cell_iterator parent( - *(pair.first.to_cell(*tria)), this); + const cell_iterator parent(*(pair.first), this); for (unsigned int child_index = 0; - child_index < GeometryInfo::max_children_per_cell; + child_index < parent->n_children(); ++child_index) { - typename hp::DoFHandler::cell_iterator child = - parent->child(child_index); + const cell_iterator child = parent->child(child_index); if (child->is_locally_owned()) { @@ -1865,10 +1857,9 @@ namespace hp // Set active_fe_indices on coarsened cells that have been determined // before the actual coarsening happened. - for (auto &pair : coarsened_cells_fe_index) + for (const auto &pair : coarsened_cells_fe_index) { - typename hp::DoFHandler::cell_iterator cell( - *(pair.first.to_cell(*tria)), this); + const cell_iterator cell(*(pair.first), this); if (cell->is_locally_owned()) {