From 21f098849341a7d4630ddb40299b61f7a122a360 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Mon, 20 Dec 2021 08:52:22 +0100 Subject: [PATCH] #8375 NNC : Create NNC generators when NNC data is available This approach fixes an NNC visibility issue related to use of m_rimFault->faultGeometry()->connectionIndices() before any was assigned in RigMainGrid::distributeNNCsToFaults() --- .../RivElementVectorResultPartMgr.cpp | 2 +- .../RivFaultGeometryGenerator.cpp | 15 ++++--- .../RivFaultGeometryGenerator.h | 5 ++- .../ModelVisualization/RivFaultPartMgr.cpp | 45 +++++++++++++------ .../RivNNCGeometryGenerator.cpp | 12 ++--- .../RivNNCGeometryGenerator.h | 18 ++++---- .../ReservoirDataModel/RigActiveCellInfo.cpp | 6 --- .../ReservoirDataModel/RigNNCData.cpp | 2 +- .../ReservoirDataModel/RigNNCData.h | 2 +- 9 files changed, 63 insertions(+), 44 deletions(-) diff --git a/ApplicationLibCode/ModelVisualization/RivElementVectorResultPartMgr.cpp b/ApplicationLibCode/ModelVisualization/RivElementVectorResultPartMgr.cpp index 6795d3534d..ba9a37efd9 100644 --- a/ApplicationLibCode/ModelVisualization/RivElementVectorResultPartMgr.cpp +++ b/ApplicationLibCode/ModelVisualization/RivElementVectorResultPartMgr.cpp @@ -247,7 +247,7 @@ void RivElementVectorResultPartMgr::appendDynamicGeometryPartsToModel( cvf::Mode for ( size_t nIdx = 0; nIdx < nncData->eclipseConnectionCount(); ++nIdx ) { - const RigConnection& conn = nncData->eclipseConnections()[nIdx]; + const RigConnection& conn = nncData->availableConnections()[nIdx]; if ( conn.polygon().size() ) { double resultValue = 0.0; diff --git a/ApplicationLibCode/ModelVisualization/RivFaultGeometryGenerator.cpp b/ApplicationLibCode/ModelVisualization/RivFaultGeometryGenerator.cpp index 8b8a436a6b..b0de47368d 100644 --- a/ApplicationLibCode/ModelVisualization/RivFaultGeometryGenerator.cpp +++ b/ApplicationLibCode/ModelVisualization/RivFaultGeometryGenerator.cpp @@ -125,13 +125,16 @@ cvf::ref RivFaultGeometryGenerator::createOutlineMeshDrawable( //-------------------------------------------------------------------------------------------------- bool RivFaultGeometryGenerator::hasConnection( size_t cellIdx, cvf::StructGridInterface::FaceType face, - RigConnectionContainer& conns ) + const RigConnectionContainer& conns, + const std::vector& nncConnectionIndices ) { cvf::StructGridInterface::FaceType oppositeFace = cvf::StructGridInterface::oppositeFace( face ); - for ( size_t i = 0; i < conns.size(); i++ ) + for ( auto i : nncConnectionIndices ) { - auto& r = conns[i]; + if ( i >= conns.size() ) continue; + + const auto& r = conns[i]; if ( ( r.c1GlobIdx() == cellIdx ) && ( r.face() == face ) && r.hasCommonArea() ) return true; @@ -152,7 +155,8 @@ void RivFaultGeometryGenerator::computeArrays( bool onlyShowFacesWithDefinedNeig cvf::Vec3d offset = m_grid->displayModelOffset(); - auto& connections = m_nncData->connections(); + auto connIndices = m_fault->connectionIndices(); + auto& connections = m_nncData->availableConnections(); const std::vector& faultFaces = m_fault->faultFaces(); @@ -172,7 +176,8 @@ void RivFaultGeometryGenerator::computeArrays( bool onlyShowFacesWithDefinedNeig if ( !( *m_cellVisibility )[cellIndex] ) continue; - if ( onlyShowFacesWithDefinedNeighbors && !hasConnection( cellIndex, face, connections ) ) continue; + if ( onlyShowFacesWithDefinedNeighbors && !hasConnection( cellIndex, face, connections, connIndices ) ) + continue; cvf::Vec3d cornerVerts[8]; m_grid->cellCornerVertices( cellIndex, cornerVerts ); diff --git a/ApplicationLibCode/ModelVisualization/RivFaultGeometryGenerator.h b/ApplicationLibCode/ModelVisualization/RivFaultGeometryGenerator.h index 0d4f74f5f4..8899a359d7 100644 --- a/ApplicationLibCode/ModelVisualization/RivFaultGeometryGenerator.h +++ b/ApplicationLibCode/ModelVisualization/RivFaultGeometryGenerator.h @@ -65,7 +65,10 @@ public: private: void computeArrays( bool onlyShowFacesWithDefinedNeighbors ); - bool hasConnection( size_t cellIdx, cvf::StructGridInterface::FaceType face, RigConnectionContainer& conns ); + bool hasConnection( size_t cellIdx, + cvf::StructGridInterface::FaceType face, + const RigConnectionContainer& conns, + const std::vector& nncConnectionIndices ); private: // Input diff --git a/ApplicationLibCode/ModelVisualization/RivFaultPartMgr.cpp b/ApplicationLibCode/ModelVisualization/RivFaultPartMgr.cpp index 5de9277273..19758adfb5 100644 --- a/ApplicationLibCode/ModelVisualization/RivFaultPartMgr.cpp +++ b/ApplicationLibCode/ModelVisualization/RivFaultPartMgr.cpp @@ -72,8 +72,6 @@ RivFaultPartMgr::RivFaultPartMgr( const RigGridBase* grid, { CVF_ASSERT( rimFault->faultGeometry() ); - cvf::ref> connIdxes = new cvf::Array; - connIdxes->assign( rimFault->faultGeometry()->connectionIndices() ); m_nativeFaultGenerator = new RivFaultGeometryGenerator( grid, rimFault->faultGeometry(), grid->mainGrid()->nncData(), true ); @@ -84,18 +82,8 @@ RivFaultPartMgr::RivFaultPartMgr( const RigGridBase* grid, m_nativeFaultFacesTextureCoords = new cvf::Vec2fArray; m_oppositeFaultFacesTextureCoords = new cvf::Vec2fArray; - m_NNCGenerator = new RivNNCGeometryGenerator( false, - grid->mainGrid()->nncData(), - grid->mainGrid()->displayModelOffset(), - connIdxes.p() ); - m_NNCTextureCoords = new cvf::Vec2fArray; - m_allanNNCGenerator = new RivNNCGeometryGenerator( true, - grid->mainGrid()->nncData(), - grid->mainGrid()->displayModelOffset(), - connIdxes.p() ); - m_allanNNCTextureCoords = new cvf::Vec2fArray; } @@ -106,8 +94,9 @@ void RivFaultPartMgr::setCellVisibility( cvf::UByteArray* cellVisibilities ) { m_nativeFaultGenerator->setCellVisibility( cellVisibilities ); m_oppositeFaultGenerator->setCellVisibility( cellVisibilities ); - m_NNCGenerator->setCellVisibility( cellVisibilities, m_grid.p() ); - m_allanNNCGenerator->setCellVisibility( cellVisibilities, m_grid.p() ); + + if ( m_NNCGenerator.notNull() ) m_NNCGenerator->setCellVisibility( cellVisibilities, m_grid.p() ); + if ( m_allanNNCGenerator.notNull() ) m_allanNNCGenerator->setCellVisibility( cellVisibilities, m_grid.p() ); clearFlags(); } @@ -403,6 +392,20 @@ void RivFaultPartMgr::generatePartGeometry() //-------------------------------------------------------------------------------------------------- void RivFaultPartMgr::generateNativeNncPartGeometry() { + if ( m_NNCGenerator.isNull() ) + { + auto nncConnectionIndices = m_rimFault->faultGeometry()->connectionIndices(); + if ( !nncConnectionIndices.empty() ) + { + m_NNCGenerator = new RivNNCGeometryGenerator( false, + m_grid->mainGrid()->nncData(), + m_grid->mainGrid()->displayModelOffset(), + nncConnectionIndices ); + } + } + + if ( m_NNCGenerator.isNull() ) return; + cvf::ref geo = m_NNCGenerator->generateSurface(); if ( geo.notNull() ) { @@ -438,6 +441,20 @@ void RivFaultPartMgr::generateNativeNncPartGeometry() //-------------------------------------------------------------------------------------------------- void RivFaultPartMgr::generateAllNncPartGeometry() { + if ( m_allanNNCGenerator.isNull() ) + { + auto nncConnectionIndices = m_rimFault->faultGeometry()->connectionIndices(); + if ( !nncConnectionIndices.empty() ) + { + m_allanNNCGenerator = new RivNNCGeometryGenerator( true, + m_grid->mainGrid()->nncData(), + m_grid->mainGrid()->displayModelOffset(), + nncConnectionIndices ); + } + } + + if ( m_allanNNCGenerator.isNull() ) return; + cvf::ref geo = m_allanNNCGenerator->generateSurface(); if ( geo.notNull() ) { diff --git a/ApplicationLibCode/ModelVisualization/RivNNCGeometryGenerator.cpp b/ApplicationLibCode/ModelVisualization/RivNNCGeometryGenerator.cpp index ffba8a42df..97cc485f40 100644 --- a/ApplicationLibCode/ModelVisualization/RivNNCGeometryGenerator.cpp +++ b/ApplicationLibCode/ModelVisualization/RivNNCGeometryGenerator.cpp @@ -31,10 +31,10 @@ //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RivNNCGeometryGenerator::RivNNCGeometryGenerator( bool includeAllan, - RigNNCData* nncData, - const cvf::Vec3d& offset, - const cvf::Array* nncIndexes ) +RivNNCGeometryGenerator::RivNNCGeometryGenerator( bool includeAllan, + RigNNCData* nncData, + const cvf::Vec3d& offset, + const std::vector& nncIndexes ) : m_includeAllanDiagramGeometry( includeAllan ) , m_nncData( nncData ) , m_nncIndexes( nncIndexes ) @@ -76,7 +76,7 @@ void RivNNCGeometryGenerator::computeArrays() const cvf::Vec3f offset( m_offset ); long long numConnections = - static_cast( m_nncIndexes.isNull() ? m_nncData->allConnections().size() : m_nncIndexes->size() ); + static_cast( m_nncIndexes.empty() ? m_nncData->allConnections().size() : m_nncIndexes.size() ); bool isVisibilityCalcActive = m_cellVisibility.notNull() && m_grid.notNull(); std::vector* allCells = nullptr; @@ -88,7 +88,7 @@ void RivNNCGeometryGenerator::computeArrays() #pragma omp parallel for ordered for ( long long nIdx = 0; nIdx < numConnections; ++nIdx ) { - size_t conIdx = m_nncIndexes.isNull() ? nIdx : ( *m_nncIndexes )[nIdx]; + size_t conIdx = m_nncIndexes.empty() ? nIdx : m_nncIndexes[nIdx]; if ( !m_includeAllanDiagramGeometry && conIdx >= m_nncData->eclipseConnectionCount() ) { diff --git a/ApplicationLibCode/ModelVisualization/RivNNCGeometryGenerator.h b/ApplicationLibCode/ModelVisualization/RivNNCGeometryGenerator.h index 1919a9ffea..88f748e2a3 100644 --- a/ApplicationLibCode/ModelVisualization/RivNNCGeometryGenerator.h +++ b/ApplicationLibCode/ModelVisualization/RivNNCGeometryGenerator.h @@ -42,10 +42,10 @@ class RigEclipseResultAddress; class RivNNCGeometryGenerator : public cvf::Object { public: - RivNNCGeometryGenerator( bool includeAllan, - RigNNCData* nncData, - const cvf::Vec3d& offset, - const cvf::Array* nncIndexes ); + RivNNCGeometryGenerator( bool includeAllan, + RigNNCData* nncData, + const cvf::Vec3d& offset, + const std::vector& nncIndexes ); ~RivNNCGeometryGenerator() override; @@ -70,11 +70,11 @@ private: bool m_includeAllanDiagramGeometry; // Input - cvf::ref m_nncData; - cvf::cref> m_nncIndexes; - cvf::cref m_cellVisibility; - cvf::cref m_grid; - cvf::Vec3d m_offset; + cvf::ref m_nncData; + std::vector m_nncIndexes; + cvf::cref m_cellVisibility; + cvf::cref m_grid; + cvf::Vec3d m_offset; // Triangles cvf::ref m_vertices; diff --git a/ApplicationLibCode/ReservoirDataModel/RigActiveCellInfo.cpp b/ApplicationLibCode/ReservoirDataModel/RigActiveCellInfo.cpp index 14df097d72..7fffd23c2c 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigActiveCellInfo.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigActiveCellInfo.cpp @@ -79,12 +79,6 @@ void RigActiveCellInfo::setCellResultIndex( size_t reservoirCellIndex, size_t re CVF_TIGHT_ASSERT( reservoirCellResultIndex < m_cellIndexToResultIndex.size() ); m_cellIndexToResultIndex[reservoirCellIndex] = reservoirCellResultIndex; - - // if ( reservoirCellResultIndex >= m_reservoirActiveCellCount ) - // { - //#pragma omp critical - // m_reservoirActiveCellCount = reservoirCellResultIndex + 1; - // } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ReservoirDataModel/RigNNCData.cpp b/ApplicationLibCode/ReservoirDataModel/RigNNCData.cpp index e674e65b16..a1343f49f9 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigNNCData.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigNNCData.cpp @@ -265,7 +265,7 @@ size_t RigNNCData::eclipseConnectionCount() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -const RigConnectionContainer& RigNNCData::eclipseConnections() const +const RigConnectionContainer& RigNNCData::availableConnections() const { // Return connections without calling ensureConnectionDataIsProcessed() to avoid potential heavy computations // Relevant if only native connection data is required diff --git a/ApplicationLibCode/ReservoirDataModel/RigNNCData.h b/ApplicationLibCode/ReservoirDataModel/RigNNCData.h index 412aea8ac8..421814981d 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigNNCData.h +++ b/ApplicationLibCode/ReservoirDataModel/RigNNCData.h @@ -57,7 +57,7 @@ public: void setEclipseConnections( RigConnectionContainer& eclipseConnections ); void buildPolygonsForEclipseConnections(); size_t eclipseConnectionCount() const; - const RigConnectionContainer& eclipseConnections() const; + const RigConnectionContainer& availableConnections() const; bool ensureAllConnectionDataIsProcessed(); RigConnectionContainer& allConnections();