From: Markus Buerg Date: Mon, 30 Aug 2010 18:22:27 +0000 (+0000) Subject: Tests for parent functions in DoFIterators X-Git-Tag: v8.0.0~5617 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96a3199b4864fe7c177f1b23e52c8e54e429ce7a;p=dealii.git Tests for parent functions in DoFIterators git-svn-id: https://svn.dealii.org/trunk@21800 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/bits/refine_and_coarsen_for_parents_02.cc b/tests/bits/refine_and_coarsen_for_parents_02.cc new file mode 100644 index 0000000000..1dcabe221d --- /dev/null +++ b/tests/bits/refine_and_coarsen_for_parents_02.cc @@ -0,0 +1,129 @@ +//---------------------------- refine_and_coarsen_3d.cc --------------------------- +// $Id: refine_and_coarsen_3d.cc 15183 2007-09-10 01:10:03Z bangerth $ +// Version: $Name$ +// +// Copyright (C) 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. +// +//----------------------- refine_and_coarsen_for_parents_02.cc ---------------------- + + +// check that, if we take an locally refined mesh, refine it globally once, +// then coarsen it globally again, the parent relation holds + +#include "../tests.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +void do_refine (Triangulation<1> &tria) +{ + const int dim = 1; + + 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::cut_x); + tria.execute_coarsening_and_refinement (); + tria.begin_active ()->set_refine_flag (RefinementPossibilities::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::cut_x); + tria.execute_coarsening_and_refinement (); + tria.begin_active()->set_refine_flag(RefinementPossibilities::cut_y); + tria.execute_coarsening_and_refinement (); + tria.begin_active()->set_refine_flag(RefinementPossibilities::cut_z); + tria.execute_coarsening_and_refinement (); + tria.begin_active()->set_refine_flag(RefinementPossibilities::cut_xy); + tria.execute_coarsening_and_refinement (); + tria.begin_active()->set_refine_flag(RefinementPossibilities::cut_xz); + tria.execute_coarsening_and_refinement (); + tria.begin_active()->set_refine_flag(RefinementPossibilities::cut_yz); + tria.execute_coarsening_and_refinement (); +} + + +template +void check () +{ + Triangulation tria; + GridGenerator::hyper_cube (tria); + do_refine (tria); + // refine the mesh globally and + // verify that the parent relation + // holds + tria.refine_global (1); + + DoFHandler dof_handler (triangulation); + + for (typename DoFHandler::cell_iterator cell = dof_handler.begin(); + cell != dof_handler.end (); ++cell) + for (unsigned int child = 0; child < cell->n_children (); ++child) + Assert (cell->child (child)->parent () == cell, + ExcInternalError ()); + + // coarsen the mesh globally and + // verify that the parent relation + // holds + for (typename Triangulation::active_cell_iterator cell = tria.begin_active (); + cell != tria.end (); ++cell) + cell->set_coarsen_flag (); + + tria.execute_coarsening_and_refinement (); + + for (typename DoFHandler::cell_iterator cell = dof_handler.begin (); + cell != dof_handler.end(); ++cell) + for (unsigned int child = 0; child < cell->n_children (); ++child) + Assert (cell->child (child)->parent () == cell, + ExcInternalError()); + + deallog << "OK for " << dim << "d" << std::endl; +} + + +int main () +{ + std::ofstream logfile("refine_and_coarsen_for_parents_02/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_parents_03.cc b/tests/bits/refine_and_coarsen_for_parents_03.cc new file mode 100644 index 0000000000..cfb0462ff3 --- /dev/null +++ b/tests/bits/refine_and_coarsen_for_parents_03.cc @@ -0,0 +1,129 @@ +//---------------------------- refine_and_coarsen_3d.cc --------------------------- +// $Id: refine_and_coarsen_3d.cc 15183 2007-09-10 01:10:03Z bangerth $ +// Version: $Name$ +// +// Copyright (C) 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. +// +//----------------------- refine_and_coarsen_for_parents_03.cc ---------------------- + + +// check that, if we take an locally refined mesh, refine it globally once, +// then coarsen it globally again, the parent relation holds + +#include "../tests.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +void do_refine (Triangulation<1> &tria) +{ + const int dim = 1; + + 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::cut_x); + tria.execute_coarsening_and_refinement (); + tria.begin_active ()->set_refine_flag (RefinementPossibilities::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::cut_x); + tria.execute_coarsening_and_refinement (); + tria.begin_active()->set_refine_flag(RefinementPossibilities::cut_y); + tria.execute_coarsening_and_refinement (); + tria.begin_active()->set_refine_flag(RefinementPossibilities::cut_z); + tria.execute_coarsening_and_refinement (); + tria.begin_active()->set_refine_flag(RefinementPossibilities::cut_xy); + tria.execute_coarsening_and_refinement (); + tria.begin_active()->set_refine_flag(RefinementPossibilities::cut_xz); + tria.execute_coarsening_and_refinement (); + tria.begin_active()->set_refine_flag(RefinementPossibilities::cut_yz); + tria.execute_coarsening_and_refinement (); +} + + +template +void check () +{ + Triangulation tria; + GridGenerator::hyper_cube (tria); + do_refine (tria); + // refine the mesh globally and + // verify that the parent relation + // holds + tria.refine_global (1); + + MGDoFHandler dof_handler (triangulation); + + for (typename MGDoFHandler::cell_iterator cell = dof_handler.begin(); + cell != dof_handler.end (); ++cell) + for (unsigned int child = 0; child < cell->n_children (); ++child) + Assert (cell->child (child)->parent () == cell, + ExcInternalError ()); + + // coarsen the mesh globally and + // verify that the parent relation + // holds + for (typename Triangulation::active_cell_iterator cell = tria.begin_active (); + cell != tria.end (); ++cell) + cell->set_coarsen_flag (); + + tria.execute_coarsening_and_refinement (); + + for (typename MGDoFHandler::cell_iterator cell = dof_handler.begin (); + cell != dof_handler.end(); ++cell) + for (unsigned int child = 0; child < cell->n_children (); ++child) + Assert (cell->child (child)->parent () == cell, + ExcInternalError()); + + deallog << "OK for " << dim << "d" << std::endl; +} + + +int main () +{ + std::ofstream logfile("refine_and_coarsen_for_parents_03/output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + check<1> (); + check<2> (); + check<3> (); +} + + +