Speed up cell search tree building in case of large LGRs (#13134)

* Speed up cell search tree building for larger LGRs by pre-calculating information needed
This commit is contained in:
JJ
2025-11-06 07:05:17 +01:00
committed by GitHub
parent 7afa639928
commit 3b24586c61
@@ -920,6 +920,27 @@ void RigMainGrid::buildCellSearchTree() const
//--------------------------------------------------------------------------------------------------
void RigMainGrid::buildCellSearchTreeOptimized( size_t cellsPerBoundingBox ) const
{
// map from main grid cell index to list of LGR cells with main grid cell as parent cell
// used to speed up cell children lookup during search tree building
std::map<size_t, std::vector<int>> subCellIndicesForMainGridCells;
for ( auto& subGrid : m_localGrids )
{
if ( subGrid->parentGrid() == this )
{
for ( size_t localIdx = 0; localIdx < subGrid->cellCount(); localIdx++ )
{
const auto& localCell = subGrid->cell( localIdx );
if ( localCell.isInvalid() ) continue;
if ( !subCellIndicesForMainGridCells.contains( localCell.mainGridCellIndex() ) )
{
subCellIndicesForMainGridCells[localCell.mainGridCellIndex()] = {};
}
subCellIndicesForMainGridCells[localCell.mainGridCellIndex()].push_back( (int)subGrid->reservoirCellIndex( localIdx ) );
}
}
}
int threadCount = RiaOpenMPTools::availableThreadCount();
std::vector<std::vector<std::vector<int>>> threadCellIndicesForBoundingBoxes( threadCount );
@@ -951,17 +972,10 @@ void RigMainGrid::buildCellSearchTreeOptimized( size_t cellsPerBoundingBox ) con
{
aggregatedCellIndices.push_back( static_cast<int>( cellIdx ) );
// Add all cells in sub grid contained in this main grid cell
if ( auto subGrid = rigCell.subGrid() )
if ( subCellIndicesForMainGridCells.contains( cellIdx ) )
{
for ( size_t localIdx = 0; localIdx < subGrid->cellCount(); localIdx++ )
{
const auto& localCell = subGrid->cell( localIdx );
if ( localCell.mainGridCellIndex() == cellIdx )
{
aggregatedCellIndices.push_back( static_cast<int>( subGrid->reservoirCellIndex( localIdx ) ) );
}
}
const auto& subCellIndices = subCellIndicesForMainGridCells[cellIdx];
aggregatedCellIndices.insert( aggregatedCellIndices.end(), subCellIndices.begin(), subCellIndices.end() );
}
const std::array<size_t, 8>& cellIndices = rigCell.cornerIndices();