]> https://gitweb.dealii.org/ - dealii.git/commitdiff
fix IndexSet::index_within_set() for an empty index set 4013/head
authorDenis Davydov <davydden@gmail.com>
Tue, 28 Feb 2017 13:56:01 +0000 (14:56 +0100)
committerDenis Davydov <davydden@gmail.com>
Tue, 28 Feb 2017 14:13:18 +0000 (15:13 +0100)
doc/news/changes/minor/20170228DenisDavydov [new file with mode: 0644]
include/deal.II/base/index_set.h
tests/base/index_set_30.cc [new file with mode: 0644]
tests/base/index_set_30.output [new file with mode: 0644]

diff --git a/doc/news/changes/minor/20170228DenisDavydov b/doc/news/changes/minor/20170228DenisDavydov
new file mode 100644 (file)
index 0000000..53e1dde
--- /dev/null
@@ -0,0 +1,4 @@
+Fixed: Fixed a bug in IndexSet::index_within_set() for the case when an index
+set is empty.
+<br>
+(Denis Davydov, 2017/02/28)
index 68726c917c8392189d928136b8e1072aaced9cef..73583035e8e4ee7d3eeec482de5c4b69bed09c0f 100644 (file)
@@ -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<size_type> (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 (file)
index 0000000..ebe9748
--- /dev/null
@@ -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 <iomanip>
+#include <iomanip>
+#include <fstream>
+#include <cmath>
+
+#include <deal.II/base/index_set.h>
+
+
+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 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.