From 729126516eeb5ae7c4f3c7fd6ac4e77c80c0a336 Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Wed, 25 Apr 2018 11:32:56 +0200 Subject: [PATCH] Only replace FECollection in *DoFHandler if necessary --- source/dofs/dof_handler.cc | 2 +- source/hp/dof_handler.cc | 5 +- tests/fe/multiple_redistribute_dofs_01.cc | 70 ++++++++++++++++++ tests/fe/multiple_redistribute_dofs_01.output | 13 ++++ tests/fe/multiple_redistribute_dofs_02.cc | 73 +++++++++++++++++++ tests/fe/multiple_redistribute_dofs_02.output | 13 ++++ 6 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 tests/fe/multiple_redistribute_dofs_01.cc create mode 100644 tests/fe/multiple_redistribute_dofs_01.output create mode 100644 tests/fe/multiple_redistribute_dofs_02.cc create mode 100644 tests/fe/multiple_redistribute_dofs_02.output diff --git a/source/dofs/dof_handler.cc b/source/dofs/dof_handler.cc index 247bf6009d..19bc763d80 100644 --- a/source/dofs/dof_handler.cc +++ b/source/dofs/dof_handler.cc @@ -1000,7 +1000,7 @@ void DoFHandler::distribute_dofs (const FiniteElement(ff); // delete all levels and set them diff --git a/source/hp/dof_handler.cc b/source/hp/dof_handler.cc index adb43c610d..b3b90b4625 100644 --- a/source/hp/dof_handler.cc +++ b/source/hp/dof_handler.cc @@ -1284,8 +1284,9 @@ namespace hp Assert (ff.size() > 0, ExcMessage("The hp::FECollection given is empty!")); - if (&fe_collection != &ff) - fe_collection = hp::FECollection(ff); + // don't create a new object if the one we have is already appropriate + if (fe_collection != ff) + fe_collection = hp::FECollection(ff); // at the beginning, make sure every processor knows the // active_fe_indices on both its own cells and all ghost cells diff --git a/tests/fe/multiple_redistribute_dofs_01.cc b/tests/fe/multiple_redistribute_dofs_01.cc new file mode 100644 index 0000000000..9c8e30c7d6 --- /dev/null +++ b/tests/fe/multiple_redistribute_dofs_01.cc @@ -0,0 +1,70 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 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 multiple redistribute dofs. + +#include "../tests.h" +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include + +using namespace dealii; + +template +void test() +{ + deallog << "Testing for dim = " << dim + << ", spacedim = " << spacedim << std::endl; + + Triangulation tria; + GridGenerator::hyper_cube (tria); + FE_Q fe(1); + + DoFHandler dh(tria); + dh.distribute_dofs(fe); + + // This stores a pointer to the fe in dh. + FEValues fe_v(dh.get_fe(), QGauss(1), update_values); + + tria.refine_global (1); + dh.distribute_dofs(fe); + + deallog << "OK" << std::endl; +} + +int main() +{ + initlog(); + + test<1,1>(); + test<1,2>(); + test<1,3>(); + test<2,2>(); + test<2,3>(); + test<3,3>(); +} diff --git a/tests/fe/multiple_redistribute_dofs_01.output b/tests/fe/multiple_redistribute_dofs_01.output new file mode 100644 index 0000000000..5937aa1d27 --- /dev/null +++ b/tests/fe/multiple_redistribute_dofs_01.output @@ -0,0 +1,13 @@ + +DEAL::Testing for dim = 1, spacedim = 1 +DEAL::OK +DEAL::Testing for dim = 1, spacedim = 2 +DEAL::OK +DEAL::Testing for dim = 1, spacedim = 3 +DEAL::OK +DEAL::Testing for dim = 2, spacedim = 2 +DEAL::OK +DEAL::Testing for dim = 2, spacedim = 3 +DEAL::OK +DEAL::Testing for dim = 3, spacedim = 3 +DEAL::OK diff --git a/tests/fe/multiple_redistribute_dofs_02.cc b/tests/fe/multiple_redistribute_dofs_02.cc new file mode 100644 index 0000000000..bab86d78f1 --- /dev/null +++ b/tests/fe/multiple_redistribute_dofs_02.cc @@ -0,0 +1,73 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 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 multiple redistribute dofs. + +#include "../tests.h" +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include + +using namespace dealii; + +template +void test() +{ + deallog << "Testing for dim = " << dim + << ", spacedim = " << spacedim << std::endl; + + Triangulation tria; + GridGenerator::hyper_cube (tria); + hp::FECollection fe_collection(FE_Q (1)); + + hp::DoFHandler dh(tria); + dh.distribute_dofs(fe_collection); + + // This stores a pointer to the fe in dh. + hp::FEValues fe_v(dh.get_fe_collection(), + hp::QCollection (QGauss(1)), + update_values); + fe_v.reinit(dh.begin_active()); + + tria.refine_global (1); + dh.distribute_dofs(fe_collection); + + deallog << "OK" << std::endl; +} + +int main() +{ + initlog(); + + test<1,1>(); + test<1,2>(); + test<1,3>(); + test<2,2>(); + test<2,3>(); + test<3,3>(); +} diff --git a/tests/fe/multiple_redistribute_dofs_02.output b/tests/fe/multiple_redistribute_dofs_02.output new file mode 100644 index 0000000000..5937aa1d27 --- /dev/null +++ b/tests/fe/multiple_redistribute_dofs_02.output @@ -0,0 +1,13 @@ + +DEAL::Testing for dim = 1, spacedim = 1 +DEAL::OK +DEAL::Testing for dim = 1, spacedim = 2 +DEAL::OK +DEAL::Testing for dim = 1, spacedim = 3 +DEAL::OK +DEAL::Testing for dim = 2, spacedim = 2 +DEAL::OK +DEAL::Testing for dim = 2, spacedim = 3 +DEAL::OK +DEAL::Testing for dim = 3, spacedim = 3 +DEAL::OK -- 2.39.5