From 523cc1e248e430ced117a1dde93779dd2244fad3 Mon Sep 17 00:00:00 2001
From: Wolfgang Bangerth <bangerth@math.tamu.edu>
Date: Thu, 16 Dec 2010 23:31:18 +0000
Subject: [PATCH] Make the awkward map a returned value, rather than a
 reference argument.

git-svn-id: https://svn.dealii.org/trunk@22987 0785d39b-7218-0410-832d-ea1e28bc413d
---
 deal.II/examples/step-38/step-38.cc              |  5 -----
 deal.II/include/deal.II/grid/grid_tools.h        | 15 +++++++++------
 deal.II/source/grid/grid_tools.cc                | 12 +++++++-----
 deal.II/source/grid/grid_tools.inst.in           | 14 +++++---------
 tests/codim_one/direction_flag_01.cc             |  5 +----
 tests/codim_one/direction_flag_02.cc             |  5 +----
 tests/codim_one/extract_boundary_mesh_00.cc      | 16 +++++++---------
 tests/codim_one/extract_boundary_mesh_01.cc      |  4 ++--
 tests/codim_one/extract_boundary_mesh_02.cc      |  4 ++--
 tests/codim_one/extract_boundary_mesh_03.cc      |  4 ++--
 tests/codim_one/extract_boundary_mesh_04.cc      |  6 +++---
 tests/codim_one/extract_boundary_mesh_05.cc      |  4 ++--
 tests/codim_one/extract_boundary_mesh_06.cc      |  4 ++--
 ...interpolate_boundary_values_1d_closed_ring.cc |  4 ++--
 tests/codim_one/normal_vectors_01.cc             |  6 +++---
 15 files changed, 48 insertions(+), 60 deletions(-)

