]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add a test for DoFRenumbering::cell_wise() with p::d::Tria
authorDenis Davydov <davydden@gmail.com>
Sat, 16 Mar 2019 06:31:05 +0000 (07:31 +0100)
committerDenis Davydov <davydden@gmail.com>
Sat, 16 Mar 2019 07:06:45 +0000 (08:06 +0100)
tests/dofs/dof_renumbering_10.cc [new file with mode: 0644]
tests/dofs/dof_renumbering_10.with_p4est=true.mpirun=1.output [new file with mode: 0644]
tests/dofs/dof_renumbering_10.with_p4est=true.mpirun=3.output [new file with mode: 0644]

diff --git a/tests/dofs/dof_renumbering_10.cc b/tests/dofs/dof_renumbering_10.cc
new file mode 100644 (file)
index 0000000..ff0204b
--- /dev/null
@@ -0,0 +1,172 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2019 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 cell_wise with p::d::Tria
+
+#include <deal.II/base/logstream.h>
+#include <deal.II/base/point.h>
+
+#include <deal.II/distributed/tria.h>
+
+#include <deal.II/dofs/dof_accessor.h>
+#include <deal.II/dofs/dof_handler.h>
+#include <deal.II/dofs/dof_renumbering.h>
+#include <deal.II/dofs/dof_tools.h>
+
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/fe/mapping_q1.h>
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_out.h>
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/tria_accessor.h>
+#include <deal.II/grid/tria_iterator.h>
+
+#include "../tests.h"
+
+template <int dim, int fe_degree = 1>
+void
+test(const bool adaptive_ref = true)
+{
+  MPI_Comm           mpi_communicator(MPI_COMM_WORLD);
+  const unsigned int this_mpi_core =
+    dealii::Utilities::MPI::this_mpi_process(mpi_communicator);
+
+  parallel::distributed::Triangulation<dim> tria(mpi_communicator);
+  GridGenerator::hyper_cube(tria, 0, 1, true);
+  tria.refine_global(1);
+  if (adaptive_ref)
+    {
+      for (auto cell : tria.active_cell_iterators())
+        if (cell->is_locally_owned())
+          if (cell->center().norm() < 0.5)
+            cell->set_refine_flag();
+      tria.execute_coarsening_and_refinement();
+      for (auto cell : tria.active_cell_iterators())
+        if (cell->is_locally_owned())
+          if (cell->center()[0] < 0.2)
+            cell->set_refine_flag();
+      tria.execute_coarsening_and_refinement();
+    }
+  else
+    {
+      tria.refine_global(1);
+    }
+
+  FE_Q<dim>       fe(fe_degree);
+  DoFHandler<dim> dof(tria);
+  dof.distribute_dofs(fe);
+
+  using CELL = typename DoFHandler<dim>::active_cell_iterator;
+  std::vector<CELL> cell_order;
+  for (auto &cell : dof.active_cell_iterators())
+    if (cell->is_locally_owned())
+      cell_order.push_back(cell);
+
+  std::sort(cell_order.begin(),
+            cell_order.end(),
+            [](const CELL &a, const CELL &b) {
+              std::vector<double> p1(dim), p2(dim);
+              for (unsigned int d = 0; d < dim; ++d)
+                {
+                  p1[d] = a->center()[d];
+                  p2[d] = b->center()[d];
+                }
+              return std::lexicographical_compare(p1.begin(),
+                                                  p1.end(),
+                                                  p2.begin(),
+                                                  p2.end());
+            });
+
+  DoFRenumbering::cell_wise(dof, cell_order);
+
+  deallog << std::endl << "cell order:" << std::endl;
+  std::vector<types::global_dof_index> cell_dofs(fe.n_dofs_per_cell());
+  for (const auto &c : cell_order)
+    {
+      c->get_active_or_mg_dof_indices(cell_dofs);
+      deallog << c->center() << ":";
+      for (const auto d : cell_dofs)
+        deallog << " " << d;
+      deallog << std::endl;
+    }
+
+  IndexSet owned_set = dof.locally_owned_dofs();
+
+  // output in Gnuplot for visual inspection
+  if (dim == 2)
+    {
+      std::map<types::global_dof_index, Point<dim>> support_points;
+      MappingQ1<dim>                                mapping;
+      DoFTools::map_dofs_to_support_points(mapping, dof, support_points);
+
+      const std::string href = (adaptive_ref ? "" : "global_");
+      const std::string base_filename =
+        href + "grid" + dealii::Utilities::int_to_string(dim) + "_" +
+        dealii::Utilities::int_to_string(fe_degree) + "_p" +
+        dealii::Utilities::int_to_string(this_mpi_core);
+
+      const std::string filename = base_filename + ".gp";
+      std::ofstream     f(filename.c_str());
+
+      f << "set terminal png size 400,410 enhanced font \"Helvetica,8\""
+        << std::endl
+        << "set output \"" << base_filename << ".png\"" << std::endl
+        << "set size square" << std::endl
+        << "set view equal xy" << std::endl
+        << "unset xtics" << std::endl
+        << "unset ytics" << std::endl
+        << "unset grid" << std::endl
+        << "unset border" << std::endl
+        << "plot '-' using 1:2 with lines notitle, '-' with labels tc rgb 'red' nopoint notitle, '-' with labels point pt 4 offset 1,1 notitle"
+        << std::endl;
+      GridOut().write_gnuplot(tria, f);
+      f << "e" << std::endl;
+
+      // output cell order
+      for (unsigned int index = 0; index < cell_order.size(); ++index)
+        f << cell_order[index]->center() << " \"" << index << "\"\n";
+
+      f << std::flush;
+      f << "e" << std::endl << std::endl;
+
+      // output only owned support points
+      for (auto it = support_points.cbegin(); it != support_points.cend();)
+        {
+          if (owned_set.is_element(it->first))
+            ++it;
+          else
+            support_points.erase(it++);
+        }
+
+      DoFTools::write_gnuplot_dof_support_point_info(f, support_points);
+
+      f << "e" << std::endl;
+    }
+}
+
+
+int
+main(int argc, char **argv)
+{
+  dealii::Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+
+  MPILogInitAll log;
+
+  test<2>(false);
+
+  return 0;
+}
diff --git a/tests/dofs/dof_renumbering_10.with_p4est=true.mpirun=1.output b/tests/dofs/dof_renumbering_10.with_p4est=true.mpirun=1.output
new file mode 100644 (file)
index 0000000..2801b5d
--- /dev/null
@@ -0,0 +1,19 @@
+
+DEAL:0::
+DEAL:0::cell order:
+DEAL:0::0.125000 0.125000: 0 1 2 3
+DEAL:0::0.125000 0.375000: 2 3 4 5
+DEAL:0::0.125000 0.625000: 4 5 6 7
+DEAL:0::0.125000 0.875000: 6 7 8 9
+DEAL:0::0.375000 0.125000: 1 10 3 11
+DEAL:0::0.375000 0.375000: 3 11 5 12
+DEAL:0::0.375000 0.625000: 5 12 7 13
+DEAL:0::0.375000 0.875000: 7 13 9 14
+DEAL:0::0.625000 0.125000: 10 15 11 16
+DEAL:0::0.625000 0.375000: 11 16 12 17
+DEAL:0::0.625000 0.625000: 12 17 13 18
+DEAL:0::0.625000 0.875000: 13 18 14 19
+DEAL:0::0.875000 0.125000: 15 20 16 21
+DEAL:0::0.875000 0.375000: 16 21 17 22
+DEAL:0::0.875000 0.625000: 17 22 18 23
+DEAL:0::0.875000 0.875000: 18 23 19 24
diff --git a/tests/dofs/dof_renumbering_10.with_p4est=true.mpirun=3.output b/tests/dofs/dof_renumbering_10.with_p4est=true.mpirun=3.output
new file mode 100644 (file)
index 0000000..bba8f11
--- /dev/null
@@ -0,0 +1,27 @@
+
+DEAL:0::
+DEAL:0::cell order:
+DEAL:0::0.125000 0.125000: 0 1 2 3
+DEAL:0::0.125000 0.375000: 2 3 4 5
+DEAL:0::0.375000 0.125000: 1 6 3 7
+DEAL:0::0.375000 0.375000: 3 7 5 8
+
+DEAL:1::
+DEAL:1::cell order:
+DEAL:1::0.125000 0.625000: 4 5 9 10
+DEAL:1::0.125000 0.875000: 9 10 11 12
+DEAL:1::0.375000 0.625000: 5 8 10 13
+DEAL:1::0.375000 0.875000: 10 13 12 14
+DEAL:1::0.625000 0.125000: 6 15 7 16
+DEAL:1::0.625000 0.375000: 7 16 8 17
+DEAL:1::0.875000 0.125000: 15 18 16 19
+DEAL:1::0.875000 0.375000: 16 19 17 20
+
+
+DEAL:2::
+DEAL:2::cell order:
+DEAL:2::0.625000 0.625000: 8 17 13 21
+DEAL:2::0.625000 0.875000: 13 21 14 22
+DEAL:2::0.875000 0.625000: 17 20 21 23
+DEAL:2::0.875000 0.875000: 21 23 22 24
+

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.