I want to implement a kd-tree quick nearest-neighbor lookup inside my Abaqus subroutine.
I have a long list of XYZ coordinates that need to be checked against integration points. The subroutine in question is DFLUX. For clarity, the subroutine runs at each integration point.
My subroutine runs smoothly, but as soon as I refine the mesh the analysis becomes very slow. This is in my opinion due to the high number of points. Therefore a kd-search, instead of my current linear search with an Euclidean distance.
I am looking into Scipy as there's already a class implemented, so I thought the easiest is to somehow call some Python inside my subroutine. I looked up and it seems possible but not an easy task. The opposite is quite common as there are some interfacing utilities out there already. The other option would be to implement a kd-tree in Fortran, but I am not the best programmer in Fortran yet, so that is why I am hesitant.
Please, let me know what is the best way to address this task.
My subroutine works as expected, but I want to optimize it for speed. To increase accuracy I also need to refine my mesh. This will generate more integration points. Therefore the idea is to substitute the linear search with kd-tree quick nearest-neighbor lookup.