]> https://gitweb.dealii.org/ - dealii.git/commitdiff
implement Tria::coarsen_global() 10995/head
authorTimo Heister <timo.heister@gmail.com>
Thu, 1 Oct 2020 17:32:51 +0000 (13:32 -0400)
committerTimo Heister <timo.heister@gmail.com>
Fri, 2 Oct 2020 18:44:08 +0000 (14:44 -0400)
include/deal.II/grid/tria.h
source/grid/tria.cc
tests/grid/coarsen_global_01.cc [new file with mode: 0644]
tests/grid/coarsen_global_01.output [new file with mode: 0644]

index 6acd2da16f0f4c1537ac22af5147b739885e4534..f1221cc3d7a9038bb0538f89817748e55e05d855 100644 (file)
@@ -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.
    *
index e280fccfb4323424920ffc8259ebe9dbc9c0747f..686e98983d36004344692a6ee30e27f6cf60767e 100644 (file)
@@ -9986,6 +9986,22 @@ Triangulation<dim, spacedim>::refine_global(const unsigned int times)
 
 
 
+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 -------------------------*/
 
 
diff --git a/tests/grid/coarsen_global_01.cc b/tests/grid/coarsen_global_01.cc
new file mode 100644 (file)
index 0000000..c9f6c59
--- /dev/null
@@ -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 <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);
+}
diff --git a/tests/grid/coarsen_global_01.output b/tests/grid/coarsen_global_01.output
new file mode 100644 (file)
index 0000000..e2b4c36
--- /dev/null
@@ -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

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.