From 445e4bf158d987ab662a73482c3afd4d1c663b77 Mon Sep 17 00:00:00 2001 From: Roy Stogner Date: Fri, 3 Nov 2023 15:17:16 -0500 Subject: [PATCH] Support old Nanoflann API *and* new Nanoflann API This gets us around the chicken-and-egg problem of not being able to get the Nanoflann update in libMesh to pass MOOSE tests. Remember to build backwards compatibility into your library API updates, kids! We can remove the `namespace nanoflann` shims after the update makes it into the libMesh submodule. Refs #25904, but we can wait until the shims are gone before we close that ticket. --- framework/include/utils/KDTree.h | 11 ++++++++++- .../src/constraints/AutomaticMortarGeneration.C | 15 ++++++++++++--- framework/src/mesh/MooseMesh.C | 15 +++++++++++++-- framework/src/userobjects/RadialAverage.C | 15 +++++++++++++-- .../src/userobjects/ThreadedRadialAverageLoop.C | 16 ++++++++++++++-- framework/src/utils/KDTree.C | 15 +++++++++++++-- modules/contact/src/actions/ContactAction.C | 15 +++++++++++++-- 7 files changed, 88 insertions(+), 14 deletions(-) diff --git a/framework/include/utils/KDTree.h b/framework/include/utils/KDTree.h index df353bd3bb19..993132c25e05 100644 --- a/framework/include/utils/KDTree.h +++ b/framework/include/utils/KDTree.h @@ -16,6 +16,15 @@ #include "libmesh/nanoflann.hpp" #include "libmesh/utility.h" +// Make newer nanoflann API compatible with older nanoflann versions +#if NANOFLANN_VERSION < 0x150 +namespace nanoflann +{ +template +using ResultItem = std::pair; +} +#endif + class KDTree { public: @@ -34,7 +43,7 @@ class KDTree void radiusSearch(const Point & query_point, Real radius, - std::vector> & indices_dist); + std::vector> & indices_dist); std::size_t numberCandidatePoints(); diff --git a/framework/src/constraints/AutomaticMortarGeneration.C b/framework/src/constraints/AutomaticMortarGeneration.C index 692fb881dafb..7ffa3bed0dfb 100644 --- a/framework/src/constraints/AutomaticMortarGeneration.C +++ b/framework/src/constraints/AutomaticMortarGeneration.C @@ -49,6 +49,15 @@ using namespace libMesh; using MetaPhysicL::DualNumber; +// Make newer nanoflann API spelling compatible with older nanoflann +// versions +#if NANOFLANN_VERSION < 0x150 +namespace nanoflann +{ +typedef SearchParams SearchParameters; +} +#endif + class MortarNodalGeometryOutput : public Output { public: @@ -1109,7 +1118,7 @@ AutomaticMortarGeneration::buildMortarSegmentMesh3d() std::vector out_dist_sqr(num_results); nanoflann::KNNResultSet result_set(num_results); result_set.init(&ret_index[0], &out_dist_sqr[0]); - kd_tree.findNeighbors(result_set, &query_pt[0], nanoflann::SearchParams(10)); + kd_tree.findNeighbors(result_set, &query_pt[0], nanoflann::SearchParameters(10)); // Initialize list of processed primary elements, we don't want to revisit processed elements std::set processed_primary_elems; @@ -1918,7 +1927,7 @@ AutomaticMortarGeneration::projectSecondaryNodesSinglePair( std::vector out_dist_sqr(num_results); nanoflann::KNNResultSet result_set(num_results); result_set.init(&ret_index[0], &out_dist_sqr[0]); - kd_tree.findNeighbors(result_set, &query_pt[0], nanoflann::SearchParams(10)); + kd_tree.findNeighbors(result_set, &query_pt[0], nanoflann::SearchParameters(10)); // If this flag gets set in the loop below, we can break out of the outer r-loop as well. bool projection_succeeded = false; @@ -2217,7 +2226,7 @@ AutomaticMortarGeneration::projectPrimaryNodesSinglePair( std::vector out_dist_sqr(num_results); nanoflann::KNNResultSet result_set(num_results); result_set.init(&ret_index[0], &out_dist_sqr[0]); - kd_tree.findNeighbors(result_set, &query_pt[0], nanoflann::SearchParams(10)); + kd_tree.findNeighbors(result_set, &query_pt[0], nanoflann::SearchParameters(10)); // If this flag gets set in the loop below, we can break out of the outer r-loop as well. bool projection_succeeded = false; diff --git a/framework/src/mesh/MooseMesh.C b/framework/src/mesh/MooseMesh.C index f0d364f6af34..1bc681ee9c82 100644 --- a/framework/src/mesh/MooseMesh.C +++ b/framework/src/mesh/MooseMesh.C @@ -62,6 +62,17 @@ static const int GRAIN_SIZE = 1; // the grain_size does not have much influence on our execution speed +// Make newer nanoflann API compatible with older nanoflann versions +#if NANOFLANN_VERSION < 0x150 +namespace nanoflann +{ +typedef SearchParams SearchParameters; + +template +using ResultItem = std::pair; +} +#endif + InputParameters MooseMesh::validParams() { @@ -1586,8 +1597,8 @@ MooseMesh::buildPeriodicNodeMap(std::multimap & period kd_tree->buildIndex(); // data structures for kd-tree search - nanoflann::SearchParams search_params; - std::vector> ret_matches; + nanoflann::SearchParameters search_params; + std::vector> ret_matches; // iterate over periodic nodes (boundary ids are in contiguous blocks) PeriodicBoundaryBase * periodic = nullptr; diff --git a/framework/src/userobjects/RadialAverage.C b/framework/src/userobjects/RadialAverage.C index 6d29aad389e0..e76d4ae63730 100644 --- a/framework/src/userobjects/RadialAverage.C +++ b/framework/src/userobjects/RadialAverage.C @@ -20,6 +20,17 @@ #include #include +// Make newer nanoflann API compatible with older nanoflann versions +#if NANOFLANN_VERSION < 0x150 +namespace nanoflann +{ +typedef SearchParams SearchParameters; + +template +using ResultItem = std::pair; +} +#endif + registerMooseObject("MooseApp", RadialAverage); // specialization for PointListAdaptor @@ -250,8 +261,8 @@ RadialAverage::updateCommunicationLists() mooseAssert(kd_tree != nullptr, "KDTree was not properly initialized."); kd_tree->buildIndex(); - std::vector> ret_matches; - nanoflann::SearchParams search_params; + std::vector> ret_matches; + nanoflann::SearchParameters search_params; // iterate over all boundary nodes and collect all boundary-near data points _boundary_data_indices.clear(); diff --git a/framework/src/userobjects/ThreadedRadialAverageLoop.C b/framework/src/userobjects/ThreadedRadialAverageLoop.C index d6b76a619191..2fa398fd105d 100644 --- a/framework/src/userobjects/ThreadedRadialAverageLoop.C +++ b/framework/src/userobjects/ThreadedRadialAverageLoop.C @@ -10,6 +10,18 @@ #include "ThreadedRadialAverageLoop.h" #include "Function.h" +// Make newer nanoflann API spelling compatible with older nanoflann +// versions +#if NANOFLANN_VERSION < 0x150 +namespace nanoflann +{ +typedef SearchParams SearchParameters; + +template +using ResultItem = std::pair; +} +#endif + ThreadedRadialAverageLoop::ThreadedRadialAverageLoop(RadialAverage & green) : _radavg(green) {} // Splitting Constructor @@ -29,8 +41,8 @@ ThreadedRadialAverageLoop::operator()(const QPDataRange & qpdata_range) const auto & weights_type = _radavg._weights_type; // tree search data structures - std::vector> ret_matches; - nanoflann::SearchParams search_params; + std::vector> ret_matches; + nanoflann::SearchParameters search_params; // result map entry const auto end_it = _radavg._average.end(); diff --git a/framework/src/utils/KDTree.C b/framework/src/utils/KDTree.C index 30ea49dcbf07..3b3e6ab15ebc 100644 --- a/framework/src/utils/KDTree.C +++ b/framework/src/utils/KDTree.C @@ -13,6 +13,17 @@ #include "libmesh/nanoflann.hpp" #include "libmesh/point.h" +// Make newer nanoflann API compatible with older nanoflann versions +#if NANOFLANN_VERSION < 0x150 +namespace nanoflann +{ +typedef SearchParams SearchParameters; + +template +using ResultItem = std::pair; +} +#endif + KDTree::KDTree(std::vector & master_points, unsigned int max_leaf_size) : _point_list_adaptor(master_points.begin(), master_points.end()), _kd_tree(std::make_unique( @@ -53,9 +64,9 @@ KDTree::neighborSearch(const Point & query_point, void KDTree::radiusSearch(const Point & query_point, Real radius, - std::vector> & indices_dist) + std::vector> & indices_dist) { - nanoflann::SearchParams sp; + nanoflann::SearchParameters sp; _kd_tree->radiusSearch(&query_point(0), radius * radius, indices_dist, sp); } diff --git a/modules/contact/src/actions/ContactAction.C b/modules/contact/src/actions/ContactAction.C index a9e2cedf3e15..e666a7a30a78 100644 --- a/modules/contact/src/actions/ContactAction.C +++ b/modules/contact/src/actions/ContactAction.C @@ -29,6 +29,17 @@ #include "libmesh/petsc_nonlinear_solver.h" #include "libmesh/string_to_enum.h" +// Make newer nanoflann API compatible with older nanoflann versions +#if NANOFLANN_VERSION < 0x150 +namespace nanoflann +{ +typedef SearchParams SearchParameters; + +template +using ResultItem = std::pair; +} +#endif + using NodeBoundaryIDInfo = std::pair; // Counter for naming mortar auxiliary kernels @@ -1291,8 +1302,8 @@ ContactAction::createSidesetsFromNodeProximity() kd_tree->buildIndex(); // data structures for kd-tree search - nanoflann::SearchParams search_params; - std::vector> ret_matches; + nanoflann::SearchParameters search_params; + std::vector> ret_matches; const auto radius_for_search = getParam("automatic_pairing_distance");