]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Move 17 lines of code which were repeated 12 times (!) into new clear_despite_subscri...
authorRalf Hartmann <Ralf.Hartmann@dlr.de>
Mon, 7 Mar 2005 15:23:45 +0000 (15:23 +0000)
committerRalf Hartmann <Ralf.Hartmann@dlr.de>
Mon, 7 Mar 2005 15:23:45 +0000 (15:23 +0000)
git-svn-id: https://svn.dealii.org/trunk@10028 0785d39b-7218-0410-832d-ea1e28bc413d

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

index 6d9ac660ee007447af47679d5d908b186b334f8b..76e2c02745b92d5f17d741cc2e8dd5e5fa4827eb 100644 (file)
@@ -3149,6 +3149,34 @@ class Triangulation : public Subscriptor
                                  std::istream            &in);
 
   private:
+
+                                    /**
+                                     * The (public) clear() will only
+                                     * work when the triangulation is
+                                     * not subscriped to by other
+                                     * users. The
+                                     * clear_despite_subscriptions()
+                                     * function now allows the
+                                     * triangulation being cleared
+                                     * even when there are
+                                     * subscriptions.
+                                     *
+                                     * Make sure, you know what you
+                                     * do, when calling this
+                                     * function, as its use is
+                                     * reasonable in very rare cases,
+                                     * only. For example, when the
+                                     * subscriptions were for the
+                                     * initially empty Triangulation
+                                     * and the Triangulation object
+                                     * wants to release its memory
+                                     * before throwing an assertion
+                                     * due to input errors (e.g. in
+                                     * the create_triangulation()
+                                     * function).
+                                     */
+    void clear_despite_subscriptions ();
+    
                                     /**
                                      *  Refine all cells on all levels which
                                      *  were previously flagged for refinement.
index 20539f2bae568dcf7d2415bc7768f0f178a804e5..210061fc53343d562c444a91bd90bc915a9a73f1 100644 (file)
@@ -305,27 +305,7 @@ void Triangulation<1>::create_triangulation (const std::vector<Point<1> >    &v,
                                               // a node must have one
                                               // or two adjacent
                                               // lines
-
-                                              // clear will only work
-                                              // if there are no
-                                              // subscriptions. however,
-                                              // this is bogus here,
-                                              // as the subscriptions
-                                              // were for the
-                                              // initially empty
-                                              // grid, and we want to
-                                              // clear it again now,
-                                              // so temporarily
-                                              // disable
-                                              // subscriptions,
-                                              // clear, and then set
-                                              // them again
-             const unsigned int n=n_subscriptions();
-             for (unsigned int i=0; i<n; ++i)
-               unsubscribe();
-             clear ();
-             for (unsigned int i=0; i<n; ++i)
-               subscribe();
+             clear_despite_subscriptions ();
 
              AssertThrow (false, ExcInternalError());
       };
@@ -334,22 +314,7 @@ void Triangulation<1>::create_triangulation (const std::vector<Point<1> >    &v,
                                   // two boundary nodes
   if (boundary_nodes != 2)
     {
-                                      // clear will only work if
-                                      // there are no
-                                      // subscriptions. however, this
-                                      // is bogus here, as the
-                                      // subscriptions were for the
-                                      // initially empty grid, and we
-                                      // want to clear it again now,
-                                      // so temporarily disable
-                                      // subscriptions, clear, and
-                                      // then set them again
-      const unsigned int n=n_subscriptions();
-      for (unsigned int i=0; i<n; ++i)
-       unsubscribe();
-      clear ();
-      for (unsigned int i=0; i<n; ++i)
-       subscribe();
+      clear_despite_subscriptions();
       
       AssertThrow (false, ExcInternalError());
     };
@@ -452,24 +417,7 @@ void Triangulation<2>::create_triangulation (const std::vector<Point<2> >    &v,
                                              // error message
             const unsigned int n_vertices = vertices.size();
 
-                                             // clear will only work
-                                            // if there are no
-                                            // subscriptions. however,
-                                            // this is bogus here, as
-                                            // the subscriptions were
-                                            // for the initially
-                                            // empty grid, and we
-                                            // want to clear it again
-                                            // now, so temporarily
-                                            // disable subscriptions,
-                                            // clear, and then set
-                                            // them again
-           const unsigned int n=n_subscriptions();
-           for (unsigned int i=0; i<n; ++i)
-             unsubscribe();
-           clear ();
-           for (unsigned int i=0; i<n; ++i)
-             subscribe();
+           clear_despite_subscriptions();
            
            Assert (false,
                    ExcInvalidVertexIndex (cell, cells[cell].vertices[vertex],
@@ -560,26 +508,7 @@ void Triangulation<2>::create_triangulation (const std::vector<Point<2> >    &v,
                 ==
                 needed_lines.end()))
            {
-                                              // clear will only work
-                                              // if there are no
-                                              // subscriptions. however,
-                                              // this is bogus here,
-                                              // as the subscriptions
-                                              // were for the
-                                              // initially empty
-                                              // grid, and we want to
-                                              // clear it again now,
-                                              // so temporarily
-                                              // disable
-                                              // subscriptions,
-                                              // clear, and then set
-                                              // them again
-             const unsigned int n=n_subscriptions();
-             for (unsigned int i=0; i<n; ++i)
-               unsubscribe();
-             clear ();
-             for (unsigned int i=0; i<n; ++i)
-               subscribe();
+             clear_despite_subscriptions();
              
              AssertThrow (false,
                           ExcGridHasInvalidCell(cell));
@@ -615,23 +544,7 @@ void Triangulation<2>::create_triangulation (const std::vector<Point<2> >    &v,
       if ( ! (* (std::min_element(vertex_touch_count.begin(),
                                  vertex_touch_count.end())) >= 2))
        {
-                                          // clear will only work if
-                                          // there are no
-                                          // subscriptions. however,
-                                          // this is bogus here, as
-                                          // the subscriptions were
-                                          // for the initially empty
-                                          // grid, and we want to
-                                          // clear it again now, so
-                                          // temporarily disable
-                                          // subscriptions, clear,
-                                          // and then set them again
-         const unsigned int n=n_subscriptions();
-         for (unsigned int i=0; i<n; ++i)
-           unsubscribe();
-         clear ();
-         for (unsigned int i=0; i<n; ++i)
-           subscribe();
+         clear_despite_subscriptions();
          
          AssertThrow (false, ExcGridHasInvalidVertices());
        };
@@ -716,23 +629,7 @@ void Triangulation<2>::create_triangulation (const std::vector<Point<2> >    &v,
       if (! ((n_adj_cells >= 1) &&
             (n_adj_cells <= 2)))
        {
-                                          // clear will only work if
-                                          // there are no
-                                          // subscriptions. however,
-                                          // this is bogus here, as
-                                          // the subscriptions were
-                                          // for the initially empty
-                                          // grid, and we want to
-                                          // clear it again now, so
-                                          // temporarily disable
-                                          // subscriptions, clear,
-                                          // and then set them again
-         const unsigned int n=n_subscriptions();
-         for (unsigned int i=0; i<n; ++i)
-           unsubscribe();
-         clear ();
-         for (unsigned int i=0; i<n; ++i)
-           subscribe();
+         clear_despite_subscriptions();
          
          AssertThrow (false, ExcInternalError());
        };
@@ -773,27 +670,7 @@ void Triangulation<2>::create_triangulation (const std::vector<Point<2> >    &v,
          else 
            {
                                               // line does not exist
-             
-                                              // clear will only work
-                                              // if there are no
-                                              // subscriptions. however,
-                                              // this is bogus here,
-                                              // as the subscriptions
-                                              // were for the
-                                              // initially empty
-                                              // grid, and we want to
-                                              // clear it again now,
-                                              // so temporarily
-                                              // disable
-                                              // subscriptions,
-                                              // clear, and then set
-                                              // them again
-             const unsigned int n=n_subscriptions();
-             for (unsigned int i=0; i<n; ++i)
-               unsubscribe();
-             clear ();
-             for (unsigned int i=0; i<n; ++i)
-               subscribe();
+             clear_despite_subscriptions();
 
              AssertThrow (false, ExcLineInexistant(line_vertices.first,
                                                    line_vertices.second));
@@ -805,23 +682,7 @@ void Triangulation<2>::create_triangulation (const std::vector<Point<2> >    &v,
       if (line->boundary_indicator() != 0 &&
          line->boundary_indicator() != 255)
        {
-                                          // clear will only work if
-                                          // there are no
-                                          // subscriptions. however,
-                                          // this is bogus here, as
-                                          // the subscriptions were
-                                          // for the initially empty
-                                          // grid, and we want to
-                                          // clear it again now, so
-                                          // temporarily disable
-                                          // subscriptions, clear,
-                                          // and then set them again
-         const unsigned int n=n_subscriptions();
-         for (unsigned int i=0; i<n; ++i)
-           unsubscribe();
-         clear ();
-         for (unsigned int i=0; i<n; ++i)
-           subscribe();
+         clear_despite_subscriptions();
          
          AssertThrow (false, ExcMultiplySetLineInfoOfLine(
            line_vertices.first, line_vertices.second));
@@ -831,13 +692,7 @@ void Triangulation<2>::create_triangulation (const std::vector<Point<2> >    &v,
                                       // are given a boundary indicator
       if (line->boundary_indicator() == 255)
        {
-                                          // same as above
-         const unsigned int n=n_subscriptions();
-         for (unsigned int i=0; i<n; ++i)
-           unsubscribe();
-         clear ();
-         for (unsigned int i=0; i<n; ++i)
-           subscribe();
+         clear_despite_subscriptions();
          
          AssertThrow (false, ExcInteriorLineCantBeBoundary());
        };
@@ -968,25 +823,8 @@ Triangulation<3>::create_triangulation (const std::vector<Point<3> >    &v,
                                              // include it in the
                                              // error message
             const unsigned int n_vertices = vertices.size();
-            
-                                            // clear will only work
-                                            // if there are no
-                                            // subscriptions. however,
-                                            // this is bogus here, as
-                                            // the subscriptions were
-                                            // for the initially
-                                            // empty grid, and we
-                                            // want to clear it again
-                                            // now, so temporarily
-                                            // disable subscriptions,
-                                            // clear, and then set
-                                            // them again
-           const unsigned int n=n_subscriptions();
-           for (unsigned int i=0; i<n; ++i)
-             unsubscribe();
-           clear ();
-           for (unsigned int i=0; i<n; ++i)
-             subscribe();
+
+           clear_despite_subscriptions();            
            
            AssertThrow (false,
                         ExcInvalidVertexIndex (cell, cells[cell].vertices[vertex],
@@ -1023,26 +861,7 @@ Triangulation<3>::create_triangulation (const std::vector<Point<3> >    &v,
                 ==
                 needed_lines.end()))
            {
-                                              // clear will only work
-                                              // if there are no
-                                              // subscriptions. however,
-                                              // this is bogus here,
-                                              // as the subscriptions
-                                              // were for the
-                                              // initially empty
-                                              // grid, and we want to
-                                              // clear it again now,
-                                              // so temporarily
-                                              // disable
-                                              // subscriptions,
-                                              // clear, and then set
-                                              // them again
-             const unsigned int n=n_subscriptions();
-             for (unsigned int i=0; i<n; ++i)
-               unsubscribe();
-             clear ();
-             for (unsigned int i=0; i<n; ++i)
-               subscribe();
+             clear_despite_subscriptions();
 
              AssertThrow (false, ExcGridHasInvalidCell(cell));
            };
@@ -1080,23 +899,7 @@ Triangulation<3>::create_triangulation (const std::vector<Point<3> >    &v,
       if (! (* (std::min_element(vertex_touch_count.begin(),
                                 vertex_touch_count.end())) >= 3))
        {
-                                          // clear will only work if
-                                          // there are no
-                                          // subscriptions. however,
-                                          // this is bogus here, as
-                                          // the subscriptions were
-                                          // for the initially empty
-                                          // grid, and we want to
-                                          // clear it again now, so
-                                          // temporarily disable
-                                          // subscriptions, clear,
-                                          // and then set them again
-         const unsigned int n=n_subscriptions();
-         for (unsigned int i=0; i<n; ++i)
-           unsubscribe();
-         clear ();
-         for (unsigned int i=0; i<n; ++i)
-           subscribe();
+         clear_despite_subscriptions();
 
          AssertThrow (false, ExcGridHasInvalidVertices());
        };
@@ -1482,23 +1285,7 @@ Triangulation<3>::create_triangulation (const std::vector<Point<3> >    &v,
       if (! ((n_adj_cells >= 1) &&
             (n_adj_cells <= 2)))
        {
-                                          // clear will only work if
-                                          // there are no
-                                          // subscriptions. however,
-                                          // this is bogus here, as
-                                          // the subscriptions were
-                                          // for the initially empty
-                                          // grid, and we want to
-                                          // clear it again now, so
-                                          // temporarily disable
-                                          // subscriptions, clear,
-                                          // and then set them again
-         const unsigned int n=n_subscriptions();
-         for (unsigned int i=0; i<n; ++i)
-           unsubscribe();
-         clear ();
-         for (unsigned int i=0; i<n; ++i)
-           subscribe();
+         clear_despite_subscriptions();
          
          AssertThrow (false, ExcInternalError());
        };
@@ -4471,6 +4258,21 @@ Triangulation<dim>::execute_coarsening_and_refinement ()
 }
 
 
+template<int dim>
+void
+Triangulation<dim>::clear_despite_subscriptions()
+{  
+                                  // disable subscriptions, clear,
+                                  // and then set them again
+  const unsigned int n=n_subscriptions();
+  for (unsigned int i=0; i<n; ++i)
+    unsubscribe();
+  clear ();
+  for (unsigned int i=0; i<n; ++i)
+    subscribe();
+}
+
+
 #if deal_II_dimension == 1
 
 template <>

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.