# An Optimized Linked-Cell NNPS Algorithm in Meshless CFD Methods **Repository Path**: zoziha/nnps ## Basic Information - **Project Name**: An Optimized Linked-Cell NNPS Algorithm in Meshless CFD Methods - **Description**: 模块化+面向对象设计,用于SPH、MPS等CFD粒子方法的近邻粒子搜索 - **Primary Language**: FORTRAN - **License**: MIT - **Default Branch**: main - **Homepage**: https://nnps.netlify.app/ - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2022-03-10 - **Last Updated**: 2025-08-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: nnps, cfd, sph ## README
# NNPS for Particle Simulation ![NNPS](https://img.shields.io/badge/NNPS-v1.5.2409-blueviolet) ![Language](https://img.shields.io/badge/-Fortran-734f96?logo=fortran&logoColor=white) ![license](https://img.shields.io/badge/License-MIT-pink)
Nearest Neighbor Particle Search (NNPS) scheme practice for particle simulation, coded in Modern Fortran. ## Build Only GFortran compiler and meson-build is supported. ```sh meson setup build meson compile -C build ``` Build the documentation with `doxygen`: ```sh doxygen ./doc/doxyfile start ./build/Doxygen/html/index.html # Open the HTML file with browser in Windows ``` ## Example ```sh ./build/example_grid2d.exe ``` ```fortran program example_grid2d use nnps_module, only: nnps_grid2d, wp use display_module, only: display implicit none type(nnps_grid2d) :: nnps real(wp), dimension(2, 4) :: loc = reshape([0.0_wp, 1.0_wp, 2.0_wp, 1.5_wp, & 1.0_wp, 1.0_wp, 0.5_wp, 1.0_wp], [2, 4]) integer, pointer :: pairs(:) real(wp), pointer :: rdxs(:) call nnps%init(loc, n=4) call nnps%query(0.6_wp, pairs, rdxs, n=4) print *, '*** grid find (2D)' call display(pairs, 'pairs index:', brief=.false.) call display(loc(:, pairs), 'pairs coordinates:', brief=.false.) call display(rdxs, 'rdxs:', brief=.false.) end program example_grid2d ! *** grid find (2D) ! [vector_type: 4] pairs index: ! 3, 4, 4, 1 ! [matrix: 2*4] pairs coordinates: ! 1.000E+00, 5.000E-01, 5.000E-01, 0.000E+00; ! 1.000E+00, 1.000E+00, 1.000E+00, 1.000E+00 ! [vector_type: 6] rdxs: ! 5.000E-01, 5.000E-01, 0.000E+00, 5.000E-01, 5.000E-01, 0.000E+00 ``` ## Benchmark There are some benchmarks in the `test` folder. Set `OMP_NUM_THREADS` environment variable to control the number of threads. ```sh export OMP_NUM_THREADS=4 ./build/bench2dn-grid.exe 10000 1.0 # choose 10k particles and loading_factor = 1.0 for benchmark program ``` ## Links + [wikipedia/Quadtree](https://en.wikipedia.org/wiki/Quadtree) + [lewisfish/quad-tree](https://github.com/lewisfish/quad-trees) + [bilibili/Dejavu32/[Coding Challenge ]:四叉树的实现 以及 碰撞检测应用(Quadtree Collisions )](https://www.bilibili.com/video/BV1ub411S7N5?spm_id_from=333.999.0.0) + [CodingTrain/QuadTree](https://github.com/CodingTrain/QuadTree)