]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Unify some functions.
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 18 Oct 2016 23:18:07 +0000 (17:18 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sun, 23 Oct 2016 02:18:47 +0000 (20:18 -0600)
Currently, the top-level functions GridReordering::reorder_cells() are duplicated
for the different (space) dimensions. Unify them all into one.

include/deal.II/grid/grid_reordering.h
source/grid/grid_reordering.cc

index a5b49fa98ff560e76e53d6503ccc7e9e85981fbe..d730a22b678baa56bc796ae9b4f10329e1915585 100644 (file)
@@ -664,21 +664,6 @@ public:
 
 
 // declaration of explicit specializations
-template<>
-void
-GridReordering<2>::reorder_cells (std::vector<CellData<2> > &original_cells,
-                                  const bool);
-
-template<>
-void
-GridReordering<2,3>::reorder_cells (std::vector<CellData<2> > &original_cells,
-                                    const bool);
-
-template<>
-void
-GridReordering<3>::reorder_cells (std::vector<CellData<3> > &original_cells,
-                                  const bool);
-
 template<>
 void
 GridReordering<2>::invert_all_cells_of_negative_grid(const std::vector<Point<2> > &all_vertices,
index 254f7e8a3a376b928c45261d8c6171f1f541ac4d..e64ccd956efbb45029bcceb5c2fa4d3a9f54afc7 100644 (file)
@@ -987,20 +987,17 @@ namespace internal
         rotate_cell (cell_list, edge_list, c, cells);
     }
 
-  }
-}
 
+    // overload of the function above for 1d -- there is nothing
+    // to orient in that case
+    void reorient (std::vector<CellData<1> > &)
+    {}
 
-template<>
-void
-GridReordering<1>::reorder_cells (std::vector<CellData<1> > &,
-                                  const bool)
-{
-  // there should not be much to do
-  // in 1d...
+  }
 }
 
 
+
 template<>
 void
 GridReordering<1>::invert_all_cells_of_negative_grid(const std::vector<Point<1> > &,
@@ -1009,14 +1006,6 @@ GridReordering<1>::invert_all_cells_of_negative_grid(const std::vector<Point<1>
   // nothing to be done in 1d
 }
 
-template<>
-void
-GridReordering<1,2>::reorder_cells (std::vector<CellData<1> > &,
-                                    const bool)
-{
-  // there should not be much to do
-  // in 1d...
-}
 
 
 template<>
@@ -1028,15 +1017,6 @@ GridReordering<1,2>::invert_all_cells_of_negative_grid(const std::vector<Point<2
 }
 
 
-template<>
-void
-GridReordering<1,3>::reorder_cells (std::vector<CellData<1> > &,
-                                    const bool)
-{
-  // there should not be much to do
-  // in 1d...
-}
-
 
 template<>
 void
@@ -1059,6 +1039,11 @@ namespace
    * do the reordering of their
    * arguments in-place.
    */
+  void
+  reorder_new_to_old_style (std::vector<CellData<1> > &)
+  {}
+
+
   void
   reorder_new_to_old_style (std::vector<CellData<2> > &cells)
   {
@@ -1084,6 +1069,11 @@ namespace
   /**
    * And now also in the opposite direction.
    */
+  void
+  reorder_old_to_new_style (std::vector<CellData<1> > &)
+  {}
+
+
   void
   reorder_old_to_new_style (std::vector<CellData<2> > &cells)
   {
@@ -1108,52 +1098,6 @@ namespace
 }
 
 
-template<>
-void
-GridReordering<2>::reorder_cells (std::vector<CellData<2> > &cells,
-                                  const bool use_new_style_ordering)
-{
-  // if necessary, convert to old (compatibility) to new-style format
-  if (!use_new_style_ordering)
-    reorder_old_to_new_style(cells);
-
-  // check if grids are already
-  // consistent. if so, do
-  // nothing. if not, then do the
-  // reordering
-  if (!internal::GridReordering2d::is_consistent (cells))
-    internal::GridReordering2d::reorient(cells);
-
-
-  // and convert back if necessary
-  if (!use_new_style_ordering)
-    reorder_new_to_old_style(cells);
-}
-
-
-template<>
-void
-GridReordering<2,3>::reorder_cells (std::vector<CellData<2> > &cells,
-                                    const bool use_new_style_ordering)
-{
-  // if necessary, convert to old (compatibility) to new-style format
-  if (!use_new_style_ordering)
-    reorder_old_to_new_style(cells);
-
-  // check if grids are already
-  // consistent. if so, do
-  // nothing. if not, then do the
-  // reordering
-  if (!internal::GridReordering2d::is_consistent (cells))
-    internal::GridReordering2d::reorient(cells);
-
-
-  // and convert back if necessary
-  if (!use_new_style_ordering)
-    reorder_new_to_old_style(cells);
-}
-
-
 
 template<>
 void
@@ -1221,14 +1165,18 @@ GridReordering<2,3>::invert_all_cells_of_negative_grid(const std::vector<Point<3
 
 
 
-template<>
+template <int dim, int spacedim>
 void
-GridReordering<3>::reorder_cells (std::vector<CellData<3> > &cells,
-                                  const bool use_new_style_ordering)
+GridReordering<dim,spacedim>::reorder_cells (std::vector<CellData<dim> > &cells,
+                                             const bool use_new_style_ordering)
 {
   Assert (cells.size() != 0,
           ExcMessage("List of elements to orient must have at least one cell"));
 
+  // there is nothing for us to do in 1d
+  if (dim == 1)
+    return;
+
   // if necessary, convert to new-style format
   if (use_new_style_ordering == false)
     reorder_old_to_new_style(cells);
@@ -1242,7 +1190,11 @@ GridReordering<3>::reorder_cells (std::vector<CellData<3> > &cells,
       }
     catch (const internal::GridReordering2d::ExcMeshNotOrientable &)
       {
-        // the mesh is not orientable
+        // the mesh is not orientable. this is acceptable if we are in 3d,
+        // as class Triangulation knows how to handle this, but it is
+        // not in 2d; in that case, re-throw the exception
+        if (dim < 3)
+          throw;
       }
 
   // and convert back if necessary
@@ -1317,5 +1269,14 @@ GridReordering<3>::invert_all_cells_of_negative_grid(
 }
 
 
+
+/* ------------------------ explicit instantiations ------------------- */
+template class GridReordering<1,1>;
+template class GridReordering<1,2>;
+template class GridReordering<1,3>;
+template class GridReordering<2,2>;
+template class GridReordering<2,3>;
+template class GridReordering<3,3>;
+
 DEAL_II_NAMESPACE_CLOSE
 

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.