mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Other improvements to bounding box calculation
This commit is contained in:
@@ -28,6 +28,8 @@
|
|||||||
#include "cvfAssert.h"
|
#include "cvfAssert.h"
|
||||||
#include "cvfBoundingBoxTree.h"
|
#include "cvfBoundingBoxTree.h"
|
||||||
|
|
||||||
|
#include <omp.h>
|
||||||
|
|
||||||
RigMainGrid::RigMainGrid()
|
RigMainGrid::RigMainGrid()
|
||||||
: RigGridBase( this )
|
: RigGridBase( this )
|
||||||
{
|
{
|
||||||
@@ -710,38 +712,55 @@ void RigMainGrid::buildCellSearchTree()
|
|||||||
|
|
||||||
size_t cellCount = m_cells.size();
|
size_t cellCount = m_cells.size();
|
||||||
|
|
||||||
std::vector<size_t> cellIndicesForBoundingBoxes;
|
std::vector<size_t> cellIndicesForBoundingBoxes;
|
||||||
cellIndicesForBoundingBoxes.reserve( cellCount );
|
|
||||||
|
|
||||||
std::vector<cvf::BoundingBox> cellBoundingBoxes;
|
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;
|
threadIndicesForBoundingBoxes.reserve( threadCellCount );
|
||||||
cellBB.add( m_nodes[cellIndices[0]] );
|
threadBoundingBoxes.reserve( threadCellCount );
|
||||||
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() )
|
#pragma omp for
|
||||||
|
for ( int cIdx = 0; cIdx < (int)cellCount; ++cIdx )
|
||||||
{
|
{
|
||||||
cellIndicesForBoundingBoxes.emplace_back( cIdx );
|
if ( m_cells[cIdx].isInvalid() ) continue;
|
||||||
cellBoundingBoxes.emplace_back( cellBB );
|
|
||||||
|
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 = new cvf::BoundingBoxTree;
|
||||||
m_cellSearchTree->buildTreeFromBoundingBoxes( cellBoundingBoxes, &cellIndicesForBoundingBoxes );
|
m_cellSearchTree->buildTreeFromBoundingBoxes( cellBoundingBoxes, &cellIndicesForBoundingBoxes );
|
||||||
}
|
}
|
||||||
@@ -868,10 +887,10 @@ void RigMainGrid::setDualPorosity( bool enable )
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
std::array<double, 6> RigMainGrid::defaultMapAxes()
|
std::array<double, 6> RigMainGrid::defaultMapAxes()
|
||||||
{
|
{
|
||||||
const double origin[2] = {0.0, 0.0};
|
const double origin[2] = { 0.0, 0.0 };
|
||||||
const double xPoint[2] = {1.0, 0.0};
|
const double xPoint[2] = { 1.0, 0.0 };
|
||||||
const double yPoint[2] = {0.0, 1.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
|
// 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] };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,8 @@ void RigNNCData::processNativeConnections( const RigMainGrid& mainGrid )
|
|||||||
{
|
{
|
||||||
// cvf::Trace::show("NNC: Total number: " + cvf::String((int)m_connections.size()));
|
// 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& c1 = mainGrid.globalCellArray()[m_connections[cnIdx].c1GlobIdx()];
|
||||||
const RigCell& c2 = mainGrid.globalCellArray()[m_connections[cnIdx].c2GlobIdx()];
|
const RigCell& c2 = mainGrid.globalCellArray()[m_connections[cnIdx].c2GlobIdx()];
|
||||||
|
|||||||
@@ -210,6 +210,7 @@ namespace cvf {
|
|||||||
};
|
};
|
||||||
|
|
||||||
std::deque<InternalNodeAndRange> m_previousLevelNodes;
|
std::deque<InternalNodeAndRange> m_previousLevelNodes;
|
||||||
|
std::deque<InternalNodeAndRange> m_currentLevelNodes;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BoundingBoxTreeImpl : public AABBTree
|
class BoundingBoxTreeImpl : public AABBTree
|
||||||
@@ -493,7 +494,7 @@ bool AABBTree::buildTree()
|
|||||||
bRes = bRes && bThreadRes;
|
bRes = bRes && bThreadRes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_previousLevelNodes.clear();
|
m_previousLevelNodes.swap(m_currentLevelNodes);
|
||||||
|
|
||||||
#pragma omp parallel
|
#pragma omp parallel
|
||||||
{
|
{
|
||||||
@@ -501,13 +502,14 @@ bool AABBTree::buildTree()
|
|||||||
#pragma omp for schedule(guided)
|
#pragma omp for schedule(guided)
|
||||||
for (int i = 0; i < m_previousLevelNodes.size(); ++i)
|
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
|
#pragma omp critical
|
||||||
{
|
{
|
||||||
bRes = bRes && bThreadRes;
|
bRes = bRes && bThreadRes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
CVF_ASSERT(m_currentLevelNodes.empty());
|
||||||
m_previousLevelNodes.clear();
|
m_previousLevelNodes.clear();
|
||||||
|
|
||||||
return bRes;
|
return bRes;
|
||||||
@@ -524,7 +526,7 @@ bool AABBTree::buildTree(AABBTreeNodeInternal* pNode, size_t iFromIdx, size_t iT
|
|||||||
{
|
{
|
||||||
#pragma omp critical
|
#pragma omp critical
|
||||||
{
|
{
|
||||||
m_previousLevelNodes.emplace_back(pNode, iFromIdx, iToIdx);
|
m_currentLevelNodes.emplace_back(pNode, iFromIdx, iToIdx);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -569,7 +571,11 @@ bool AABBTree::buildTree(AABBTreeNodeInternal* pNode, size_t iFromIdx, size_t iT
|
|||||||
{
|
{
|
||||||
cvf::BoundingBox box = leafBoundingBox(iFromIdx, iMid);
|
cvf::BoundingBox box = leafBoundingBox(iFromIdx, iMid);
|
||||||
|
|
||||||
AABBTreeNodeInternal* newNode = createNode();
|
AABBTreeNodeInternal* newNode = nullptr;
|
||||||
|
#pragma omp critical
|
||||||
|
{
|
||||||
|
newNode = createNode();
|
||||||
|
}
|
||||||
newNode->setBoundingBox(box);
|
newNode->setBoundingBox(box);
|
||||||
pNode->setLeft(newNode);
|
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);
|
cvf::BoundingBox box = leafBoundingBox(iMid + 1, iToIdx);
|
||||||
|
|
||||||
AABBTreeNodeInternal* newNode = createNode();
|
AABBTreeNodeInternal* newNode = nullptr;
|
||||||
|
#pragma omp critical
|
||||||
|
{
|
||||||
|
newNode = createNode();
|
||||||
|
}
|
||||||
newNode->setBoundingBox(box);
|
newNode->setBoundingBox(box);
|
||||||
pNode->setRight(newNode);
|
pNode->setRight(newNode);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user