From: Denis Davydov Date: Tue, 28 Feb 2017 13:56:01 +0000 (+0100) Subject: fix IndexSet::index_within_set() for an empty index set X-Git-Tag: v8.5.0-rc1~89^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=232916aafa0cae2d130a930d542190e0e437df24;p=dealii.git fix IndexSet::index_within_set() for an empty index set --- diff --git a/doc/news/changes/minor/20170228DenisDavydov b/doc/news/changes/minor/20170228DenisDavydov new file mode 100644 index 0000000000..53e1ddef31 --- /dev/null +++ b/doc/news/changes/minor/20170228DenisDavydov @@ -0,0 +1,4 @@ +Fixed: Fixed a bug in IndexSet::index_within_set() for the case when an index +set is empty. +
+(Denis Davydov, 2017/02/28) diff --git a/include/deal.II/base/index_set.h b/include/deal.II/base/index_set.h index 68726c917c..73583035e8 100644 --- a/include/deal.II/base/index_set.h +++ b/include/deal.II/base/index_set.h @@ -1657,6 +1657,10 @@ IndexSet::index_within_set (const size_type n) const Assert (is_compressed == true, ExcMessage ("IndexSet must be compressed.")); Assert (n < size(), ExcIndexRangeType (n, 0, size())); + // return immediately if the index set is empty + if (is_empty()) + return numbers::invalid_dof_index; + // check whether the index is in the largest range. use the result to // perform a one-sided binary search afterward Assert (largest_range < ranges.size(), ExcInternalError()); diff --git a/tests/base/index_set_30.cc b/tests/base/index_set_30.cc new file mode 100644 index 0000000000..ebe9748c20 --- /dev/null +++ b/tests/base/index_set_30.cc @@ -0,0 +1,51 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2016 - 2017 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 an empty index set + +#include "../tests.h" +#include +#include +#include +#include + +#include + + +void test () +{ + IndexSet index_set (20); + + index_set.compress (); + + AssertThrow (index_set.index_within_set(2) == numbers::invalid_dof_index, + ExcInternalError()); + + deallog << "OK" << std::endl; + +} + + + + +int main() +{ + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.threshold_double(1.e-10); + + test (); +} diff --git a/tests/base/index_set_30.output b/tests/base/index_set_30.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/base/index_set_30.output @@ -0,0 +1,2 @@ + +DEAL::OK