kdTree_test.f90 Source File


This file depends on

sourcefile~~kdtree_test.f90~~EfferentGraph sourcefile~kdtree_test.f90 kdTree_test.f90 sourcefile~kdtree.f90 kdTree.f90 sourcefile~kdtree_test.f90->sourcefile~kdtree.f90 sourcefile~path_operator.f90 path_operator.f90 sourcefile~kdtree_test.f90->sourcefile~path_operator.f90 sourcefile~unstructuredgrid.f90 unstructuredGrid.f90 sourcefile~kdtree_test.f90->sourcefile~unstructuredgrid.f90 sourcefile~sort.f90 sort.f90 sourcefile~kdtree.f90->sourcefile~sort.f90 sourcefile~terminalcontroler.f90 terminalControler.f90 sourcefile~kdtree.f90->sourcefile~terminalcontroler.f90 sourcefile~unstructuredgrid.f90->sourcefile~kdtree.f90 sourcefile~unstructuredgrid.f90->sourcefile~path_operator.f90 sourcefile~adjacency_solver.f90 adjacency_solver.f90 sourcefile~unstructuredgrid.f90->sourcefile~adjacency_solver.f90 sourcefile~array.f90 array.f90 sourcefile~unstructuredgrid.f90->sourcefile~array.f90 sourcefile~scffile_reader.f90 SCFfile_reader.f90 sourcefile~unstructuredgrid.f90->sourcefile~scffile_reader.f90 sourcefile~sctfile_reader.f90 SCTfile_reader.f90 sourcefile~unstructuredgrid.f90->sourcefile~sctfile_reader.f90 sourcefile~unstructuredelement.f90 unstructuredElement.f90 sourcefile~unstructuredgrid.f90->sourcefile~unstructuredelement.f90 sourcefile~vector.f90 vector.f90 sourcefile~unstructuredgrid.f90->sourcefile~vector.f90 sourcefile~vtkmesh_operator.f90 vtkMesh_operator.f90 sourcefile~unstructuredgrid.f90->sourcefile~vtkmesh_operator.f90 sourcefile~adjacency_solver.f90->sourcefile~terminalcontroler.f90 sourcefile~scffile_reader.f90->sourcefile~terminalcontroler.f90 sourcefile~vtkmesh_operator.f90->sourcefile~unstructuredelement.f90

Contents

Source Code


Source Code

program kdTree_test
    !!kdTreeによる探索結果と、厳密なnearest探索結果が一致するかどうかをテスト
    use kdTree_m
    use path_operator_m
    use unstructuredGrid_m
    implicit none 
    type(FlowFieldUnstructuredGrid) grid
    real, allocatable :: xyz(:,:)
    type(kdTree) kd_tree
    ! integer n_unit 
    integer iimx
    character(:), allocatable :: vtkFName, kd_treeFName
    character(10), parameter :: output_dir = 'test_check'
    logical existance

    vtkFName = "VTK/sample.vtk"
    kd_treeFName = "kdTreeOfsample.txt"
    call make_directory(output_dir)
    call grid%setupWithFlowFieldFile(vtkFName)
    iimx = grid%get_info('cell')
    xyz = grid%get_allOfCellCenters()



    inquire(file = output_dir//'/'//kd_treeFName, exist=existance)
    if(.not.existance) then

        kd_tree = kdTree_(xyz)
        call kd_tree%saveAsDOT(xyz, output_dir//'/kdTree.dot')
        call kd_tree%saveAsTXT(output_dir//'/'//kd_treeFName)
    
    else

        call kd_tree%read_kdTree(output_dir//'/'//kd_treeFName)

    end if

    call test

    contains

    subroutine test
        !!乱数で発生させた点に対して、kdTreeによる探索結果と、厳密なnearest探索結果が一致するかどうかをテスト
        integer, parameter :: num_test = 10000
        integer n
        integer result_exact, result_kdTree
        real, dimension(3) :: min_cdn, max_cdn, delta, rand,  point

        call grid%get_MinMaxOfGrid(min_cdn, max_cdn)
        delta = max_cdn - min_cdn

        do n = 1, num_test
            call random_number(rand)
            point = min_cdn + delta*rand
            ! print*, point

            result_exact = grid%nearest_search_exact(point)
            call kd_tree%search(xyz, point, result_kdTree)

            if(result_exact /= result_kdTree) then
                print*, point
                print*, result_exact, xyz(:, result_exact)
                print*, result_kdTree, xyz(:, result_kdTree)
                error stop
            end if

        end do

    end subroutine

end program kdTree_test