From ab0b05b31c40a74c13b711dabd9d424a9a4db43e Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Thu, 14 May 2020 19:11:45 +0200 Subject: [PATCH] Improve NNC memory use --- .../FileInterface/RifReaderEclipseOutput.cpp | 5 +- .../RiaGrpcNNCPropertiesService.cpp | 6 +- .../RivNNCGeometryGenerator.cpp | 18 ++-- .../RimFaultInViewCollection.cpp | 4 +- .../RigCaseCellResultsData.cpp | 15 +-- .../RigCellFaceGeometryTools.cpp | 65 +++++-------- .../RigCellFaceGeometryTools.h | 6 +- .../ReservoirDataModel/RigGridBase.cpp | 10 ++ .../ReservoirDataModel/RigGridBase.h | 1 + .../ReservoirDataModel/RigMainGrid.cpp | 8 +- .../ReservoirDataModel/RigNNCData.cpp | 25 ++--- .../ReservoirDataModel/RigNncConnection.cpp | 97 +++++++++++-------- .../ReservoirDataModel/RigNncConnection.h | 46 ++++++--- ...igNumberOfFloodedPoreVolumesCalculator.cpp | 4 +- .../RigReservoirBuilderMock.cpp | 4 +- .../SocketInterface/RiaNNCCommands.cpp | 4 +- .../RiuCellAndNncPickEventHandler.cpp | 10 +- .../UserInterface/RiuResultTextBuilder.cpp | 12 +-- 18 files changed, 178 insertions(+), 162 deletions(-) diff --git a/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp b/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp index 82240e6e8d..c1e6e57145 100644 --- a/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp +++ b/ApplicationCode/FileInterface/RifReaderEclipseOutput.cpp @@ -734,9 +734,8 @@ void RifReaderEclipseOutput::transferStaticNNCData( const ecl_grid_type* mainEcl RigGridBase* grid1 = mainGrid->gridByIndex( geometry_pair->grid_nr1 ); RigGridBase* grid2 = mainGrid->gridByIndex( geometry_pair->grid_nr2 ); - RigConnection nncConnection; - nncConnection.m_c1GlobIdx = grid1->reservoirCellIndex( geometry_pair->global_index1 ); - nncConnection.m_c2GlobIdx = grid2->reservoirCellIndex( geometry_pair->global_index2 ); + RigConnection nncConnection( grid1->reservoirCellIndex( geometry_pair->global_index1 ), + grid2->reservoirCellIndex( geometry_pair->global_index2 ) ); nncConnections.push_back( nncConnection ); diff --git a/ApplicationCode/GrpcInterface/RiaGrpcNNCPropertiesService.cpp b/ApplicationCode/GrpcInterface/RiaGrpcNNCPropertiesService.cpp index 7a837d0e26..0ecaa2f122 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcNNCPropertiesService.cpp +++ b/ApplicationCode/GrpcInterface/RiaGrpcNNCPropertiesService.cpp @@ -97,9 +97,9 @@ grpc::Status RiaNNCConnectionsStateHandler::assignReply( rips::NNCConnections* r reply->mutable_connections()->Reserve( (int)packageSize ); for ( ; indexInPackage < packageSize && m_currentIdx < connectionCount; ++indexInPackage ) { - RigConnection connection = connections[m_currentIdx]; - const RigCell& cell1 = mainGrid->globalCellArray()[connection.m_c1GlobIdx]; - const RigCell& cell2 = mainGrid->globalCellArray()[connection.m_c2GlobIdx]; + const RigConnection& connection = connections[m_currentIdx]; + const RigCell& cell1 = mainGrid->globalCellArray()[connection.c1GlobIdx()]; + const RigCell& cell2 = mainGrid->globalCellArray()[connection.c2GlobIdx()]; NNCConnection* nncConnection = reply->add_connections(); nncConnection->set_allocated_cell1( createConnectionVec3i( cell1 ) ); diff --git a/ApplicationCode/ModelVisualization/RivNNCGeometryGenerator.cpp b/ApplicationCode/ModelVisualization/RivNNCGeometryGenerator.cpp index 003c7e5177..8698450521 100644 --- a/ApplicationCode/ModelVisualization/RivNNCGeometryGenerator.cpp +++ b/ApplicationCode/ModelVisualization/RivNNCGeometryGenerator.cpp @@ -97,7 +97,7 @@ void RivNNCGeometryGenerator::computeArrays() const RigConnection& conn = m_nncData->connections()[conIdx]; - if ( conn.m_polygon.size() ) + if ( conn.polygon().size() ) { bool isVisible = true; if ( isVisibilityCalcActive ) @@ -105,15 +105,15 @@ void RivNNCGeometryGenerator::computeArrays() bool cell1Visible = false; bool cell2Visible = false; - if ( ( *allCells )[conn.m_c1GlobIdx].hostGrid() == m_grid.p() ) + if ( ( *allCells )[conn.c1GlobIdx()].hostGrid() == m_grid.p() ) { - size_t cell1GridLocalIdx = ( *allCells )[conn.m_c1GlobIdx].gridLocalCellIndex(); + size_t cell1GridLocalIdx = ( *allCells )[conn.c1GlobIdx()].gridLocalCellIndex(); cell1Visible = ( *m_cellVisibility )[cell1GridLocalIdx]; } - if ( ( *allCells )[conn.m_c2GlobIdx].hostGrid() == m_grid.p() ) + if ( ( *allCells )[conn.c2GlobIdx()].hostGrid() == m_grid.p() ) { - size_t cell2GridLocalIdx = ( *allCells )[conn.m_c2GlobIdx].gridLocalCellIndex(); + size_t cell2GridLocalIdx = ( *allCells )[conn.c2GlobIdx()].gridLocalCellIndex(); cell2Visible = ( *m_cellVisibility )[cell2GridLocalIdx]; } @@ -122,14 +122,14 @@ void RivNNCGeometryGenerator::computeArrays() if ( isVisible ) { - cvf::Vec3f vx1 = conn.m_polygon[0] - offset; + cvf::Vec3f vx1 = conn.polygon()[0] - offset; cvf::Vec3f vx2; - cvf::Vec3f vx3 = conn.m_polygon[1] - offset; + cvf::Vec3f vx3 = conn.polygon()[1] - offset; - for ( size_t vxIdx = 2; vxIdx < conn.m_polygon.size(); ++vxIdx ) + for ( size_t vxIdx = 2; vxIdx < conn.polygon().size(); ++vxIdx ) { vx2 = vx3; - vx3 = conn.m_polygon[vxIdx] - offset; + vx3 = conn.polygon()[vxIdx] - offset; #pragma omp critical( critical_section_RivNNCGeometryGenerator_computeArrays ) { vertices.push_back( vx1 ); diff --git a/ApplicationCode/ProjectDataModel/RimFaultInViewCollection.cpp b/ApplicationCode/ProjectDataModel/RimFaultInViewCollection.cpp index eb5edd50b0..50a3026b2f 100644 --- a/ApplicationCode/ProjectDataModel/RimFaultInViewCollection.cpp +++ b/ApplicationCode/ProjectDataModel/RimFaultInViewCollection.cpp @@ -280,7 +280,7 @@ void RimFaultInViewCollection::syncronizeFaults() { size_t gridLocalCellIndex; const RigGridBase* hostGrid = - mainGrid->gridAndGridLocalIdxFromGlobalCellIdx( nncConnections[connIndex].m_c1GlobIdx, + mainGrid->gridAndGridLocalIdxFromGlobalCellIdx( nncConnections[connIndex].c1GlobIdx(), &gridLocalCellIndex ); size_t i, j, k; @@ -303,7 +303,7 @@ void RimFaultInViewCollection::syncronizeFaults() { size_t gridLocalCellIndex; const RigGridBase* hostGrid = - mainGrid->gridAndGridLocalIdxFromGlobalCellIdx( nncConnections[connIndex].m_c2GlobIdx, + mainGrid->gridAndGridLocalIdxFromGlobalCellIdx( nncConnections[connIndex].c2GlobIdx(), &gridLocalCellIndex ); size_t i, j, k; diff --git a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp index e88004b5a4..adec138a5c 100644 --- a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp +++ b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp @@ -2323,9 +2323,10 @@ void RigCaseCellResultsData::computeNncCombRiTrans() const RigConnectionContainer& nncConnections = m_ownerMainGrid->nncData()->connections(); for ( size_t connIdx = 0; connIdx < nncConnections.size(); connIdx++ ) { - size_t nativeResvCellIndex = nncConnections[connIdx].m_c1GlobIdx; - size_t neighborResvCellIdx = nncConnections[connIdx].m_c2GlobIdx; - cvf::StructGridInterface::FaceType faceId = nncConnections[connIdx].m_c1Face; + size_t nativeResvCellIndex = nncConnections[connIdx].c1GlobIdx(); + size_t neighborResvCellIdx = nncConnections[connIdx].c2GlobIdx(); + cvf::StructGridInterface::FaceType faceId = + static_cast( nncConnections[connIdx].face() ); ResultIndexFunction permIdxFunc = nullptr; std::vector* permResults = nullptr; @@ -2370,7 +2371,7 @@ void RigCaseCellResultsData::computeNncCombRiTrans() cvf::Vec3f faceCenter = cvf::Vec3f::ZERO; // Polygon center - const std::vector& realPolygon = nncConnections[connIdx].m_polygon; + const std::vector& realPolygon = nncConnections[connIdx].polygon(); for ( size_t pIdx = 0; pIdx < realPolygon.size(); ++pIdx ) { faceCenter += realPolygon[pIdx]; @@ -2686,7 +2687,7 @@ void RigCaseCellResultsData::computeNncCombRiTRANSbyArea() for ( size_t nncConIdx = 0; nncConIdx < riAreaNormTransResults.size(); ++nncConIdx ) { - const std::vector& realPolygon = connections[nncConIdx].m_polygon; + const std::vector& realPolygon = connections[nncConIdx].polygon(); cvf::Vec3f faceAreaVec = cvf::GeometryTools::polygonAreaNormal3D( realPolygon ); double areaOfOverlap = faceAreaVec.length(); @@ -3166,8 +3167,8 @@ void RigCaseCellResultsData::computeAllanResults( RigCaseCellResultsData* cellRe { const auto& c = nncConnections[i]; - size_t globCellIdx1 = c.m_c1GlobIdx; - size_t globCellIdx2 = c.m_c2GlobIdx; + size_t globCellIdx1 = c.c1GlobIdx(); + size_t globCellIdx2 = c.c2GlobIdx(); int formation1 = (int)( fnData[globCellIdx1] ); int formation2 = (int)( fnData[globCellIdx2] ); diff --git a/ApplicationCode/ReservoirDataModel/RigCellFaceGeometryTools.cpp b/ApplicationCode/ReservoirDataModel/RigCellFaceGeometryTools.cpp index d432efdebd..ab920f4f05 100644 --- a/ApplicationCode/ReservoirDataModel/RigCellFaceGeometryTools.cpp +++ b/ApplicationCode/ReservoirDataModel/RigCellFaceGeometryTools.cpp @@ -119,23 +119,12 @@ cvf::StructGridInterface::FaceType return cvf::StructGridInterface::NO_FACE; } -void assignThreadConnections( std::set>& existingPairs, - RigConnectionContainer& allConnections, - RigConnectionContainer& threadConnections ) +void assignThreadConnections( RigConnectionContainer& allConnections, RigConnectionContainer& threadConnections ) { - for ( size_t i = 0; i < threadConnections.size(); ++i ) - { #pragma omp critical - { - RigConnection connection = threadConnections[i]; - auto it = existingPairs.emplace( connection.m_c1GlobIdx, connection.m_c2GlobIdx ); - if ( it.second ) - { - allConnections.push_back( connection ); - } - } + { + allConnections.push_back( threadConnections ); } - threadConnections.clear(); } //-------------------------------------------------------------------------------------------------- @@ -155,7 +144,7 @@ RigConnectionContainer RigCellFaceGeometryTools::computeOtherNncs( const RigMain for ( size_t i = 0; i < nativeConnections.size(); ++i ) { RigConnection c = nativeConnections[i]; - nativeCellPairs.emplace( c.m_c1GlobIdx, c.m_c2GlobIdx ); + nativeCellPairs.emplace( static_cast( c.c1GlobIdx() ), static_cast( c.c2GlobIdx() ) ); } if ( nativeConnections.size() != nativeCellPairs.size() ) @@ -168,8 +157,7 @@ RigConnectionContainer RigCellFaceGeometryTools::computeOtherNncs( const RigMain const cvf::Collection& faults = mainGrid->faults(); - std::set> existingPairs; - RigConnectionContainer otherConnections; + RigConnectionContainer otherConnections; for ( int faultIdx = 0; faultIdx < (int)faults.size(); faultIdx++ ) { @@ -195,38 +183,39 @@ RigConnectionContainer RigCellFaceGeometryTools::computeOtherNncs( const RigMain if ( atLeastOneCellActive ) activeFaceIndices.push_back( faceIdx ); } + size_t totalNumberOfConnections = 0u; #pragma omp parallel { RigConnectionContainer threadConnections; -#pragma omp for schedule( guided ) +#pragma omp for schedule( guided ) reduction( + : totalNumberOfConnections ) for ( int activeFaceIdx = 0; activeFaceIdx < static_cast( activeFaceIndices.size() ); activeFaceIdx++ ) { - size_t faceIdx = activeFaceIndices[activeFaceIdx]; - const RigFault::FaultFace& f = faultFaces[faceIdx]; - - RigConnectionContainer faceConnections = extractConnectionsForFace( f, mainGrid, nativeCellPairs ); - threadConnections.insert( faceConnections ); + size_t faceIdx = activeFaceIndices[activeFaceIdx]; + extractConnectionsForFace( faultFaces[faceIdx], mainGrid, nativeCellPairs, threadConnections ); } +#pragma omp barrier + otherConnections.reserve( otherConnections.size() + totalNumberOfConnections ); + // Merge together connections per thread - assignThreadConnections( existingPairs, otherConnections, threadConnections ); + assignThreadConnections( otherConnections, threadConnections ); } // end parallel region } + otherConnections.remove_duplicates(); return otherConnections; } -RigConnectionContainer - RigCellFaceGeometryTools::extractConnectionsForFace( const RigFault::FaultFace& face, - const RigMainGrid* mainGrid, - const std::set>& nativeCellPairs ) +void RigCellFaceGeometryTools::extractConnectionsForFace( const RigFault::FaultFace& face, + const RigMainGrid* mainGrid, + const std::set>& nativeCellPairs, + RigConnectionContainer& connections ) { - RigConnectionContainer faceConnections; size_t sourceReservoirCellIndex = face.m_nativeReservoirCellIndex; cvf::StructGridInterface::FaceType sourceCellFace = face.m_nativeFace; if ( sourceReservoirCellIndex >= mainGrid->cellCount() ) { - return {}; + return; } const std::vector& mainGridNodes = mainGrid->nodes(); @@ -317,7 +306,8 @@ RigConnectionContainer } } - std::pair candidate( sourceReservoirCellIndex, candidateCellIndex ); + std::pair candidate( static_cast( sourceReservoirCellIndex ), + static_cast( candidateCellIndex ) ); if ( nativeCellPairs.count( candidate ) > 0 ) { @@ -341,17 +331,14 @@ RigConnectionContainer if ( foundOverlap ) { - RigConnection conn; - conn.m_c1GlobIdx = sourceReservoirCellIndex; - conn.m_c2GlobIdx = candidateCellIndex; - conn.m_c1Face = sourceCellFace; + RigConnection conn( sourceReservoirCellIndex, + candidateCellIndex, + sourceCellFace, + RigCellFaceGeometryTools::extractPolygon( mainGridNodes, polygon, intersections ) ); - conn.m_polygon = RigCellFaceGeometryTools::extractPolygon( mainGridNodes, polygon, intersections ); - - faceConnections.push_back( conn ); + connections.push_back( conn ); } } - return faceConnections; } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ReservoirDataModel/RigCellFaceGeometryTools.h b/ApplicationCode/ReservoirDataModel/RigCellFaceGeometryTools.h index d506e13969..243a0fd80c 100644 --- a/ApplicationCode/ReservoirDataModel/RigCellFaceGeometryTools.h +++ b/ApplicationCode/ReservoirDataModel/RigCellFaceGeometryTools.h @@ -51,10 +51,10 @@ public: const RigActiveCellInfo* activeCellInfo, bool includeInactiveCells ); - static RigConnectionContainer - extractConnectionsForFace( const RigFault::FaultFace& face, + static void extractConnectionsForFace( const RigFault::FaultFace& face, const RigMainGrid* mainGrid, - const std::set>& nativeCellPairs ); + const std::set>& nativeCellPairs, + RigConnectionContainer& connections ); static std::vector extractPolygon( const std::vector& nativeNodes, const std::vector& connectionPolygon, const std::vector& connectionIntersections ); diff --git a/ApplicationCode/ReservoirDataModel/RigGridBase.cpp b/ApplicationCode/ReservoirDataModel/RigGridBase.cpp index 1ede4502b5..ff42c7aa8c 100644 --- a/ApplicationCode/ReservoirDataModel/RigGridBase.cpp +++ b/ApplicationCode/ReservoirDataModel/RigGridBase.cpp @@ -176,6 +176,16 @@ size_t RigGridBase::cellIndexFromIJK( size_t i, size_t j, size_t k ) const return ci; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +size_t RigGridBase::cellIndexFromIJKUnguarded( size_t i, size_t j, size_t k ) const +{ + size_t ci = i + j * ( m_gridPointDimensions.x() - 1 ) + + k * ( ( m_gridPointDimensions.x() - 1 ) * ( m_gridPointDimensions.y() - 1 ) ); + return ci; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ReservoirDataModel/RigGridBase.h b/ApplicationCode/ReservoirDataModel/RigGridBase.h index 6da2b79e0f..6d99c44b3d 100644 --- a/ApplicationCode/ReservoirDataModel/RigGridBase.h +++ b/ApplicationCode/ReservoirDataModel/RigGridBase.h @@ -91,6 +91,7 @@ public: cvf::Vec3d displayModelOffset() const override; size_t cellIndexFromIJK( size_t i, size_t j, size_t k ) const override; + size_t cellIndexFromIJKUnguarded( size_t i, size_t j, size_t k ) const; bool ijkFromCellIndex( size_t cellIndex, size_t* i, size_t* j, size_t* k ) const override; bool cellIJKFromCoordinate( const cvf::Vec3d& coord, size_t* i, size_t* j, size_t* k ) const override; diff --git a/ApplicationCode/ReservoirDataModel/RigMainGrid.cpp b/ApplicationCode/ReservoirDataModel/RigMainGrid.cpp index 90df3c435a..999dda9034 100644 --- a/ApplicationCode/ReservoirDataModel/RigMainGrid.cpp +++ b/ApplicationCode/ReservoirDataModel/RigMainGrid.cpp @@ -579,16 +579,16 @@ void RigMainGrid::distributeNNCsToFaults() int fIdx1 = RigFaultsPrCellAccumulator::NO_FAULT; int fIdx2 = RigFaultsPrCellAccumulator::NO_FAULT; - if ( conn.m_c1Face != StructGridInterface::NO_FACE ) + if ( conn.face() != StructGridInterface::NO_FACE ) { - fIdx1 = m_faultsPrCellAcc->faultIdx( conn.m_c1GlobIdx, conn.m_c1Face ); - fIdx2 = m_faultsPrCellAcc->faultIdx( conn.m_c2GlobIdx, StructGridInterface::oppositeFace( conn.m_c1Face ) ); + fIdx1 = m_faultsPrCellAcc->faultIdx( conn.c1GlobIdx(), conn.face() ); + fIdx2 = m_faultsPrCellAcc->faultIdx( conn.c2GlobIdx(), StructGridInterface::oppositeFace( conn.face() ) ); } if ( fIdx1 < 0 && fIdx2 < 0 ) { cvf::String lgrString( "Same Grid" ); - if ( m_cells[conn.m_c1GlobIdx].hostGrid() != m_cells[conn.m_c2GlobIdx].hostGrid() ) + if ( m_cells[conn.c1GlobIdx()].hostGrid() != m_cells[conn.c2GlobIdx()].hostGrid() ) { lgrString = "Different Grid"; } diff --git a/ApplicationCode/ReservoirDataModel/RigNNCData.cpp b/ApplicationCode/ReservoirDataModel/RigNNCData.cpp index a205756cd2..85b6db83fc 100644 --- a/ApplicationCode/ReservoirDataModel/RigNNCData.cpp +++ b/ApplicationCode/ReservoirDataModel/RigNNCData.cpp @@ -41,8 +41,8 @@ void RigNNCData::processNativeConnections( const RigMainGrid& mainGrid ) for ( size_t cnIdx = 0; cnIdx < m_connections.size(); ++cnIdx ) { - const RigCell& c1 = mainGrid.globalCellArray()[m_connections[cnIdx].m_c1GlobIdx]; - const RigCell& c2 = mainGrid.globalCellArray()[m_connections[cnIdx].m_c2GlobIdx]; + const RigCell& c1 = mainGrid.globalCellArray()[m_connections[cnIdx].c1GlobIdx()]; + const RigCell& c2 = mainGrid.globalCellArray()[m_connections[cnIdx].c2GlobIdx()]; std::vector connectionPolygon; std::vector connectionIntersections; @@ -53,21 +53,9 @@ void RigNNCData::processNativeConnections( const RigMainGrid& mainGrid ) if ( connectionFace != cvf::StructGridInterface::NO_FACE ) { - // Found an overlap polygon. Store data about connection - - m_connections.face( cnIdx ) = connectionFace; - - m_connections.polygon( cnIdx ) = - RigCellFaceGeometryTools::extractPolygon( mainGrid.nodes(), connectionPolygon, connectionIntersections ); - - // Add to search map, possibly not needed - // m_cellIdxToFaceToConnectionIdxMap[m_connections[cnIdx].m_c1GlobIdx][connectionFace].push_back(cnIdx); - // m_cellIdxToFaceToConnectionIdxMap[m_connections[cnIdx].m_c2GlobIdx][cvf::StructGridInterface::oppositeFace(connectionFace].push_back(cnIdx); - } - else - { - // cvf::Trace::show("NNC: No overlap found for : C1: " + cvf::String((int)m_connections[cnIdx].m_c1GlobIdx) - // + "C2: " + cvf::String((int)m_connections[cnIdx].m_c2GlobIdx)); + m_connections[cnIdx].setFace( connectionFace ); + m_connections[cnIdx].setPolygon( + RigCellFaceGeometryTools::extractPolygon( mainGrid.nodes(), connectionPolygon, connectionIntersections ) ); } } } @@ -80,13 +68,12 @@ void RigNNCData::computeCompleteSetOfNncs( const RigMainGrid* mainGrid, bool includeInactiveCells ) { m_nativeConnectionCount = m_connections.size(); - RigConnectionContainer otherConnections = RigCellFaceGeometryTools::computeOtherNncs( mainGrid, m_connections, activeCellInfo, includeInactiveCells ); if ( !otherConnections.empty() ) { - m_connections.insert( otherConnections ); + m_connections.push_back( otherConnections ); // Transmissibility values from Eclipse has been read into propertyNameCombTrans in // RifReaderEclipseOutput::transferStaticNNCData(). Initialize computed NNCs with zero transmissibility diff --git a/ApplicationCode/ReservoirDataModel/RigNncConnection.cpp b/ApplicationCode/ReservoirDataModel/RigNncConnection.cpp index 1c7b789e26..2d0f93f28f 100644 --- a/ApplicationCode/ReservoirDataModel/RigNncConnection.cpp +++ b/ApplicationCode/ReservoirDataModel/RigNncConnection.cpp @@ -18,7 +18,7 @@ #include "RigNncConnection.h" -#include "cvfMath.h" +#include "cvfAssert.h" //-------------------------------------------------------------------------------------------------- /// @@ -26,7 +26,7 @@ RigConnection::RigConnection() : m_c1GlobIdx( cvf::UNDEFINED_UINT ) , m_c2GlobIdx( cvf::UNDEFINED_UINT ) - , m_c1Face( cvf::StructGridInterface::NO_FACE ) + , m_c1Face( static_cast( cvf::StructGridInterface::NO_FACE ) ) { } @@ -39,11 +39,26 @@ RigConnection::RigConnection( unsigned c1GlobIdx, const std::vector& polygon ) : m_c1GlobIdx( c1GlobIdx ) , m_c2GlobIdx( c2GlobIdx ) - , m_c1Face( c1Face ) + , m_c1Face( static_cast( c1Face ) ) , m_polygon( polygon ) { } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RigConnection::RigConnection( size_t c1GlobIdx, + size_t c2GlobIdx, + cvf::StructGridInterface::FaceType c1Face, + const std::vector& polygon ) + : m_c1GlobIdx( static_cast( c1GlobIdx ) ) + , m_c2GlobIdx( static_cast( c2GlobIdx ) ) + , m_c1Face( static_cast( c1Face ) ) + , m_polygon( polygon ) +{ + CVF_ASSERT( c1GlobIdx < std::numeric_limits::max() && c2GlobIdx < std::numeric_limits::max() ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -58,7 +73,7 @@ RigConnection::RigConnection( const RigConnection& rhs ) //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RigConnection& RigConnection::operator=( RigConnection& rhs ) +RigConnection& RigConnection::operator=( const RigConnection& rhs ) { m_c1GlobIdx = rhs.m_c1GlobIdx; m_c2GlobIdx = rhs.m_c2GlobIdx; @@ -75,6 +90,14 @@ bool RigConnection::hasCommonArea() const return m_polygon.size() > 0; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RigConnection::operator==( const RigConnection& rhs ) +{ + return m_c1GlobIdx == rhs.m_c1GlobIdx && m_c2GlobIdx == rhs.m_c2GlobIdx; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -91,37 +114,17 @@ bool RigConnection::operator<( const RigConnection& other ) const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RigConnection RigConnectionContainer::operator[]( size_t i ) const +const RigConnection& RigConnectionContainer::operator[]( size_t i ) const { - const auto& globIndices = m_globalIndices[i]; - return RigConnection( globIndices.first, - globIndices.second, - static_cast( m_faces[i] ), - m_polygons[i] ); + return m_connections[i]; } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::pair& RigConnectionContainer::indexPair( size_t i ) +RigConnection& RigConnectionContainer::operator[]( size_t i ) { - return m_globalIndices[i]; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -unsigned char& RigConnectionContainer::face( size_t i ) -{ - return m_faces[i]; -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -std::vector& RigConnectionContainer::polygon( size_t i ) -{ - return m_polygons[i]; + return m_connections[i]; } //-------------------------------------------------------------------------------------------------- @@ -129,19 +132,15 @@ std::vector& RigConnectionContainer::polygon( size_t i ) //-------------------------------------------------------------------------------------------------- void RigConnectionContainer::push_back( const RigConnection& connection ) { - m_globalIndices.push_back( std::make_pair( connection.m_c1GlobIdx, connection.m_c2GlobIdx ) ); - m_faces.push_back( connection.m_c1Face ); - m_polygons.push_back( connection.m_polygon ); + m_connections.push_back( connection ); } //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RigConnectionContainer::insert( const RigConnectionContainer& other ) +void RigConnectionContainer::push_back( const RigConnectionContainer& other ) { - m_globalIndices.insert( m_globalIndices.end(), other.m_globalIndices.begin(), other.m_globalIndices.end() ); - m_faces.insert( m_faces.end(), other.m_faces.begin(), other.m_faces.end() ); - m_polygons.insert( m_polygons.end(), other.m_polygons.begin(), other.m_polygons.end() ); + m_connections.insert( m_connections.end(), other.m_connections.begin(), other.m_connections.end() ); } //-------------------------------------------------------------------------------------------------- @@ -149,7 +148,7 @@ void RigConnectionContainer::insert( const RigConnectionContainer& other ) //-------------------------------------------------------------------------------------------------- size_t RigConnectionContainer::size() const { - return m_globalIndices.size(); + return m_connections.size(); } //-------------------------------------------------------------------------------------------------- @@ -157,9 +156,7 @@ size_t RigConnectionContainer::size() const //-------------------------------------------------------------------------------------------------- void RigConnectionContainer::clear() { - m_globalIndices.clear(); - m_faces.clear(); - m_polygons.clear(); + m_connections.clear(); } //-------------------------------------------------------------------------------------------------- @@ -167,5 +164,25 @@ void RigConnectionContainer::clear() //-------------------------------------------------------------------------------------------------- bool RigConnectionContainer::empty() const { - return m_globalIndices.empty(); + return m_connections.empty(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigConnectionContainer::remove_duplicates() +{ + std::sort( m_connections.begin(), m_connections.end() ); + m_connections.erase( std::unique( m_connections.begin(), m_connections.end() ), m_connections.end() ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigConnectionContainer::reserve( size_t requiredSize ) +{ + if ( m_connections.capacity() < requiredSize ) + { + m_connections.reserve( requiredSize ); + } } diff --git a/ApplicationCode/ReservoirDataModel/RigNncConnection.h b/ApplicationCode/ReservoirDataModel/RigNncConnection.h index 8cbccb5c28..3cc215e614 100644 --- a/ApplicationCode/ReservoirDataModel/RigNncConnection.h +++ b/ApplicationCode/ReservoirDataModel/RigNncConnection.h @@ -33,38 +33,54 @@ public: RigConnection(); RigConnection( unsigned c1GlobIdx, unsigned c2GlobIdx, - cvf::StructGridInterface::FaceType c1Face, - const std::vector& polygon ); + cvf::StructGridInterface::FaceType c1Face = cvf::StructGridInterface::NO_FACE, + const std::vector& polygon = {} ); + + RigConnection( size_t c1GlobIdx, + size_t c2GlobIdx, + cvf::StructGridInterface::FaceType c1Face = cvf::StructGridInterface::NO_FACE, + const std::vector& polygon = {} ); RigConnection( const RigConnection& rhs ); - RigConnection& operator=( RigConnection& rhs ); + RigConnection& operator=( const RigConnection& rhs ); + bool operator==( const RigConnection& rhs ); bool operator<( const RigConnection& other ) const; bool hasCommonArea() const; - unsigned m_c1GlobIdx; - unsigned m_c2GlobIdx; - cvf::StructGridInterface::FaceType m_c1Face; - std::vector m_polygon; + inline size_t c1GlobIdx() const { return m_c1GlobIdx; } + inline size_t c2GlobIdx() const { return m_c2GlobIdx; } + inline cvf::StructGridInterface::FaceType face() const + { + return static_cast( m_c1Face ); + } + inline void setFace( cvf::StructGridInterface::FaceType face ) { m_c1Face = static_cast( face ); } + inline const std::vector& polygon() const { return m_polygon; } + inline void setPolygon( const std::vector& polygon ) { m_polygon = polygon; } + +private: + unsigned m_c1GlobIdx; + unsigned m_c2GlobIdx; + unsigned char m_c1Face; + std::vector m_polygon; }; class RigConnectionContainer { public: - RigConnection operator[]( size_t i ) const; + RigConnectionContainer() = default; - std::pair& indexPair( size_t i ); - unsigned char& face( size_t i ); - std::vector& polygon( size_t i ); + const RigConnection& operator[]( size_t i ) const; + RigConnection& operator[]( size_t i ); void push_back( const RigConnection& connection ); - void insert( const RigConnectionContainer& other ); + void push_back( const RigConnectionContainer& connection ); size_t size() const; void clear(); bool empty() const; + void remove_duplicates(); + void reserve( size_t requiredSize ); private: - std::vector> m_globalIndices; - std::vector m_faces; - std::vector> m_polygons; + std::vector m_connections; }; diff --git a/ApplicationCode/ReservoirDataModel/RigNumberOfFloodedPoreVolumesCalculator.cpp b/ApplicationCode/ReservoirDataModel/RigNumberOfFloodedPoreVolumesCalculator.cpp index 57f8ff337d..69101430c3 100644 --- a/ApplicationCode/ReservoirDataModel/RigNumberOfFloodedPoreVolumesCalculator.cpp +++ b/ApplicationCode/ReservoirDataModel/RigNumberOfFloodedPoreVolumesCalculator.cpp @@ -311,10 +311,10 @@ void RigNumberOfFloodedPoreVolumesCalculator::distributeNNCflow( const RigConnec RigConnection connection = connections[connectionIndex]; double connectionValue = flowrateNNC->at( connectionIndex ); - size_t cell1Index = connection.m_c1GlobIdx; + size_t cell1Index = connection.c1GlobIdx(); size_t cell1ResultIndex = actCellInfo->cellResultIndex( cell1Index ); - size_t cell2Index = connection.m_c2GlobIdx; + size_t cell2Index = connection.c2GlobIdx(); size_t cell2ResultIndex = actCellInfo->cellResultIndex( cell2Index ); if ( connectionValue > 0 ) diff --git a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp index 396b623ef1..d806f1176a 100644 --- a/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp +++ b/ApplicationCode/ReservoirDataModel/RigReservoirBuilderMock.cpp @@ -591,9 +591,7 @@ void RigReservoirBuilderMock::addNnc( RigMainGrid* grid, size_t c1GlobalIndex = grid->cellIndexFromIJK( i1, j1, k1 ); size_t c2GlobalIndex = grid->cellIndexFromIJK( i2, j2, k2 ); - RigConnection conn; - conn.m_c1GlobIdx = static_cast( c1GlobalIndex ); - conn.m_c2GlobIdx = static_cast( c2GlobalIndex ); + RigConnection conn( c1GlobalIndex, c2GlobalIndex ); nncConnections.push_back( conn ); } diff --git a/ApplicationCode/SocketInterface/RiaNNCCommands.cpp b/ApplicationCode/SocketInterface/RiaNNCCommands.cpp index d603848a2a..59a550c862 100644 --- a/ApplicationCode/SocketInterface/RiaNNCCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaNNCCommands.cpp @@ -73,8 +73,8 @@ public: { RigConnection connection = mainGrid->nncData()->connections()[i]; - const RigCell& cell1 = mainGrid->globalCellArray()[connection.m_c1GlobIdx]; - const RigCell& cell2 = mainGrid->globalCellArray()[connection.m_c2GlobIdx]; + const RigCell& cell1 = mainGrid->globalCellArray()[connection.c1GlobIdx()]; + const RigCell& cell2 = mainGrid->globalCellArray()[connection.c2GlobIdx()]; sendCellInfo( socketStream, cell1 ); sendCellInfo( socketStream, cell2 ); diff --git a/ApplicationCode/UserInterface/RiuCellAndNncPickEventHandler.cpp b/ApplicationCode/UserInterface/RiuCellAndNncPickEventHandler.cpp index a09a4e2e95..3240ccbd25 100644 --- a/ApplicationCode/UserInterface/RiuCellAndNncPickEventHandler.cpp +++ b/ApplicationCode/UserInterface/RiuCellAndNncPickEventHandler.cpp @@ -221,7 +221,7 @@ bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eve RigMainGrid* mainGrid = eclipseView->eclipseCase()->eclipseCaseData()->mainGrid(); const RigConnection& nncConn = mainGrid->nncData()->connections()[nncIndex]; - mainGrid->gridAndGridLocalIdxFromGlobalCellIdx( nncConn.m_c1GlobIdx, &gridLocalCellIndex ); + mainGrid->gridAndGridLocalIdxFromGlobalCellIdx( nncConn.c1GlobIdx(), &gridLocalCellIndex ); } } else @@ -298,10 +298,10 @@ bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eve const RigConnection& nncConn = mainGrid->nncData()->connections()[nncIndex]; size_t c1LocalIdx = cvf::UNDEFINED_SIZE_T; - const RigGridBase* grid1 = mainGrid->gridAndGridLocalIdxFromGlobalCellIdx(nncConn.m_c1GlobIdx, &c1LocalIdx); + const RigGridBase* grid1 = mainGrid->gridAndGridLocalIdxFromGlobalCellIdx(nncConn.c1GlobIdx(), &c1LocalIdx); size_t c1GridIdx = grid1->gridIndex(); size_t c2LocalIdx = cvf::UNDEFINED_SIZE_T; - const RigGridBase* grid2 = mainGrid->gridAndGridLocalIdxFromGlobalCellIdx(nncConn.m_c2GlobIdx, &c2LocalIdx); + const RigGridBase* grid2 = mainGrid->gridAndGridLocalIdxFromGlobalCellIdx(nncConn.c2GlobIdx(), &c2LocalIdx); size_t c2GridIdx = grid2->gridIndex(); if (gridLocalCellIndex == c1LocalIdx && gridIndex == c1GridIdx) @@ -311,7 +311,7 @@ bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eve if (face == cvf::StructGridInterface::NO_FACE) { - face = nncConn.m_c1Face; + face = nncConn.face(); } else { @@ -324,7 +324,7 @@ bool RiuCellAndNncPickEventHandler::handle3dPickEvent( const Ric3dPickEvent& eve gridIndex = c1GridIdx; if (face == cvf::StructGridInterface::NO_FACE) { - face = cvf::StructGridInterface::oppositeFace(nncConn.m_c1Face); + face = cvf::StructGridInterface::oppositeFace(nncConn.face()); } else { diff --git a/ApplicationCode/UserInterface/RiuResultTextBuilder.cpp b/ApplicationCode/UserInterface/RiuResultTextBuilder.cpp index 47319cd515..ccda2f74ee 100644 --- a/ApplicationCode/UserInterface/RiuResultTextBuilder.cpp +++ b/ApplicationCode/UserInterface/RiuResultTextBuilder.cpp @@ -446,7 +446,7 @@ QString RiuResultTextBuilder::nncResultText() { const RigConnection& conn = nncData->connections()[m_nncIndex]; - cvf::StructGridInterface::FaceEnum face( conn.m_c1Face ); + cvf::StructGridInterface::FaceEnum face( conn.face() ); if ( m_viewWithFaultsSettings && m_viewWithFaultsSettings->currentFaultResultColors() ) { @@ -804,12 +804,12 @@ QString RiuResultTextBuilder::nncDetails() text += "-- NNC details --\n"; { const RigConnection& conn = nncData->connections()[m_nncIndex]; - cvf::StructGridInterface::FaceEnum face( conn.m_c1Face ); + cvf::StructGridInterface::FaceEnum face( conn.face() ); // First cell of NNC { - CVF_ASSERT( conn.m_c1GlobIdx < grid->globalCellArray().size() ); - const RigCell& cell = grid->globalCellArray()[conn.m_c1GlobIdx]; + CVF_ASSERT( conn.c1GlobIdx() < grid->globalCellArray().size() ); + const RigCell& cell = grid->globalCellArray()[conn.c1GlobIdx()]; RigGridBase* hostGrid = cell.hostGrid(); size_t gridLocalCellIndex = cell.gridLocalCellIndex(); @@ -834,8 +834,8 @@ QString RiuResultTextBuilder::nncDetails() // Second cell of NNC { - CVF_ASSERT( conn.m_c2GlobIdx < grid->globalCellArray().size() ); - const RigCell& cell = grid->globalCellArray()[conn.m_c2GlobIdx]; + CVF_ASSERT( conn.c2GlobIdx() < grid->globalCellArray().size() ); + const RigCell& cell = grid->globalCellArray()[conn.c2GlobIdx()]; RigGridBase* hostGrid = cell.hostGrid(); size_t gridLocalCellIndex = cell.gridLocalCellIndex();