From: David Wells Date: Tue, 3 May 2022 20:32:45 +0000 (-0400) Subject: Fix a DoFRenumbering issue with serial data structures. X-Git-Tag: v9.4.0-rc1~285^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F13667%2Fhead;p=dealii.git Fix a DoFRenumbering issue with serial data structures. --- diff --git a/source/dofs/dof_handler_policy.cc b/source/dofs/dof_handler_policy.cc index 58d71ca312..013641130c 100644 --- a/source/dofs/dof_handler_policy.cc +++ b/source/dofs/dof_handler_policy.cc @@ -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 index 0000000000..745a47f837 --- /dev/null +++ b/tests/fe/fe_nothing_02.cc @@ -0,0 +1,32 @@ +#include +#include + +#include + +#include +#include + +#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 index 0000000000..f6c905aefb --- /dev/null +++ b/tests/fe/fe_nothing_02.output @@ -0,0 +1,3 @@ + +DEAL::Number of DoFs = 0 +DEAL::Number of DoFs = 0