Other improvements to bounding box calculation

This commit is contained in:
Gaute Lindkvist
2020-05-13 12:09:07 +02:00
parent 64b0687dee
commit 99aa65c611
3 changed files with 63 additions and 33 deletions

View File

@@ -28,6 +28,8 @@
#include "cvfAssert.h"
#include "cvfBoundingBoxTree.h"
#include <omp.h>
RigMainGrid::RigMainGrid()
: RigGridBase( this )
{
@@ -710,38 +712,55 @@ void RigMainGrid::buildCellSearchTree()
size_t cellCount = m_cells.size();
std::vector<size_t> cellIndicesForBoundingBoxes;
cellIndicesForBoundingBoxes.reserve( cellCount );
std::vector<size_t> cellIndicesForBoundingBoxes;
std::vector<cvf::BoundingBox> cellBoundingBoxes;
cellBoundingBoxes.reserve( cellCount );
for ( size_t cIdx = 0; cIdx < cellCount; ++cIdx )
#pragma omp parallel
{
if ( m_cells[cIdx].isInvalid() ) continue;
size_t threadCellCount = std::ceil( cellCount / static_cast<double>( omp_get_num_threads() ) );
const std::array<size_t, 8>& cellIndices = m_cells[cIdx].cornerIndices();
std::vector<size_t> threadIndicesForBoundingBoxes;
std::vector<cvf::BoundingBox> threadBoundingBoxes;
cvf::BoundingBox cellBB;
cellBB.add( m_nodes[cellIndices[0]] );
cellBB.add( m_nodes[cellIndices[1]] );
cellBB.add( m_nodes[cellIndices[2]] );
cellBB.add( m_nodes[cellIndices[3]] );
cellBB.add( m_nodes[cellIndices[4]] );
cellBB.add( m_nodes[cellIndices[5]] );
cellBB.add( m_nodes[cellIndices[6]] );
cellBB.add( m_nodes[cellIndices[7]] );
threadIndicesForBoundingBoxes.reserve( threadCellCount );
threadBoundingBoxes.reserve( threadCellCount );
if ( cellBB.isValid() )
#pragma omp for
for ( int cIdx = 0; cIdx < (int)cellCount; ++cIdx )
{
cellIndicesForBoundingBoxes.emplace_back( cIdx );
cellBoundingBoxes.emplace_back( cellBB );
if ( m_cells[cIdx].isInvalid() ) continue;
const std::array<size_t, 8>& cellIndices = m_cells[cIdx].cornerIndices();
cvf::BoundingBox cellBB;
cellBB.add( m_nodes[cellIndices[0]] );
cellBB.add( m_nodes[cellIndices[1]] );
cellBB.add( m_nodes[cellIndices[2]] );
cellBB.add( m_nodes[cellIndices[3]] );
cellBB.add( m_nodes[cellIndices[4]] );
cellBB.add( m_nodes[cellIndices[5]] );
cellBB.add( m_nodes[cellIndices[6]] );
cellBB.add( m_nodes[cellIndices[7]] );
if ( cellBB.isValid() )
{
threadIndicesForBoundingBoxes.emplace_back( cIdx );
threadBoundingBoxes.emplace_back( cellBB );
}
}
threadIndicesForBoundingBoxes.shrink_to_fit();
threadBoundingBoxes.shrink_to_fit();
#pragma omp critical
{
cellIndicesForBoundingBoxes.insert( cellIndicesForBoundingBoxes.end(),
threadIndicesForBoundingBoxes.begin(),
threadIndicesForBoundingBoxes.end() );
cellBoundingBoxes.insert( cellBoundingBoxes.end(), threadBoundingBoxes.begin(), threadBoundingBoxes.end() );
}
}
cellIndicesForBoundingBoxes.shrink_to_fit();
cellBoundingBoxes.shrink_to_fit();
m_cellSearchTree = new cvf::BoundingBoxTree;
m_cellSearchTree->buildTreeFromBoundingBoxes( cellBoundingBoxes, &cellIndicesForBoundingBoxes );
}
@@ -868,10 +887,10 @@ void RigMainGrid::setDualPorosity( bool enable )
//--------------------------------------------------------------------------------------------------
std::array<double, 6> RigMainGrid::defaultMapAxes()
{
const double origin[2] = {0.0, 0.0};
const double xPoint[2] = {1.0, 0.0};
const double yPoint[2] = {0.0, 1.0};
const double origin[2] = { 0.0, 0.0 };
const double xPoint[2] = { 1.0, 0.0 };
const double yPoint[2] = { 0.0, 1.0 };
// Order (see Elipse Reference Manual for keyword MAPAXES): Y_x, Y_y, O_x, O_y, X_x, X_y
return {yPoint[0], yPoint[1], origin[0], origin[1], xPoint[0], xPoint[1]};
return { yPoint[0], yPoint[1], origin[0], origin[1], xPoint[0], xPoint[1] };
}

