<h3>Specific improvements</h3>
<ol>
+<li> New: The function IndexSet::fill_binary_vector creates a numerical
+representation of an IndexSet containing zeros and ones.
+<br>
+(Wolfgang Bangerth, 2012/02/12)
+
<li> New: The function IndexSet::clear resets an index set to be empty.
<br>
(Wolfgang Bangerth, 2012/02/12)
*/
void fill_index_vector(std::vector<unsigned int> & indices) const;
+ /**
+ * Fill the given vector with either
+ * zero or one elements, providing
+ * a binary representation of this
+ * index set. The given vector is
+ * assumed to already have the correct
+ * size.
+ *
+ * The given argument is filled with
+ * integer values zero and one, using
+ * <code>vector.operator[]</code>. Thus,
+ * any object that has such an operator
+ * can be used as long as it allows
+ * conversion of integers zero and one to
+ * elements of the vector. Specifically,
+ * this is the case for classes Vector,
+ * BlockVector, but also
+ * std::vector@<bool@>,
+ * std::vector@<int@>, and
+ * std::vector@<double@>.
+ */
+ template <typename Vector>
+ void fill_binary_vector (Vector &vector) const;
/**
* Outputs a text representation of this
return ranges != is.ranges;
}
+
+
+template <typename Vector>
+void
+IndexSet::fill_binary_vector (Vector &vector) const
+{
+ Assert (vector.size() == size(),
+ ExcDimensionMismatch (vector.size(), size()));
+
+ compress();
+ // first fill all elements of the vector
+ // with zeroes.
+ std::fill (vector.begin(), vector.end(), 0);
+
+ // then write ones into the elements whose
+ // indices are contained in the index set
+ for (std::vector<Range>::iterator it = ranges.begin();
+ it != ranges.end();
+ ++it)
+ for (unsigned int i=it->begin; i<it->end; ++i)
+ vector[i] = 1;
+}
+
+
+
template <class STREAM>
inline
void
--- /dev/null
+//-----------------------------------------------------------------------------
+// $Id$
+// Version: $Name$
+//
+// Copyright (C) 2010, 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::fill_binary_vector
+
+#include "../tests.h"
+#include <iomanip>
+#include <iomanip>
+#include <fstream>
+#include <cmath>
+#include <stdlib.h>
+
+#include <deal.II/base/index_set.h>
+
+
+void test ()
+{
+ IndexSet is1 (100);
+
+ // randomly add 90 elements to each
+ // set, some of which may be
+ // repetitions of previous ones
+ for (unsigned int i=0; i<9*is1.size()/10; ++i)
+ is1.add_index (rand() % is1.size());
+
+ std::vector<bool> zeros_and_ones(is1.size());
+ is1.fill_binary_vector (zeros_and_ones);
+
+ deallog << "Original index set: " << std::endl;
+ is1.print(deallog);
+
+ for (unsigned int i=0; i<is1.size(); i++)
+ Assert(is1.is_element(i) == zeros_and_ones[i],
+ ExcInternalError());
+
+ deallog << "OK" << std::endl;
+}
+
+
+
+
+int main()
+{
+ std::ofstream logfile("index_set_22/output");
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ test ();
+}
--- /dev/null
+
+DEAL::Original index set:
+DEAL::{[2,3], 5, 8, 11, [13,15], 19, [21,27], [29,30], [34,37], 40, [42,43], [45,46], [49,51], 54, [56,59], [62,64], [67,70], [72,73], [76,78], [80,84], [86,88], [90,93], [95,96], [98,99]}
+DEAL::OK