]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
IndexSet::clear().
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 12 Feb 2012 16:35:24 +0000 (16:35 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 12 Feb 2012 16:35:24 +0000 (16:35 +0000)
git-svn-id: https://svn.dealii.org/trunk@25041 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/doc/news/changes.h
deal.II/include/deal.II/base/index_set.h
tests/base/index_set_21.cc [new file with mode: 0644]
tests/base/index_set_21/cmp/generic [new file with mode: 0644]

index 27efd234fa3f317cf3427491f1a23eb9425f256b..89f9899599e10221f6a5450154ab22e0471f45e6 100644 (file)
@@ -87,6 +87,10 @@ enabled due to a missing include file in file
 <h3>Specific improvements</h3>
 
 <ol>
+<li> New: The function IndexSet::clear resets an index set to be empty.
+<br>
+(Wolfgang Bangerth, 2012/02/12)
+
 <li> New: There are now global functions l1_norm() and linfty_norm() that compute
 the respective norms of a rank-2 tensor.
 <br>
index a7840c485c326f82020e8113175f4b4d4de83a81..28f8310f44b0626e4a0c0e3dcefccfc6bd92efac 100644 (file)
@@ -1,7 +1,7 @@
 //---------------------------------------------------------------------------
 //    $Id$
 //
-//    Copyright (C) 2009, 2010, 2011 by the deal.II authors
+//    Copyright (C) 2009, 2010, 2011, 2012 by the deal.II authors
 //
 //    This file is subject to QPL and may not be  distributed
 //    without copyright and license information. Please refer
@@ -66,6 +66,13 @@ class IndexSet
                                      */
     IndexSet (const unsigned int size);
 
+                                    /**
+                                     * Remove all indices from this
+                                     * index set. The index set retains
+                                     * its size, however.
+                                     */
+    void clear ();
+
                                     /**
                                      * Set the maximal size of the
                                      * indices upon which this object
@@ -74,6 +81,8 @@ class IndexSet
                                      * This function can only be
                                      * called if the index set does
                                      * not yet contain any elements.
+                                     * This can be achieved by calling
+                                     * clear(), for example.
                                      */
     void set_size (const unsigned int size);
 
@@ -121,7 +130,7 @@ class IndexSet
                                      * *this and @p other.
                                      */
     void add_indices(const IndexSet & other);
-    
+
                                     /**
                                      * Return whether the specified
                                      * index is an element of the
@@ -369,11 +378,11 @@ class IndexSet
     DeclException1 (ExcIndexNotPresent, int,
                    << "The global index " << arg1
                    << " is not an element of this set.");
-                   
+
     /**
-     * Write or read the data of this object to or 
+     * Write or read the data of this object to or
      * from a stream for the purpose of serialization
-     */ 
+     */
     template <class Archive>
     void serialize (Archive & ar, const unsigned int version);
 
@@ -410,7 +419,7 @@ class IndexSet
         * never get to see an invalid range in the wild.
         **/
        Range ();
-       
+
        /**
         * Constructor. Create a half-open interval with the given indices.
         *
@@ -456,11 +465,11 @@ class IndexSet
        {
          return sizeof(Range);
        }
-         
+
          /**
-          * Write or read the data of this object to or 
+          * Write or read the data of this object to or
           * from a stream for the purpose of serialization
-          */ 
+          */
          template <class Archive>
          void serialize (Archive & ar, const unsigned int version);
     };
@@ -568,6 +577,16 @@ IndexSet::IndexSet (const unsigned int size)
 
 
 
+inline
+void
+IndexSet::clear ()
+{
+  ranges.clear ();
+  largest_range = 0;
+  is_compressed = true;
+}
+
+
 inline
 void
 IndexSet::set_size (const unsigned int sz)
