From: Peter Munch Date: Sat, 29 May 2021 13:36:34 +0000 (+0200) Subject: MGTransferGlobalCoarseningTools::create_geometric_coarsening_sequence() for additiona... X-Git-Tag: v9.4.0-rc1~1290^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F12346%2Fhead;p=dealii.git MGTransferGlobalCoarseningTools::create_geometric_coarsening_sequence() for additional types of triangulations --- diff --git a/include/deal.II/multigrid/mg_transfer_global_coarsening.h b/include/deal.II/multigrid/mg_transfer_global_coarsening.h index b5f829cda6..b542cad6b6 100644 --- a/include/deal.II/multigrid/mg_transfer_global_coarsening.h +++ b/include/deal.II/multigrid/mg_transfer_global_coarsening.h @@ -93,7 +93,9 @@ namespace MGTransferGlobalCoarseningTools * * @note For convenience, a reference to the input triangulation is stored in * the last entry of the return vector. - * @note Currently, only implemented for parallel::distributed::Triangulation. + * @note Currently, not implemented for parallel::fullydistributed::Triangulation. + * @note The type of the returned triangulations is the same as of the input + * triangulation. */ template std::vector>> 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 1b2c1a20e0..fb930adcf3 100644 --- a/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h +++ b/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h @@ -22,6 +22,10 @@ #include #include +#include +#include +#include + #include #include @@ -2140,25 +2144,47 @@ namespace MGTransferGlobalCoarseningTools if (fine_triangulation_in.n_global_levels() == 1) return coarse_grid_triangulations; -#ifndef DEAL_II_WITH_P4EST - Assert(false, ExcNotImplemented()); -#else - const auto fine_triangulation = - dynamic_cast *>( - &fine_triangulation_in); - - Assert(fine_triangulation, ExcNotImplemented()); + Assert( + (dynamic_cast< + const parallel::fullydistributed::Triangulation *>( + &fine_triangulation_in) == nullptr), + ExcMessage( + "Triangulations of type parallel::fullydistributed::Triangulation are " + "not supported by this function!")); + + const auto create_new_empty_triangulation = + [&]() -> std::shared_ptr> { +#ifdef DEAL_II_WITH_P4EST + if (const auto fine_triangulation = dynamic_cast< + const parallel::distributed::Triangulation *>( + &fine_triangulation_in)) + return std::make_shared< + parallel::distributed::Triangulation>( + fine_triangulation->get_communicator(), + fine_triangulation->get_mesh_smoothing()); + else +#endif +#ifdef DEAL_II_WITH_MPI + if (const auto fine_triangulation = dynamic_cast< + const parallel::shared::Triangulation *>( + &fine_triangulation_in)) + return std::make_shared>( + fine_triangulation->get_communicator(), + fine_triangulation->get_mesh_smoothing(), + fine_triangulation->with_artificial_cells()); + else +#endif + return std::make_shared>( + fine_triangulation_in.get_mesh_smoothing()); + }; - const unsigned int max_level = fine_triangulation->n_global_levels() - 1; + const unsigned int max_level = fine_triangulation_in.n_global_levels() - 1; // create coarse meshes for (unsigned int l = max_level; l > 0; --l) { // copy triangulation - auto new_tria = - std::make_shared>( - fine_triangulation->get_communicator(), - fine_triangulation->get_mesh_smoothing()); + auto new_tria = create_new_empty_triangulation(); new_tria->copy_triangulation(*coarse_grid_triangulations[l]); @@ -2168,7 +2194,6 @@ namespace MGTransferGlobalCoarseningTools // save mesh coarse_grid_triangulations[l - 1] = new_tria; } -#endif return coarse_grid_triangulations; }