From: Martin Kronbichler Date: Sat, 11 May 2019 13:56:35 +0000 (+0200) Subject: Merge pull request #7752 from GivAlz/GuessOwnerTree X-Git-Tag: v9.1.0-rc1~69 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b2a625825b45022c25968451e74d6fd25436bfcd;p=dealii.git Merge pull request #7752 from GivAlz/GuessOwnerTree New function GridTools::guess_point_owner from covering tree --- b2a625825b45022c25968451e74d6fd25436bfcd diff --cc source/grid/grid_tools.cc index d61caeeb6b,fd42a00dd7..dfff05c3de --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@@ -2086,11 -2091,71 +2086,64 @@@ namespace GridTool map_owners_guessed[pt] = owners_found; } - std::tuple>, - std::map, - std::map>> - 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 + #ifndef DOXYGEN + std::tuple>, + std::map, + std::map>> + #else + return_type + #endif + guess_point_owner( + const RTree, unsigned int>> &covering_rtree, + const std::vector> & points) + { + std::map> point_owners; + std::map map_owners_found; + std::map> map_owners_guessed; + std::vector, 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 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