]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add utility functions to create polynomial coarsening sequences 11706/head
authorPeter Munch <peterrmuench@gmail.com>
Sat, 6 Feb 2021 21:13:49 +0000 (22:13 +0100)
committerPeter Munch <peterrmuench@gmail.com>
Tue, 9 Feb 2021 08:10:10 +0000 (09:10 +0100)
include/deal.II/multigrid/mg_transfer_global_coarsening.h
include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h
tests/multigrid-global-coarsening/create_polynomial_coarsening_sequence_01.cc [new file with mode: 0644]
tests/multigrid-global-coarsening/create_polynomial_coarsening_sequence_01.output [new file with mode: 0644]
tests/multigrid-global-coarsening/multigrid_p_01.cc
tests/multigrid-global-coarsening/multigrid_util.h

index dc88c7e8fafc39a55bb0ae8066899d07944788ba..c640e407c87fe33cbd522c95723d7f3b9a7119a5 100644 (file)
@@ -37,6 +37,60 @@ namespace internal
 
 
 
+/**
+ * Global coarsening utility functions.
+ */
+namespace MGTransferGlobalCoarseningTools
+{
+  /**
+   * Common polynomial coarsening sequences.
+   *
+   * @note These polynomial coarsening sequences up to a degree of 9 are
+   *   precompiled in MGTwoLevelTransfer. See also:
+   *   MGTwoLevelTransfer::fast_polynomial_transfer_supported()
+   */
+  enum class PolynomialCoarseningSequenceType
+  {
+    /**
+     * Half polynomial degree by integer division. For example, for degree=7
+     * the following sequence would be obtained:: 7 -> 3 -> 1
+     */
+    bisect,
+    /**
+     * Decrease the polynomial degree by one. E.g., for degree=7 following
+     * sequence would result: 7 -> 6 -> 5 -> 4 -> 3 -> 2 -> 1
+     */
+    decrease_by_one,
+    /**
+     * Decrease the polynomial degree to one. E.g., for degree=7 following
+     * sequence would result: 7 -> 1
+     */
+    go_to_one
+  };
+
+  /**
+   * For a given @p degree and polynomial coarsening sequence @p p_sequence,
+   * determine the next coarser degree.
+   */
+  unsigned int
+  create_next_polynomial_coarsening_degree(
+    const unsigned int                      degree,
+    const PolynomialCoarseningSequenceType &p_sequence);
+
+  /**
+   * For a given @p max_degree and polynomial coarsening sequence @p p_sequence,
+   * determine the full sequence of polynomial degrees, sorted in ascending
+   * order.
+   */
+  std::vector<unsigned int>
+  create_polynomial_coarsening_sequence(
+    const unsigned int                      max_degree,
+    const PolynomialCoarseningSequenceType &p_sequence);
+
+} // namespace MGTransferGlobalCoarseningTools
+
+
+
 /**
  * Class for transfer between two multigrid levels for p- or global coarsening.
  */
index 4985e280006d9c21ea249b5263837e9c18d14e72..104f9784a68f82dfa76ad1023c4f159579f18055 100644 (file)
@@ -1620,6 +1620,49 @@ namespace internal
 } // namespace internal
 
 
