]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Only replace FECollection in *DoFHandler if necessary
authorLuca Heltai <luca.heltai@sissa.it>
Wed, 25 Apr 2018 09:32:56 +0000 (11:32 +0200)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Fri, 27 Apr 2018 12:05:42 +0000 (14:05 +0200)
source/dofs/dof_handler.cc
source/hp/dof_handler.cc
tests/fe/multiple_redistribute_dofs_01.cc [new file with mode: 0644]
tests/fe/multiple_redistribute_dofs_01.output [new file with mode: 0644]
tests/fe/multiple_redistribute_dofs_02.cc [new file with mode: 0644]
tests/fe/multiple_redistribute_dofs_02.output [new file with mode: 0644]

index 247bf6009da35538b7182ef4ba0c6ddcc9ff0458..19bc763d80b3cd60f9c12fc0bed134e3682de846 100644 (file)
@@ -1000,7 +1000,7 @@ void DoFHandler<dim,spacedim>::distribute_dofs (const FiniteElement<dim,spacedim
 
   // Only recreate the FECollection if we don't already store
   // the exact same FiniteElement object.
-  if  (fe_collection.size() == 0 || &(fe_collection[0]) != &ff)
+  if  (fe_collection.size() == 0 || fe_collection[0] != ff)
     fe_collection = hp::FECollection<dim, spacedim>(ff);
 
   // delete all levels and set them
index adb43c610dc3dcc1f9ee1fcb5b1e30727c96274f..b3b90b462513b8239471790fdb1fabaa5ed0a6ec 100644 (file)
@@ -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<dim, spacedim>(ff);
+    // don't create a new object if the one we have is already appropriate
+    if (fe_collection != ff)
+      fe_collection = hp::FECollection<dim,spacedim>(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 (file)
index 0000000..9c8e30c
--- /dev/null
@@ -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 <iostream>
+
+#include <deal.II/grid/tria.h>
+#include <deal.II/dofs/dof_handler.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_tools.h>
+
+#include <deal.II/dofs/dof_accessor.h>
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/dofs/dof_tools.h>
+
+#include <deal.II/fe/fe_values.h>
+#include <deal.II/base/quadrature_lib.h>
+#include <deal.II/numerics/fe_field_function.h>
+
+#include <deal.II/fe/mapping_q.h>
+
+using namespace dealii;
+
+template <int dim, int spacedim>
+void test()
+{
+  deallog << "Testing for dim = " << dim
+          << ", spacedim = " << spacedim <<  std::endl;
+
+  Triangulation<dim,spacedim> tria;
+  GridGenerator::hyper_cube (tria);
+  FE_Q<dim,spacedim> fe(1);
+
+  DoFHandler<dim,spacedim> dh(tria);
+  dh.distribute_dofs(fe);
+
+  // This stores a pointer to the fe in dh.
+  FEValues<dim,spacedim> fe_v(dh.get_fe(), QGauss<dim>(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 (file)
index 0000000..5937aa1
--- /dev/null
@@ -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 (file)
index 0000000..bab86d7
--- /dev/null
@@ -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 <iostream>
+
+#include <deal.II/grid/tria.h>
+#include <deal.II/dofs/dof_handler.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_tools.h>
+
+#include <deal.II/dofs/dof_accessor.h>
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/dofs/dof_tools.h>
+
+#include <deal.II/hp/fe_values.h>
+#include <deal.II/base/quadrature_lib.h>
+#include <deal.II/numerics/fe_field_function.h>
+
+#include <deal.II/fe/mapping_q.h>
+
+using namespace dealii;
+
+template <int dim, int spacedim>
+void test()
+{
+  deallog << "Testing for dim = " << dim
+          << ", spacedim = " << spacedim <<  std::endl;
+
+  Triangulation<dim,spacedim> tria;
+  GridGenerator::hyper_cube (tria);
+  hp::FECollection<dim, spacedim> fe_collection(FE_Q<dim,spacedim> (1));
+
+  hp::DoFHandler<dim,spacedim> dh(tria);
+  dh.distribute_dofs(fe_collection);
+
+  // This stores a pointer to the fe in dh.
+  hp::FEValues<dim,spacedim> fe_v(dh.get_fe_collection(),
+                                  hp::QCollection<dim> (QGauss<dim>(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 (file)
index 0000000..5937aa1
--- /dev/null
@@ -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

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.