--- /dev/null
+New: Modify IndexSet::index_within_set() to return numbers::invalid_dof_index
+if the global index is not a member of this index set.
+<br>
+(Denis Davydov, 2016/12/23)
/**
* Return the how-manyth element of this set (counted in ascending order) @p
* global_index is. @p global_index needs to be less than the size(). This
- * function throws an exception if the index @p global_index is not actually
+ * function returns numbers::invalid_dof_index if the index @p global_index is not actually
* a member of this index set, i.e. if is_element(global_index) is false.
*/
size_type index_within_set (const size_type global_index) const;
}
-
inline
IndexSet::size_type
IndexSet::index_within_set (const size_type n) const
// to make this call thread-safe, compress() must not be called through this
// function
Assert (is_compressed == true, ExcMessage ("IndexSet must be compressed."));
- Assert (is_element(n) == true, ExcIndexNotPresent (n));
Assert (n < size(), ExcIndexRangeType<size_type> (n, 0, size()));
// check whether the index is in the largest range. use the result to
p = Utilities::lower_bound(range_begin, range_end, r,
Range::end_compare);
+ // if n is not in this set
+ if (p==range_end || p->end == n || p->begin > n)
+ return numbers::invalid_dof_index;
+
Assert(p!=ranges.end(), ExcInternalError());
Assert(p->begin<=n, ExcInternalError());
Assert(n<p->end, ExcInternalError());
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+// test IndexSet::index_within_set () for global indices which are not
+// part of a contiguous index set.
+// This test has exactly the same output as index_set_10
+
+#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_index (2);
+ index_set.add_index (3);
+ index_set.add_index (4);
+
+ index_set.add_index (6);
+ index_set.add_index (7);
+
+ index_set.compress ();
+
+ index_set.add_index (5);
+
+ for (unsigned int i=0; i<index_set.n_elements(); ++i)
+ {
+ deallog << index_set.nth_index_in_set(i)
+ << std::endl;
+
+ AssertThrow (index_set.index_within_set(index_set.nth_index_in_set(i) == i),
+ ExcInternalError());
+ }
+ deallog << "OK" << std::endl;
+
+ for (unsigned int i=0; i<index_set.size(); ++i)
+ {
+ const unsigned int i_out = index_set.index_within_set(i);
+ const bool within = (i_out != numbers::invalid_dof_index);
+ AssertThrow (within == index_set.is_element(i),
+ ExcInternalError());
+
+ if (within)
+ deallog << i << ' ' << i_out
+ << std::endl;
+
+ }
+}
+
+
+
+
+int main()
+{
+ std::ofstream logfile("output");
+ deallog.attach(logfile);
+ deallog.threshold_double(1.e-10);
+
+ test ();
+}
--- /dev/null
+
+DEAL::2
+DEAL::3
+DEAL::4
+DEAL::5
+DEAL::6
+DEAL::7
+DEAL::OK
+DEAL::2 0
+DEAL::3 1
+DEAL::4 2
+DEAL::5 3
+DEAL::6 4
+DEAL::7 5
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+// test IndexSet::index_within_set () for global indices which are not
+// part of a non-contiguous index set.
+// This test has exactly the same output as index_set_12
+
+#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_index (2);
+ index_set.add_index (3);
+ index_set.add_index (4);
+
+ index_set.add_index (6);
+ index_set.add_index (7);
+
+ index_set.compress ();
+
+ index_set.add_index (9);
+
+ for (unsigned int i=0; i<index_set.n_elements(); ++i)
+ {
+ deallog << index_set.nth_index_in_set(i)
+ << std::endl;
+
+ AssertThrow (index_set.index_within_set(index_set.nth_index_in_set(i) == i),
+ ExcInternalError());
+ }
+ deallog << "OK" << std::endl;
+
+ for (unsigned int i=0; i<index_set.size(); ++i)
+ {
+ const unsigned int i_out = index_set.index_within_set(i);
+ const bool within = (i_out != numbers::invalid_dof_index);
+ AssertThrow (within == index_set.is_element(i),
+ ExcInternalError());
+
+ if (within)
+ deallog << i << ' ' << i_out
+ << std::endl;
+
+ }
+}
+
+
+
+
+int main()
+{
+ std::ofstream logfile("output");
+ deallog.attach(logfile);
+ deallog.threshold_double(1.e-10);
+
+ test ();
+}
--- /dev/null
+
+DEAL::2
+DEAL::3
+DEAL::4
+DEAL::6
+DEAL::7
+DEAL::9
+DEAL::OK
+DEAL::2 0
+DEAL::3 1
+DEAL::4 2
+DEAL::6 3
+DEAL::7 4
+DEAL::9 5