Understanding the search for neighboring particles in the program fluidv3 , could not someone explain how it happens
SetupGridAllocate ( Vector3DF min, Vector3DF max, float sim_scale, float cell_size, float border ) { float world_cellsize = cell_size / sim_scale; m_GridMin = min; m_GridMax = max; m_GridSize = m_GridMax; m_GridSize -= m_GridMin; m_GridRes.x = ceil ( m_GridSize.x / world_cellsize ); m_GridRes.y = ceil ( m_GridSize.y / world_cellsize ); m_GridRes.z = ceil ( m_GridSize.z / world_cellsize ); m_GridSize.x = m_GridRes.x * cell_size / sim_scale; m_GridSize.y = m_GridRes.y * cell_size / sim_scale; m_GridSize.z = m_GridRes.z * cell_size / sim_scale; m_GridDelta = m_GridRes; m_GridDelta /= m_GridSize; m_GridTotal = (int)(m_GridRes.x * m_GridRes.y * m_GridRes.z); // Allocate grid if ( m_Grid == 0x0 ) free (m_Grid); if ( m_GridCnt == 0x0 ) free (m_GridCnt); m_Grid = (uint*) malloc ( sizeof(uint*) * m_GridTotal ); m_GridCnt = (uint*) malloc ( sizeof(uint*) * m_GridTotal ); memset ( m_Grid, GRID_UCHAR, m_GridTotal*sizeof(uint) ); memset ( m_GridCnt, GRID_UCHAR, m_GridTotal*sizeof(uint) ); m_Param[PSTAT_GMEM] = 12 * m_GridTotal; // Grid memory used // Number of cells to search: // n = (2r / w) +1, where n = 1D cell search count, r = search radius, w = world cell width // m_GridSrch = floor(2*(m_Param[PSMOOTHRADIUS]/sim_scale) / world_cellsize) + 1; if ( m_GridSrch < 2 ) m_GridSrch = 2; m_GridAdjCnt = m_GridSrch * m_GridSrch * m_GridSrch ; if ( m_GridSrch > 6 ) { app_printf ( "ERROR: Neighbor search is n > 6. \n " ); exit(-1); } int cell = 0; // Не понимаю этот участок for (int y=0; y < m_GridSrch; y++ ) for (int z=0; z < m_GridSrch; z++ ) for (int x=0; x < m_GridSrch; x++ ) m_GridAdj[cell++] = ( y*m_GridRes.z + z )*m_GridRes.x + x ; // -1 compensates for ndx 0=empty app_printf ( "Adjacency table (CPU) \n"); for (int n=0; n < m_GridAdjCnt; n++ ) { app_printf ( " ADJ: %d, %d\n", n, m_GridAdj[n] ); } if ( mPackGrid != 0x0 ) free ( mPackGrid ); mPackGrid = (int*) malloc ( sizeof(int) * m_GridTotal ); } and this part how to search
for ( i=0; i < NumPoints(); i++ ) { sum = 0.0; if ( *(mGridCell+i) != GRID_UNDEF ) { for (int cell=0; cell < m_GridAdjCnt; cell++) { j = m_Grid [ *(mGridCell+i) - nadj + m_GridAdj[cell] ] ; while ( j != GRID_UNDEF ) { if ( i==j ) { j = *(mGridNext+j) ; continue; } //вычисление } }