]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Test that active cell indices are correct after serialization.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Fri, 10 Apr 2015 22:37:34 +0000 (17:37 -0500)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 13 Apr 2015 00:10:18 +0000 (19:10 -0500)
tests/bits/refine_and_coarsen_for_active_cell_index_05.cc [new file with mode: 0644]
tests/bits/refine_and_coarsen_for_active_cell_index_05.output [new file with mode: 0644]

diff --git a/tests/bits/refine_and_coarsen_for_active_cell_index_05.cc b/tests/bits/refine_and_coarsen_for_active_cell_index_05.cc
new file mode 100644 (file)
index 0000000..e6b3041
--- /dev/null
@@ -0,0 +1,175 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2010 - 2015 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.
+//
+// ---------------------------------------------------------------------
+
+
+
+// check that cell->active_cell_index() works as advertised
+//
+// like _03, but with a triangulation restored from serialization
+
+
+#include "../tests.h"
+
+#include <deal.II/base/geometry_info.h>
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/quadrature_lib.h>
+#include <deal.II/dofs/dof_accessor.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/tria_accessor.h>
+#include <deal.II/grid/grid_generator.h>
+
+#include <fstream>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <sstream>
+
+
+
+template <int dim>
+void check (const Triangulation<dim> &tria)
+{
+  unsigned int index = 0;
+  for (typename Triangulation<dim>::active_cell_iterator cell=tria.begin_active();
+      cell!=tria.end(); ++cell, ++index)
+    Assert (cell->active_cell_index() == index, ExcInternalError());
+}
+
+
+
+void do_refine (Triangulation<1> &tria)
+{
+  tria.refine_global (2);
+  tria.begin_active()->set_refine_flag();
+  tria.execute_coarsening_and_refinement ();
+}
+
+
+void do_refine (Triangulation<2> &tria)
+{
+  const int dim = 2;
+
+  tria.refine_global (2);
+  tria.begin_active()->set_refine_flag();
+  tria.execute_coarsening_and_refinement ();
+  tria.begin_active ()->set_refine_flag (RefinementPossibilities<dim>::cut_x);
+  tria.execute_coarsening_and_refinement ();
+  tria.begin_active ()->set_refine_flag (RefinementPossibilities<dim>::cut_y);
+  tria.execute_coarsening_and_refinement ();
+}
+
+
+void do_refine (Triangulation<3> &tria)
+{
+  const int dim = 3;
+
+  tria.refine_global (2);
+  tria.begin_active()->set_refine_flag();
+  tria.execute_coarsening_and_refinement ();
+  tria.begin_active()->set_refine_flag(RefinementPossibilities<dim>::cut_x);
+  tria.execute_coarsening_and_refinement ();
+  tria.begin_active()->set_refine_flag(RefinementPossibilities<dim>::cut_y);
+  tria.execute_coarsening_and_refinement ();
+  tria.begin_active()->set_refine_flag(RefinementPossibilities<dim>::cut_z);
+  tria.execute_coarsening_and_refinement ();
+  tria.begin_active()->set_refine_flag(RefinementPossibilities<dim>::cut_xy);
+  tria.execute_coarsening_and_refinement ();
+  tria.begin_active()->set_refine_flag(RefinementPossibilities<dim>::cut_xz);
+  tria.execute_coarsening_and_refinement ();
+  tria.begin_active()->set_refine_flag(RefinementPossibilities<dim>::cut_yz);
+  tria.execute_coarsening_and_refinement ();
+}
+
+
+template <int dim>
+void check ()
+{
+  Triangulation<dim> tria;
+  GridGenerator::hyper_cube (tria);
+  do_refine (tria);
+  // refine the mesh globally and
+  // verify that the parent relation
+  // holds
+  tria.refine_global (1);
+
+  DoFHandler<dim> dof_handler (tria);
+
+  check (tria);
+  {
+    Triangulation<dim> x;
+    
+    // save data to archive
+    std::ostringstream oss;
+    {
+      boost::archive::text_oarchive oa(oss, boost::archive::no_header);
+      oa << tria;
+    }
+    {
+      std::istringstream  iss(oss.str());
+      boost::archive::text_iarchive ia(iss, boost::archive::no_header);
+
+      // restore triangulation
+      ia >> x;
+    }
+    
+    check(x);
+  }
+
+  // coarsen the mesh globally and
+  // verify again
+  for (typename Triangulation<dim>::active_cell_iterator cell = tria.begin_active ();
+       cell != tria.end (); ++cell)
+    cell->set_coarsen_flag ();
+
+  tria.execute_coarsening_and_refinement ();
+
+  check (tria);
+  {
+    Triangulation<dim> x;
+    
+    // save data to archive
+    std::ostringstream oss;
+    {
+      boost::archive::text_oarchive oa(oss, boost::archive::no_header);
+      oa << tria;
+    }
+    {
+      std::istringstream  iss(oss.str());
+      boost::archive::text_iarchive ia(iss, boost::archive::no_header);
+
+      // restore triangulation
+      ia >> x;
+    }
+    
+    check(x);
+  }
+
+  deallog << "OK for " << dim << "d" << std::endl;
+}
+
+
+int main ()
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  check<1> ();
+  check<2> ();
+  check<3> ();
+}
+
+
+
diff --git a/tests/bits/refine_and_coarsen_for_active_cell_index_05.output b/tests/bits/refine_and_coarsen_for_active_cell_index_05.output
new file mode 100644 (file)
index 0000000..292df5f
--- /dev/null
@@ -0,0 +1,4 @@
+
+DEAL::OK for 1d
+DEAL::OK for 2d
+DEAL::OK for 3d

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.