]> https://gitweb.dealii.org/ - dealii.git/commitdiff
p:d:T:copy_triangulation() for refined meshes.
authorMarc Fehling <mafehling.git@gmail.com>
Sat, 20 Mar 2021 21:32:58 +0000 (15:32 -0600)
committerMarc Fehling <mafehling.git@gmail.com>
Mon, 22 Mar 2021 18:56:22 +0000 (12:56 -0600)
doc/news/changes/minor/20210319Fehling [new file with mode: 0644]
include/deal.II/distributed/tria.h
source/distributed/tria.cc
tests/mpi/tria_copy_triangulation_01.cc [moved from tests/mpi/tria_copy_triangulation.cc with 100% similarity]
tests/mpi/tria_copy_triangulation_01.mpirun=1.with_p4est=true.output [moved from tests/mpi/tria_copy_triangulation.mpirun=1.with_p4est=true.output with 100% similarity]
tests/mpi/tria_copy_triangulation_01.mpirun=2.with_p4est=true.output [moved from tests/mpi/tria_copy_triangulation.mpirun=2.with_p4est=true.output with 100% similarity]
tests/mpi/tria_copy_triangulation_01.mpirun=4.with_p4est=true.output [moved from tests/mpi/tria_copy_triangulation.mpirun=4.with_p4est=true.output with 100% similarity]
tests/mpi/tria_copy_triangulation_02.cc [new file with mode: 0644]
tests/mpi/tria_copy_triangulation_02.mpirun=1.with_p4est=true.output [new file with mode: 0644]
tests/mpi/tria_copy_triangulation_02.mpirun=2.with_p4est=true.output [new file with mode: 0644]
tests/mpi/tria_copy_triangulation_02.mpirun=4.with_p4est=true.output [new file with mode: 0644]

