]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Added tests with different compositions of criteria vectors for fixed number refinement. 9969/head
authorMarc Fehling <marc.fehling@gmx.net>
Thu, 14 May 2020 18:44:41 +0000 (20:44 +0200)
committerMarc Fehling <marc.fehling@gmx.net>
Thu, 14 May 2020 20:41:12 +0000 (22:41 +0200)
tests/grid/refine_and_coarsen_fixed_number_03.cc [new file with mode: 0644]
tests/grid/refine_and_coarsen_fixed_number_03.output [new file with mode: 0644]
tests/mpi/refine_and_coarsen_fixed_number_08.cc [new file with mode: 0644]
tests/mpi/refine_and_coarsen_fixed_number_08.mpirun=1.with_p4est=true.output [new file with mode: 0644]
tests/mpi/refine_and_coarsen_fixed_number_08.mpirun=4.with_p4est=true.output [new file with mode: 0644]

diff --git a/tests/grid/refine_and_coarsen_fixed_number_03.cc b/tests/grid/refine_and_coarsen_fixed_number_03.cc
new file mode 100644 (file)
index 0000000..96c22dc
--- /dev/null
@@ -0,0 +1,116 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2020 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.
+//
+// ---------------------------------------------------------------------
+
+
+// verify the binary search algorithm in different compositions of
+// criteria and refinement and coarsening fractions for
+// GridRefinement::refine_and_coarsen_fixed_number().
+
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_refinement.h>
+#include <deal.II/grid/tria.h>
+
+#include <deal.II/lac/vector.h>
+
+#include "../tests.h"
+
+
+template <int dim>
+void
+verify(Triangulation<dim> & tr,
+       const Vector<float> &criteria,
+       const float          refinement_fraction,
+       const float          coarsening_fraction)
+{
+  GridRefinement::refine_and_coarsen_fixed_number(tr,
+                                                  criteria,
+                                                  refinement_fraction,
+                                                  coarsening_fraction);
+
+  unsigned int n_refine_flags = 0, n_coarsen_flags = 0;
+  for (const auto &cell : tr.active_cell_iterators())
+    {
+      if (cell->refine_flag_set())
+        {
+          ++n_refine_flags;
+          cell->clear_refine_flag();
+        }
+      if (cell->coarsen_flag_set())
+        {
+          ++n_coarsen_flags;
+          cell->clear_coarsen_flag();
+        }
+    }
+
+  deallog << "  refinement_fraction:" << refinement_fraction
+          << " coarsening_fraction:" << coarsening_fraction << std::endl
+          << "    n_refine_flags:" << n_refine_flags
+          << " n_coarsen_flags:" << n_coarsen_flags << std::endl;
+}
+
+
+template <int dim>
+void
+test()
+{
+  const unsigned int n_cells             = 100;
+  const float        refinement_fraction = 0.1, coarsening_fraction = 0.1;
+
+  Triangulation<dim>        tr;
+  std::vector<unsigned int> rep(dim, 1);
+  rep[0] = n_cells;
+  Point<dim> p1, p2;
+  for (unsigned int d = 0; d < dim; ++d)
+    {
+      p1[d] = 0;
+      p2[d] = (d == 0) ? n_cells : 1;
+    }
+  GridGenerator::subdivided_hyper_rectangle(tr, rep, p1, p2);
+
+  deallog << "n_cells:" << n_cells << std::endl;
+  Vector<float> criteria(n_cells);
+  {
+    deallog << "criteria:[b>0,e>0]" << std::endl;
+
+    std::iota(criteria.begin(), criteria.end(), 1);
+    Assert(criteria(0) > 0. && criteria(n_cells - 1) > 0., ExcInternalError());
+
+    verify<dim>(tr, criteria, refinement_fraction, coarsening_fraction);
+    verify<dim>(tr, criteria, refinement_fraction, 0.);
+    verify<dim>(tr, criteria, 0., coarsening_fraction);
+  }
+
+  {
+    deallog << "criteria:[b=0,e>0]" << std::endl;
+
+    std::iota(criteria.begin(), criteria.end(), 0);
+    Assert(criteria(0) == 0. && criteria(n_cells - 1) > 0., ExcInternalError());
+
+    verify<dim>(tr, criteria, refinement_fraction, coarsening_fraction);
+    verify<dim>(tr, criteria, refinement_fraction, 0.);
+    verify<dim>(tr, criteria, 0., coarsening_fraction);
+  }
+}
+
+
+int
+main(int argc, char *argv[])
+{
+  initlog();
+  deallog << std::setprecision(1);
+
+  test<2>();
+}
diff --git a/tests/grid/refine_and_coarsen_fixed_number_03.output b/tests/grid/refine_and_coarsen_fixed_number_03.output
new file mode 100644 (file)
index 0000000..a356242
--- /dev/null
@@ -0,0 +1,16 @@
+
+DEAL::n_cells:100
+DEAL::criteria:[b>0,e>0]
+DEAL::  refinement_fraction:0.1 coarsening_fraction:0.1
+DEAL::    n_refine_flags:10 n_coarsen_flags:10
+DEAL::  refinement_fraction:0.1 coarsening_fraction:0.
+DEAL::    n_refine_flags:10 n_coarsen_flags:0
+DEAL::  refinement_fraction:0. coarsening_fraction:0.1
+DEAL::    n_refine_flags:0 n_coarsen_flags:10
+DEAL::criteria:[b=0,e>0]
+DEAL::  refinement_fraction:0.1 coarsening_fraction:0.1
+DEAL::    n_refine_flags:10 n_coarsen_flags:10
+DEAL::  refinement_fraction:0.1 coarsening_fraction:0.
+DEAL::    n_refine_flags:10 n_coarsen_flags:0
+DEAL::  refinement_fraction:0. coarsening_fraction:0.1
+DEAL::    n_refine_flags:0 n_coarsen_flags:10
diff --git a/tests/mpi/refine_and_coarsen_fixed_number_08.cc b/tests/mpi/refine_and_coarsen_fixed_number_08.cc
new file mode 100644 (file)
index 0000000..a949957
--- /dev/null
@@ -0,0 +1,125 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2020 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.
+//
+// ---------------------------------------------------------------------
+
+
+// verify the binary search algorithm in different compositions of
+// criteria and refinement and coarsening fractions for
+// parallel::distributed::GridRefinement::refine_and_coarsen_fixed_number().
+
+#include <deal.II/distributed/grid_refinement.h>
+#include <deal.II/distributed/tria.h>
+
+#include <deal.II/grid/grid_generator.h>
+
+#include <deal.II/lac/vector.h>
+
+#include "../tests.h"
+
+
+template <int dim>
+void
+verify(parallel::distributed::Triangulation<dim> &tr,
+       const Vector<float> &                      criteria,
+       const float                                refinement_fraction,
+       const float                                coarsening_fraction)
+{
+  parallel::distributed::GridRefinement::refine_and_coarsen_fixed_number(
+    tr, criteria, refinement_fraction, coarsening_fraction);
+
+  unsigned int n_refine_flags = 0, n_coarsen_flags = 0;
+  for (const auto &cell : tr.active_cell_iterators())
+    if (cell->is_locally_owned())
+      {
+        if (cell->refine_flag_set())
+          {
+            ++n_refine_flags;
+            cell->clear_refine_flag();
+          }
+        if (cell->coarsen_flag_set())
+          {
+            ++n_coarsen_flags;
+            cell->clear_coarsen_flag();
+          }
+      }
+
+  const unsigned int n_global_refine_flags =
+                       Utilities::MPI::sum(n_refine_flags, MPI_COMM_WORLD),
+                     n_global_coarsen_flags =
+                       Utilities::MPI::sum(n_coarsen_flags, MPI_COMM_WORLD);
+
+  deallog << "  refinement_fraction:" << refinement_fraction
+          << " coarsening_fraction:" << coarsening_fraction << std::endl
+          << "    n_refine_flags:" << n_global_refine_flags
+          << " n_coarsen_flags:" << n_global_coarsen_flags << std::endl;
+}
+
+
+template <int dim>
+void
+test()
+{
+  const unsigned int n_cells             = 100;
+  const float        refinement_fraction = 0.1, coarsening_fraction = 0.1;
+
+  parallel::distributed::Triangulation<dim> tr(MPI_COMM_WORLD);
+  std::vector<unsigned int>                 rep(dim, 1);
+  rep[0] = n_cells;
+  Point<dim> p1, p2;
+  for (unsigned int d = 0; d < dim; ++d)
+    {
+      p1[d] = 0;
+      p2[d] = (d == 0) ? n_cells : 1;
+    }
+  GridGenerator::subdivided_hyper_rectangle(tr, rep, p1, p2);
+
+  deallog << "n_cells:" << n_cells << std::endl;
+  Vector<float> criteria(n_cells);
+  {
+    deallog << "criteria:[b>0,e>0]" << std::endl;
+
+    std::iota(criteria.begin(), criteria.end(), 1);
+    Assert(criteria(0) > 0. && criteria(n_cells - 1) > 0., ExcInternalError());
+
+    verify<dim>(tr, criteria, refinement_fraction, coarsening_fraction);
+    verify<dim>(tr, criteria, refinement_fraction, 0.);
+    verify<dim>(tr, criteria, 0., coarsening_fraction);
+  }
+
+  {
+    deallog << "criteria:[b=0,e>0]" << std::endl;
+
+    std::iota(criteria.begin(), criteria.end(), 0);
+    Assert(criteria(0) == 0. && criteria(n_cells - 1) > 0., ExcInternalError());
+
+    verify<dim>(tr, criteria, refinement_fraction, coarsening_fraction);
+    verify<dim>(tr, criteria, refinement_fraction, 0.);
+    verify<dim>(tr, criteria, 0., coarsening_fraction);
+  }
+}
+
+
+int
+main(int argc, char *argv[])
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+
+  if (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0)
+    {
+      initlog();
+      deallog << std::setprecision(1);
+    }
+
+  test<2>();
+}
diff --git a/tests/mpi/refine_and_coarsen_fixed_number_08.mpirun=1.with_p4est=true.output b/tests/mpi/refine_and_coarsen_fixed_number_08.mpirun=1.with_p4est=true.output
new file mode 100644 (file)
index 0000000..a356242
--- /dev/null
@@ -0,0 +1,16 @@
+
+DEAL::n_cells:100
+DEAL::criteria:[b>0,e>0]
+DEAL::  refinement_fraction:0.1 coarsening_fraction:0.1
+DEAL::    n_refine_flags:10 n_coarsen_flags:10
+DEAL::  refinement_fraction:0.1 coarsening_fraction:0.
+DEAL::    n_refine_flags:10 n_coarsen_flags:0
+DEAL::  refinement_fraction:0. coarsening_fraction:0.1
+DEAL::    n_refine_flags:0 n_coarsen_flags:10
+DEAL::criteria:[b=0,e>0]
+DEAL::  refinement_fraction:0.1 coarsening_fraction:0.1
+DEAL::    n_refine_flags:10 n_coarsen_flags:10
+DEAL::  refinement_fraction:0.1 coarsening_fraction:0.
+DEAL::    n_refine_flags:10 n_coarsen_flags:0
+DEAL::  refinement_fraction:0. coarsening_fraction:0.1
+DEAL::    n_refine_flags:0 n_coarsen_flags:10
diff --git a/tests/mpi/refine_and_coarsen_fixed_number_08.mpirun=4.with_p4est=true.output b/tests/mpi/refine_and_coarsen_fixed_number_08.mpirun=4.with_p4est=true.output
new file mode 100644 (file)
index 0000000..a356242
--- /dev/null
@@ -0,0 +1,16 @@
+
+DEAL::n_cells:100
+DEAL::criteria:[b>0,e>0]
+DEAL::  refinement_fraction:0.1 coarsening_fraction:0.1
+DEAL::    n_refine_flags:10 n_coarsen_flags:10
+DEAL::  refinement_fraction:0.1 coarsening_fraction:0.
+DEAL::    n_refine_flags:10 n_coarsen_flags:0
+DEAL::  refinement_fraction:0. coarsening_fraction:0.1
+DEAL::    n_refine_flags:0 n_coarsen_flags:10
+DEAL::criteria:[b=0,e>0]
+DEAL::  refinement_fraction:0.1 coarsening_fraction:0.1
+DEAL::    n_refine_flags:10 n_coarsen_flags:10
+DEAL::  refinement_fraction:0.1 coarsening_fraction:0.
+DEAL::    n_refine_flags:10 n_coarsen_flags:0
+DEAL::  refinement_fraction:0. coarsening_fraction:0.1
+DEAL::    n_refine_flags:0 n_coarsen_flags:10

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.