]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Merge pull request #7752 from GivAlz/GuessOwnerTree
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Sat, 11 May 2019 13:56:35 +0000 (15:56 +0200)
committerGitHub <noreply@github.com>
Sat, 11 May 2019 13:56:35 +0000 (15:56 +0200)
New function GridTools::guess_point_owner from covering tree

1  2 
include/deal.II/grid/grid_tools.h
source/grid/grid_tools.cc
source/grid/grid_tools.inst.in

Simple merge
index d61caeeb6bf7ff92ac18041aa58e3a7f80ace265,fd42a00dd75456bd2f2858de3381ae6dcbb73b55..dfff05c3defa1d20beb46ead58fd5840d7ee22ee
@@@ -2086,11 -2091,71 +2086,64 @@@ namespace GridTool
            map_owners_guessed[pt] = owners_found;
        }
  
 -    std::tuple<std::vector<std::vector<unsigned int>>,
 -               std::map<unsigned int, unsigned int>,
 -               std::map<unsigned int, std::vector<unsigned int>>>
 -      output_tuple;
 -
 -    std::get<0>(output_tuple) = point_owners;
 -    std::get<1>(output_tuple) = map_owners_found;
 -    std::get<2>(output_tuple) = map_owners_guessed;
 -
 -    return output_tuple;
 +    return std::make_tuple(std::move(point_owners),
 +                           std::move(map_owners_found),
 +                           std::move(map_owners_guessed));
    }
  
+   template <int spacedim>
+ #ifndef DOXYGEN
+   std::tuple<std::map<unsigned int, std::vector<unsigned int>>,
+              std::map<unsigned int, unsigned int>,
+              std::map<unsigned int, std::vector<unsigned int>>>
+ #else
+   return_type
+ #endif
+   guess_point_owner(
+     const RTree<std::pair<BoundingBox<spacedim>, unsigned int>> &covering_rtree,
+     const std::vector<Point<spacedim>> &                         points)
+   {
+     std::map<unsigned int, std::vector<unsigned int>> point_owners;
+     std::map<unsigned int, unsigned int>              map_owners_found;
+     std::map<unsigned int, std::vector<unsigned int>> map_owners_guessed;
+     std::vector<std::pair<BoundingBox<spacedim>, unsigned int>> search_result;
+     unsigned int n_points = points.size();
+     for (unsigned int pt_n = 0; pt_n < n_points; ++pt_n)
+       {
+         search_result.clear(); // clearing last output
+         // Running tree search
+         covering_rtree.query(boost::geometry::index::intersects(points[pt_n]),
+                              std::back_inserter(search_result));
+         // Keep track of how many processes we guess to own the point
+         std::set<unsigned int> owners_found;
+         // Check in which other processes the point might be
+         for (const auto &rank_bbox : search_result)
+           {
+             // Try to add the owner to the owners found,
+             // and check if it was already present
+             const bool pt_inserted = owners_found.insert(pt_n).second;
+             if (pt_inserted)
+               point_owners[rank_bbox.second].emplace_back(pt_n);
+           }
+         Assert(owners_found.size() > 0,
+                ExcMessage("No owners found for the point " +
+                           std::to_string(pt_n)));
+         if (owners_found.size() == 1)
+           map_owners_found[pt_n] = *owners_found.begin();
+         else
+           // Multiple owners
+           std::copy(owners_found.begin(),
+                     owners_found.end(),
+                     std::back_inserter(map_owners_guessed[pt_n]));
+       }
+     return std::make_tuple(std::move(point_owners),
+                            std::move(map_owners_found),
+                            std::move(map_owners_guessed));
+   }
  
  
    template <int dim, int spacedim>
Simple merge

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.