From 8a149348f0af852030f04cc96aabf6ba05167225 Mon Sep 17 00:00:00 2001 From: Marc Fehling Date: Sat, 20 Mar 2021 15:32:58 -0600 Subject: [PATCH] p:d:T:copy_triangulation() for refined meshes. --- doc/news/changes/minor/20210319Fehling | 5 + include/deal.II/distributed/tria.h | 2 - source/distributed/tria.cc | 55 ++++--- ...ation.cc => tria_copy_triangulation_01.cc} | 0 ...lation_01.mpirun=1.with_p4est=true.output} | 0 ...lation_01.mpirun=2.with_p4est=true.output} | 0 ...lation_01.mpirun=4.with_p4est=true.output} | 0 tests/mpi/tria_copy_triangulation_02.cc | 135 ++++++++++++++++++ ...ulation_02.mpirun=1.with_p4est=true.output | 79 ++++++++++ ...ulation_02.mpirun=2.with_p4est=true.output | 51 +++++++ ...ulation_02.mpirun=4.with_p4est=true.output | 43 ++++++ 11 files changed, 350 insertions(+), 20 deletions(-) create mode 100644 doc/news/changes/minor/20210319Fehling rename tests/mpi/{tria_copy_triangulation.cc => tria_copy_triangulation_01.cc} (100%) rename tests/mpi/{tria_copy_triangulation.mpirun=1.with_p4est=true.output => tria_copy_triangulation_01.mpirun=1.with_p4est=true.output} (100%) rename tests/mpi/{tria_copy_triangulation.mpirun=2.with_p4est=true.output => tria_copy_triangulation_01.mpirun=2.with_p4est=true.output} (100%) rename tests/mpi/{tria_copy_triangulation.mpirun=4.with_p4est=true.output => tria_copy_triangulation_01.mpirun=4.with_p4est=true.output} (100%) create mode 100644 tests/mpi/tria_copy_triangulation_02.cc create mode 100644 tests/mpi/tria_copy_triangulation_02.mpirun=1.with_p4est=true.output create mode 100644 tests/mpi/tria_copy_triangulation_02.mpirun=2.with_p4est=true.output create mode 100644 tests/mpi/tria_copy_triangulation_02.mpirun=4.with_p4est=true.output diff --git a/doc/news/changes/minor/20210319Fehling b/doc/news/changes/minor/20210319Fehling new file mode 100644 index 0000000000..0b34f0214a --- /dev/null +++ b/doc/news/changes/minor/20210319Fehling @@ -0,0 +1,5 @@ +Improved: The function parallel::distributed::Triangulation::copy_triangulation() +now also works with locally refined meshes of type +parallel::distributed::Triangulation. +
+(Marc Fehling, 2021/03/19) diff --git a/include/deal.II/distributed/tria.h b/include/deal.II/distributed/tria.h index 9e629bd120..6deb092a97 100644 --- a/include/deal.II/distributed/tria.h +++ b/include/deal.II/distributed/tria.h @@ -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. diff --git a/source/distributed/tria.cc b/source/distributed/tria.cc index 310fcfa4b3..571532f646 100644 --- a/source/distributed/tria.cc +++ b/source/distributed/tria.cc @@ -3266,10 +3266,14 @@ namespace parallel Triangulation::copy_triangulation( const dealii::Triangulation &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 *>( + &other_tria)) || + (other_tria.n_global_levels() == 1), + ExcNotImplemented()); + + dealii::parallel::distributed::Triangulation::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 - *other_tria_x = + *other_distributed = dynamic_cast *>(&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::connectivity + *temp_connectivity = const_cast< + typename dealii::internal::p4est::types::connectivity *>( + other_distributed->connectivity); + connectivity = + dealii::internal::p4est::copy_connectivity(temp_connectivity); + + // create deep copy of parallel forest + typename dealii::internal::p4est::types::forest *temp_forest = + const_cast::forest *>( + other_distributed->parallel_forest); + parallel_forest = + dealii::internal::p4est::functions::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()); } - copy_new_triangulation_to_p4est(std::integral_constant()); - try { copy_local_forest_to_triangulation(); diff --git a/tests/mpi/tria_copy_triangulation.cc b/tests/mpi/tria_copy_triangulation_01.cc similarity index 100% rename from tests/mpi/tria_copy_triangulation.cc rename to tests/mpi/tria_copy_triangulation_01.cc diff --git a/tests/mpi/tria_copy_triangulation.mpirun=1.with_p4est=true.output b/tests/mpi/tria_copy_triangulation_01.mpirun=1.with_p4est=true.output similarity index 100% rename from tests/mpi/tria_copy_triangulation.mpirun=1.with_p4est=true.output rename to tests/mpi/tria_copy_triangulation_01.mpirun=1.with_p4est=true.output diff --git a/tests/mpi/tria_copy_triangulation.mpirun=2.with_p4est=true.output b/tests/mpi/tria_copy_triangulation_01.mpirun=2.with_p4est=true.output similarity index 100% rename from tests/mpi/tria_copy_triangulation.mpirun=2.with_p4est=true.output rename to tests/mpi/tria_copy_triangulation_01.mpirun=2.with_p4est=true.output diff --git a/tests/mpi/tria_copy_triangulation.mpirun=4.with_p4est=true.output b/tests/mpi/tria_copy_triangulation_01.mpirun=4.with_p4est=true.output similarity index 100% rename from tests/mpi/tria_copy_triangulation.mpirun=4.with_p4est=true.output rename to tests/mpi/tria_copy_triangulation_01.mpirun=4.with_p4est=true.output diff --git a/tests/mpi/tria_copy_triangulation_02.cc b/tests/mpi/tria_copy_triangulation_02.cc new file mode 100644 index 0000000000..960447ff0d --- /dev/null +++ b/tests/mpi/tria_copy_triangulation_02.cc @@ -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 + +#include + +#include "../tests.h" + + +template +void +test() +{ + unsigned int myid = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); + + parallel::distributed::Triangulation tria1(MPI_COMM_WORLD); + { + GridGenerator::hyper_shell(tria1, Point(), 1., 2., 0, true); + tria1.begin_active()->set_refine_flag(); + tria1.execute_coarsening_and_refinement(); + } + + parallel::distributed::Triangulation 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::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::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 index 0000000000..f7cc201c10 --- /dev/null +++ b/tests/mpi/tria_copy_triangulation_02.mpirun=1.with_p4est=true.output @@ -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 index 0000000000..6fe7b68902 --- /dev/null +++ b/tests/mpi/tria_copy_triangulation_02.mpirun=2.with_p4est=true.output @@ -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 index 0000000000..5c15772526 --- /dev/null +++ b/tests/mpi/tria_copy_triangulation_02.mpirun=4.with_p4est=true.output @@ -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 -- 2.39.5