diff --git a/deal.II/examples/step-38/step-38.cc b/deal.II/examples/step-38/step-38.cc
index e5d78044a6..ad2e48152c 100755
--- a/deal.II/examples/step-38/step-38.cc
+++ b/deal.II/examples/step-38/step-38.cc
@@ -205,10 +205,6 @@ LaplaceBeltrami<dim>::~LaplaceBeltrami ()
 template <int dim>
 void LaplaceBeltrami<dim>::make_mesh ()
 {
-  std::map<typename Triangulation<dim-1,dim>::cell_iterator,
-           typename Triangulation<dim,dim>::face_iterator>
-  surface_to_volume_mapping;
-
   HyperBallBoundary<dim> boundary_description;
   Triangulation<dim> volume_mesh;
   GridGenerator::half_hyper_ball(volume_mesh);
@@ -225,7 +221,6 @@ void LaplaceBeltrami<dim>::make_mesh ()
   boundary_ids.insert(0);
   
   GridTools::extract_boundary_mesh (volume_mesh, triangulation,
-				    surface_to_volume_mapping,
 				    boundary_ids);
   triangulation.refine_global(3);
 
diff --git a/deal.II/include/deal.II/grid/grid_tools.h b/deal.II/include/deal.II/grid/grid_tools.h
index 77d682ded0..48dc6e36bb 100644
--- a/deal.II/include/deal.II/grid/grid_tools.h
+++ b/deal.II/include/deal.II/grid/grid_tools.h
@@ -804,11 +804,15 @@ class GridTools
 				      * mesh").  The boundary to be extracted
 				      * is specified by a list of
 				      * boundary_ids.  If none is specified
-				      * the whole boundary will be extracted.
+				      * the whole boundary will be
+				      * extracted. The function is used in
+				      * step-38.
 				      *
 				      * It also builds a mapping linking the
 				      * cells on the surface mesh to the
-				      * corresponding faces on the volume one.
+				      * corresponding faces on the volume
+				      * one. This mapping is the return value
+				      * of the function.
 				      *
 				      * @note The function builds the surface
 				      * mesh by creating a coarse mesh from
@@ -878,12 +882,11 @@ class GridTools
 				      * curved boundaries.
 				      */
     template <template <int,int> class Container, int dim, int spacedim>
-    static void
+    static
+    std::map<typename Container<dim-1,spacedim>::cell_iterator,
+	     typename Container<dim,spacedim>::face_iterator>
     extract_boundary_mesh (const Container<dim,spacedim> &volume_mesh,
 			   Container<dim-1,spacedim>     &surface_mesh,
-			   std::map<typename Container<dim-1,spacedim>::cell_iterator,
-			            typename Container<dim,spacedim>::face_iterator>
-			   &surface_to_volume_mapping,
 			   const std::set<unsigned char> &boundary_ids
 			   = std::set<unsigned char>());
 
diff --git a/deal.II/source/grid/grid_tools.cc b/deal.II/source/grid/grid_tools.cc
index bfe89e2bf2..466847fc2e 100644
--- a/deal.II/source/grid/grid_tools.cc
+++ b/deal.II/source/grid/grid_tools.cc
@@ -1830,19 +1830,19 @@ fix_up_distorted_child_cells (const typename Triangulation<dim,spacedim>::Distor
 
 
 template <template <int,int> class Container, int dim, int spacedim>
-void
+std::map<typename Container<dim-1,spacedim>::cell_iterator,
+	 typename Container<dim,spacedim>::face_iterator>
 GridTools::extract_boundary_mesh (const Container<dim,spacedim> &volume_mesh,
 				  Container<dim-1,spacedim>     &surface_mesh,
-				  std::map<typename Container<dim-1,spacedim>::cell_iterator,
-				  typename Container<dim,spacedim>::face_iterator>
-				    &surface_to_volume_mapping,
 				  const std::set<unsigned char> &boundary_ids)
 {
 // Assumption:
 //    We are relying below on the fact that Triangulation::create_triangulation(...) will keep the order
 //    pass by CellData and that it will not reorder the vertices.
 
-  surface_to_volume_mapping.clear();
+  std::map<typename Container<dim-1,spacedim>::cell_iterator,
+    typename Container<dim,spacedim>::face_iterator>
+  surface_to_volume_mapping;
 
   const unsigned int boundary_dim = dim-1; //dimension of the boundary mesh
 
@@ -1939,6 +1939,8 @@ GridTools::extract_boundary_mesh (const Container<dim,spacedim> &volume_mesh,
 	break;
     }
   while (true);
+
+  return surface_to_volume_mapping;
 }
 
 // explicit instantiations
diff --git a/deal.II/source/grid/grid_tools.inst.in b/deal.II/source/grid/grid_tools.inst.in
index e4b4f392d9..7a507444a4 100644
--- a/deal.II/source/grid/grid_tools.inst.in
+++ b/deal.II/source/grid/grid_tools.inst.in
@@ -213,12 +213,10 @@ for (deal_II_dimension : DIMENSIONS)
   {
 #if deal_II_dimension != 1
     template
-      void
+      std::map<  Triangulation<deal_II_dimension-1,deal_II_dimension>::cell_iterator,
+		 Triangulation<deal_II_dimension>::face_iterator>
       GridTools::extract_boundary_mesh (const Triangulation<deal_II_dimension> &volume_mesh,
 					Triangulation<deal_II_dimension-1,deal_II_dimension>  &surface_mesh,
-					std::map<  Triangulation<deal_II_dimension-1,deal_II_dimension>::cell_iterator,
-						   Triangulation<deal_II_dimension>::face_iterator>
-      &surface_to_volume_mapping,
 					const std::set<unsigned char> &boundary_ids);
 #endif
   }
@@ -228,12 +226,10 @@ for (deal_II_dimension : DIMENSIONS; Container : DOFHANDLER_TEMPLATES)
 
 #if deal_II_dimension != 1
     template
-      void
+      std::map<  Container<deal_II_dimension-1,deal_II_dimension>::cell_iterator,
+		 Container<deal_II_dimension>::face_iterator>
       GridTools::extract_boundary_mesh (const Container<deal_II_dimension> &volume_mesh,
 					Container<deal_II_dimension-1,deal_II_dimension>  &surface_mesh,
-					std::map<  Container<deal_II_dimension-1,deal_II_dimension>::cell_iterator,
-						   Container<deal_II_dimension>::face_iterator>
-      &surface_to_volume_mapping,
 					const std::set<unsigned char> &boundary_ids);
 #endif
-  }
\ No newline at end of file
+  }
diff --git a/tests/codim_one/direction_flag_01.cc b/tests/codim_one/direction_flag_01.cc
index 8afa7b36ee..459e1f211a 100644
--- a/tests/codim_one/direction_flag_01.cc
+++ b/tests/codim_one/direction_flag_01.cc
@@ -30,12 +30,9 @@ void test ()
   const unsigned int dim = spacedim-1;
 
   Triangulation<dim,spacedim> boundary_mesh;
-  map<Triangulation<dim,spacedim>::cell_iterator,Triangulation<spacedim,spacedim>::face_iterator >
-    surface_to_volume_mapping;
   Triangulation<spacedim> volume_mesh;
   GridGenerator::hyper_cube(volume_mesh);
