Skip to content

Commit

Permalink
Always compute bounding box of main grid and use OpenMP
Browse files Browse the repository at this point in the history
  • Loading branch information
magnesj committed Jan 31, 2024
1 parent 5151717 commit 661840f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
38 changes: 31 additions & 7 deletions ApplicationLibCode/ReservoirDataModel/RigMainGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ void RigMainGrid::computeCachedData( std::string* aabbTreeInfo )
*aabbTreeInfo += "Cells per bounding box : " + std::to_string( cellsPerBoundingBox ) + "\n";
*aabbTreeInfo += m_cellSearchTree->info();
}

computeBoundingBox();
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -433,6 +435,35 @@ bool RigMainGrid::hasFaultWithName( const QString& name ) const
return false;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigMainGrid::computeBoundingBox()
{
m_boundingBox.reset();

const int numberOfThreads = RiaOpenMPTools::availableThreadCount();

std::vector<cvf::BoundingBox> threadBoundingBoxes( numberOfThreads );

#pragma omp parallel
{
int myThread = RiaOpenMPTools::currentThreadIndex();

// NB! We are inside a parallel section, do not use "parallel for" here
#pragma omp for
for ( long i = 0; i < static_cast<long>( m_nodes.size() ); i++ )
{
threadBoundingBoxes[myThread].add( m_nodes[i] );
}
}

for ( int i = 0; i < numberOfThreads; i++ )
{
m_boundingBox.add( threadBoundingBoxes[i] );
}
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -943,13 +974,6 @@ void RigMainGrid::buildCellSearchTreeOptimized( size_t cellsPerBoundingBox )
//--------------------------------------------------------------------------------------------------
cvf::BoundingBox RigMainGrid::boundingBox() const
{
if ( m_boundingBox.isValid() ) return m_boundingBox;

for ( const auto& node : m_nodes )
{
m_boundingBox.add( node );
}

return m_boundingBox;
}

Expand Down
3 changes: 2 additions & 1 deletion ApplicationLibCode/ReservoirDataModel/RigMainGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class RigMainGrid : public RigGridBase
void buildCellSearchTree();
void buildCellSearchTreeOptimized( size_t cellsPerBoundingBox );
bool hasFaultWithName( const QString& name ) const;
void computeBoundingBox();

static std::array<double, 6> defaultMapAxes();

Expand All @@ -133,7 +134,7 @@ class RigMainGrid : public RigGridBase

cvf::Vec3d m_displayModelOffset;
cvf::ref<cvf::BoundingBoxTree> m_cellSearchTree;
mutable cvf::BoundingBox m_boundingBox;
cvf::BoundingBox m_boundingBox;

bool m_flipXAxis;
bool m_flipYAxis;
Expand Down

0 comments on commit 661840f

Please sign in to comment.