@@ -693,7 +712,7 @@ IndexSet::add_indices(const IndexSet & other)
 {
   if (this == &other)
     return;
-  
+
   for (std::vector<Range>::iterator range = other.ranges.begin();
        range != other.ranges.end();
        ++range)
@@ -739,7 +758,7 @@ IndexSet::is_element (const unsigned int index) const
                                       // of the following ranges
                                       // because otherwise p would be
                                       // a different iterator
-                                      // 
+                                      //
                                       // since we already know the position
                                       // relative to the largest range (we
                                       // called compress!), we can perform
@@ -749,7 +768,7 @@ IndexSet::is_element (const unsigned int index) const
       std::vector<Range>::const_iterator
        p = std::upper_bound (ranges.begin() + (index<ranges[largest_range].begin?
                                                0 : largest_range+1),
-                             index<ranges[largest_range].begin ? 
+                             index<ranges[largest_range].begin ?
                              ranges.begin() + largest_range:
                              ranges.end(),
                              Range (index, size()+1));
@@ -799,16 +818,16 @@ IndexSet::n_elements () const
       Range & r = ranges.back();
       v = r.nth_index_in_set + r.end - r.begin;
     }
-  
-#ifdef DEBUG  
+
+#ifdef DEBUG
   unsigned int s = 0;
   for (std::vector<Range>::iterator range = ranges.begin();
        range != ranges.end();
        ++range)
     s += (range->end - range->begin);
   Assert(s==v, ExcInternalError());
-#endif  
-  
+#endif
+
   return v;
 }
 
@@ -850,7 +869,7 @@ IndexSet::nth_index_in_set (const unsigned int n) const
       range_end   = ranges.end();
     }
 
-  std::vector<Range>::const_iterator 
+  std::vector<Range>::const_iterator
     p = Utilities::lower_bound(range_begin, range_end, r,
                         Range::nth_index_compare);
 
@@ -896,7 +915,7 @@ IndexSet::index_within_set (const unsigned int n) const
       range_end   = ranges.end();
     }
 
-  std::vector<Range>::const_iterator 
+  std::vector<Range>::const_iterator
     p = Utilities::lower_bound(range_begin, range_end, r,
                         Range::end_compare);
 
diff --git a/tests/base/index_set_21.cc b/tests/base/index_set_21.cc
new file mode 100644 (file)
index 0000000..ef0c1d7
--- /dev/null
@@ -0,0 +1,62 @@
+//-----------------------------------------------------------------------------
+//    $Id$
+//    Version: $Name$
+//
+//    Copyright (C) 2009, 2012 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//-----------------------------------------------------------------------------
+
+// test IndexSet::clear
+
+#include "../tests.h"
+#include <iomanip>
+#include <iomanip>
+#include <fstream>
+#include <cmath>
+
+#include <deal.II/base/index_set.h>
+
+
+void test ()
+{
+  IndexSet index_set (20);
+  index_set.add_range (2,4);
+  index_set.add_range (12,18);
+  index_set.add_index (6);
+  index_set.add_index (8);
+  index_set.add_index (14);
+  index_set.add_index (16);
+
+                                  // clear the IndexSet and then set elements
+                                  // again
+  index_set.clear ();
+
+  index_set.add_range (2,4);
+  index_set.add_range (12,18);
+  index_set.add_index (6);
+  index_set.add_index (8);
+  index_set.add_index (14);
+  index_set.add_index (16);
+
+  for (unsigned int i=0; i<index_set.size(); ++i)
+    deallog << i << ' ' << (index_set.is_element(i) ? "true" : "false")
+           << std::endl;
+}
+
+
+
+
+int main()
+{
+  std::ofstream logfile("index_set_21/output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  test ();
+}
diff --git a/tests/base/index_set_21/cmp/generic b/tests/base/index_set_21/cmp/generic
new file mode 100644 (file)
index 0000000..00d6009
--- /dev/null
@@ -0,0 +1,21 @@
+
+DEAL::0 false
+DEAL::1 false
+DEAL::2 true
+DEAL::3 true
+DEAL::4 false
+DEAL::5 false
+DEAL::6 true
+DEAL::7 false
+DEAL::8 true
+DEAL::9 false
+DEAL::10 false
+DEAL::11 false
+DEAL::12 true
+DEAL::13 true
+DEAL::14 true
+DEAL::15 true
+DEAL::16 true
+DEAL::17 true
+DEAL::18 false
+DEAL::19 false

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.