From: Wolfgang Bangerth Date: Fri, 23 Jun 2017 14:58:16 +0000 (-0600) Subject: Let DoFHandler policy classes return the NumberCache also in distribute_mg_dofs(). X-Git-Tag: v9.0.0-rc1~1475^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be196ab7289a38168e6073d895cc4c06b74e3d7e;p=dealii.git Let DoFHandler policy classes return the NumberCache also in distribute_mg_dofs(). This follows the same pattern as a previous commit. However, it involves less drama, with the exception of an innocent assertion that had to be removed (see the last commit). Other than that, everything seems to work. --- diff --git a/include/deal.II/dofs/dof_handler_policy.h b/include/deal.II/dofs/dof_handler_policy.h index 4e725dfb66..375ffd04b8 100644 --- a/include/deal.II/dofs/dof_handler_policy.h +++ b/include/deal.II/dofs/dof_handler_policy.h @@ -75,11 +75,12 @@ namespace internal /** * Distribute the multigrid dofs on each level of the DoFHandler - * associated with this policy object. + * associated with this policy object. Return a vector of number + * caches for all of the levels. */ virtual - void - distribute_mg_dofs (std::vector &number_caches) const = 0; + std::vector + distribute_mg_dofs () const = 0; /** * Renumber degrees of freedom as specified by the first argument. The @@ -118,8 +119,8 @@ namespace internal // documentation is inherited virtual - void - distribute_mg_dofs (std::vector &number_caches) const; + std::vector + distribute_mg_dofs () const; // documentation is inherited virtual @@ -165,8 +166,8 @@ namespace internal * This function is not yet implemented. */ virtual - void - distribute_mg_dofs (std::vector &number_caches) const; + std::vector + distribute_mg_dofs () const; /** * Renumber degrees of freedom as specified by the first argument. @@ -206,8 +207,8 @@ namespace internal // documentation is inherited virtual - void - distribute_mg_dofs (std::vector &number_caches) const; + std::vector + distribute_mg_dofs () const; // documentation is inherited virtual diff --git a/include/deal.II/dofs/number_cache.h b/include/deal.II/dofs/number_cache.h index 07615788e0..16c44d7e2c 100644 --- a/include/deal.II/dofs/number_cache.h +++ b/include/deal.II/dofs/number_cache.h @@ -39,12 +39,24 @@ namespace internal */ NumberCache (); + /** + * Copy constructor. Simply copy all members of the referenced + * object to the current object. + */ + NumberCache (const NumberCache &) = default; + /** * Move constructor. Simply move all members of the referenced * object to the current object. */ NumberCache (NumberCache &&) = default; + /** + * Copy operator. Simply copy all members of the referenced + * object to the current object. + */ + NumberCache &operator= (const NumberCache &) = default; + /** * Move assignment operator. Simply move all members of the referenced * object to the current object. diff --git a/source/dofs/dof_handler.cc b/source/dofs/dof_handler.cc index 08f9011c18..18be6f1882 100644 --- a/source/dofs/dof_handler.cc +++ b/source/dofs/dof_handler.cc @@ -1126,13 +1126,7 @@ void DoFHandler::distribute_mg_dofs (const FiniteElement *dist_tr = dynamic_cast*>(&*tria); - if (!dist_tr) - mg_number_cache.resize((*tria).n_levels()); - else - mg_number_cache.resize(dist_tr->n_global_levels()); - - policy->distribute_mg_dofs (mg_number_cache); + mg_number_cache = policy->distribute_mg_dofs (); // initialize the block info object // only if this is a sequential diff --git a/source/dofs/dof_handler_policy.cc b/source/dofs/dof_handler_policy.cc index 681056c601..86f8794735 100644 --- a/source/dofs/dof_handler_policy.cc +++ b/source/dofs/dof_handler_policy.cc @@ -957,29 +957,40 @@ namespace internal template - void + std::vector Sequential:: - distribute_mg_dofs (std::vector &number_caches) const + distribute_mg_dofs () const { std::vector user_flags; - dof_handler->get_triangulation().save_user_flags (user_flags); + const_cast&>(dof_handler->get_triangulation()).clear_user_flags (); + std::vector number_caches; + number_caches.reserve (dof_handler->get_triangulation().n_levels()); for (unsigned int level = 0; level < dof_handler->get_triangulation().n_levels(); ++level) { - types::global_dof_index next_free_dof = Implementation::distribute_dofs_on_level(0, numbers::invalid_subdomain_id, - *dof_handler, level); - - number_caches[level].n_global_dofs = next_free_dof; - number_caches[level].n_locally_owned_dofs = next_free_dof; - number_caches[level].locally_owned_dofs = complete_index_set(next_free_dof); - number_caches[level].locally_owned_dofs_per_processor.resize(1); - number_caches[level].locally_owned_dofs_per_processor[0] = complete_index_set(next_free_dof); - number_caches[level].n_locally_owned_dofs_per_processor.resize(1); - number_caches[level].n_locally_owned_dofs_per_processor[0] = next_free_dof; + const types::global_dof_index next_free_dof + = Implementation::distribute_dofs_on_level(0, numbers::invalid_subdomain_id, + *dof_handler, level); + + // set up the number cache of this level + NumberCache number_cache; + number_cache.n_global_dofs = next_free_dof; + number_cache.n_locally_owned_dofs = next_free_dof; + number_cache.locally_owned_dofs = complete_index_set(next_free_dof); + number_cache.locally_owned_dofs_per_processor.resize(1); + number_cache.locally_owned_dofs_per_processor[0] = complete_index_set(next_free_dof); + number_cache.n_locally_owned_dofs_per_processor.resize(1); + number_cache.n_locally_owned_dofs_per_processor[0] = next_free_dof; + + // then push the current level's number cache onto the array + number_caches.emplace_back (number_cache); } + const_cast&>(dof_handler->get_triangulation()).load_user_flags (user_flags); + + return number_caches; } @@ -1270,14 +1281,17 @@ namespace internal template - void + std::vector ParallelShared:: - distribute_mg_dofs (std::vector &number_caches) const + distribute_mg_dofs () const { // first, call the sequential function to distribute dofs - this->Sequential::distribute_mg_dofs (number_caches); + std::vector number_caches + = this->Sequential::distribute_mg_dofs (); // now we need to update the number cache. This part is not yet implemented. - AssertThrow(false,ExcNotImplemented()); + Assert(false,ExcNotImplemented()); + + return number_caches; } @@ -2484,13 +2498,13 @@ namespace internal template - void + std::vector ParallelDistributed:: - distribute_mg_dofs (std::vector &number_caches) const + distribute_mg_dofs () const { #ifndef DEAL_II_WITH_P4EST - (void)number_caches; Assert (false, ExcNotImplemented()); + return std::vector(); #else parallel::distributed::Triangulation< dim, spacedim > *tr @@ -2515,9 +2529,11 @@ namespace internal // Triangulation has fewer levels. we need to do this because // we need to communicate across all processors on all levels const unsigned int n_levels = tr->n_global_levels(); + std::vector number_caches; + number_caches.reserve(n_levels); for (unsigned int level = 0; level < n_levels; ++level) { - NumberCache &level_number_cache = number_caches[level]; + NumberCache level_number_cache; //* 1. distribute on own subdomain const unsigned int n_initial_local_dofs = @@ -2646,6 +2662,7 @@ namespace internal == shift, ExcInternalError()); + number_caches.emplace_back (level_number_cache); } @@ -2729,6 +2746,8 @@ namespace internal } #endif // DEBUG + return number_caches; + #endif // DEAL_II_WITH_P4EST }