diff --git a/kratos/spatial_containers/search_wrapper.cpp b/kratos/spatial_containers/search_wrapper.cpp index c0a248fec8b0..f819711342e8 100644 --- a/kratos/spatial_containers/search_wrapper.cpp +++ b/kratos/spatial_containers/search_wrapper.cpp @@ -161,9 +161,15 @@ void SearchWrapper::LocalSearchInRadius( const int AllocationSize ) { + // Get the rank + const int rank = GetRank(); + // If we are using GeometricalObjectBins we can use the optimized search if constexpr (IsGeometricalObjectBins) { mpSearchObject->SearchInRadius(rPoint, Radius, rResults); + for(auto& r_result : rResults) { + r_result.Get().SetRank(rank); + } } else { // Using trees // We search if geometrical objects are provided if (mpPointVector) { @@ -171,9 +177,6 @@ void SearchWrapper::LocalSearchInRadius( DistanceVector results_distances(AllocationSize); const std::size_t number_of_results = mpSearchObject->SearchInRadius(rPoint, Radius, results.begin(), results_distances.begin(), AllocationSize); if (number_of_results > 0) { - // Get the rank - const int rank = GetRank(); - // Set the results rResults.reserve(number_of_results); for (std::size_t i = 0; i < number_of_results; ++i) { @@ -198,9 +201,13 @@ void SearchWrapper::LocalSearchNearestInRadius( const int AllocationSize ) { + // Get the rank + const int rank = GetRank(); + // If we are using GeometricalObjectBins we can use the optimized search if constexpr (IsGeometricalObjectBins) { rResult = mpSearchObject->SearchNearestInRadius(rPoint, Radius); + rResult.Get().SetRank(rank); } else { // Using trees // We search if geometrical objects are provided if (mpPointVector) { @@ -211,9 +218,6 @@ void SearchWrapper::LocalSearchNearestInRadius( // Resize the results results_distances.resize(number_of_results); - // Get the rank - const int rank = GetRank(); - // Find the iterator pointing to the smallest value auto it_min = std::min_element(results_distances.begin(), results_distances.end()); @@ -237,15 +241,16 @@ void SearchWrapper::LocalSearchNearest( ResultType& rResult ) { + // Get the rank + const int rank = GetRank(); + // If we are using GeometricalObjectBins we can use the optimized search if constexpr (IsGeometricalObjectBins) { rResult = mpSearchObject->SearchNearest(rPoint); + rResult.Get().SetRank(rank); } else { // Using trees // We search if geometrical objects are provided if (mpPointVector) { - // Get the rank - const int rank = GetRank(); - // Search nearest double distance = 0.0; auto p_point = mpSearchObject->SearchNearestPoint(rPoint, distance); @@ -266,9 +271,13 @@ void SearchWrapper::LocalSearchIsInside( ResultType& rResult ) { + // Get the rank + const int rank = GetRank(); + // If we are using GeometricalObjectBins we can use the optimized search if constexpr (IsGeometricalObjectBins) { rResult = mpSearchObject->SearchIsInside(rPoint); + rResult.Get().SetRank(rank); } else { // Using trees KRATOS_ERROR << "SearchIsInside not compatible with Search trees" << std::endl; } diff --git a/kratos/spatial_containers/search_wrapper.h b/kratos/spatial_containers/search_wrapper.h index b0dd554d140e..b61d91c0635f 100644 --- a/kratos/spatial_containers/search_wrapper.h +++ b/kratos/spatial_containers/search_wrapper.h @@ -109,7 +109,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper if (rGeometricalObjectsVector.size() > 0) { // Defining the PointVector mpPointVector = Kratos::make_unique(SearchUtilities::PreparePointsSearch(rGeometricalObjectsVector)); - + // Create the search object if constexpr (!IsDynamicBins) { const int bucket_size = mSettings["bucket_size"].GetInt(); @@ -379,7 +379,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper TPointIteratorType itPointBegin, TPointIteratorType itPointEnd, const double Radius, - ResultContainerVectorType& rResults, + ResultContainerVectorType& rResults, const bool ClearSolution = true ) { @@ -434,7 +434,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper TPointIteratorType itPointBegin, TPointIteratorType itPointEnd, const double Radius, - ResultContainerVectorType& rResults, + ResultContainerVectorType& rResults, const bool ClearSolution = true ) { @@ -459,7 +459,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper ResultType result; LocalSearchNearestInRadius(*it_point, Radius, result, allocation_size); r_point_result.AddResult(result); - + // Synchronize r_point_result.SynchronizeAll(mrDataCommunicator); @@ -482,7 +482,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper void SerialSearchNearest( TPointIteratorType itPointBegin, TPointIteratorType itPointEnd, - ResultContainerVectorType& rResults, + ResultContainerVectorType& rResults, const bool ClearSolution = true ) { @@ -504,10 +504,10 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper ResultType result; LocalSearchNearest(*it_point, result); r_point_result.AddResult(result); - + // Synchronize r_point_result.SynchronizeAll(mrDataCommunicator); - + // Update counter ++counter; } @@ -529,7 +529,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper void SerialSearchIsInside( TPointIteratorType itPointBegin, TPointIteratorType itPointEnd, - ResultContainerVectorType& rResults, + ResultContainerVectorType& rResults, const bool ClearSolution = true ) { @@ -595,7 +595,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper SearchUtilities::SynchronousPointSynchronization(itPointBegin, itPointEnd, all_points_coordinates, all_points_ids, mrDataCommunicator); // The local bounding box - const auto& r_local_bb = mpSearchObject ? mpSearchObject->GetBoundingBox() : BoundingBox(); + const auto& r_local_bb = mpSearchObject ? mpSearchObject->GetBoundingBox() : BoundingBox(); // Perform the corresponding searches const std::size_t total_number_of_points = all_points_coordinates.size()/3; @@ -657,7 +657,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper const int current_rank = GetRank(); // The local bounding box - const auto& r_local_bb = mpSearchObject ? mpSearchObject->GetBoundingBox() : BoundingBox(); + const auto& r_local_bb = mpSearchObject ? mpSearchObject->GetBoundingBox() : BoundingBox(); // Perform the corresponding searches const std::size_t total_number_of_points = all_points_coordinates.size()/3; @@ -666,7 +666,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper // Perform local search const Point point(all_points_coordinates[i_point * 3 + 0], all_points_coordinates[i_point * 3 + 1], all_points_coordinates[i_point * 3 + 2]); auto& r_partial_result = rResults.InitializeResult(all_points_ids[i_point]); - + // Result of search ResultType local_result; @@ -720,7 +720,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper // Retrieving parameters const int allocation_size = mSettings["allocation_size"].GetInt(); - + // Prepare MPI search std::vector all_points_coordinates; std::vector all_points_ids; @@ -795,7 +795,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper if (ClearSolution) { rResults.Clear(); } - + // Prepare MPI search std::vector all_points_coordinates; std::vector all_points_ids; @@ -805,7 +805,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper const int current_rank = GetRank(); // The local bounding box - const auto& r_local_bb = mpSearchObject ? mpSearchObject->GetBoundingBox() : BoundingBox(); + const auto& r_local_bb = mpSearchObject ? mpSearchObject->GetBoundingBox() : BoundingBox(); // Perform the corresponding searches const std::size_t total_number_of_points = all_points_coordinates.size()/3; @@ -872,7 +872,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper */ void LocalSearchNearestInRadius( const PointType& rPoint, - const double Radius, + const double Radius, ResultType& rResult, const int AllocationSize = 1000 ); @@ -885,7 +885,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper * @param rResult The result of the search */ void LocalSearchNearest( - const PointType& rPoint, + const PointType& rPoint, ResultType& rResult ); @@ -899,7 +899,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper * @param rResult The result of the search */ void LocalSearchIsInside( - const PointType& rPoint, + const PointType& rPoint, ResultType& rResult );