]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Have a is_valid_entry() function for SparsityPattern accessors. Use it to disallow...
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 31 Mar 2004 23:12:30 +0000 (23:12 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 31 Mar 2004 23:12:30 +0000 (23:12 +0000)
git-svn-id: https://svn.dealii.org/trunk@8932 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/sparse_matrix.h
deal.II/lac/include/lac/sparsity_pattern.h

index 9e22791974de37720e45c2f1a023ead69ba70b38..13bd6003f51d681cd48b21b341bc31c400116210 100644 (file)
@@ -2042,9 +2042,7 @@ namespace internals
     Iterator<number,Constness>::
     operator == (const Iterator& other) const
     {
-      return (&accessor.get_matrix() == &other.accessor.get_matrix() &&
-              accessor.row()   == other.accessor.row() &&
-              accessor.index() == other.accessor.index());
+      return (accessor == other.accessor);
     }
 
 
@@ -2067,9 +2065,7 @@ namespace internals
       Assert (accessor.matrix == other.accessor.matrix,
               ExcInternalError());
       
-      return (accessor.row() < other.accessor.row() ||
-              (accessor.row() == other.accessor.row() &&
-               accessor.index() < other.accessor.index()));
+      return (accessor < other.accessor);
     }
     
   }
index 05794b7788a0a01f7be682e6adfb4f6e373cbec9..2d4a5b0c46998b163289f3e844c13fb2e63f2b89 100644 (file)
@@ -66,30 +66,75 @@ namespace internals
                                          /**
                                           * Row number of the element
                                           * represented by this
-                                          * object.
+                                          * object. This
+                                          * function can only be called for
+                                          * entries for which is_valid_entry() is
+                                          * true.
                                           */
-        unsigned int row() const;
+        unsigned int row () const;
 
                                          /**
                                           * Index in row of the element
                                           * represented by this
-                                          * object.
+                                          * object. This
+                                          * function can only be called for
+                                          * entries for which is_valid_entry() is
+                                          * true.
                                           */
-        unsigned int index() const;
+        unsigned int index () const;
 
                                          /**
-                                          * Column number of the
-                                          * element represented by
-                                          * this object.
+                                          * Column number of the element
+                                          * represented by this object. This
+                                          * function can only be called for
+                                          * entries for which is_valid_entry() is
+                                          * true.
+                                          */
+        unsigned int column () const;
+
+                                         /**
+                                          * Return whether the sparsity
+                                          * pattern entry pointed to by this
+                                          * iterator is valid or not. Note
+                                          * that after compressing the
+                                          * sparsity pattern, all entries are
+                                          * valid. However, before
+                                          * compression, the sparsity pattern
+                                          * allocated some memory to be used
+                                          * while still adding new nonzero
+                                          * entries; if you create iterators
+                                          * in this phase of the sparsity
+                                          * pattern's lifetime, you will
+                                          * iterate over elements that are not
+                                          * valid. If this is so, then this
+                                          * function will return false.
+                                          */
+        bool is_valid_entry () const;
+
+
+                                         /**
+                                          * Comparison. True, if
+                                          * both iterators point to
+                                          * the same matrix
+                                          * position.
+                                          */
+       bool operator == (const Accessor &) const;
+
+
+                                         /**
+                                          * Comparison
+                                          * operator. Result is true
+                                          * if either the first row
+                                          * number is smaller or if
+                                          * the row numbers are
+                                          * equal and the first
+                                          * index is smaller.
                                           *
-                                          * Note that if the underlying
-                                          * sparsity pattern has not yet been
-                                          * compressed, then this function may
-                                          * return @p
-                                          * SparsityPattern::invalid_index for
-                                          * certain elements of the matrix.
+                                          * This function is only valid if
+                                          * both iterators point into the same
+                                          * sparsity pattern.
                                           */
-        unsigned int column() const;
+       bool operator < (const Accessor &) const;
 
                                          /**
                                           * Move the accessor to the next
@@ -102,7 +147,12 @@ namespace internals
                                           * use it in your own programs.
                                           */
         void advance ();
-       
+
+                                         /**
+                                          * Exception
+                                          */
+        DeclException0 (ExcInvalidIterator);
+        
       protected:
                                          /**
                                           * The sparsity pattern we operate on
@@ -1529,6 +1579,8 @@ namespace internals
     unsigned int
     Accessor::row() const
     {
+      Assert (is_valid_entry() == true, ExcInvalidIterator());
+
       return a_row;
     }
 
@@ -1537,6 +1589,8 @@ namespace internals
     unsigned int
     Accessor::column() const
     {
+      Assert (is_valid_entry() == true, ExcInvalidIterator());
+      
       return (sparsity_pattern
               ->get_column_numbers()[sparsity_pattern
                                      ->get_rowstart_indices()[a_row]+a_index]);
@@ -1547,11 +1601,49 @@ namespace internals
     unsigned int
     Accessor::index() const
     {
+      Assert (is_valid_entry() == true, ExcInvalidIterator());
+
       return a_index;
     }
 
 
 
+    inline
+    bool
+    Accessor::is_valid_entry () const
+    {
+      return (sparsity_pattern
+              ->get_column_numbers()[sparsity_pattern
+                                     ->get_rowstart_indices()[a_row]+a_index]
+              != SparsityPattern::invalid_entry);
+    }
+
+
+
+    inline
+    bool
+    Accessor::operator == (const Accessor& other) const
+    {      
+      return (sparsity_pattern  == other.sparsity_pattern &&
+              a_row   == other.a_row &&
+              a_index == other.a_index);
+    }
+
+
+
+    inline
+    bool
+    Accessor::operator < (const Accessor& other) const
+    {      
+      Assert (sparsity_pattern == other.sparsity_pattern,
+              ExcInternalError());
+      
+      return (a_row < other.a_row ||
+              (a_row == other.a_row &&
+               a_index < other.a_index));
+    }
+    
+
     inline
     void
     Accessor::advance ()
@@ -1629,9 +1721,7 @@ namespace internals
     bool
     Iterator::operator == (const Iterator& other) const
     {
-      return (accessor.sparsity_pattern  == other.accessor.sparsity_pattern &&
-              accessor.row()   == other.accessor.row() &&
-              accessor.index() == other.accessor.index());
+      return (accessor == other.accessor);
     }
 
 
@@ -1648,12 +1738,7 @@ namespace internals
     bool
     Iterator::operator < (const Iterator& other) const
     {
-      Assert (accessor.sparsity_pattern == other.accessor.sparsity_pattern,
-              ExcInternalError());
-      
-      return (accessor.row() < other.accessor.row() ||
-              (accessor.row() == other.accessor.row() &&
-               accessor.index() < other.accessor.index()));
+      return accessor < other.accessor;
     }
     
   }

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.