From 30c3fe3a5c733ed17e0e3a9736d629397245ae2d Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Fri, 2 Sep 2022 06:51:21 +0200 Subject: [PATCH] Scale length threshold based on average DZ --- .../RigEclipseWellLogExtractor.cpp | 39 +++++++++++++++++-- .../RigEclipseWellLogExtractor.h | 5 ++- .../RigGeoMechWellLogExtractor.cpp | 3 +- .../RigWellLogExtractionTools.h | 16 +++++--- .../RigWellLogExtractor.cpp | 24 +++++++----- .../ReservoirDataModel/RigWellLogExtractor.h | 1 + 6 files changed, 68 insertions(+), 20 deletions(-) diff --git a/ApplicationLibCode/ReservoirDataModel/RigEclipseWellLogExtractor.cpp b/ApplicationLibCode/ReservoirDataModel/RigEclipseWellLogExtractor.cpp index 62834bc59a..a9d88f17fd 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigEclipseWellLogExtractor.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigEclipseWellLogExtractor.cpp @@ -21,6 +21,7 @@ #include "RiaLogging.h" +#include "RigCaseCellResultsData.h" #include "RigEclipseCaseData.h" #include "RigMainGrid.h" #include "RigResultAccessor.h" @@ -57,6 +58,8 @@ void RigEclipseWellLogExtractor::calculateIntersection() if ( m_wellPathGeometry->wellPathPoints().empty() ) return; + double tolerance = computeLengthThreshold(); + for ( size_t wpp = 0; wpp < m_wellPathGeometry->wellPathPoints().size() - 1; ++wpp ) { std::vector intersections; @@ -99,7 +102,7 @@ void RigEclipseWellLogExtractor::calculateIntersection() double md1 = m_wellPathGeometry->measuredDepths()[wpp]; double md2 = m_wellPathGeometry->measuredDepths()[wpp + 1]; - insertIntersectionsInMap( intersections, p1, md1, p2, md2, &uniqueIntersections ); + insertIntersectionsInMap( intersections, p1, md1, p2, md2, tolerance, &uniqueIntersections ); } if ( uniqueIntersections.empty() && m_wellPathGeometry->wellPathPoints().size() > 1 ) @@ -139,7 +142,8 @@ void RigEclipseWellLogExtractor::calculateIntersection() globalCellIndex ); RigMDCellIdxEnterLeaveKey enterLeaveKey( m_wellPathGeometry->measuredDepths().front(), globalCellIndex, - isEntering ); + isEntering, + tolerance ); uniqueIntersections.insert( std::make_pair( enterLeaveKey, info ) ); } @@ -151,7 +155,8 @@ void RigEclipseWellLogExtractor::calculateIntersection() HexIntersectionInfo info( lastPoint, isEntering, cvf::StructGridInterface::NO_FACE, globalCellIndex ); RigMDCellIdxEnterLeaveKey enterLeaveKey( m_wellPathGeometry->measuredDepths().back(), globalCellIndex, - isEntering ); + isEntering, + tolerance ); uniqueIntersections.insert( std::make_pair( enterLeaveKey, info ) ); } @@ -208,3 +213,31 @@ cvf::Vec3d RigEclipseWellLogExtractor::calculateLengthInCell( size_t return RigWellPathIntersectionTools::calculateLengthInCell( hexCorners, startPoint, endPoint ); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +double RigEclipseWellLogExtractor::computeLengthThreshold() const +{ + // Default length tolerance for most common grid sizes + double tolerance = 0.1; + + // For grids with very thin z-layers, reduce the tolerance to be able to find the intersections + // If not, the intersection will be considered as non-valid cell edge intersection and discarded + // https://github.com/OPM/ResInsight/issues/9244 + + auto gridCellResult = + const_cast( m_caseData->results( RiaDefines::PorosityModelType::MATRIX_MODEL ) ); + + auto resultAdr = RigEclipseResultAddress( RiaDefines::ResultCatType::STATIC_NATIVE, "DZ" ); + if ( gridCellResult && gridCellResult->hasResultEntry( resultAdr ) ) + { + double averageDZ = 0.1; + gridCellResult->meanCellScalarValues( resultAdr, averageDZ ); + + const double scaleFactor = 0.05; + tolerance = std::min( tolerance, averageDZ * scaleFactor ); + } + + return tolerance; +} diff --git a/ApplicationLibCode/ReservoirDataModel/RigEclipseWellLogExtractor.h b/ApplicationLibCode/ReservoirDataModel/RigEclipseWellLogExtractor.h index a05bf68f9c..1193bcc567 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigEclipseWellLogExtractor.h +++ b/ApplicationLibCode/ReservoirDataModel/RigEclipseWellLogExtractor.h @@ -38,7 +38,7 @@ class RigEclipseWellLogExtractor : public RigWellLogExtractor public: RigEclipseWellLogExtractor( gsl::not_null aCase, gsl::not_null wellpath, - const std::string& wellCaseErrorMsgName ); + const std::string& wellCaseErrorMsgName ); void curveData( const RigResultAccessor* resultAccessor, std::vector* values ); const RigEclipseCaseData* caseData() { return m_caseData.p(); } @@ -49,5 +49,8 @@ private: cvf::Vec3d calculateLengthInCell( size_t cellIndex, const cvf::Vec3d& startPoint, const cvf::Vec3d& endPoint ) const override; + double computeLengthThreshold() const; + +private: cvf::cref m_caseData; }; diff --git a/ApplicationLibCode/ReservoirDataModel/RigGeoMechWellLogExtractor.cpp b/ApplicationLibCode/ReservoirDataModel/RigGeoMechWellLogExtractor.cpp index 9cd44595ce..b6369533ad 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigGeoMechWellLogExtractor.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigGeoMechWellLogExtractor.cpp @@ -1025,7 +1025,8 @@ void RigGeoMechWellLogExtractor::calculateIntersection() double md1 = m_wellPathGeometry->measuredDepths()[wpp]; double md2 = m_wellPathGeometry->measuredDepths()[wpp + 1]; - insertIntersectionsInMap( intersections, p1, md1, p2, md2, &uniqueIntersections ); + const double tolerance = 0.1; + insertIntersectionsInMap( intersections, p1, md1, p2, md2, tolerance, &uniqueIntersections ); } this->populateReturnArrays( uniqueIntersections ); diff --git a/ApplicationLibCode/ReservoirDataModel/RigWellLogExtractionTools.h b/ApplicationLibCode/ReservoirDataModel/RigWellLogExtractionTools.h index 2560bc63e1..9e1922f0e0 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigWellLogExtractionTools.h +++ b/ApplicationLibCode/ReservoirDataModel/RigWellLogExtractionTools.h @@ -30,7 +30,7 @@ struct RigWellLogExtractionTools { - static bool isEqualDepth( double d1, double d2, const double tolerance = 0.1 ) + static bool isEqualDepth( double d1, double d2, const double tolerance ) { double depthDiff = d1 - d2; @@ -46,10 +46,11 @@ struct RigWellLogExtractionTools struct RigMDCellIdxEnterLeaveKey { - RigMDCellIdxEnterLeaveKey( double md, size_t cellIdx, bool entering ) + RigMDCellIdxEnterLeaveKey( double md, size_t cellIdx, bool entering, double tolerance ) : measuredDepth( md ) , hexIndex( cellIdx ) , isEnteringCell( entering ) + , tolerance( tolerance ) { } @@ -57,10 +58,11 @@ struct RigMDCellIdxEnterLeaveKey size_t hexIndex; bool isEnteringCell; // As opposed to leaving. bool isLeavingCell() const { return !isEnteringCell; } + double tolerance; bool operator<( const RigMDCellIdxEnterLeaveKey& other ) const { - if ( RigWellLogExtractionTools::isEqualDepth( measuredDepth, other.measuredDepth ) ) + if ( RigWellLogExtractionTools::isEqualDepth( measuredDepth, other.measuredDepth, tolerance ) ) { if ( hexIndex == other.hexIndex ) { @@ -90,10 +92,11 @@ struct RigMDCellIdxEnterLeaveKey struct RigMDEnterLeaveCellIdxKey { - RigMDEnterLeaveCellIdxKey( double md, bool entering, size_t cellIdx ) + RigMDEnterLeaveCellIdxKey( double md, bool entering, size_t cellIdx, double tolerance ) : measuredDepth( md ) , isEnteringCell( entering ) , hexIndex( cellIdx ) + , tolerance( tolerance ) { } @@ -101,10 +104,11 @@ struct RigMDEnterLeaveCellIdxKey bool isEnteringCell; // As opposed to leaving. bool isLeavingCell() const { return !isEnteringCell; } size_t hexIndex; + double tolerance; bool operator<( const RigMDEnterLeaveCellIdxKey& other ) const { - if ( RigWellLogExtractionTools::isEqualDepth( measuredDepth, other.measuredDepth ) ) + if ( RigWellLogExtractionTools::isEqualDepth( measuredDepth, other.measuredDepth, tolerance ) ) { if ( isEnteringCell == other.isEnteringCell ) { @@ -128,6 +132,6 @@ struct RigMDEnterLeaveCellIdxKey static bool isProperCellEnterLeavePair( const RigMDEnterLeaveCellIdxKey& key1, const RigMDEnterLeaveCellIdxKey& key2 ) { return ( key1.hexIndex == key2.hexIndex && key1.isEnteringCell && key2.isLeavingCell() && - !RigWellLogExtractionTools::isEqualDepth( key1.measuredDepth, key2.measuredDepth ) ); + !RigWellLogExtractionTools::isEqualDepth( key1.measuredDepth, key2.measuredDepth, key1.tolerance ) ); } }; diff --git a/ApplicationLibCode/ReservoirDataModel/RigWellLogExtractor.cpp b/ApplicationLibCode/ReservoirDataModel/RigWellLogExtractor.cpp index f9c5e6daad..38998b7c66 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigWellLogExtractor.cpp +++ b/ApplicationLibCode/ReservoirDataModel/RigWellLogExtractor.cpp @@ -111,6 +111,7 @@ void RigWellLogExtractor::insertIntersectionsInMap( const std::vector* uniqueIntersections ) { for ( size_t intIdx = 0; intIdx < intersections.size(); ++intIdx ) @@ -130,11 +131,11 @@ void RigWellLogExtractor::insertIntersectionsInMap( const std::vectorinsert( - std::make_pair( RigMDCellIdxEnterLeaveKey( measuredDepthOfPoint, - intersections[intIdx].m_hexIndex, - intersections[intIdx].m_isIntersectionEntering ), - intersections[intIdx] ) ); + uniqueIntersections->insert( std::make_pair( RigMDCellIdxEnterLeaveKey( measuredDepthOfPoint, + intersections[intIdx].m_hexIndex, + intersections[intIdx].m_isIntersectionEntering, + tolerance ), + intersections[intIdx] ) ); } } @@ -156,7 +157,9 @@ void RigWellLogExtractor::populateReturnArrays( std::mapfirst.measuredDepth, it2->first.measuredDepth ) ) + if ( RigWellLogExtractionTools::isEqualDepth( it1->first.measuredDepth, + it2->first.measuredDepth, + it1->first.tolerance ) ) { if ( it1->first.hexIndex == it2->first.hexIndex ) { @@ -187,7 +190,8 @@ void RigWellLogExtractor::populateReturnArrays( std::mapfirst.measuredDepth, it->first.isEnteringCell, - it->first.hexIndex ), + it->first.hexIndex, + it->first.tolerance ), it->second ) ); ++it; } @@ -210,7 +214,8 @@ void RigWellLogExtractor::populateReturnArrays( std::mapmeasuredDepths()[0], true, - firstLeavingPoint.m_hexIndex ), + firstLeavingPoint.m_hexIndex, + it->first.tolerance ), firstLeavingPoint ) ); } @@ -230,7 +235,8 @@ void RigWellLogExtractor::populateReturnArrays( std::mapmeasuredDepths().back(), false, - lastEnterPoint.m_hexIndex ), + lastEnterPoint.m_hexIndex, + rit->first.tolerance ), lastEnterPoint ) ); } } diff --git a/ApplicationLibCode/ReservoirDataModel/RigWellLogExtractor.h b/ApplicationLibCode/ReservoirDataModel/RigWellLogExtractor.h index ae745d3219..c24ff94d26 100644 --- a/ApplicationLibCode/ReservoirDataModel/RigWellLogExtractor.h +++ b/ApplicationLibCode/ReservoirDataModel/RigWellLogExtractor.h @@ -75,6 +75,7 @@ protected: double md1, cvf::Vec3d p2, double md2, + double tolerance, std::map* uniqueIntersections ); void populateReturnArrays( std::map& uniqueIntersections );