From 4f5011b1be9995e521f358ca187136d4b0fe8a6b Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Tue, 9 Feb 2021 10:30:48 +0100 Subject: [PATCH] MGTransferGlobalCoarseningTools::create_geometric_coarsening_sequence load forest directly --- doc/news/changes/minor/20210209Munch | 6 +++ include/deal.II/distributed/p4est_wrappers.h | 6 +++ include/deal.II/distributed/tria.h | 8 ++++ .../mg_transfer_global_coarsening.templates.h | 38 ++++++++++++---- source/distributed/p4est_wrappers.cc | 6 +++ source/distributed/tria.cc | 43 +++++++++++++++++++ 6 files changed, 98 insertions(+), 9 deletions(-) create mode 100644 doc/news/changes/minor/20210209Munch diff --git a/doc/news/changes/minor/20210209Munch b/doc/news/changes/minor/20210209Munch new file mode 100644 index 0000000000..e8e7e83aaa --- /dev/null +++ b/doc/news/changes/minor/20210209Munch @@ -0,0 +1,6 @@ +New: The method parallel::distributed::Triagnulation::load() +can now also accept a p4est/p8est forest, which can be queried +from an existing triangulation via parallel::distributed::Triagnulation::get_p4est(). +
+(Marc Fehling, Peter Munch, 2021/02/09) + diff --git a/include/deal.II/distributed/p4est_wrappers.h b/include/deal.II/distributed/p4est_wrappers.h index 0d48339d3a..27894a5a74 100644 --- a/include/deal.II/distributed/p4est_wrappers.h +++ b/include/deal.II/distributed/p4est_wrappers.h @@ -180,6 +180,9 @@ namespace internal p4est_init_t init_fn, void * user_pointer); + static types<2>::forest *(©_forest)(types<2>::forest *input, + int copy_data); + static void (&destroy)(types<2>::forest *p4est); static void (&refine)(types<2>::forest *p4est, @@ -350,6 +353,9 @@ namespace internal p8est_init_t init_fn, void * user_pointer); + static types<3>::forest *(©_forest)(types<3>::forest *input, + int copy_data); + static void (&destroy)(types<3>::forest *p8est); static void (&refine)(types<3>::forest *p8est, diff --git a/include/deal.II/distributed/tria.h b/include/deal.II/distributed/tria.h index 272ed414a6..238db08b55 100644 --- a/include/deal.II/distributed/tria.h +++ b/include/deal.II/distributed/tria.h @@ -604,6 +604,14 @@ namespace parallel load(const std::string &filename, const bool autopartition = true) override; + /** + * Load the refinement information from a given parallel forest. This + * forest might be obtained from the function call to + * parallel::distributed::Triangulation::get_p4est(); + */ + void + load(const typename dealii::internal::p4est::types::forest *forest); + /** * Return a permutation vector for the order the coarse cells are handed * off to p4est. For example the value of the $i$th element in this diff --git a/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h b/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h index 4ba56a2f64..9c6bf048e8 100644 --- a/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h +++ b/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h @@ -1694,6 +1694,30 @@ namespace MGTransferGlobalCoarseningTools } + namespace internal + { + template + void + load_forest(const parallel::distributed::Triangulation &in, + parallel::distributed::Triangulation & out) + { +#ifndef DEAL_II_WITH_P4EST + (void)in; + (void)out; +#else + out.load(in.get_p4est()); +#endif + } + + template + void + load_forest(const parallel::distributed::Triangulation<1, spacedim> &in, + parallel::distributed::Triangulation<1, spacedim> & out) + { + (void)in; + (void)out; + } + } // namespace internal template std::vector>> @@ -1730,13 +1754,6 @@ namespace MGTransferGlobalCoarseningTools // create coarse meshes for (unsigned int l = max_level; l > 0; --l) { - // store finer mesh to file - dynamic_cast< - const parallel::distributed::Triangulation *>( - coarse_grid_triangulations[l].get()) - ->save("mesh"); - MPI_Barrier(fine_triangulation->get_communicator()); - // create empty triangulation auto new_tria = std::make_shared>( @@ -1753,8 +1770,11 @@ namespace MGTransferGlobalCoarseningTools new_tria->set_manifold(i, fine_triangulation->get_manifold(i)); // create refinement hierarchy (by loading stored mesh) - new_tria->load("mesh", false); - MPI_Barrier(fine_triangulation->get_communicator()); + internal::load_forest( + *dynamic_cast< + const parallel::distributed::Triangulation *>( + coarse_grid_triangulations[l].get()), + *new_tria); // coarsen mesh new_tria->coarsen_global(); diff --git a/source/distributed/p4est_wrappers.cc b/source/distributed/p4est_wrappers.cc index c1de26ef33..07b15cdb74 100644 --- a/source/distributed/p4est_wrappers.cc +++ b/source/distributed/p4est_wrappers.cc @@ -401,6 +401,9 @@ namespace internal p4est_init_t init_fn, void * user_pointer) = p4est_new_ext; + types<2>::forest *(&functions<2>::copy_forest)(types<2>::forest *input, + int copy_data) = p4est_copy; + void (&functions<2>::destroy)(types<2>::forest *p4est) = p4est_destroy; void (&functions<2>::refine)(types<2>::forest *p4est, @@ -588,6 +591,9 @@ namespace internal p8est_init_t init_fn, void * user_pointer) = p8est_new_ext; + types<3>::forest *(&functions<3>::copy_forest)(types<3>::forest *input, + int copy_data) = p8est_copy; + void (&functions<3>::destroy)(types<3>::forest *p8est) = p8est_destroy; void (&functions<3>::refine)(types<3>::forest *p8est, diff --git a/source/distributed/tria.cc b/source/distributed/tria.cc index 60898ada35..cf2b51eae3 100644 --- a/source/distributed/tria.cc +++ b/source/distributed/tria.cc @@ -1608,6 +1608,49 @@ namespace parallel } + template + void + Triangulation::load( + const typename dealii::internal::p4est::types::forest *forest) + { + if (parallel_ghost != nullptr) + { + dealii::internal::p4est::functions::ghost_destroy( + parallel_ghost); + parallel_ghost = nullptr; + } + dealii::internal::p4est::functions::destroy(parallel_forest); + parallel_forest = nullptr; + + // note: we can keep the connectivity, since the coarse grid does not + // change + + // create deep copy + typename dealii::internal::p4est::types::forest *temp = + const_cast::forest *>( + forest); + parallel_forest = + dealii::internal::p4est::functions::copy_forest(temp, false); + parallel_forest->user_pointer = this; + + try + { + copy_local_forest_to_triangulation(); + } + catch (const typename Triangulation::DistortedCellList &) + { + // the underlying + // triangulation should not + // be checking for + // distorted cells + Assert(false, ExcInternalError()); + } + + this->update_periodic_face_map(); + this->update_number_cache(); + } + + template unsigned int -- 2.39.5