+
+namespace MGTransferGlobalCoarseningTools
+{
+  unsigned int
+  create_next_polynomial_coarsening_degree(
+    const unsigned int                      previous_fe_degree,
+    const PolynomialCoarseningSequenceType &p_sequence)
+  {
+    switch (p_sequence)
+      {
+        case PolynomialCoarseningSequenceType::bisect:
+          return std::max(previous_fe_degree / 2, 1u);
+        case PolynomialCoarseningSequenceType::decrease_by_one:
+          return std::max(previous_fe_degree - 1, 1u);
+        case PolynomialCoarseningSequenceType::go_to_one:
+          return 1u;
+        default:
+          Assert(false, StandardExceptions::ExcNotImplemented());
+          return 1u;
+      }
+  }
+
+
+
+  std::vector<unsigned int>
+  create_polynomial_coarsening_sequence(
+    const unsigned int                      max_degree,
+    const PolynomialCoarseningSequenceType &p_sequence)
+  {
+    std::vector<unsigned int> degrees{max_degree};
+
+    while (degrees.back() > 1)
+      degrees.push_back(
+        create_next_polynomial_coarsening_degree(degrees.back(), p_sequence));
+
+    std::reverse(degrees.begin(), degrees.end());
+
+    return degrees;
+  }
+} // namespace MGTransferGlobalCoarseningTools
+
+
+
 template <int dim, typename Number>
 void
 MGTwoLevelTransfer<dim, LinearAlgebra::distributed::Vector<Number>>::prolongate(
diff --git a/tests/multigrid-global-coarsening/create_polynomial_coarsening_sequence_01.cc b/tests/multigrid-global-coarsening/create_polynomial_coarsening_sequence_01.cc
new file mode 100644 (file)
index 0000000..60289e4
--- /dev/null
@@ -0,0 +1,52 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2021 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.
+//
+// ---------------------------------------------------------------------
+
+// Print all polynomial coarsening sequences up to degree 15.
+
+#include <deal.II/multigrid/mg_transfer_global_coarsening.h>
+
+#include "../tests.h"
+
+using namespace dealii;
+
+void
+test(
+  const MGTransferGlobalCoarseningTools::PolynomialCoarseningSequenceType type)
+{
+  for (unsigned int i = 1; i <= 15; i++)
+    {
+      const auto sequence =
+        MGTransferGlobalCoarseningTools::create_polynomial_coarsening_sequence(
+          i, type);
+
+      for (const auto i : sequence)
+        deallog << i << " ";
+      deallog << std::endl;
+    }
+  deallog << std::endl;
+}
+
+int
+main()
+{
+  initlog();
+
+  test(
+    MGTransferGlobalCoarseningTools::PolynomialCoarseningSequenceType::bisect);
+  test(MGTransferGlobalCoarseningTools::PolynomialCoarseningSequenceType::
+         decrease_by_one);
+  test(MGTransferGlobalCoarseningTools::PolynomialCoarseningSequenceType::
+         go_to_one);
+}
diff --git a/tests/multigrid-global-coarsening/create_polynomial_coarsening_sequence_01.output b/tests/multigrid-global-coarsening/create_polynomial_coarsening_sequence_01.output
new file mode 100644 (file)
index 0000000..b8394d2
--- /dev/null
@@ -0,0 +1,49 @@
+
+DEAL::1 
+DEAL::1 2 
+DEAL::1 3 
+DEAL::1 2 4 
+DEAL::1 2 5 
+DEAL::1 3 6 
+DEAL::1 3 7 
+DEAL::1 2 4 8 
+DEAL::1 2 4 9 
+DEAL::1 2 5 10 
+DEAL::1 2 5 11 
+DEAL::1 3 6 12 
+DEAL::1 3 6 13 
+DEAL::1 3 7 14 
+DEAL::1 3 7 15 
+DEAL::
+DEAL::1 
+DEAL::1 2 
+DEAL::1 2 3 
+DEAL::1 2 3 4 
+DEAL::1 2 3 4 5 
+DEAL::1 2 3 4 5 6 
+DEAL::1 2 3 4 5 6 7 
+DEAL::1 2 3 4 5 6 7 8 
+DEAL::1 2 3 4 5 6 7 8 9 
+DEAL::1 2 3 4 5 6 7 8 9 10 
+DEAL::1 2 3 4 5 6 7 8 9 10 11 
+DEAL::1 2 3 4 5 6 7 8 9 10 11 12 
+DEAL::1 2 3 4 5 6 7 8 9 10 11 12 13 
+DEAL::1 2 3 4 5 6 7 8 9 10 11 12 13 14 
+DEAL::1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 
+DEAL::
+DEAL::1 
+DEAL::1 2 
+DEAL::1 3 
+DEAL::1 4 
+DEAL::1 5 
+DEAL::1 6 
+DEAL::1 7 
+DEAL::1 8 
+DEAL::1 9 
+DEAL::1 10 
+DEAL::1 11 
+DEAL::1 12 
+DEAL::1 13 
+DEAL::1 14 
+DEAL::1 15 
+DEAL::
index 623d35b62d87ea7eb984fa77893ffce5973bfc1f..1f1e6a23d24c6dae0cfb8636784a8136cfb66ea4 100644 (file)
@@ -36,9 +36,11 @@ test(const unsigned int n_refinements,
     GridGenerator::subdivided_hyper_cube(tria, 2);
   tria.refine_global(n_refinements);
 
-  const auto level_degrees = MGTransferGlobalCoarseningTools::create_p_sequence(
-    fe_degree_fine,
-    MGTransferGlobalCoarseningTools::PolynomialSequenceType::bisect);
+  const auto level_degrees =
+    MGTransferGlobalCoarseningTools::create_polynomial_coarsening_sequence(
+      fe_degree_fine,
+      MGTransferGlobalCoarseningTools::PolynomialCoarseningSequenceType::
+        bisect);
 
   const unsigned int min_level = 0;
   const unsigned int max_level = level_degrees.size() - 1;
index e3176b616c0929a8e4e2622028f1186e869d89d5..d52957f3bba237072ebd2cb3a9f6fe9e99285d01 100644 (file)
 
 #include "../tests.h"
 
-namespace MGTransferGlobalCoarseningTools
-{
-  enum class PolynomialSequenceType
-  {
-    bisect,
-    decrease_by_one,
-    go_to_one
-  };
-
-  unsigned int
-  generate_level_degree(const unsigned int            previous_fe_degree,
-                        const PolynomialSequenceType &p_sequence)
-  {
-    switch (p_sequence)
-      {
-        case PolynomialSequenceType::bisect:
-          return std::max(previous_fe_degree / 2, 1u);
-        case PolynomialSequenceType::decrease_by_one:
-          return std::max(previous_fe_degree - 1, 1u);
-        case PolynomialSequenceType::go_to_one:
-          return 1u;
-        default:
-          Assert(false, StandardExceptions::ExcNotImplemented());
-          return 1u;
-      }
-  }
-
-  std::vector<unsigned int>
-  create_p_sequence(const unsigned int            degree,
-                    const PolynomialSequenceType &p_sequence)
-  {
-    std::vector<unsigned int> degrees;
-    degrees.push_back(degree);
-
-    unsigned int previous_fe_degree = degree;
-    while (previous_fe_degree > 1)
-      {
-        const unsigned int level_degree =
-          generate_level_degree(previous_fe_degree, p_sequence);
-
-        degrees.push_back(level_degree);
-        previous_fe_degree = level_degree;
-      }
-
-    std::reverse(degrees.begin(), degrees.end());
-
-    return degrees;
-  }
-
-} // namespace MGTransferGlobalCoarseningTools
-
 template <int dim_, typename Number>
 class Operator : public Subscriptor
 {

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.