From: David Wells Date: Fri, 14 Jun 2024 20:01:54 +0000 (-0400) Subject: Add another constructor for RemotePointEvaluation. X-Git-Tag: v9.6.0-rc1~187^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=982cfb224a28f4e2840325e0862e2486bba113f0;p=dealii.git Add another constructor for RemotePointEvaluation. Rather than setting up its own cache, we can just re-use the existing one. Also re-use cached values. --- diff --git a/include/deal.II/base/mpi_remote_point_evaluation.h b/include/deal.II/base/mpi_remote_point_evaluation.h index 9691d4349d..d7725d4dbc 100644 --- a/include/deal.II/base/mpi_remote_point_evaluation.h +++ b/include/deal.II/base/mpi_remote_point_evaluation.h @@ -27,6 +27,9 @@ DEAL_II_NAMESPACE_OPEN // Forward declarations namespace GridTools { + template + class Cache; + namespace internal { template @@ -151,6 +154,20 @@ namespace Utilities const Triangulation &tria, const Mapping &mapping); + /** + * Set up internal data structures and communication pattern based on + * an existing Cache and a list of points @p points. + * + * @warning This is a collective call that needs to be executed by all + * processors in the communicator. + * + * @note If you want to be sure that all points have been found, call + * all_points_found() after calling this function. + */ + void + reinit(const GridTools::Cache &cache, + const std::vector> &points); + /** * Set up internal data structures and communication pattern based on * GridTools::internal::DistributedComputePointLocationsInternal. diff --git a/source/base/mpi_remote_point_evaluation.cc b/source/base/mpi_remote_point_evaluation.cc index 76f6580d58..0789ae9314 100644 --- a/source/base/mpi_remote_point_evaluation.cc +++ b/source/base/mpi_remote_point_evaluation.cc @@ -88,32 +88,35 @@ namespace Utilities const Triangulation &tria, const Mapping &mapping) { + const GridTools::Cache cache(tria, mapping); + + this->reinit(cache, points); + } + + + + template + void + RemotePointEvaluation::reinit( + const GridTools::Cache &cache, + const std::vector> &points) + { #ifndef DEAL_II_WITH_MPI Assert(false, ExcNeedsMPI()); + (void)cache; (void)points; - (void)tria; - (void)mapping; #else if (tria_signal.connected()) tria_signal.disconnect(); - tria_signal = - tria.signals.any_change.connect([&]() { this->ready_flag = false; }); - - std::vector> local_boxes; - for (const auto &cell : - tria.active_cell_iterators() | IteratorFilters::LocallyOwnedCell()) - local_boxes.push_back(mapping.get_bounding_box(cell)); - - // create r-tree of bounding boxes - const auto local_tree = pack_rtree(local_boxes); + tria_signal = cache.get_triangulation().signals.any_change.connect( + [&]() { this->ready_flag = false; }); // compress r-tree to a minimal set of bounding boxes - std::vector>> global_bboxes(1); - global_bboxes[0] = - extract_rtree_level(local_tree, additional_data.rtree_level); - - const GridTools::Cache cache(tria, mapping); + std::vector>> global_bboxes; + global_bboxes.emplace_back( + extract_rtree_level(cache.get_locally_owned_cell_bounding_boxes_rtree(), + additional_data.rtree_level)); const auto data = GridTools::internal::distributed_compute_point_locations( @@ -126,7 +129,7 @@ namespace Utilities true, additional_data.enforce_unique_mapping); - this->reinit(data, tria, mapping); + this->reinit(data, cache.get_triangulation(), cache.get_mapping()); #endif } diff --git a/tests/remote_point_evaluation/mapping_03.cc b/tests/remote_point_evaluation/mapping_03.cc index 0b6364cdaf..86c1ec81c1 100644 --- a/tests/remote_point_evaluation/mapping_03.cc +++ b/tests/remote_point_evaluation/mapping_03.cc @@ -23,6 +23,7 @@ #include #include +#include #include @@ -32,7 +33,7 @@ template void -test(const bool enforce_unique_map) +test(const bool enforce_unique_map, const bool use_cache) { parallel::distributed::Triangulation tria(MPI_COMM_WORLD); GridGenerator::subdivided_hyper_cube(tria, 2); @@ -59,6 +60,11 @@ test(const bool enforce_unique_map) additional_data.tolerance = 1e-6; Utilities::MPI::RemotePointEvaluation eval(additional_data); + if (use_cache) + { + GridTools::Cache cache(tria, mapping); + eval.reinit(cache, evaluation_points); + } const auto result_avg = VectorTools::point_values<1>(mapping, @@ -89,6 +95,7 @@ main(int argc, char **argv) Utilities::MPI::MPI_InitFinalize mpi(argc, argv, 1); MPILogInitAll all; - test<2>(false); - test<2>(true); + test<2>(false, false); + test<2>(true, false); + test<2>(true, true); } diff --git a/tests/remote_point_evaluation/mapping_03.with_p4est=true.mpirun=2.output b/tests/remote_point_evaluation/mapping_03.with_p4est=true.mpirun=2.output index 6fc910c6f3..1952162ffe 100644 --- a/tests/remote_point_evaluation/mapping_03.with_p4est=true.mpirun=2.output +++ b/tests/remote_point_evaluation/mapping_03.with_p4est=true.mpirun=2.output @@ -27,6 +27,20 @@ DEAL:0::1e-11 1.00000 1.00000 1.00000 1.00000 1 DEAL:0::1e-12 1.00000 1.00000 1.00000 1.00000 1 DEAL:0::1e-13 1.00000 1.00000 1.00000 1.00000 1 DEAL:0::1e-14 1.00000 1.00000 1.00000 1.00000 1 +DEAL:0::1e-1 2.00000 2.00000 2.00000 2.00000 1 +DEAL:0::1e-2 2.00000 2.00000 2.00000 2.00000 1 +DEAL:0::1e-3 2.00000 2.00000 2.00000 2.00000 1 +DEAL:0::1e-4 2.00000 2.00000 2.00000 2.00000 1 +DEAL:0::1e-5 2.00000 2.00000 2.00000 2.00000 1 +DEAL:0::1e-6 2.00000 2.00000 2.00000 2.00000 1 +DEAL:0::1e-7 1.00000 1.00000 1.00000 1.00000 1 +DEAL:0::1e-8 1.00000 1.00000 1.00000 1.00000 1 +DEAL:0::1e-9 1.00000 1.00000 1.00000 1.00000 1 +DEAL:0::1e-10 1.00000 1.00000 1.00000 1.00000 1 +DEAL:0::1e-11 1.00000 1.00000 1.00000 1.00000 1 +DEAL:0::1e-12 1.00000 1.00000 1.00000 1.00000 1 +DEAL:0::1e-13 1.00000 1.00000 1.00000 1.00000 1 +DEAL:0::1e-14 1.00000 1.00000 1.00000 1.00000 1 DEAL:1::1e-1 2.00000 2.00000 2.00000 2.00000 2 DEAL:1::1e-2 2.00000 2.00000 2.00000 2.00000 2 @@ -56,4 +70,18 @@ DEAL:1::1e-11 1.00000 1.00000 1.00000 1.00000 1 DEAL:1::1e-12 1.00000 1.00000 1.00000 1.00000 1 DEAL:1::1e-13 1.00000 1.00000 1.00000 1.00000 1 DEAL:1::1e-14 1.00000 1.00000 1.00000 1.00000 1 +DEAL:1::1e-1 2.00000 2.00000 2.00000 2.00000 1 +DEAL:1::1e-2 2.00000 2.00000 2.00000 2.00000 1 +DEAL:1::1e-3 2.00000 2.00000 2.00000 2.00000 1 +DEAL:1::1e-4 2.00000 2.00000 2.00000 2.00000 1 +DEAL:1::1e-5 2.00000 2.00000 2.00000 2.00000 1 +DEAL:1::1e-6 2.00000 2.00000 2.00000 2.00000 1 +DEAL:1::1e-7 1.00000 1.00000 1.00000 1.00000 1 +DEAL:1::1e-8 1.00000 1.00000 1.00000 1.00000 1 +DEAL:1::1e-9 1.00000 1.00000 1.00000 1.00000 1 +DEAL:1::1e-10 1.00000 1.00000 1.00000 1.00000 1 +DEAL:1::1e-11 1.00000 1.00000 1.00000 1.00000 1 +DEAL:1::1e-12 1.00000 1.00000 1.00000 1.00000 1 +DEAL:1::1e-13 1.00000 1.00000 1.00000 1.00000 1 +DEAL:1::1e-14 1.00000 1.00000 1.00000 1.00000 1