View File

@@ -63,7 +63,8 @@ void RigNNCData::processNativeConnections( const RigMainGrid& mainGrid )
{
// cvf::Trace::show("NNC: Total number: " + cvf::String((int)m_connections.size()));
for ( size_t cnIdx = 0; cnIdx < m_connections.size(); ++cnIdx )
#pragma omp parallel for
for ( int cnIdx = 0; cnIdx < (int) m_connections.size(); ++cnIdx )
{
const RigCell& c1 = mainGrid.globalCellArray()[m_connections[cnIdx].c1GlobIdx()];
const RigCell& c2 = mainGrid.globalCellArray()[m_connections[cnIdx].c2GlobIdx()];

View File

@@ -210,6 +210,7 @@ namespace cvf {
};
std::deque<InternalNodeAndRange> m_previousLevelNodes;
std::deque<InternalNodeAndRange> m_currentLevelNodes;
};
class BoundingBoxTreeImpl : public AABBTree
@@ -493,7 +494,7 @@ bool AABBTree::buildTree()
bRes = bRes && bThreadRes;
}
}
m_previousLevelNodes.clear();
m_previousLevelNodes.swap(m_currentLevelNodes);
#pragma omp parallel
{
@@ -501,13 +502,14 @@ bool AABBTree::buildTree()
#pragma omp for schedule(guided)
for (int i = 0; i < m_previousLevelNodes.size(); ++i)
{
bThreadRes = bThreadRes && buildTree(m_previousLevelNodes[i].node, m_previousLevelNodes[i].fromIdx, m_previousLevelNodes[i].toIdx, 7);
bThreadRes = bThreadRes && buildTree(m_previousLevelNodes[i].node, m_previousLevelNodes[i].fromIdx, m_previousLevelNodes[i].toIdx, 6);
}
#pragma omp critical
{
bRes = bRes && bThreadRes;
}
}
CVF_ASSERT(m_currentLevelNodes.empty());
m_previousLevelNodes.clear();
return bRes;
@@ -524,7 +526,7 @@ bool AABBTree::buildTree(AABBTreeNodeInternal* pNode, size_t iFromIdx, size_t iT
{
#pragma omp critical
{
m_previousLevelNodes.emplace_back(pNode, iFromIdx, iToIdx);
m_currentLevelNodes.emplace_back(pNode, iFromIdx, iToIdx);
}
return true;
}
@@ -569,7 +571,11 @@ bool AABBTree::buildTree(AABBTreeNodeInternal* pNode, size_t iFromIdx, size_t iT
{
cvf::BoundingBox box = leafBoundingBox(iFromIdx, iMid);
AABBTreeNodeInternal* newNode = createNode();
AABBTreeNodeInternal* newNode = nullptr;
#pragma omp critical
{
newNode = createNode();
}
newNode->setBoundingBox(box);
pNode->setLeft(newNode);
@@ -585,7 +591,11 @@ bool AABBTree::buildTree(AABBTreeNodeInternal* pNode, size_t iFromIdx, size_t iT
{
cvf::BoundingBox box = leafBoundingBox(iMid + 1, iToIdx);
AABBTreeNodeInternal* newNode = createNode();
AABBTreeNodeInternal* newNode = nullptr;
#pragma omp critical
{
newNode = createNode();
}
newNode->setBoundingBox(box);
pNode->setRight(newNode);