From b4921c2a1378f966cb7e80dc930525de88894cb1 Mon Sep 17 00:00:00 2001 From: Vicente Mataix Ferrandiz Date: Fri, 15 Dec 2023 16:16:01 +0100 Subject: [PATCH] More generic --- kratos/utilities/search_utilities.h | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/kratos/utilities/search_utilities.h b/kratos/utilities/search_utilities.h index a636605f2d6f..3568b00fd144 100644 --- a/kratos/utilities/search_utilities.h +++ b/kratos/utilities/search_utilities.h @@ -656,9 +656,23 @@ class SearchUtilities std::vector& rAllPointsIds, const DataCommunicator& rDataCommunicator, const int NumberOfPoints, - const int TotalNumberOfPoints + const int TotalNumberOfPoints, + const bool IndexItIsJustCounter = false ) { + // Define lambda to retrieve Id + const auto GetIdNode = [](std::vector& rIds, TPointIteratorType& ItPoint, const std::size_t Counter, const std::size_t InitialId) { + if constexpr (std::is_same::value || std::is_same::value) { + rIds[Counter] = ItPoint->Id(); + } else { + rIds[Counter] = InitialId + Counter; + } + }; + const auto GetIdJustCounter = [](std::vector& rIds, TPointIteratorType& ItPoint, const std::size_t Counter, const std::size_t InitialId) { + rIds[Counter] = Counter; + }; + const auto GetId = IndexItIsJustCounter ? GetIdJustCounter : GetIdNode; + // Get the World Size and rank in MPI const int world_size = rDataCommunicator.Size(); const int rank = rDataCommunicator.Rank(); @@ -701,11 +715,7 @@ class SearchUtilities } } noalias(coordinates) = it_point->Coordinates(); - if constexpr (std::is_same::value || std::is_same::value) { - send_points_ids[counter] = it_point->Id(); - } else { - send_points_ids[counter] = initial_id + counter; - } + GetId(send_points_ids, it_point, counter, initial_id); send_points_ranks[counter] = rank; for (i_coord = 0; i_coord < 3; ++i_coord) { send_points_coordinates[3 * counter + i_coord] = coordinates[i_coord];