From 49d77428992e1fcb75e9d40b5c958ffc518b54ce Mon Sep 17 00:00:00 2001 From: Marc Fehling Date: Mon, 25 Jan 2021 19:00:40 -0700 Subject: [PATCH] Bugfix: Clear DoFHandler in Triangulation create signal. --- include/deal.II/grid/grid_generator.h | 1 + include/deal.II/grid/tria.h | 4 +- source/dofs/dof_handler.cc | 2 +- tests/hp/crash_22.cc | 68 +++++++++++++++++++++++++++ tests/hp/crash_22.output | 2 + 5 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 tests/hp/crash_22.cc create mode 100644 tests/hp/crash_22.output diff --git a/include/deal.II/grid/grid_generator.h b/include/deal.II/grid/grid_generator.h index d17c7e5d02..6dfaee23c6 100644 --- a/include/deal.II/grid/grid_generator.h +++ b/include/deal.II/grid/grid_generator.h @@ -1522,6 +1522,7 @@ namespace GridGenerator * Given the two triangulations specified as the first two arguments, create * the triangulation that contains the cells of both triangulation and store * it in the third parameter. Previous content of @p result will be deleted. + * One of the two input triangulations can also be the @p result triangulation. * * This function is most often used to compose meshes for more complicated * geometries if the geometry can be composed of simpler parts for which diff --git a/include/deal.II/grid/tria.h b/include/deal.II/grid/tria.h index 058550145c..55b0e7e5b0 100644 --- a/include/deal.II/grid/tria.h +++ b/include/deal.II/grid/tria.h @@ -1830,7 +1830,9 @@ public: * @note This function is used in step-14 and step-19. * * @note This function triggers the "create" signal after doing its work. See - * the section on signals in the general documentation of this class. + * the section on signals in the general documentation of this class. For + * example as a consequence of this, all DoFHandler objects connected to + * this triangulation will be reinitialized via DoFHandler::reinit(). * * @note The check for distorted cells is only done if dim==spacedim, as * otherwise cells can legitimately be twisted if the manifold they describe diff --git a/source/dofs/dof_handler.cc b/source/dofs/dof_handler.cc index d0b2a6661b..d88ce7c135 100644 --- a/source/dofs/dof_handler.cc +++ b/source/dofs/dof_handler.cc @@ -3043,7 +3043,7 @@ DoFHandler::connect_to_triangulation_signals() { // connect functions to signals of the underlying triangulation this->tria_listeners.push_back(this->tria->signals.create.connect( - [this]() { this->create_active_fe_table(); })); + [this]() { this->reinit(*(this->tria)); })); // attach corresponding callback functions dealing with the transfer of // active FE indices depending on the type of triangulation diff --git a/tests/hp/crash_22.cc b/tests/hp/crash_22.cc new file mode 100644 index 0000000000..b3966972de --- /dev/null +++ b/tests/hp/crash_22.cc @@ -0,0 +1,68 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2021 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + + +// Consider a Triangulation with a connected DoFHandler. +// When Triangulation::create_triangulation() gets called (e.g. in +// GridGenerator::merge_triangulations()) the corresponding create signal +// gets triggered. +// At some point, we forgot to reset the DoFHandler at this stage. + + +#include + +#include +#include + +#include "../tests.h" + + +template +void +test() +{ + Triangulation triangulation; + DoFHandler dof_handler(triangulation); + + /*Make a square*/ + Point point_1, point_2; + point_1(0) = 0; + point_1(1) = 0; + point_2(0) = 1; + point_2(1) = 1; + GridGenerator::hyper_rectangle(triangulation, point_1, point_2); + + Triangulation triangulation_temp; + point_1(0) = 1; + point_2(0) = 2; + GridGenerator::hyper_rectangle(triangulation_temp, point_1, point_2); + /*glue squares together*/ + GridGenerator::merge_triangulations(triangulation_temp, + triangulation, + triangulation); + + deallog << "OK" << std::endl; +} + +int +main() +{ + initlog(); + + deallog.push("2d"); + test<2>(); + deallog.pop(); +} diff --git a/tests/hp/crash_22.output b/tests/hp/crash_22.output new file mode 100644 index 0000000000..f445833684 --- /dev/null +++ b/tests/hp/crash_22.output @@ -0,0 +1,2 @@ + +DEAL:2d::OK -- 2.39.5