From 661840f425c27252017387c2731e88be4ad2020d Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 31 Jan 2024 12:58:03 +0100 Subject: [PATCH] Always compute bounding box of main grid and use OpenMP --- .../ReservoirDataModel/RigMainGrid.cpp | 38 +++++++++++++++---- .../ReservoirDataModel/RigMainGrid.h | 3 +- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/ApplicationLibCode/ReservoirDataModel/RigMainGrid.cpp b/ApplicationLibCode/ReservoirDataModel/RigMainGrid.cpp index 24c1d6c33d..71fab84de7 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigMainGrid.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigMainGrid.cpp @@ -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(); } //-------------------------------------------------------------------------------------------------- @@ -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 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( m_nodes.size() ); i++ ) + { + threadBoundingBoxes[myThread].add( m_nodes[i] ); + } + } + + for ( int i = 0; i < numberOfThreads; i++ ) + { + m_boundingBox.add( threadBoundingBoxes[i] ); + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -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; } diff --git a/ApplicationLibCode/ReservoirDataModel/RigMainGrid.h b/ApplicationLibCode/ReservoirDataModel/RigMainGrid.h index dc0b682603..536a2a2d12 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigMainGrid.h +++ b/ApplicationLibCode/ReservoirDataModel/RigMainGrid.h @@ -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 defaultMapAxes(); @@ -133,7 +134,7 @@ class RigMainGrid : public RigGridBase cvf::Vec3d m_displayModelOffset; cvf::ref m_cellSearchTree; - mutable cvf::BoundingBox m_boundingBox; + cvf::BoundingBox m_boundingBox; bool m_flipXAxis; bool m_flipYAxis;