]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Do not throw assertions from Triangulation::begin(level) and Triangulation::end(level...
authorGuido Kanschat <dr.guido.kanschat@gmail.com>
Sun, 26 May 2013 15:44:10 +0000 (15:44 +0000)
committerGuido Kanschat <dr.guido.kanschat@gmail.com>
Sun, 26 May 2013 15:44:10 +0000 (15:44 +0000)
git-svn-id: https://svn.dealii.org/trunk@29611 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/include/deal.II/multigrid/multigrid.templates.h
deal.II/source/grid/tria.cc

index 291868facf2874b9d35048b1b6b112161cd499e7..e54d6a4e598e6202d491473e4b164c36c3096a93 100644 (file)
@@ -130,6 +130,14 @@ this function.
 <h3>Specific improvements</h3>
 
 <ol>
+
+<li> Improved: Triangulation::begin(level) and Triangulation::end(level) now return an
+empty iterator range if the level is larger than the maximal locally owned level,
+but still in the global level range of a distributed Triangulation.
+<br>
+(Timo Heister and Guido Kanschat, 2013/05/26)
+</li>
+
 <li> New: The IndexSet::add_indices function that takes another IndexSet
 object now has an additional argument <code>offset</code> that can be used
 to offset the indices of first argument.
index cfee9c22a91726738ab16b44640f5f483bc02fab..4422edac91ba2e568f94d7f2315fd5188ebaeaff 100644 (file)
@@ -1,7 +1,7 @@
 //---------------------------------------------------------------------------
 //    $Id$
 //
-//    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009, 2010, 2012 by the deal.II authors
+//    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009, 2010, 2012, 2013 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -153,6 +153,10 @@ Multigrid<VECTOR>::level_v_step(const unsigned int level)
     deallog << "Residual on      level " << level << std::endl;
   // t = A*solution[level]
   matrix->vmult(level, t[level], solution[level]);
+
+  if (debug>2)
+    deallog << "Residual norm          " << t[level].l2_norm()
+            << std::endl;
 //  std::cout<<std::endl;
 //  t[level].print(std::cout, 2,false);
 
@@ -168,7 +172,7 @@ Multigrid<VECTOR>::level_v_step(const unsigned int level)
         {
           edge_out->vmult_add(level, t[level], solution[level]);
           if (debug>2)
-            deallog << "Norm t[" << level << "] " << t[level].l2_norm() << std::endl;
+            deallog << "Norm     t[" << level << "] " << t[level].l2_norm() << std::endl;
         }
 
       if (l==level && edge_down != 0)
@@ -179,7 +183,7 @@ Multigrid<VECTOR>::level_v_step(const unsigned int level)
         deallog << "restrict t[" << l-1 << "] " << t[l-1].l2_norm() << std::endl;
       defect[l-1] -= t[l-1];
       if (debug>3)
-        deallog << "defect d[" << l-1 << "] " << defect[l-1].l2_norm() << std::endl;
+        deallog << "defect   d[" << l-1 << "] " << defect[l-1].l2_norm() << std::endl;
     }
 
   // do recursion
@@ -194,6 +198,8 @@ Multigrid<VECTOR>::level_v_step(const unsigned int level)
 
   // do coarse grid correction
   transfer->prolongate(level, t[level], solution[level-1]);
+  if (debug>2)
+    deallog << "Prolongate norm        " << t[level].l2_norm() << std::endl;
 
   solution[level] += t[level];
 
