From: Timo Heister Date: Thu, 1 Oct 2020 17:32:51 +0000 (-0400) Subject: implement Tria::coarsen_global() X-Git-Tag: v9.3.0-rc1~1046^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31bfa5a305cac706f45d825b136ffa6646f04420;p=dealii.git implement Tria::coarsen_global() --- diff --git a/include/deal.II/grid/tria.h b/include/deal.II/grid/tria.h index 6acd2da16f..f1221cc3d7 100644 --- a/include/deal.II/grid/tria.h +++ b/include/deal.II/grid/tria.h @@ -1910,6 +1910,21 @@ public: void refine_global(const unsigned int times = 1); + /** + * Coarsen all cells the given number of times. + * + * In each of one of the @p times iterations, all cells will be marked for + * coarsening. If an active cell is already on the coarsest level, it will + * be ignored. + * + * @note This function triggers the pre- and post-refinement signals before + * and after doing each individual coarsening cycle (i.e. more than once if + * `times > 1`) . See the section on signals in the general documentation of + * this class. + */ + void + coarsen_global(const unsigned int times = 1); + /** * Execute both refinement and coarsening of the triangulation. * diff --git a/source/grid/tria.cc b/source/grid/tria.cc index e280fccfb4..686e98983d 100644 --- a/source/grid/tria.cc +++ b/source/grid/tria.cc @@ -9986,6 +9986,22 @@ Triangulation::refine_global(const unsigned int times) +template +void +Triangulation::coarsen_global(const unsigned int times) +{ + for (unsigned int i = 0; i < times; ++i) + { + for (const auto &cell : this->active_cell_iterators()) + { + cell->clear_refine_flag(); + cell->set_coarsen_flag(); + } + execute_coarsening_and_refinement(); + } +} + + /*-------------------- refine/coarsen flags -------------------------*/ diff --git a/tests/grid/coarsen_global_01.cc b/tests/grid/coarsen_global_01.cc new file mode 100644 index 0000000000..c9f6c594dc --- /dev/null +++ b/tests/grid/coarsen_global_01.cc @@ -0,0 +1,66 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2010 - 2018 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +// Test Triangulation::coarsen_global + +#include + +#include +#include + +#include +#include +#include + +#include "../tests.h" + +template +void +check(int number) +{ + Triangulation tria; + GridGenerator::hyper_cube(tria); + tria.refine_global(2); + + tria.begin_active()->set_refine_flag(); + tria.execute_coarsening_and_refinement(); + + deallog << "dim = " << dim << ", number = " << number << std::endl; + + deallog << "before n_active_cells: " << tria.n_active_cells() << std::endl; + + tria.coarsen_global(number); + + deallog << "after n_active_cells: " << tria.n_active_cells() << std::endl; +} + + +int +main() +{ + initlog(); + + check<1>(1); + check<1>(2); + check<1>(3); + + check<2>(1); + check<2>(2); + check<2>(3); + + check<3>(1); + check<3>(2); + check<3>(3); +} diff --git a/tests/grid/coarsen_global_01.output b/tests/grid/coarsen_global_01.output new file mode 100644 index 0000000000..e2b4c36671 --- /dev/null +++ b/tests/grid/coarsen_global_01.output @@ -0,0 +1,28 @@ + +DEAL::dim = 1, number = 1 +DEAL::before n_active_cells: 5 +DEAL::after n_active_cells: 3 +DEAL::dim = 1, number = 2 +DEAL::before n_active_cells: 5 +DEAL::after n_active_cells: 2 +DEAL::dim = 1, number = 3 +DEAL::before n_active_cells: 5 +DEAL::after n_active_cells: 1 +DEAL::dim = 2, number = 1 +DEAL::before n_active_cells: 19 +DEAL::after n_active_cells: 7 +DEAL::dim = 2, number = 2 +DEAL::before n_active_cells: 19 +DEAL::after n_active_cells: 4 +DEAL::dim = 2, number = 3 +DEAL::before n_active_cells: 19 +DEAL::after n_active_cells: 1 +DEAL::dim = 3, number = 1 +DEAL::before n_active_cells: 71 +DEAL::after n_active_cells: 15 +DEAL::dim = 3, number = 2 +DEAL::before n_active_cells: 71 +DEAL::after n_active_cells: 8 +DEAL::dim = 3, number = 3 +DEAL::before n_active_cells: 71 +DEAL::after n_active_cells: 1