From: Peter Munch Date: Thu, 14 May 2020 08:32:50 +0000 (+0200) Subject: Fix extract_rtree_level for small problem sizes X-Git-Tag: v9.3.0-rc1~1640^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfe81e2b89a39792ee48dd7d028e8860cc44551e;p=dealii.git Fix extract_rtree_level for small problem sizes --- diff --git a/include/deal.II/numerics/rtree.h b/include/deal.II/numerics/rtree.h index b230debecc..59f1f822e2 100644 --- a/include/deal.II/numerics/rtree.h +++ b/include/deal.II/numerics/rtree.h @@ -423,18 +423,28 @@ extract_rtree_level(const Rtree &tree, const unsigned int level) std::vector> boxes; - const unsigned int target_level = - std::min(level, rtv.depth() - 1); - // There should always be at least one level. - Assert(target_level >= 0, ExcInternalError()); - - ExtractLevelVisitor - extract_level_visitor(rtv.translator(), target_level, boxes); - rtv.apply_visitor(extract_level_visitor); + if (rtv.depth() == 0) + { + // The below algorithm does not work for `rtv.depth()==0`, which might + // happen if the number entries in the tree is too small. + // In this case, simply return a single bounding box. + boxes.resize(1); + boost::geometry::convert(tree.bounds(), boxes[0]); + } + else + { + const unsigned int target_level = + std::min(level, rtv.depth() - 1); + + ExtractLevelVisitor + extract_level_visitor(rtv.translator(), target_level, boxes); + rtv.apply_visitor(extract_level_visitor); + } + return boxes; } diff --git a/tests/boost/extract_representative_set_02.cc b/tests/boost/extract_representative_set_02.cc index c6ce7ac007..c083ab08eb 100644 --- a/tests/boost/extract_representative_set_02.cc +++ b/tests/boost/extract_representative_set_02.cc @@ -49,17 +49,13 @@ print(const BoundingBox<2> &box) return str.str(); } - -int -main(int argc, char **argv) +void +test(const unsigned int n_refinements) { - auto mpi_init = Utilities::MPI::MPI_InitFinalize(argc, argv); - MPILogInitAll log; - parallel::distributed::Triangulation<2> tria(MPI_COMM_WORLD); GridGenerator::hyper_ball(tria); - tria.refine_global(3); + tria.refine_global(n_refinements); std::vector> all_boxes(tria.n_locally_owned_active_cells()); unsigned int i = 0; @@ -70,6 +66,7 @@ main(int argc, char **argv) const auto tree = pack_rtree(all_boxes); const auto boxes = extract_rtree_level(tree, 0); + deallog << "Refinements: " << n_refinements << std::endl; deallog << "LEVEL 0: N boxes: " << boxes.size() << std::endl; for (const auto &b : boxes) deallog << print(b) << std::endl; @@ -89,3 +86,14 @@ main(int argc, char **argv) // for (const auto &b : all_boxes) // all << print(b); } + + +int +main(int argc, char **argv) +{ + auto mpi_init = Utilities::MPI::MPI_InitFinalize(argc, argv); + MPILogInitAll log; + + for (unsigned int i = 0; i <= 3; ++i) + test(i); +} diff --git a/tests/boost/extract_representative_set_02.with_p4est=true.mpirun=3.output b/tests/boost/extract_representative_set_02.with_p4est=true.mpirun=3.output index ba95e51838..2f62344900 100644 --- a/tests/boost/extract_representative_set_02.with_p4est=true.mpirun=3.output +++ b/tests/boost/extract_representative_set_02.with_p4est=true.mpirun=3.output @@ -1,4 +1,35 @@ +DEAL:0::Refinements: 0 +DEAL:0::LEVEL 0: N boxes: 1 +DEAL:0::-0.707107 -0.707107 +0.707107 -0.707107 +0.707107 -0.292893 +-0.707107 -0.292893 +-0.707107 -0.707107 + +DEAL:0::Refinements: 1 +DEAL:0::LEVEL 0: N boxes: 1 +DEAL:0::-1 -1 +0.707107 -1 +0.707107 0.707107 +-1 0.707107 +-1 -1 + +DEAL:0::Refinements: 2 +DEAL:0::LEVEL 0: N boxes: 2 +DEAL:0::-1 -0.92388 +-0.146447 -0.92388 +-0.146447 0.707107 +-1 0.707107 +-1 -0.92388 + +DEAL:0::-0.382683 -1 +0.707107 -1 +0.707107 -0.292893 +-0.382683 -0.292893 +-0.382683 -1 + +DEAL:0::Refinements: 3 DEAL:0::LEVEL 0: N boxes: 7 DEAL:0::-0.92388 -0.92388 -0.297335 -0.92388 @@ -43,6 +74,37 @@ DEAL:0::-4.16334e-17 -0.558058 -4.16334e-17 -0.558058 +DEAL:1::Refinements: 0 +DEAL:1::LEVEL 0: N boxes: 1 +DEAL:1::-0.707107 -0.707107 +0.292893 -0.707107 +0.292893 0.707107 +-0.707107 0.707107 +-0.707107 -0.707107 + +DEAL:1::Refinements: 1 +DEAL:1::LEVEL 0: N boxes: 1 +DEAL:1::-0.292893 -0.292893 +0.292893 -0.292893 +0.292893 0.292893 +-0.292893 0.292893 +-0.292893 -0.292893 + +DEAL:1::Refinements: 2 +DEAL:1::LEVEL 0: N boxes: 2 +DEAL:1::-0.646447 -0.292893 +0.146447 -0.292893 +0.146447 0.5 +-0.646447 0.5 +-0.646447 -0.292893 + +DEAL:1::0.146447 -0.707107 +1 -0.707107 +1 0.292893 +0.146447 0.292893 +0.146447 -0.707107 + +DEAL:1::Refinements: 3 DEAL:1::LEVEL 0: N boxes: 7 DEAL:1::-0.292893 -0.292893 0 -0.292893 @@ -75,19 +137,50 @@ DEAL:1::0.5 -0.707107 0.5 -0.707107 DEAL:1::-0.0732233 -0.0732233 -0.292893 -0.0732233 -0.292893 0.292893 +0.21967 -0.0732233 +0.21967 0.292893 -0.0732233 0.292893 -0.0732233 -0.0732233 -DEAL:1::0.21967 -0.0732233 -1 -0.0732233 +DEAL:1::0.21967 -1.11022e-16 +1 -1.11022e-16 1 0.382683 0.21967 0.382683 -0.21967 -0.0732233 +0.21967 -1.11022e-16 +DEAL:2::Refinements: 0 +DEAL:2::LEVEL 0: N boxes: 1 +DEAL:2::-0.707107 -0.707107 +0.707107 -0.707107 +0.707107 0.707107 +-0.707107 0.707107 +-0.707107 -0.707107 + +DEAL:2::Refinements: 1 +DEAL:2::LEVEL 0: N boxes: 1 +DEAL:2::-0.707107 -0.707107 +1 -0.707107 +1 1 +-0.707107 1 +-0.707107 -0.707107 + +DEAL:2::Refinements: 2 +DEAL:2::LEVEL 0: N boxes: 2 +DEAL:2::-0.707107 -0.396447 +0.5 -0.396447 +0.5 1 +-0.707107 1 +-0.707107 -0.396447 + +DEAL:2::0.25 -0.5 +1 -0.5 +1 0.92388 +0.25 0.92388 +0.25 -0.5 + +DEAL:2::Refinements: 3 DEAL:2::LEVEL 0: N boxes: 7 DEAL:2::-0.448223 0.292893 0.297335 0.292893