]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix a DoFRenumbering issue with serial data structures. 13667/head
authorDavid Wells <drwells@email.unc.edu>
Tue, 3 May 2022 20:32:45 +0000 (16:32 -0400)
committerDavid Wells <drwells@email.unc.edu>
Tue, 3 May 2022 22:06:02 +0000 (18:06 -0400)
source/dofs/dof_handler_policy.cc
tests/fe/fe_nothing_02.cc [new file with mode: 0644]
tests/fe/fe_nothing_02.output [new file with mode: 0644]

index 58d71ca31221c881886f647749fed759d414e621..013641130cd0f0fcebe430106ccda33ab7e5c75a 100644 (file)
@@ -2931,8 +2931,11 @@ namespace internal
         // independently, and then unifies some located at vertices or faces;
         // this leaves us with fewer DoFs than there were before, so use the
         // largest index as the one to determine the size of the index space
-        return NumberCache(
-          *std::max_element(new_numbers.begin(), new_numbers.end()) + 1);
+        if (new_numbers.size() == 0)
+          return NumberCache();
+        else
+          return NumberCache(
+            *std::max_element(new_numbers.begin(), new_numbers.end()) + 1);
       }
 
 
diff --git a/tests/fe/fe_nothing_02.cc b/tests/fe/fe_nothing_02.cc
new file mode 100644 (file)
index 0000000..745a47f
--- /dev/null
@@ -0,0 +1,32 @@
+#include <deal.II/dofs/dof_handler.h>
+#include <deal.II/dofs/dof_renumbering.h>
+
+#include <deal.II/fe/fe_nothing.h>
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria.h>
+
+#include "../tests.h"
+
+// Verify that we can set up a mesh consisting entirely of FE_Nothing FEs. While
+// this by itself would be useless, its possible in other contexts to get
+// DoFHandlers with zero DoFs on them with uncommon parallel data distributions.
+// This previously crashed with a segmentation fault inside
+// DoFHandlerImplementation::Policy::Sequential::renumber_dofs().
+
+using namespace dealii;
+int
+main()
+{
+  initlog();
+
+  Triangulation<2> tria;
+  GridGenerator::hyper_cube(tria);
+  FE_Nothing<2> fe;
+  DoFHandler<2> dof_handler(tria);
+  dof_handler.distribute_dofs(fe);
+
+  deallog << "Number of DoFs = " << dof_handler.n_dofs() << std::endl;
+  DoFRenumbering::random(dof_handler);
+  deallog << "Number of DoFs = " << dof_handler.n_dofs() << std::endl;
+}
diff --git a/tests/fe/fe_nothing_02.output b/tests/fe/fe_nothing_02.output
new file mode 100644 (file)
index 0000000..f6c905a
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::Number of DoFs = 0
+DEAL::Number of DoFs = 0

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.