]> https://gitweb.dealii.org/ - dealii.git/commitdiff
MGTransferGlobalCoarseningTools::create_geometric_coarsening_sequence() for additiona... 12346/head
authorPeter Munch <peterrmuench@gmail.com>
Sat, 29 May 2021 13:36:34 +0000 (15:36 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Sat, 29 May 2021 14:29:54 +0000 (16:29 +0200)
include/deal.II/multigrid/mg_transfer_global_coarsening.h
include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h

index b5f829cda622f76be4a811f79fc7a2c5e5b895e4..b542cad6b69c6b6e86dae6ed0327d07b8e059ef4 100644 (file)
@@ -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 <int dim, int spacedim>
   std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
index 1b2c1a20e01f84aee1af926f95b3cd448d8a4798..fb930adcf38706c4531beb880a74d79776190704 100644 (file)
 #include <deal.II/base/mpi_compute_index_owner_internal.h>
 #include <deal.II/base/mpi_consensus_algorithms.h>
 
+#include <deal.II/distributed/fully_distributed_tria.h>
+#include <deal.II/distributed/shared_tria.h>
+#include <deal.II/distributed/tria.h>
+
 #include <deal.II/dofs/dof_handler.h>
 #include <deal.II/dofs/dof_tools.h>
 
@@ -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<const parallel::distributed::Triangulation<dim, spacedim> *>(
-        &fine_triangulation_in);
-
-    Assert(fine_triangulation, ExcNotImplemented());
+    Assert(
+      (dynamic_cast<
+         const parallel::fullydistributed::Triangulation<dim, spacedim> *>(
+         &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<Triangulation<dim, spacedim>> {
+#ifdef DEAL_II_WITH_P4EST
+      if (const auto fine_triangulation = dynamic_cast<
+            const parallel::distributed::Triangulation<dim, spacedim> *>(
+            &fine_triangulation_in))
+        return std::make_shared<
+          parallel::distributed::Triangulation<dim, spacedim>>(
+          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<dim, spacedim> *>(
+              &fine_triangulation_in))
+        return std::make_shared<parallel::shared::Triangulation<dim, spacedim>>(
+          fine_triangulation->get_communicator(),
+          fine_triangulation->get_mesh_smoothing(),
+          fine_triangulation->with_artificial_cells());
+      else
+#endif
+        return std::make_shared<Triangulation<dim, spacedim>>(
+          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<parallel::distributed::Triangulation<dim, spacedim>>(
-            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;
   }

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.