-  GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh,
-				    surface_to_volume_mapping);
+  GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh);
   for (Triangulation<dim,spacedim>::active_cell_iterator
 	 cell = boundary_mesh.begin_active();
        cell != boundary_mesh.end(); ++cell)
diff --git a/tests/codim_one/direction_flag_02.cc b/tests/codim_one/direction_flag_02.cc
index 525209c614..09a56be2f3 100644
--- a/tests/codim_one/direction_flag_02.cc
+++ b/tests/codim_one/direction_flag_02.cc
@@ -30,12 +30,9 @@ void test ()
   const unsigned int dim = spacedim-1;
 
   Triangulation<dim,spacedim> boundary_mesh;
-  map<Triangulation<dim,spacedim>::cell_iterator,Triangulation<spacedim,spacedim>::face_iterator >
-    surface_to_volume_mapping;
   Triangulation<spacedim> volume_mesh;
   GridGenerator::hyper_cube(volume_mesh);
-  GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh,
-				    surface_to_volume_mapping);
+  GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh);
   for (Triangulation<dim,spacedim>::active_cell_iterator
 	 cell = boundary_mesh.begin_active();
        cell != boundary_mesh.end(); ++cell)
diff --git a/tests/codim_one/extract_boundary_mesh_00.cc b/tests/codim_one/extract_boundary_mesh_00.cc
index 831bb59ac2..63eb96d55e 100644
--- a/tests/codim_one/extract_boundary_mesh_00.cc
+++ b/tests/codim_one/extract_boundary_mesh_00.cc
@@ -104,9 +104,8 @@ int main ()
 
     Triangulation<dim-1,dim> boundary_mesh;
 
-
-    GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh,
-				      surface_to_volume_mapping);
+    surface_to_volume_mapping
+      = GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh);
 
     if (test_vertices_orientation(boundary_mesh, surface_to_volume_mapping))
       deallog << "Passed.";
@@ -135,9 +134,8 @@ int main ()
 
     Triangulation<dim-1,dim> boundary_mesh;
 
-
-    GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh,
-				      surface_to_volume_mapping);
+    surface_to_volume_mapping
+      = GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh);
 
     if (test_vertices_orientation(boundary_mesh, surface_to_volume_mapping))
       deallog << "Passed.";
@@ -170,9 +168,9 @@ int main ()
     set<unsigned char> boundary_ids;
     boundary_ids.insert(0);
 
-    GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh,
-				      surface_to_volume_mapping,
-				      boundary_ids);
+    surface_to_volume_mapping
+      = GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh,
+					  boundary_ids);
 
     if (test_vertices_orientation(boundary_mesh, surface_to_volume_mapping))
       deallog << "Passed.";
diff --git a/tests/codim_one/extract_boundary_mesh_01.cc b/tests/codim_one/extract_boundary_mesh_01.cc
index e7183458ce..bcc413749c 100644
--- a/tests/codim_one/extract_boundary_mesh_01.cc
+++ b/tests/codim_one/extract_boundary_mesh_01.cc
@@ -107,8 +107,8 @@ int main ()
 
     Triangulation<dim-1,dim> boundary_mesh;
 
-    GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh,
-				      surface_to_volume_mapping);
+    surface_to_volume_mapping
+      = GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh);
 
     Assert (test_vertices_orientation(boundary_mesh, surface_to_volume_mapping,2),
 	    ExcInternalError());
diff --git a/tests/codim_one/extract_boundary_mesh_02.cc b/tests/codim_one/extract_boundary_mesh_02.cc
index 6da03eb6fc..40e2f06fee 100644
--- a/tests/codim_one/extract_boundary_mesh_02.cc
+++ b/tests/codim_one/extract_boundary_mesh_02.cc
@@ -100,8 +100,8 @@ int main ()
     Triangulation<dim-1,dim> boundary_mesh;
     boundary_mesh.set_boundary (0, surface_description);
 
-    GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh,
-				      surface_to_volume_mapping);
+    surface_to_volume_mapping
+      = GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh);
     deallog << volume_mesh.n_active_cells () << std::endl;
     deallog << boundary_mesh.n_active_cells () << std::endl;
     save_mesh(boundary_mesh);
diff --git a/tests/codim_one/extract_boundary_mesh_03.cc b/tests/codim_one/extract_boundary_mesh_03.cc
index 9b01670bc5..ba892045ba 100644
--- a/tests/codim_one/extract_boundary_mesh_03.cc
+++ b/tests/codim_one/extract_boundary_mesh_03.cc
@@ -114,8 +114,8 @@ int main ()
     Triangulation<dim-1,dim> boundary_mesh;
     boundary_mesh.set_boundary (1, surface_description);
 
