From 0d213e659c56df95fbe30c2a2e161cb2b593785e Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 16 Dec 2021 11:52:04 +0100 Subject: [PATCH] #8371 Make sure all NNC faces are created and assigned Make sure that the first cell in RigConnection is assigned the lowest cell index. Assign the opposite face if the cell indexes are swapped. In RigCellFaceGeometryTools, test both combinations of (cellA, cellB) and (cellB, cellA) --- .../RigCellFaceGeometryTools.cpp | 14 +++++++-- .../ReservoirDataModel/RigFault.cpp | 30 +++++++++++++++++++ .../ReservoirDataModel/RigFault.h | 21 ++----------- .../ReservoirDataModel/RigNncConnection.cpp | 16 +++++++--- .../Python/rips/tests/test_nnc_properties.py | 2 +- 5 files changed, 58 insertions(+), 25 deletions(-) diff --git a/ApplicationLibCode/ReservoirDataModel/RigCellFaceGeometryTools.cpp b/ApplicationLibCode/ReservoirDataModel/RigCellFaceGeometryTools.cpp index b91cd3ecc4..0e33d3bce5 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigCellFaceGeometryTools.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigCellFaceGeometryTools.cpp @@ -304,8 +304,18 @@ void RigCellFaceGeometryTools::extractConnectionsForFace( const RigFault::FaultF } } - std::pair candidate( static_cast( sourceReservoirCellIndex ), - static_cast( candidateCellIndex ) ); + // Test if this pair of cells already has a connection. Check both combinations of cell index ordering to avoid + // duplicate NNC geometry for the same pair of cells + + auto candidate = std::make_pair( static_cast( sourceReservoirCellIndex ), + static_cast( candidateCellIndex ) ); + + if ( nativeCellPairs.count( candidate ) > 0 ) + { + continue; + } + + std::swap( candidate.first, candidate.second ); if ( nativeCellPairs.count( candidate ) > 0 ) { diff --git a/ApplicationLibCode/ReservoirDataModel/RigFault.cpp b/ApplicationLibCode/ReservoirDataModel/RigFault.cpp index 9df8d36d34..04b9cb6b78 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigFault.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigFault.cpp @@ -203,3 +203,33 @@ void RigFault::accumulateFaultsPrCell( RigFaultsPrCellAccumulator* faultsPrCellA faultIdx ); } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RigFaultsPrCellAccumulator::RigFaultsPrCellAccumulator( size_t reservoirCellCount ) +{ + std::array initVals = { NO_FAULT, NO_FAULT, NO_FAULT, NO_FAULT, NO_FAULT, NO_FAULT }; + m_faultIdxForCellFace.resize( reservoirCellCount, initVals ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +int RigFaultsPrCellAccumulator::faultIdx( size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face ) const +{ + // Ensure no crash after creating temporary LGRs + if ( reservoirCellIndex < m_faultIdxForCellFace.size() ) + { + return m_faultIdxForCellFace[reservoirCellIndex][face]; + } + return NO_FAULT; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigFaultsPrCellAccumulator::setFaultIdx( size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face, int faultIdx ) +{ + m_faultIdxForCellFace[reservoirCellIndex][face] = faultIdx; +} diff --git a/ApplicationLibCode/ReservoirDataModel/RigFault.h b/ApplicationLibCode/ReservoirDataModel/RigFault.h index d498763129..a763a7bff9 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigFault.h +++ b/ApplicationLibCode/ReservoirDataModel/RigFault.h @@ -46,26 +46,11 @@ public: }; public: - explicit RigFaultsPrCellAccumulator( size_t reservoirCellCount ) - { - std::array initVals = {NO_FAULT, NO_FAULT, NO_FAULT, NO_FAULT, NO_FAULT, NO_FAULT}; - m_faultIdxForCellFace.resize( reservoirCellCount, initVals ); - } + explicit RigFaultsPrCellAccumulator( size_t reservoirCellCount ); - inline int faultIdx( size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face ) const - { - // Ensure no crash after creating temporary LGRs - if ( reservoirCellIndex < m_faultIdxForCellFace.size() ) - { - return m_faultIdxForCellFace[reservoirCellIndex][face]; - } - return NO_FAULT; - } + int faultIdx( size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face ) const; - inline void setFaultIdx( size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face, int faultIdx ) - { - m_faultIdxForCellFace[reservoirCellIndex][face] = faultIdx; - } + void setFaultIdx( size_t reservoirCellIndex, cvf::StructGridInterface::FaceType face, int faultIdx ); private: std::vector> m_faultIdxForCellFace; diff --git a/ApplicationLibCode/ReservoirDataModel/RigNncConnection.cpp b/ApplicationLibCode/ReservoirDataModel/RigNncConnection.cpp index 65ba39f922..b608ac957f 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigNncConnection.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigNncConnection.cpp @@ -45,10 +45,14 @@ RigConnection::RigConnection( unsigned c1GlobIdx, if ( c1GlobIdx >= c2GlobIdx ) { // Ensure the smallest cell index is the first index - // TODO : The face type is related to cell 1, so face should be changed to opposite face - // This causes visual artifacts for some models, so this change will require more investigation m_c1GlobIdx = c2GlobIdx; m_c2GlobIdx = c1GlobIdx; + + if ( c1Face != cvf::StructGridInterface::FaceType::NO_FACE ) + { + // The face type is related to cell 1, so use opposite face + m_c1Face = cvf::StructGridInterface::oppositeFace( c1Face ); + } } } @@ -69,10 +73,14 @@ RigConnection::RigConnection( size_t c1GlobIdx, if ( c1GlobIdx >= c2GlobIdx ) { // Ensure the smallest cell index is the first index - // TODO : The face type is related to cell 1, so face should be changed to opposite face - // This causes visual artifacts for some models, so this change will require more investigation m_c1GlobIdx = static_cast( c2GlobIdx ); m_c2GlobIdx = static_cast( c1GlobIdx ); + + if ( c1Face != cvf::StructGridInterface::FaceType::NO_FACE ) + { + // The face type is related to cell 1, so use opposite face + m_c1Face = cvf::StructGridInterface::oppositeFace( c1Face ); + } } } diff --git a/GrpcInterface/Python/rips/tests/test_nnc_properties.py b/GrpcInterface/Python/rips/tests/test_nnc_properties.py index e55cd1a289..b5b2fa85d9 100644 --- a/GrpcInterface/Python/rips/tests/test_nnc_properties.py +++ b/GrpcInterface/Python/rips/tests/test_nnc_properties.py @@ -25,7 +25,7 @@ def test_10kSync(rips_instance, initialize_test): ) nnc_connections = case.nnc_connections() - assert len(nnc_connections) == 3627 + assert len(nnc_connections) == 3416 connection = nnc_connections[0] assert connection.cell1.i == 33