Skip to content

Commit

Permalink
Setting missing rank
Browse files Browse the repository at this point in the history
  • Loading branch information
loumalouomega committed Nov 3, 2023
1 parent e7ff186 commit d6873a9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
27 changes: 18 additions & 9 deletions kratos/spatial_containers/search_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,22 @@ void SearchWrapper<TSearchObject>::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) {
PointVector results(AllocationSize);
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) {
Expand All @@ -198,9 +201,13 @@ void SearchWrapper<TSearchObject>::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) {
Expand All @@ -211,9 +218,6 @@ void SearchWrapper<TSearchObject>::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());

Expand All @@ -237,15 +241,16 @@ void SearchWrapper<TSearchObject>::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);
Expand All @@ -266,9 +271,13 @@ void SearchWrapper<TSearchObject>::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;
}
Expand Down
34 changes: 17 additions & 17 deletions kratos/spatial_containers/search_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper
if (rGeometricalObjectsVector.size() > 0) {
// Defining the PointVector
mpPointVector = Kratos::make_unique<PointVector>(SearchUtilities::PreparePointsSearch(rGeometricalObjectsVector));

// Create the search object
if constexpr (!IsDynamicBins) {
const int bucket_size = mSettings["bucket_size"].GetInt();
Expand Down Expand Up @@ -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
)
{
Expand Down Expand Up @@ -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
)
{
Expand All @@ -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);

Expand All @@ -482,7 +482,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper
void SerialSearchNearest(
TPointIteratorType itPointBegin,
TPointIteratorType itPointEnd,
ResultContainerVectorType& rResults,
ResultContainerVectorType& rResults,
const bool ClearSolution = true
)
{
Expand All @@ -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;
}
Expand All @@ -529,7 +529,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper
void SerialSearchIsInside(
TPointIteratorType itPointBegin,
TPointIteratorType itPointEnd,
ResultContainerVectorType& rResults,
ResultContainerVectorType& rResults,
const bool ClearSolution = true
)
{
Expand Down Expand Up @@ -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<PointType>();
const auto& r_local_bb = mpSearchObject ? mpSearchObject->GetBoundingBox() : BoundingBox<PointType>();

// Perform the corresponding searches
const std::size_t total_number_of_points = all_points_coordinates.size()/3;
Expand Down Expand Up @@ -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<PointType>();
const auto& r_local_bb = mpSearchObject ? mpSearchObject->GetBoundingBox() : BoundingBox<PointType>();

// Perform the corresponding searches
const std::size_t total_number_of_points = all_points_coordinates.size()/3;
Expand All @@ -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;

Expand Down Expand Up @@ -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<double> all_points_coordinates;
std::vector<IndexType> all_points_ids;
Expand Down Expand Up @@ -795,7 +795,7 @@ class KRATOS_API(KRATOS_CORE) SearchWrapper
if (ClearSolution) {
rResults.Clear();
}

// Prepare MPI search
std::vector<double> all_points_coordinates;
std::vector<IndexType> all_points_ids;
Expand All @@ -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<PointType>();
const auto& r_local_bb = mpSearchObject ? mpSearchObject->GetBoundingBox() : BoundingBox<PointType>();

// Perform the corresponding searches
const std::size_t total_number_of_points = all_points_coordinates.size()/3;
Expand Down Expand Up @@ -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
);
Expand All @@ -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
);

Expand All @@ -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
);

Expand Down

0 comments on commit d6873a9

Please sign in to comment.