-    GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh,
-				      surface_to_volume_mapping);
+    surface_to_volume_mapping
+      = GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh);
     deallog << volume_mesh.n_active_cells () << std::endl;
     deallog << boundary_mesh.n_active_cells () << std::endl;
     save_mesh(boundary_mesh);
diff --git a/tests/codim_one/extract_boundary_mesh_04.cc b/tests/codim_one/extract_boundary_mesh_04.cc
index 2bac4696be..d7a6c5703d 100644
--- a/tests/codim_one/extract_boundary_mesh_04.cc
+++ b/tests/codim_one/extract_boundary_mesh_04.cc
@@ -120,9 +120,9 @@ int main ()
     set<unsigned char> boundary_ids;
     boundary_ids.insert(1);
 
-    GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh,
-				      surface_to_volume_mapping,
-				      boundary_ids);
+    surface_to_volume_mapping
+      = GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh,
+					  boundary_ids);
 
     deallog << volume_mesh.n_active_cells () << std::endl;
     deallog << boundary_mesh.n_active_cells () << std::endl;
diff --git a/tests/codim_one/extract_boundary_mesh_05.cc b/tests/codim_one/extract_boundary_mesh_05.cc
index ffd07a5ec6..bc3fdf4a79 100644
--- a/tests/codim_one/extract_boundary_mesh_05.cc
+++ b/tests/codim_one/extract_boundary_mesh_05.cc
@@ -38,8 +38,8 @@ void test ()
   Triangulation<dim> volume_mesh;
   GridGenerator::hyper_cube(volume_mesh);
 
-  GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh,
-				    surface_to_volume_mapping);
+  surface_to_volume_mapping
+    = GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh);
 
   FE_Q <dim-1,dim>  boundary_fe (1);
   DoFHandler<dim-1,dim> boundary_dh(boundary_mesh);
diff --git a/tests/codim_one/extract_boundary_mesh_06.cc b/tests/codim_one/extract_boundary_mesh_06.cc
index f88f023b44..96e7eed076 100644
--- a/tests/codim_one/extract_boundary_mesh_06.cc
+++ b/tests/codim_one/extract_boundary_mesh_06.cc
@@ -39,8 +39,8 @@ void test ()
   Triangulation<spacedim> volume_mesh;
   GridGenerator::hyper_cube(volume_mesh);
   volume_mesh.refine_global(1);
-  GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh,
-				    surface_to_volume_mapping);
+  surface_to_volume_mapping
+    = GridTools::extract_boundary_mesh (volume_mesh, boundary_mesh);
   boundary_mesh.refine_global(1);
 
   for (Triangulation<dim,spacedim>::active_cell_iterator
diff --git a/tests/codim_one/interpolate_boundary_values_1d_closed_ring.cc b/tests/codim_one/interpolate_boundary_values_1d_closed_ring.cc
index ba5d43a9e9..9ce59ed03e 100644
--- a/tests/codim_one/interpolate_boundary_values_1d_closed_ring.cc
+++ b/tests/codim_one/interpolate_boundary_values_1d_closed_ring.cc
@@ -50,8 +50,8 @@ void test() {
   Triangulation<spacedim> volume_mesh;
   GridGenerator::hyper_cube(volume_mesh);
 
-  GridTools::extract_boundary_mesh (volume_mesh, tria,
-				      surface_to_volume_mapping);
+  surface_to_volume_mapping
+    = GridTools::extract_boundary_mesh (volume_mesh, tria);
 
     FE_Q<dim,spacedim> fe(2);
     DoFHandler<dim,spacedim> dof_handler (tria);
diff --git a/tests/codim_one/normal_vectors_01.cc b/tests/codim_one/normal_vectors_01.cc
index ec33ec0db9..7b6a0160cf 100644
--- a/tests/codim_one/normal_vectors_01.cc
+++ b/tests/codim_one/normal_vectors_01.cc
@@ -53,9 +53,9 @@ void test ()
   std::set<unsigned char> boundary_ids;
   boundary_ids.insert(0);
   
-  GridTools::extract_boundary_mesh (volume_mesh, tria,
-				    surface_to_volume_mapping,
-				    boundary_ids);
+  surface_to_volume_mapping
+    = GridTools::extract_boundary_mesh (volume_mesh, tria,
+					boundary_ids);
   
   FE_Q<dim-1,dim> fe (1);
   DoFHandler<dim-1,dim> dh(tria);
-- 
2.39.5