]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix extract_rtree_level for small problem sizes 10207/head
authorPeter Munch <peterrmuench@gmail.com>
Thu, 14 May 2020 08:32:50 +0000 (10:32 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Thu, 14 May 2020 08:34:21 +0000 (10:34 +0200)
include/deal.II/numerics/rtree.h
tests/boost/extract_representative_set_02.cc
tests/boost/extract_representative_set_02.with_p4est=true.mpirun=3.output

index b230debecc6a2c35cc1b17316df70e4568695a5a..59f1f822e29e2492f1de6d5bcdc6883f5a343634 100644 (file)
@@ -423,18 +423,28 @@ extract_rtree_level(const Rtree &tree, const unsigned int level)
 
   std::vector<BoundingBox<dim>> boxes;
 
-  const unsigned int target_level =
-    std::min<unsigned int>(level, rtv.depth() - 1);
-  // There should always be at least one level.
-  Assert(target_level >= 0, ExcInternalError());
-
-  ExtractLevelVisitor<typename RtreeView::value_type,
-                      typename RtreeView::options_type,
-                      typename RtreeView::translator_type,
-                      typename RtreeView::box_type,
-                      typename RtreeView::allocators_type>
-    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<unsigned int>(level, rtv.depth() - 1);
+
+      ExtractLevelVisitor<typename RtreeView::value_type,
+                          typename RtreeView::options_type,
+                          typename RtreeView::translator_type,
+                          typename RtreeView::box_type,
+                          typename RtreeView::allocators_type>
+        extract_level_visitor(rtv.translator(), target_level, boxes);
+      rtv.apply_visitor(extract_level_visitor);
+    }
+
   return boxes;
 }
 
index c6ce7ac0077fd1e1f76c81ed1fac579a5ff27269..c083ab08ebd4ac4ecf5f4978f85a381248dd6d75 100644 (file)
@@ -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<BoundingBox<2>> 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);
+}
index ba95e518381c60672b00c161f9066a0422ee64d5..2f62344900a43c25f264c5625f0d62c891f9402d 100644 (file)
@@ -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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.