]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Simplify code of create_geometric_coarsening_sequence() 11805/head
authorPeter Munch <peterrmuench@gmail.com>
Wed, 24 Feb 2021 23:49:12 +0000 (00:49 +0100)
committerPeter Munch <peterrmuench@gmail.com>
Thu, 25 Feb 2021 09:10:08 +0000 (10:10 +0100)
include/deal.II/multigrid/mg_transfer_global_coarsening.h
include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h
source/multigrid/mg_transfer_global_coarsening.inst.in

index 5d2d276bb2922cba22a170300e9fed3952ae1b6e..228f1ab2d330b88e75ddfaa97e7bd9b63b7d10eb 100644 (file)
@@ -96,7 +96,7 @@ namespace MGTransferGlobalCoarseningTools
    * @note Currently, only implemented for parallel::distributed::Triangulation.
    */
   template <int dim, int spacedim>
-  std::vector<std::shared_ptr<Triangulation<dim, spacedim>>>
+  std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
   create_geometric_coarsening_sequence(
     const Triangulation<dim, spacedim> &tria);
 
index 034dff589e85bebddced0da21a5c2b567e5d1120..933f550cbc508f10cfc9ca380a9ced8cee010dd7 100644 (file)
@@ -1873,15 +1873,23 @@ namespace MGTransferGlobalCoarseningTools
   } // namespace internal
 
   template <int dim, int spacedim>
-  std::vector<std::shared_ptr<Triangulation<dim, spacedim>>>
+  std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
   create_geometric_coarsening_sequence(
     const Triangulation<dim, spacedim> &fine_triangulation_in)
   {
-    std::vector<std::shared_ptr<Triangulation<dim, spacedim>>>
-      coarse_grid_triangulations;
+    std::vector<std::shared_ptr<const Triangulation<dim, spacedim>>>
+      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<Triangulation<dim, spacedim> *>(&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)
       {
index 458227c55ba13c033e89fb526687b9cb36c49958..65365814f9026944f909882966ba0c82d0adfb28 100644 (file)
@@ -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<std::shared_ptr<
-      Triangulation<deal_II_dimension, deal_II_space_dimension>>>
+      const Triangulation<deal_II_dimension, deal_II_space_dimension>>>
     MGTransferGlobalCoarseningTools::create_geometric_coarsening_sequence(
       const Triangulation<deal_II_dimension, deal_II_space_dimension>
         &fine_triangulation_in);

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.