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.
*
+template <int dim, int spacedim>
+void
+Triangulation<dim, spacedim>::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 -------------------------*/
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// 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 <deal.II/base/geometry_info.h>
+
+#include <deal.II/dofs/dof_accessor.h>
+#include <deal.II/dofs/dof_handler.h>
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/tria_accessor.h>
+
+#include "../tests.h"
+
+template <int dim>
+void
+check(int number)
+{
+ Triangulation<dim> 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);
+}
--- /dev/null
+
+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