From 8f01cf595bfdf4b127967c47cac3ad610d57101b Mon Sep 17 00:00:00 2001 From: David Wells Date: Tue, 3 May 2022 16:32:45 -0400 Subject: [PATCH] Fix a DoFRenumbering issue with serial data structures. --- source/dofs/dof_handler_policy.cc | 7 +++++-- tests/fe/fe_nothing_02.cc | 32 +++++++++++++++++++++++++++++++ tests/fe/fe_nothing_02.output | 3 +++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 tests/fe/fe_nothing_02.cc create mode 100644 tests/fe/fe_nothing_02.output 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 -- 2.39.5