added function for finding the (non-periodic) nearest neighbor

This commit is contained in:
Christoph Kords 2013-03-27 10:14:44 +00:00
parent 44eb771583
commit e25af5db04
2 changed files with 39 additions and 1 deletions

View File

@ -70,6 +70,14 @@ python module core ! in
real*8, dimension(size(field,1),size(field,2),size(field,3),size(field,4)), depend(field) :: math_divergenceFDM
end function math_divergenceFDM
function math_nearestNeighbor(querySet,domainSet) ! in :math:math.f90
! input variables
real*8, dimension(:,:), intent(in) :: querySet
real*8, dimension(:,:), intent(in) :: domainSet
! function definition
integer, dimension(size(querySet,2)), depend(querySet) :: math_nearestNeighbor
end function math_nearestNeighbor
function math_periodicNearestNeighbor(geomdim,Favg,querySet,domainSet) ! in :math:math.f90
! input variables
real*8, dimension(3), intent(in) :: geomdim

View File

@ -3177,7 +3177,7 @@ function math_divergenceFDM(geomdim,order,field)
end function math_divergenceFDM
!--------------------------------------------------------------------------------------------------
!> @brief Obtain the nearest neighbor from domainSet at points in querySet
!> @brief Obtain the nearest neighbor from periodic domainSet at points in querySet
!--------------------------------------------------------------------------------------------------
function math_periodicNearestNeighbor(geomdim, Favg, querySet, domainSet)
use kdtree2_module
@ -3227,6 +3227,36 @@ function math_periodicNearestNeighbor(geomdim, Favg, querySet, domainSet)
end function math_periodicNearestNeighbor
!--------------------------------------------------------------------------------------------------
!> @brief Obtain the nearest neighbor from domainSet at points in querySet
!--------------------------------------------------------------------------------------------------
function math_nearestNeighbor(querySet, domainSet)
use kdtree2_module
use IO, only: &
IO_error
implicit none
real(pReal), dimension(:,:), intent(in) :: querySet
real(pReal), dimension(:,:), intent(in) :: domainSet
integer(pInt), dimension(size(querySet,2)) :: math_nearestNeighbor
integer(pInt) :: i,j, l,m,n, spatialDim
type(kdtree2), pointer :: tree
type(kdtree2_result), dimension(1) :: Results
if (size(querySet,1) /= size(domainSet,1)) call IO_error(407_pInt,ext_msg='query set')
spatialDim = size(querySet,1)
tree => kdtree2_create(domainSet,sort=.true.,rearrange=.true.)
do j = 1_pInt, size(querySet,2)
call kdtree2_n_nearest(tp=tree, qv=querySet(1:spatialDim,j),nn=1_pInt, results = Results)
math_nearestNeighbor(j) = Results(1)%idx
enddo
math_nearestNeighbor = math_nearestNeighbor -1_pInt ! let them run from 0 to domainPoints -1
end function math_nearestNeighbor
!--------------------------------------------------------------------------------------------------
!> @brief Obtain the distances to the next N nearest neighbors from domainSet at points in querySet