From 11eb5ad267ec3d8b9809b9e6fa7ea2b09931efbc Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 15 Jul 2009 04:25:26 +0000 Subject: [PATCH] Add a test for the preceding bug fix. git-svn-id: https://svn.dealii.org/trunk@19084 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/deal.II/Makefile | 3 +- tests/deal.II/recursively_set_material_id.cc | 97 +++++++++++++++++++ .../recursively_set_material_id/cmp/generic | 19 ++++ 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 tests/deal.II/recursively_set_material_id.cc create mode 100644 tests/deal.II/recursively_set_material_id/cmp/generic diff --git a/tests/deal.II/Makefile b/tests/deal.II/Makefile index 875c79bf95..fb49128eee 100644 --- a/tests/deal.II/Makefile +++ b/tests/deal.II/Makefile @@ -82,7 +82,8 @@ tests_x = block_matrices \ rt_covariant \ coarsening_* \ number_cache_* \ - kelly_crash_* + kelly_crash_* \ + recursively_set_material_id # from above list of regular expressions, generate the real set of # tests diff --git a/tests/deal.II/recursively_set_material_id.cc b/tests/deal.II/recursively_set_material_id.cc new file mode 100644 index 0000000000..c0c26cdab5 --- /dev/null +++ b/tests/deal.II/recursively_set_material_id.cc @@ -0,0 +1,97 @@ +//---------------------------------------------------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2007, 2008, 2009 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. +// +//---------------------------------------------------------------------- + + +// TriaAccessor::recursively_set_material_id had a bug in that it only +// set the material_id for two of its children, not all + +#include "../tests.h" +#include +#include +#include +#include + +#include +#include + + + +template +void test() +{ + for (unsigned int t=0; t<2; ++t) + { + deallog << "dim=" << dim << ", test=" << t << std::endl; + + Triangulation tr; + if (dim > 1) + GridGenerator::hyper_ball(tr); + else + GridGenerator::hyper_cube(tr); + + tr.refine_global(1); + + // for test 1, refine a second + // time isotropically. for test + // 2, cut in only one direction + if (t==0) + tr.refine_global(1); + else + { + for (typename Triangulation::active_cell_iterator + cell = tr.begin_active(); cell != tr.end(); ++cell) + cell->set_refine_flag (RefinementCase::cut_x); + tr.execute_coarsening_and_refinement(); + } + + deallog << tr.n_active_cells() << std::endl; + + // now call the function once + // for one of the cells on + // level 1 + tr.begin(1)->recursively_set_material_id (1); + + // and then count how many + // active cells inherited this + // flag + unsigned int n=0; + for (typename Triangulation::active_cell_iterator + cell = tr.begin_active(); cell != tr.end(); ++cell) + if (cell->material_id() == 1) + ++n; + + deallog << n << std::endl; + + if (t==0) + Assert (n == GeometryInfo::max_children_per_cell, + ExcInternalError()) + else + Assert (n == 2, + ExcInternalError()); + } +} + + +int main() +{ + std::ofstream logfile ("recursively_set_material_id/output"); + deallog << std::setprecision (2); + + deallog.attach(logfile); + deallog.depth_console (0); + deallog.threshold_double(1.e-12); + + test<1>(); + test<2>(); + test<3>(); +} diff --git a/tests/deal.II/recursively_set_material_id/cmp/generic b/tests/deal.II/recursively_set_material_id/cmp/generic new file mode 100644 index 0000000000..283148b25c --- /dev/null +++ b/tests/deal.II/recursively_set_material_id/cmp/generic @@ -0,0 +1,19 @@ + +DEAL::dim=1, test=0 +DEAL::4 +DEAL::2 +DEAL::dim=1, test=1 +DEAL::4 +DEAL::2 +DEAL::dim=2, test=0 +DEAL::80 +DEAL::4 +DEAL::dim=2, test=1 +DEAL::40 +DEAL::2 +DEAL::dim=3, test=0 +DEAL::448 +DEAL::8 +DEAL::dim=3, test=1 +DEAL::168 +DEAL::2 -- 2.39.5