From: Daniel Arndt Date: Wed, 10 Jan 2018 23:49:19 +0000 (+0100) Subject: Make sure distribute_dofs doesn't copy unnecessarily X-Git-Tag: v9.0.0-rc1~577^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b348b5d78d89e37978d7eedc58667ef729313d9;p=dealii.git Make sure distribute_dofs doesn't copy unnecessarily --- diff --git a/source/dofs/dof_handler.cc b/source/dofs/dof_handler.cc index 0b455016fa..deb6abb60e 100644 --- a/source/dofs/dof_handler.cc +++ b/source/dofs/dof_handler.cc @@ -997,7 +997,10 @@ void DoFHandler::distribute_dofs (const FiniteElementn_levels() > 0, ExcMessage("The Triangulation you are using is empty!")); - fe_collection = std_cxx14::make_unique>(ff); + // Only recreate the FECollection if we don't already store + // the exact same FiniteElement object. + if (fe_collection == nullptr || &((*fe_collection)[0]) != &ff) + fe_collection = std_cxx14::make_unique>(ff); // delete all levels and set them // up newly. note that we still diff --git a/tests/dofs/dof_handler_redistributed_dofs_01.cc b/tests/dofs/dof_handler_redistributed_dofs_01.cc new file mode 100644 index 0000000000..fa63f42326 --- /dev/null +++ b/tests/dofs/dof_handler_redistributed_dofs_01.cc @@ -0,0 +1,45 @@ +// +// Copyright (C) 2018 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 that calling hp::DoFhandler::distribute_dofs again with the same +// hp::FECollection doesn't recreate the copy. + + +#include +#include +#include +#include + +#include "../tests.h" + +int main() +{ + initlog(); + + constexpr int dim = 2; + constexpr int spacedim = 2; + + Triangulation tria; + GridGenerator::hyper_cube (tria); + FE_Q fe(1); + + DoFHandler dh(tria); + dh.distribute_dofs(fe); + + SmartPointer> fe_p(&dh.get_fe()); + + dh.distribute_dofs(*fe_p); + + deallog << "OK" << std::endl; +} diff --git a/tests/dofs/dof_handler_redistributed_dofs_01.output b/tests/dofs/dof_handler_redistributed_dofs_01.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/dofs/dof_handler_redistributed_dofs_01.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/dofs/dof_handler_redistributed_dofs_02.cc b/tests/dofs/dof_handler_redistributed_dofs_02.cc new file mode 100644 index 0000000000..3849562a3f --- /dev/null +++ b/tests/dofs/dof_handler_redistributed_dofs_02.cc @@ -0,0 +1,46 @@ +// +// Copyright (C) 2018 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 that calling hp::DoFhandler::distribute_dofs again with the same +// hp::FECollection doesn't recreate the copy. + + +#include +#include +#include +#include + +#include "../tests.h" + +int main() +{ + initlog(); + + constexpr int dim = 2; + constexpr int spacedim = 2; + + Triangulation tria; + GridGenerator::hyper_cube (tria); + FE_Q fe(1); + hp::FECollection fe_collection(fe); + + hp::DoFHandler dh(tria); + dh.distribute_dofs(fe_collection); + + SmartPointer> fe_p(&dh.get_fe_collection()); + + dh.distribute_dofs(*fe_p); + + deallog << "OK" << std::endl; +} diff --git a/tests/dofs/dof_handler_redistributed_dofs_02.output b/tests/dofs/dof_handler_redistributed_dofs_02.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/dofs/dof_handler_redistributed_dofs_02.output @@ -0,0 +1,2 @@ + +DEAL::OK