]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
add test showing bug in NumberCache after clear()
authorheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 1 Nov 2012 18:57:32 +0000 (18:57 +0000)
committerheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 1 Nov 2012 18:57:32 +0000 (18:57 +0000)
git-svn-id: https://svn.dealii.org/trunk@27290 0785d39b-7218-0410-832d-ea1e28bc413d

tests/deal.II/dof_handler_number_cache_02.cc [new file with mode: 0644]
tests/deal.II/dof_handler_number_cache_02/cmp/generic [new file with mode: 0644]

diff --git a/tests/deal.II/dof_handler_number_cache_02.cc b/tests/deal.II/dof_handler_number_cache_02.cc
new file mode 100644 (file)
index 0000000..6826a02
--- /dev/null
@@ -0,0 +1,128 @@
+//---------------------------------------------------------------------------
+//    $Id: dof_handler_number_cache.cc 24924 2012-01-25 12:35:17Z kormann $
+//    Version: $Name$
+//
+//    Copyright (C) 2008, 2010 by the deal.II authors
+//
+//    This file is subject to QPL and may not be  distributed
+//    without copyright and license information. Please refer
+//    to the file deal.II/doc/license.html for the  text  and
+//    further information on this license.
+//
+//---------------------------------------------------------------------------
+
+
+// Check that DoFHandler::clear() clears the numbercache (a bug right now)
+
+
+#include "../tests.h"
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/tensor.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/tria_accessor.h>
+#include <deal.II/grid/tria_iterator.h>
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/intergrid_map.h>
+#include <deal.II/base/utilities.h>
+#include <deal.II/dofs/dof_handler.h>
+#include <deal.II/fe/fe_system.h>
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/fe/fe_dgq.h>
+
+#include <fstream>
+#include <cstdlib>
+
+
+template<int dim>
+void test()
+{
+  Triangulation<dim> triangulation (Triangulation<dim>::limit_level_difference_at_vertices);
+
+  FESystem<dim> fe (FE_Q<dim>(3),2,
+                   FE_DGQ<dim>(1),1);
+
+  DoFHandler<dim> dof_handler (triangulation);
+
+  GridGenerator::hyper_cube(triangulation);
+  triangulation.refine_global (2);
+
+  const unsigned int n_refinements[] = { 0, 4, 3, 2 };
+  for (unsigned int i=0; i<n_refinements[dim]; ++i)
+    {
+                                      // refine one-fifth of cells randomly
+      std::vector<bool> flags (triangulation.n_active_cells(), false);
+      for (unsigned int k=0; k<flags.size()/5 + 1; ++k)
+       flags[rand() % flags.size()] = true;
+                                      // make sure there's at least one that
+                                      // will be refined
+      flags[0] = true;
+
+                                      // refine triangulation
+      unsigned int index=0;
+      for (typename Triangulation<dim>::active_cell_iterator
+            cell = triangulation.begin_active();
+          cell != triangulation.end(); ++cell, ++index)
+       if (flags[index])
+         cell->set_refine_flag();
+      Assert (index == triangulation.n_active_cells(), ExcInternalError());
+
+                                      // flag all other cells for coarsening
+                                      // (this should ensure that at least
+                                      // some of them will actually be
+                                      // coarsened)
+      index=0;
+      for (typename Triangulation<dim>::active_cell_iterator
+            cell = triangulation.begin_active();
+          cell != triangulation.end(); ++cell, ++index)
+       if (!flags[index])
+         cell->set_coarsen_flag();
+
+      triangulation.execute_coarsening_and_refinement ();
+      dof_handler.distribute_dofs (fe);
+
+      const unsigned int N = dof_handler.n_dofs();
+      deallog << N << std::endl;
+
+      IndexSet all (N);
+      all.add_range (0, N);
+
+      Assert (dof_handler.n_locally_owned_dofs() == N,
+             ExcInternalError());
+      Assert (dof_handler.locally_owned_dofs() == all,
+             ExcInternalError());
+      Assert (dof_handler.n_locally_owned_dofs_per_processor() ==
+             std::vector<unsigned int> (1,N),
+             ExcInternalError());
+      Assert (dof_handler.locally_owned_dofs_per_processor() ==
+             std::vector<IndexSet>(1,all),
+             ExcInternalError());
+
+      dof_handler.clear();
+      deallog << "those should be zero: "
+             << dof_handler.n_locally_owned_dofs()
+             << " " << dof_handler.n_locally_owned_dofs_per_processor().size()
+             << " " << dof_handler.n_dofs()
+             << std::endl;
+    }
+}
+
+
+int main()
+{
+  std::ofstream logfile(JobIdentifier::base_name(__FILE__)+"/output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  deallog.push("1d");
+  test<1>();
+  deallog.pop();
+
+  deallog.push("2d");
+  test<2>();
+  deallog.pop();
+
+  deallog.push("3d");
+  test<3>();
+  deallog.pop();
+}
diff --git a/tests/deal.II/dof_handler_number_cache_02/cmp/generic b/tests/deal.II/dof_handler_number_cache_02/cmp/generic
new file mode 100644 (file)
index 0000000..789cd00
--- /dev/null
@@ -0,0 +1,10 @@
+
+DEAL:1d::50
+DEAL:1d::82
+DEAL:1d::90
+DEAL:1d::90
+DEAL:2d::816
+DEAL:2d::1264
+DEAL:2d::2192
+DEAL:3d::13524
+DEAL:3d::42768

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.