]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make sure distribute_dofs doesn't copy unnecessarily 5717/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 10 Jan 2018 23:49:19 +0000 (00:49 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Thu, 11 Jan 2018 09:32:05 +0000 (10:32 +0100)
source/dofs/dof_handler.cc
tests/dofs/dof_handler_redistributed_dofs_01.cc [new file with mode: 0644]
tests/dofs/dof_handler_redistributed_dofs_01.output [new file with mode: 0644]
tests/dofs/dof_handler_redistributed_dofs_02.cc [new file with mode: 0644]
tests/dofs/dof_handler_redistributed_dofs_02.output [new file with mode: 0644]

index 0b455016fa2a53d4473cabda55739e05ba041d54..deb6abb60ea5a3099afbd7d9f664617c85ca61a7 100644 (file)
@@ -997,7 +997,10 @@ void DoFHandler<dim,spacedim>::distribute_dofs (const FiniteElement<dim,spacedim
   Assert (tria->n_levels() > 0,
           ExcMessage("The Triangulation you are using is empty!"));
 
-  fe_collection = std_cxx14::make_unique<hp::FECollection<dim, spacedim>>(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<hp::FECollection<dim, spacedim>>(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 (file)
index 0000000..fa63f42
--- /dev/null
@@ -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 <deal.II/dofs/dof_handler.h>
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/grid_generator.h>
+
+#include  "../tests.h"
+
+int main()
+{
+  initlog();
+
+  constexpr int dim = 2;
+  constexpr int spacedim = 2;
+
+  Triangulation<dim,spacedim> tria;
+  GridGenerator::hyper_cube (tria);
+  FE_Q<dim,spacedim> fe(1);
+
+  DoFHandler<dim,spacedim> dh(tria);
+  dh.distribute_dofs(fe);
+
+  SmartPointer<const FiniteElement<dim,spacedim>> 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 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -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 (file)
index 0000000..3849562
--- /dev/null
@@ -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 <deal.II/hp/dof_handler.h>
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/grid_generator.h>
+
+#include  "../tests.h"
+
+int main()
+{
+  initlog();
+
+  constexpr int dim = 2;
+  constexpr int spacedim = 2;
+
+  Triangulation<dim,spacedim> tria;
+  GridGenerator::hyper_cube (tria);
+  FE_Q<dim,spacedim> fe(1);
+  hp::FECollection<dim, spacedim> fe_collection(fe);
+
+  hp::DoFHandler<dim,spacedim> dh(tria);
+  dh.distribute_dofs(fe_collection);
+
+  SmartPointer<const hp::FECollection<dim,spacedim>> 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 (file)
index 0000000..0fd8fc1
--- /dev/null
@@ -0,0 +1,2 @@
+
+DEAL::OK

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.