--- /dev/null
+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)
/**
* 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.
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
{
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();
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// 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>();
+}
--- /dev/null
+
+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
--- /dev/null
+
+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
--- /dev/null
+
+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