]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Unify several copies of the same function into a single templated one. Saves a good...
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 3 Apr 2014 00:51:26 +0000 (00:51 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 3 Apr 2014 00:51:26 +0000 (00:51 +0000)
git-svn-id: https://svn.dealii.org/trunk@32708 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/source/distributed/tria.cc

index 4085903ce0b2afd76dd87113209becc1cc5f4e7c..770dc964bbb91d203ca84714dd8f1073434a5709 100644 (file)
@@ -3530,104 +3530,52 @@ namespace parallel
       }
     }
 
-    template <>
-    void
-    Triangulation<1,1>::
-    fill_vertices_with_ghost_neighbors
-    (std::map<unsigned int, std::set<dealii::types::subdomain_id> >
-     &vertices_with_ghost_neighbors)
-    {
-      Assert (false, ExcNotImplemented());
-    }
-
-    template <>
-    void
-    Triangulation<1,2>::
-    fill_vertices_with_ghost_neighbors
-    (std::map<unsigned int, std::set<dealii::types::subdomain_id> >
-     &vertices_with_ghost_neighbors)
-    {
-      Assert (false, ExcNotImplemented());
-    }
-
-    template <>
-    void
-    Triangulation<1,3>::
-    fill_vertices_with_ghost_neighbors
-    (std::map<unsigned int, std::set<dealii::types::subdomain_id> >
-     &vertices_with_ghost_neighbors)
-    {
-      Assert (false, ExcNotImplemented());
-    }
 
     /**
      * Determine the neighboring subdomains that are adjacent to each vertex.
-     * This is achieved via the p4est_iterate tool
+     * This is achieved via the p4est_iterate/p8est_iterate tool
      */
-    template <>
+    template <int dim, int spacedim>
     void
-    Triangulation<2,2>::
+    Triangulation<dim,spacedim>::
     fill_vertices_with_ghost_neighbors
     (std::map<unsigned int, std::set<dealii::types::subdomain_id> >
      &vertices_with_ghost_neighbors)
     {
-      struct find_ghosts<2,2> fg;
+      Assert (dim>1, ExcNotImplemented());
 
-      fg.subids = sc_array_new (sizeof (dealii::types::subdomain_id));
-      fg.triangulation = this;
-      fg.vertices_with_ghost_neighbors = &(vertices_with_ghost_neighbors);
-
-      p4est_iterate (this->parallel_forest, this->parallel_ghost, static_cast<void *>(&fg),
-                     NULL, find_ghosts_face<2,2>, find_ghosts_corner<2,2>);
-
-      sc_array_destroy (fg.subids);
-    }
-
-    /**
-     * Determine the neighboring subdomains that are adjacent to each vertex.
-     * This is achieved via the p4est_iterate tool
-     */
-    template <>
-    void
-    Triangulation<2,3>::
-    fill_vertices_with_ghost_neighbors
-    (std::map<unsigned int, std::set<dealii::types::subdomain_id> >
-     &vertices_with_ghost_neighbors)
-    {
-      struct find_ghosts<2,3> fg;
+      struct find_ghosts<dim,spacedim> fg;
 
       fg.subids = sc_array_new (sizeof (dealii::types::subdomain_id));
       fg.triangulation = this;
-      fg.vertices_with_ghost_neighbors = &(vertices_with_ghost_neighbors);
+      fg.vertices_with_ghost_neighbors = &vertices_with_ghost_neighbors;
 
-      p4est_iterate (this->parallel_forest, this->parallel_ghost, static_cast<void *>(&fg),
-                     NULL, find_ghosts_face<2,3>, find_ghosts_corner<2,3>);
+      // switch between functions. to make the compiler happy, we need to cast
+      // the first two arguments to the type p[48]est_iterate wants to see. this
+      // cast is the identity cast in each of the two branches, so it is safe.
+      switch (dim)
+      {
+      case 2:
+        p4est_iterate (reinterpret_cast<internal::p4est::types<2>::forest*>(this->parallel_forest),
+                       reinterpret_cast<internal::p4est::types<2>::ghost*>(this->parallel_ghost),
+                       static_cast<void *>(&fg),
+                       NULL, find_ghosts_face<2,spacedim>, find_ghosts_corner<2,spacedim>);
+        break;
+
+      case 3:
+        p8est_iterate (reinterpret_cast<internal::p4est::types<3>::forest*>(this->parallel_forest),
+                       reinterpret_cast<internal::p4est::types<3>::ghost*>(this->parallel_ghost),
+                       static_cast<void *>(&fg),
+                       NULL, find_ghosts_face<3,spacedim>, find_ghosts_edge<3,spacedim>, find_ghosts_corner<3,spacedim>);
+        break;
+
+      default:
+        Assert (false, ExcNotImplemented());
+      }
 
       sc_array_destroy (fg.subids);
     }
 
-    /**
-     * Determine the neighboring subdomains that are adjacent to each vertex.
-     * This is achieved via the p8est_iterate tool
-     */
-    template <>
-    void
-    Triangulation<3,3>::
-    fill_vertices_with_ghost_neighbors
-    (std::map<unsigned int, std::set<dealii::types::subdomain_id> >
-     &vertices_with_ghost_neighbors)
-    {
-      struct find_ghosts<3,3> fg;
-
-      fg.subids = sc_array_new (sizeof (dealii::types::subdomain_id));
-      fg.triangulation = this;
-      fg.vertices_with_ghost_neighbors = &(vertices_with_ghost_neighbors);
-
-      p8est_iterate (this->parallel_forest, this->parallel_ghost, static_cast<void *>(&fg),
-                     NULL, find_ghosts_face<3,3>, find_ghosts_edge<3,3>, find_ghosts_corner<3,3>);
-
-      sc_array_destroy (fg.subids);
-    }
 
     template <int dim, int spacedim>
     MPI_Comm
@@ -3636,6 +3584,7 @@ namespace parallel
       return mpi_communicator;
     }
 
+
     template<int dim, int spacedim>
     void
     Triangulation<dim,spacedim>::add_periodicity

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.