From b3e962418fbd81bdb9e2bfaaa0e4c7e64b8161b8 Mon Sep 17 00:00:00 2001 From: bangerth Date: Sun, 12 Feb 2012 16:35:24 +0000 Subject: [PATCH] IndexSet::clear(). git-svn-id: https://svn.dealii.org/trunk@25041 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/doc/news/changes.h | 4 ++ deal.II/include/deal.II/base/index_set.h | 55 ++++++++++++++------- tests/base/index_set_21.cc | 62 ++++++++++++++++++++++++ tests/base/index_set_21/cmp/generic | 21 ++++++++ 4 files changed, 124 insertions(+), 18 deletions(-) create mode 100644 tests/base/index_set_21.cc create mode 100644 tests/base/index_set_21/cmp/generic diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 27efd234fa..89f9899599 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -87,6 +87,10 @@ enabled due to a missing include file in file

Specific improvements

    +
  1. New: The function IndexSet::clear resets an index set to be empty. +
    +(Wolfgang Bangerth, 2012/02/12) +
  2. New: There are now global functions l1_norm() and linfty_norm() that compute the respective norms of a rank-2 tensor.
    diff --git a/deal.II/include/deal.II/base/index_set.h b/deal.II/include/deal.II/base/index_set.h index a7840c485c..28f8310f44 100644 --- a/deal.II/include/deal.II/base/index_set.h +++ b/deal.II/include/deal.II/base/index_set.h @@ -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 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 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::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::const_iterator p = std::upper_bound (ranges.begin() + (index::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::const_iterator + std::vector::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::const_iterator + std::vector::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 index 0000000000..ef0c1d7bf1 --- /dev/null +++ b/tests/base/index_set_21.cc @@ -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 +#include +#include +#include + +#include + + +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