From f71120453d81d5ec6d3491d291b60a426c6ed002 Mon Sep 17 00:00:00 2001
From: Wolfgang Bangerth <bangerth@colostate.edu>
Date: Thu, 25 Jan 2018 10:45:45 -0700
Subject: [PATCH] Restrict the template arguments of
 GridGenerator::hyper_sphere.

This function can only work for dim==spacedim-1, and this is also documented.
Consequently, get rid of the dim template argument.
---
 include/deal.II/grid/grid_generator.h | 10 +++++-----
 source/grid/grid_generator.cc         | 22 ++++++----------------
 source/grid/grid_generator.inst.in    | 14 ++++++++++++++
 3 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/include/deal.II/grid/grid_generator.h b/include/deal.II/grid/grid_generator.h
index a2b392a013..c9ba00a1c1 100644
--- a/include/deal.II/grid/grid_generator.h
+++ b/include/deal.II/grid/grid_generator.h
@@ -461,7 +461,7 @@ namespace GridGenerator
   /**
    * Creates a hyper sphere, i.e., a surface of a ball in @p spacedim
    * dimensions. This function only exists for dim+1=spacedim in 2 and 3 space
-   * dimensions.
+   * dimensions. (To create a mesh of a ball, use GridGenerator::hyper_ball().)
    *
    * You should attach a SphericalManifold to the cells and faces for correct
    * placement of vertices upon refinement and to be able to use higher order
@@ -490,10 +490,10 @@ namespace GridGenerator
    * @note The triangulation needs to be void upon calling this function.
    */
 
-  template <int dim, int spacedim>
-  void hyper_sphere (Triangulation<dim,spacedim> &tria,
-                     const Point<spacedim>   &center = Point<spacedim>(),
-                     const double        radius = 1.);
+  template <int spacedim>
+  void hyper_sphere (Triangulation<spacedim-1,spacedim> &tria,
+                     const Point<spacedim>              &center = Point<spacedim>(),
+                     const double                        radius = 1.);
 
   /**
    * This class produces a hyper-ball intersected with the positive orthant
diff --git a/source/grid/grid_generator.cc b/source/grid/grid_generator.cc
index 67cbecd255..550411a1dc 100644
--- a/source/grid/grid_generator.cc
+++ b/source/grid/grid_generator.cc
@@ -3060,11 +3060,13 @@ namespace GridGenerator
       SubCellData());       // no boundary information
   }
 
-  template <int dim, int spacedim>
+
+
+  template <int spacedim>
   void
-  hyper_sphere (Triangulation<dim,spacedim> &tria,
-                const Point<spacedim>   &p,
-                const double      radius)
+  hyper_sphere (Triangulation<spacedim-1,spacedim> &tria,
+                const Point<spacedim>              &p,
+                const double                        radius)
   {
     Triangulation<spacedim> volume_mesh;
     GridGenerator::hyper_ball(volume_mesh,p,radius);
@@ -4646,18 +4648,6 @@ namespace GridGenerator
 }
 
 // explicit instantiations
-namespace GridGenerator
-{
-
-  template void
-  hyper_sphere< 1,  2 > (Triangulation< 1,   2> &,
-                         const Point<2>   &center,
-                         const double        radius);
-  template void
-  hyper_sphere< 2,  3 > (Triangulation< 2,   3> &,
-                         const Point<3>   &center,
-                         const double        radius);
-}
 #include "grid_generator.inst"
 
 DEAL_II_NAMESPACE_CLOSE
diff --git a/source/grid/grid_generator.inst.in b/source/grid/grid_generator.inst.in
index 5a7783f593..5913a232b0 100644
--- a/source/grid/grid_generator.inst.in
+++ b/source/grid/grid_generator.inst.in
@@ -167,6 +167,20 @@ for (deal_II_dimension : DIMENSIONS)
 }
 
 
+
+for (deal_II_space_dimension : DIMENSIONS)
+{
+    namespace GridGenerator \{
+
+#if deal_II_space_dimension >= 2
+    template void
+    hyper_sphere<deal_II_space_dimension> (
+        Triangulation<deal_II_space_dimension-1, deal_II_space_dimension> &, const Point<deal_II_space_dimension> &, double);
+#endif
+
+    \}
+}
+
 for (deal_II_dimension : DIMENSIONS ; deal_II_space_dimension : SPACE_DIMENSIONS; deal_II_space_dimension_2 : SPACE_DIMENSIONS)
 {
     namespace GridGenerator \{
-- 
2.39.5