index 4350049bccf5797eae5f9e33afe6816d3527f6d4..6f7d4af79bea267be9c2cee75a49c351b0f5f8f0 100644 (file)
@@ -10999,9 +10999,9 @@ template <int dim, int spacedim>
 typename Triangulation<dim,spacedim>::cell_iterator
 Triangulation<dim,spacedim>::last (const unsigned int level) const
 {
-  Assert (level<levels.size(), ExcInvalidLevel(level));
-  Assert (levels[level]->cells.cells.size() != 0,
-          ExcEmptyLevel (level));
+  Assert (level<n_global_levels() || level<levels.size(), ExcInvalidLevel(level));
+  if (levels[level]->cells.cells.size() ==0)
+    return end(level);
 
   // find the last raw iterator on
   // this level
@@ -11026,13 +11026,16 @@ Triangulation<dim,spacedim>::last_active () const
 {
   // get the last used cell
   cell_iterator cell = last();
-
-  // then move to the last active one
-  if (cell->active()==true)
-    return cell;
-  while ((--cell).state() == IteratorState::valid)
-    if (cell->active()==true)
-      return cell;
+  
+  if (cell != end())
+    {
+      // then move to the last active one
+      if (cell->active()==true)
+       return cell;
+      while ((--cell).state() == IteratorState::valid)
+       if (cell->active()==true)
+         return cell;
+    }
   return cell;
 }
 
@@ -11045,12 +11048,15 @@ Triangulation<dim,spacedim>::last_active (const unsigned int level) const
   // get the last used cell on this level
   cell_iterator cell = last(level);
 
-  // then move to the last active one
-  if (cell->active()==true)
-    return cell;
-  while ((--cell).state() == IteratorState::valid)
-    if (cell->active()==true)
-      return cell;
+ if (cell != end(level))
+   {
+     // then move to the last active one
+     if (cell->active()==true)
+       return cell;
+     while ((--cell).state() == IteratorState::valid)
+       if (cell->active()==true)
+        return cell;
+   }
   return cell;
 }
 
@@ -11071,9 +11077,11 @@ template <int dim, int spacedim>
 typename Triangulation<dim, spacedim>::raw_cell_iterator
 Triangulation<dim, spacedim>::end_raw (const unsigned int level) const
 {
-  return (level == levels.size()-1 ?
-          end() :
-          begin_raw (level+1));
+  Assert (level<n_global_levels(), ExcInvalidLevel(level));
+  if (level < levels.size()-1)
+    return begin_raw (level+1);
+  else
+    return end();
 }
 
 
@@ -11081,9 +11089,10 @@ template <int dim, int spacedim>
 typename Triangulation<dim, spacedim>::cell_iterator
 Triangulation<dim, spacedim>::end (const unsigned int level) const
 {
-  return (level == levels.size()-1 ?
-          cell_iterator(end()) :
-          begin (level+1));
+  if (level < levels.size()-1)
+    return begin (level+1);
+  Assert (level<n_global_levels() || level<levels.size(), ExcInvalidLevel(level));
+  return end();
 }
 
 
@@ -11175,10 +11184,10 @@ Triangulation<dim, spacedim>::begin_raw_line (const unsigned int level) const
   switch (dim)
     {
     case 1:
-      Assert (level<levels.size(), ExcInvalidLevel(level));
-
-      if (levels[level]->cells.cells.size() == 0)
-        return end_line ();
+      Assert (level<n_global_levels() || level<levels.size(), ExcInvalidLevel(level));
+      
+      if (level >= levels.size() || levels[level]->cells.cells.size() == 0)
+        return end_line();
 
       return raw_line_iterator (const_cast<Triangulation<dim,spacedim>*>(this),
                                 level,
@@ -11250,9 +11259,9 @@ Triangulation<dim,spacedim>::begin_raw_quad (const unsigned int level) const
       return raw_hex_iterator();
     case 2:
     {
-      Assert (level<levels.size(), ExcInvalidLevel(level));
+      Assert (level<n_global_levels() || level<levels.size(), ExcInvalidLevel(level));
 
-      if (levels[level]->cells.cells.size() == 0)
+      if (level >= levels.size() || levels[level]->cells.cells.size() == 0)
         return end_quad();
 
       return raw_quad_iterator (const_cast<Triangulation<dim,spacedim>*>(this),
@@ -11335,11 +11344,11 @@ Triangulation<dim,spacedim>::begin_raw_hex (const unsigned int level) const
       return raw_hex_iterator();
     case 3:
     {
-      Assert (level<levels.size(), ExcInvalidLevel(level));
-
-      if (levels[level]->cells.cells.size() == 0)
+      Assert (level<n_global_levels() || level<levels.size(), ExcInvalidLevel(level));
+      
+      if (level >= levels.size() || levels[level]->cells.cells.size() == 0)
         return end_hex();
-
+      
       return raw_hex_iterator (const_cast<Triangulation<dim,spacedim>*>(this),
                                level,
                                0);

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.