diff --git a/doc/news/changes/minor/20210319Fehling b/doc/news/changes/minor/20210319Fehling
new file mode 100644 (file)
index 0000000..0b34f02
--- /dev/null
@@ -0,0 +1,5 @@
+Improved: The function parallel::distributed::Triangulation::copy_triangulation()
+now also works with locally refined meshes of type
+parallel::distributed::Triangulation.
+<br>
+(Marc Fehling, 2021/03/19)
index 9e629bd120399fc6b9f4af2e4226b5bfc4f730b4..6deb092a97e2cab02f3b890709123be2c305c008 100644 (file)
@@ -400,8 +400,6 @@ namespace parallel
       /**
        * Implementation of the same function as in the base class.
        *
-       * @note This function cannot copy a triangulation that has been refined.
-       *
        * @note This function can be used to copy a serial Triangulation to a
        * parallel::distributed::Triangulation but only if the serial
        * Triangulation has never been refined.
index 310fcfa4b3065261135f315d0a0a640c7ebf22df..571532f6464f55433e111807a8d57eab7a34c6c5 100644 (file)
@@ -3266,10 +3266,14 @@ namespace parallel
     Triangulation<dim, spacedim>::copy_triangulation(
       const dealii::Triangulation<dim, spacedim> &other_tria)
     {
-      Assert(other_tria.n_levels() == 1,
-             ExcMessage(
-               "Parallel distributed triangulations can only be copied, "
-               "if they are not refined!"));
+      Assert(
+        (dynamic_cast<
+          const dealii::parallel::distributed::Triangulation<dim, spacedim> *>(
+          &other_tria)) ||
+          (other_tria.n_global_levels() == 1),
+        ExcNotImplemented());
+
+      dealii::parallel::distributed::Triangulation<dim, spacedim>::clear();
 
       try
         {
@@ -3285,32 +3289,47 @@ namespace parallel
           Assert(false, ExcInternalError());
         }
 
-      // note that now we have some content in the p4est objects and call the
-      // functions that do the actual work (which are dimension dependent, so
-      // separate)
-      triangulation_has_content = true;
-
       if (const dealii::parallel::distributed::Triangulation<dim, spacedim>
-            *other_tria_x =
+            *other_distributed =
               dynamic_cast<const dealii::parallel::distributed::
                              Triangulation<dim, spacedim> *>(&other_tria))
         {
+          // copy parallel distributed specifics
+          settings = other_distributed->settings;
+          triangulation_has_content =
+            other_distributed->triangulation_has_content;
           coarse_cell_to_p4est_tree_permutation =
-            other_tria_x->coarse_cell_to_p4est_tree_permutation;
+            other_distributed->coarse_cell_to_p4est_tree_permutation;
           p4est_tree_to_coarse_cell_permutation =
-            other_tria_x->p4est_tree_to_coarse_cell_permutation;
-          this->cell_attached_data = other_tria_x->cell_attached_data;
-          this->data_transfer      = other_tria_x->data_transfer;
-
-          settings = other_tria_x->settings;
+            other_distributed->p4est_tree_to_coarse_cell_permutation;
+          this->cell_attached_data = other_distributed->cell_attached_data;
+          this->data_transfer      = other_distributed->data_transfer;
+
+          // create deep copy of connectivity graph
+          typename dealii::internal::p4est::types<dim>::connectivity
+            *temp_connectivity = const_cast<
+              typename dealii::internal::p4est::types<dim>::connectivity *>(
+              other_distributed->connectivity);
+          connectivity =
+            dealii::internal::p4est::copy_connectivity<dim>(temp_connectivity);
+
+          // create deep copy of parallel forest
+          typename dealii::internal::p4est::types<dim>::forest *temp_forest =
+            const_cast<typename dealii::internal::p4est::types<dim>::forest *>(
+              other_distributed->parallel_forest);
+          parallel_forest =
+            dealii::internal::p4est::functions<dim>::copy_forest(temp_forest,
+                                                                 false);
+          parallel_forest->connectivity = connectivity;
+          parallel_forest->user_pointer = this;
         }
       else
         {
+          triangulation_has_content = true;
           setup_coarse_cell_to_p4est_tree_permutation();
+          copy_new_triangulation_to_p4est(std::integral_constant<int, dim>());
         }
 
-      copy_new_triangulation_to_p4est(std::integral_constant<int, dim>());
-
       try
         {
           copy_local_forest_to_triangulation();
diff --git a/tests/mpi/tria_copy_triangulation_02.cc b/tests/mpi/tria_copy_triangulation_02.cc
new file mode 100644 (file)
index 0000000..960447f
--- /dev/null
@@ -0,0 +1,135 @@
+// ---------------------------------------------------------------------
+//
+// 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.
+//
+// ---------------------------------------------------------------------
+
+
+
+// Same as tria_copy_triangulation_01, but for locally refined meshes.
+
+
+#include <deal.II/distributed/tria.h>
+
+#include <deal.II/grid/grid_generator.h>
+
+#include "../tests.h"
+
+
+template <int dim>
+void
+test()
+{
+  unsigned int myid = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
+
+  parallel::distributed::Triangulation<dim> tria1(MPI_COMM_WORLD);
+  {
+    GridGenerator::hyper_shell(tria1, Point<dim>(), 1., 2., 0, true);
+    tria1.begin_active()->set_refine_flag();
+    tria1.execute_coarsening_and_refinement();
+  }
+
+  parallel::distributed::Triangulation<dim> tria2(MPI_COMM_WORLD);
+  tria2.copy_triangulation(tria1);
+
+  Assert(tria1.n_active_cells() == tria2.n_active_cells(), ExcInternalError());
+  Assert(tria1.n_levels() == tria2.n_levels(), ExcInternalError());
+
+  typename Triangulation<dim, dim>::active_cell_iterator cell1, cell2;
+  for (cell1 = tria1.begin_active(), cell2 = tria2.begin_active();
+       cell1 != tria1.end();
+       ++cell1, ++cell2)
+    {
+      for (unsigned int f = 0; f < cell1->n_faces(); ++f)
+        if (cell1->face(f)->at_boundary())
+          Assert(cell1->face(f)->boundary_id() == cell2->face(f)->boundary_id(),
+                 ExcInternalError());
+      Assert(cell1->manifold_id() == cell2->manifold_id(), ExcInternalError());
+
+      if (cell1->is_locally_owned())
+        {
+          if (myid == 0)
+            {
+              deallog << "triangulation::cell     " << cell1
+                      << ": locally owned, subdomain_id = "
+                      << cell1->subdomain_id() << std::endl;
+              deallog << "new_triangulation::cell " << cell2
+                      << ": locally owned, subdomain_id = "
+                      << cell2->subdomain_id() << std::endl;
+            };
+
+          Assert(cell2->is_locally_owned(), ExcInternalError());
+          Assert(cell1->subdomain_id() == cell2->subdomain_id(),
+                 ExcInternalError());
+
+          for (const unsigned int vertex : GeometryInfo<dim>::vertex_indices())
+            {
+              Assert(cell1->vertex(vertex).distance(cell2->vertex(vertex)) <
+                       1.e-14,
+                     ExcInternalError());
+
+              if (myid == 0)
+                deallog << "  vertices " << vertex << " coincide" << std::endl;
+            };
+        }
+      else if (cell1->is_ghost())
+        {
+          if (myid == 0)
+            {
+              deallog << "triangulation::cell     " << cell1
+                      << ": ghost, subdomain_id = " << cell1->subdomain_id()
+                      << std::endl;
+              deallog << "new_triangulation::cell " << cell2
+                      << ": ghost, subdomain_id = " << cell2->subdomain_id()
+                      << std::endl;
+            };
+
+          Assert(cell2->is_ghost(), ExcInternalError());
+        }
+      else if (cell1->is_artificial())
+        {
+          if (myid == 0)
+            {
+              deallog << "triangulation::cell     " << cell1 << ": artificial"
+                      << std::endl;
+              deallog << "new_triangulation::cell " << cell2 << ": artificial"
+                      << std::endl;
+            };
+
+          Assert(cell2->is_artificial(), ExcInternalError());
+        }
+      else
+        Assert(false, ExcInternalError());
+    };
+}
+
+
+int
+main(int argc, char *argv[])
+{
+  Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1);
+
+  unsigned int myid = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
+
+  deallog.push(Utilities::int_to_string(myid));
+
+  if (myid == 0)
+    {
+      initlog();
+
+      deallog.push("2d");
+      test<2>();
+      deallog.pop();
+    }
+  else
+    test<2>();
+}
diff --git a/tests/mpi/tria_copy_triangulation_02.mpirun=1.with_p4est=true.output b/tests/mpi/tria_copy_triangulation_02.mpirun=1.with_p4est=true.output
new file mode 100644 (file)
index 0000000..f7cc201
--- /dev/null
@@ -0,0 +1,79 @@
+
+DEAL:0:2d::triangulation::cell     0.1: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 0.1: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     0.2: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 0.2: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     0.3: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 0.3: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     0.4: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 0.4: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     0.5: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 0.5: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     0.6: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 0.6: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     0.7: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 0.7: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     0.8: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 0.8: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     0.9: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 0.9: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     1.0: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 1.0: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     1.1: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 1.1: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     1.2: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 1.2: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     1.3: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 1.3: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
diff --git a/tests/mpi/tria_copy_triangulation_02.mpirun=2.with_p4est=true.output b/tests/mpi/tria_copy_triangulation_02.mpirun=2.with_p4est=true.output
new file mode 100644 (file)
index 0000000..6fe7b68
--- /dev/null
@@ -0,0 +1,51 @@
+
+DEAL:0:2d::triangulation::cell     0.1: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 0.1: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     0.2: ghost, subdomain_id = 1
+DEAL:0:2d::new_triangulation::cell 0.2: ghost, subdomain_id = 1
+DEAL:0:2d::triangulation::cell     0.3: artificial
+DEAL:0:2d::new_triangulation::cell 0.3: artificial
+DEAL:0:2d::triangulation::cell     0.4: artificial
+DEAL:0:2d::new_triangulation::cell 0.4: artificial
+DEAL:0:2d::triangulation::cell     0.5: artificial
+DEAL:0:2d::new_triangulation::cell 0.5: artificial
+DEAL:0:2d::triangulation::cell     0.6: artificial
+DEAL:0:2d::new_triangulation::cell 0.6: artificial
+DEAL:0:2d::triangulation::cell     0.7: artificial
+DEAL:0:2d::new_triangulation::cell 0.7: artificial
+DEAL:0:2d::triangulation::cell     0.8: ghost, subdomain_id = 1
+DEAL:0:2d::new_triangulation::cell 0.8: ghost, subdomain_id = 1
+DEAL:0:2d::triangulation::cell     0.9: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 0.9: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     1.0: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 1.0: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     1.1: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 1.1: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     1.2: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 1.2: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     1.3: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 1.3: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
diff --git a/tests/mpi/tria_copy_triangulation_02.mpirun=4.with_p4est=true.output b/tests/mpi/tria_copy_triangulation_02.mpirun=4.with_p4est=true.output
new file mode 100644 (file)
index 0000000..5c15772
--- /dev/null
@@ -0,0 +1,43 @@
+
+DEAL:0:2d::triangulation::cell     0.1: ghost, subdomain_id = 1
+DEAL:0:2d::new_triangulation::cell 0.1: ghost, subdomain_id = 1
+DEAL:0:2d::triangulation::cell     0.2: artificial
+DEAL:0:2d::new_triangulation::cell 0.2: artificial
+DEAL:0:2d::triangulation::cell     0.3: artificial
+DEAL:0:2d::new_triangulation::cell 0.3: artificial
+DEAL:0:2d::triangulation::cell     0.4: artificial
+DEAL:0:2d::new_triangulation::cell 0.4: artificial
+DEAL:0:2d::triangulation::cell     0.5: artificial
+DEAL:0:2d::new_triangulation::cell 0.5: artificial
+DEAL:0:2d::triangulation::cell     0.6: artificial
+DEAL:0:2d::new_triangulation::cell 0.6: artificial
+DEAL:0:2d::triangulation::cell     0.7: artificial
+DEAL:0:2d::new_triangulation::cell 0.7: artificial
+DEAL:0:2d::triangulation::cell     0.8: artificial
+DEAL:0:2d::new_triangulation::cell 0.8: artificial
+DEAL:0:2d::triangulation::cell     0.9: ghost, subdomain_id = 1
+DEAL:0:2d::new_triangulation::cell 0.9: ghost, subdomain_id = 1
+DEAL:0:2d::triangulation::cell     1.0: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 1.0: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     1.1: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 1.1: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     1.2: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 1.2: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide
+DEAL:0:2d::triangulation::cell     1.3: locally owned, subdomain_id = 0
+DEAL:0:2d::new_triangulation::cell 1.3: locally owned, subdomain_id = 0
+DEAL:0:2d::  vertices 0 coincide
+DEAL:0:2d::  vertices 1 coincide
+DEAL:0:2d::  vertices 2 coincide
+DEAL:0:2d::  vertices 3 coincide

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.