From: Denis Davydov Date: Fri, 23 Dec 2016 10:59:11 +0000 (+0100) Subject: extend IndexSet::index_within_set() X-Git-Tag: v8.5.0-rc1~306^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=881b9b79d49a89ee8b1b54b6aa7ad892bd81e700;p=dealii.git extend IndexSet::index_within_set() to return numbers::invalid_dof_index if the global index is not a member of the index set --- diff --git a/doc/news/changes/minor/20161223DenisDavydov b/doc/news/changes/minor/20161223DenisDavydov new file mode 100644 index 0000000000..197f9b8c2e --- /dev/null +++ b/doc/news/changes/minor/20161223DenisDavydov @@ -0,0 +1,4 @@ +New: Modify IndexSet::index_within_set() to return numbers::invalid_dof_index +if the global index is not a member of this index set. +
+(Denis Davydov, 2016/12/23) diff --git a/include/deal.II/base/index_set.h b/include/deal.II/base/index_set.h index c1e3472c33..79f66cac53 100644 --- a/include/deal.II/base/index_set.h +++ b/include/deal.II/base/index_set.h @@ -250,7 +250,7 @@ public: /** * 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; @@ -1648,7 +1648,6 @@ IndexSet::nth_index_in_set (const unsigned int n) const } - inline IndexSet::size_type IndexSet::index_within_set (const size_type n) const @@ -1656,7 +1655,6 @@ 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 (n, 0, size())); // check whether the index is in the largest range. use the result to @@ -1683,6 +1681,10 @@ IndexSet::index_within_set (const size_type n) const 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(nend, ExcInternalError()); diff --git a/tests/base/index_set_28.cc b/tests/base/index_set_28.cc new file mode 100644 index 0000000000..09d80ddc94 --- /dev/null +++ b/tests/base/index_set_28.cc @@ -0,0 +1,79 @@ +// --------------------------------------------------------------------- +// +// 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 +#include +#include +#include + +#include + + +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 +#include +#include +#include + +#include + + +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