Optimization notes: Part 1
less than a minute
KdTree and radius-based searches
When it comes to k-nearest neighbor (KNN) searches with unsorted radius queries in C++, I’ve decided to utilize nanoflann as the backend for these operations.
Their API is user-friendly, but there’s a specific challenge with the dynamic KdTree
. During my testing of the KdTree wrapper, I noticed that modifying the list of point positions for searches can be tricky. To address this, I’ve implemented a solution where I hash the current list and compare it before each KNN search.
If the point list has undergone significant changes, the KdTree index becomes invalid and needs resetting. However, if the list only receives new points without alterations to old ones, I simply add the new points to the index.
At this point, I have three key unanswered questions:
- What’s the efficiency of hashing the point list?
- How efficient is OpenFOAM’s implementation of the Jenkins hasher?
- Is resetting the KdTree index efficient compared to removing all points and adding the new ones?