From d0dde4997f0a3c4d6eea4f75a3be1be02bf929b3 Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Thu, 25 Feb 2021 00:49:12 +0100 Subject: [PATCH] Simplify code of create_geometric_coarsening_sequence() --- .../multigrid/mg_transfer_global_coarsening.h | 2 +- .../mg_transfer_global_coarsening.templates.h | 25 +++++++++---------- .../mg_transfer_global_coarsening.inst.in | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/include/deal.II/multigrid/mg_transfer_global_coarsening.h b/include/deal.II/multigrid/mg_transfer_global_coarsening.h index 5d2d276bb2..228f1ab2d3 100644 --- a/include/deal.II/multigrid/mg_transfer_global_coarsening.h +++ b/include/deal.II/multigrid/mg_transfer_global_coarsening.h @@ -96,7 +96,7 @@ namespace MGTransferGlobalCoarseningTools * @note Currently, only implemented for parallel::distributed::Triangulation. */ template - std::vector>> + std::vector>> create_geometric_coarsening_sequence( const Triangulation &tria); diff --git a/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h b/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h index 034dff589e..933f550cbc 100644 --- a/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h +++ b/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h @@ -1873,15 +1873,23 @@ namespace MGTransferGlobalCoarseningTools } // namespace internal template - std::vector>> + std::vector>> create_geometric_coarsening_sequence( const Triangulation &fine_triangulation_in) { - std::vector>> - coarse_grid_triangulations; + std::vector>> + coarse_grid_triangulations(fine_triangulation_in.n_global_levels()); + + coarse_grid_triangulations.back().reset(&fine_triangulation_in, [](auto &) { + // empty deleter, since fine_triangulation_in is an external field + // and its destructor is called somewhere else + }); + + // for a single level nothing has to be done + if (fine_triangulation_in.n_global_levels() == 1) + return coarse_grid_triangulations; #ifndef DEAL_II_WITH_P4EST - (void)fine_triangulation_in; Assert(false, ExcNotImplemented()); #else const auto fine_triangulation = @@ -1895,15 +1903,6 @@ namespace MGTransferGlobalCoarseningTools const auto coarse_mesh_description = GridTools::get_coarse_mesh_description(*fine_triangulation); - coarse_grid_triangulations.resize(fine_triangulation->n_global_levels()); - - coarse_grid_triangulations[max_level].reset( - const_cast *>(&fine_triangulation_in), - [](auto &) { - // empty deleter, since fine_triangulation_in is an external field - // and its destructor is called somewhere else - }); - // create coarse meshes for (unsigned int l = max_level; l > 0; --l) { diff --git a/source/multigrid/mg_transfer_global_coarsening.inst.in b/source/multigrid/mg_transfer_global_coarsening.inst.in index 458227c55b..65365814f9 100644 --- a/source/multigrid/mg_transfer_global_coarsening.inst.in +++ b/source/multigrid/mg_transfer_global_coarsening.inst.in @@ -25,7 +25,7 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS) { #if deal_II_dimension <= deal_II_space_dimension template std::vector>> + const Triangulation>> MGTransferGlobalCoarseningTools::create_geometric_coarsening_sequence( const Triangulation &fine_triangulation_in); -- 2.39.5