2015-10-14 08:08:13 +02:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) Statoil ASA
|
|
|
|
|
// Copyright (C) Ceetron Solutions AS
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
2015-10-14 08:08:13 +02:00
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
2015-10-14 08:08:13 +02:00
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
2019-09-06 10:40:57 +02:00
|
|
|
//
|
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2015-10-14 08:08:13 +02:00
|
|
|
// for more details.
|
|
|
|
|
//
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
#include "RigWellLogExtractor.h"
|
2023-03-31 16:27:14 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
#include "RiaLogging.h"
|
2015-10-14 08:08:13 +02:00
|
|
|
#include "RigWellPath.h"
|
2023-03-31 16:27:14 +02:00
|
|
|
|
2026-08-06 21:18:33 +02:00
|
|
|
#include "cafAssert.h"
|
|
|
|
|
|
2026-11-04 16:58:42 +01:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
2015-10-14 08:08:13 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2015-10-14 08:08:13 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2026-06-20 11:49:52 +02:00
|
|
|
RigWellLogExtractor::RigWellLogExtractor( const RigWellPath* wellpath, const std::string& wellCaseErrorMsgName )
|
2020-10-06 12:37:16 +02:00
|
|
|
: m_wellPathGeometry( wellpath )
|
2019-09-06 10:40:57 +02:00
|
|
|
, m_wellCaseErrorMsgName( wellCaseErrorMsgName )
|
2015-10-14 08:08:13 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2015-10-14 08:08:13 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-12 11:13:38 +01:00
|
|
|
RigWellLogExtractor::~RigWellLogExtractor()
|
|
|
|
|
{
|
|
|
|
|
}
|
2017-10-27 14:28:51 +02:00
|
|
|
|
2018-09-04 11:40:21 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-07 11:08:47 +01:00
|
|
|
const std::vector<double>& RigWellLogExtractor::cellIntersectionMDs() const
|
2018-09-04 11:40:21 +02:00
|
|
|
{
|
|
|
|
|
return m_intersectionMeasuredDepths;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-07 11:08:47 +01:00
|
|
|
const std::vector<double>& RigWellLogExtractor::cellIntersectionTVDs() const
|
2018-09-04 11:40:21 +02:00
|
|
|
{
|
|
|
|
|
return m_intersectionTVDs;
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-27 14:28:51 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2017-10-27 14:28:51 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-12-12 16:32:57 +01:00
|
|
|
std::vector<WellPathCellIntersectionInfo> RigWellLogExtractor::cellIntersectionInfosAlongWellPath() const
|
2017-10-27 14:28:51 +02:00
|
|
|
{
|
2017-12-12 13:53:02 +01:00
|
|
|
std::vector<WellPathCellIntersectionInfo> infoVector;
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( m_intersectedCellsGlobIdx.empty() ) return infoVector;
|
2017-10-27 14:28:51 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
for ( size_t i = 0; i < m_intersectedCellsGlobIdx.size() - 1; i = i + 2 )
|
2017-10-27 14:28:51 +02:00
|
|
|
{
|
2026-08-06 21:18:33 +02:00
|
|
|
CAF_ASSERT( m_intersectedCellsGlobIdx[i] == m_intersectedCellsGlobIdx[i + 1] );
|
2017-10-27 14:28:51 +02:00
|
|
|
|
2017-12-12 13:53:02 +01:00
|
|
|
WellPathCellIntersectionInfo cellInfo;
|
2017-10-27 14:28:51 +02:00
|
|
|
|
|
|
|
|
cellInfo.globCellIndex = m_intersectedCellsGlobIdx[i];
|
2019-09-06 10:40:57 +02:00
|
|
|
cellInfo.startPoint = m_intersections[i];
|
|
|
|
|
cellInfo.endPoint = m_intersections[i + 1];
|
|
|
|
|
cellInfo.startMD = m_intersectionMeasuredDepths[i];
|
|
|
|
|
cellInfo.endMD = m_intersectionMeasuredDepths[i + 1];
|
2017-11-06 22:21:42 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
cellInfo.intersectedCellFaceIn = m_intersectedCellFaces[i];
|
|
|
|
|
cellInfo.intersectedCellFaceOut = m_intersectedCellFaces[i + 1];
|
2017-10-27 14:28:51 +02:00
|
|
|
|
2023-08-04 09:04:14 +02:00
|
|
|
cellInfo.intersectionLengthsInCellCS = calculateLengthInCell( cellInfo.globCellIndex, cellInfo.startPoint, cellInfo.endPoint );
|
2017-12-12 14:49:10 +01:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
infoVector.push_back( cellInfo );
|
2017-10-27 14:28:51 +02:00
|
|
|
}
|
2019-09-06 10:40:57 +02:00
|
|
|
|
2017-10-27 14:28:51 +02:00
|
|
|
return infoVector;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-31 16:27:14 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
/// Insert additional intersections if the distance between two intersections is larger than maxDistanceBetweenIntersections
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void RigWellLogExtractor::resampleIntersections( double maxDistanceBetweenIntersections )
|
|
|
|
|
{
|
|
|
|
|
if ( maxDistanceBetweenIntersections <= 0.0 ) return;
|
|
|
|
|
|
|
|
|
|
std::vector<cvf::Vec3d> resampledIntersections;
|
|
|
|
|
std::vector<size_t> resampledIntersectedCellsGlobIdx;
|
|
|
|
|
std::vector<cvf::StructGridInterface::FaceType> resampledIntersectedCellFaces;
|
|
|
|
|
std::vector<double> resampledIntersectionMeasuredDepths;
|
|
|
|
|
std::vector<double> resampledIntersectionTVDs;
|
|
|
|
|
|
|
|
|
|
if ( m_intersections.size() > 1 )
|
|
|
|
|
{
|
|
|
|
|
resampledIntersections.push_back( m_intersections[0] );
|
|
|
|
|
resampledIntersectedCellsGlobIdx.push_back( m_intersectedCellsGlobIdx[0] );
|
|
|
|
|
resampledIntersectedCellFaces.push_back( m_intersectedCellFaces[0] );
|
|
|
|
|
resampledIntersectionMeasuredDepths.push_back( m_intersectionMeasuredDepths[0] );
|
|
|
|
|
resampledIntersectionTVDs.push_back( m_intersectionTVDs[0] );
|
|
|
|
|
|
|
|
|
|
for ( size_t i = 1; i < m_intersections.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
const cvf::Vec3d p1 = m_intersections[i - 1];
|
|
|
|
|
const cvf::Vec3d p2 = m_intersections[i];
|
|
|
|
|
const double distance = ( p2 - p1 ).length();
|
|
|
|
|
if ( distance > maxDistanceBetweenIntersections )
|
|
|
|
|
{
|
|
|
|
|
size_t numberOfPoints = static_cast<size_t>( distance / maxDistanceBetweenIntersections ) + 1;
|
|
|
|
|
for ( size_t j = 1; j < numberOfPoints; j++ )
|
|
|
|
|
{
|
|
|
|
|
// Insert data twice, as the curve visualization algorithm is based on pairs of intersections
|
|
|
|
|
|
|
|
|
|
resampledIntersectedCellsGlobIdx.push_back( m_intersectedCellsGlobIdx[i] );
|
|
|
|
|
resampledIntersectedCellsGlobIdx.push_back( m_intersectedCellsGlobIdx[i] );
|
|
|
|
|
resampledIntersectedCellFaces.push_back( m_intersectedCellFaces[i] );
|
|
|
|
|
resampledIntersectedCellFaces.push_back( m_intersectedCellFaces[i] );
|
|
|
|
|
|
|
|
|
|
const double t = static_cast<double>( j ) / static_cast<double>( numberOfPoints );
|
|
|
|
|
const cvf::Vec3d p = p1 + ( p2 - p1 ) * t;
|
|
|
|
|
resampledIntersections.push_back( p );
|
|
|
|
|
resampledIntersections.push_back( p );
|
|
|
|
|
|
|
|
|
|
const double md = m_intersectionMeasuredDepths[i - 1] +
|
|
|
|
|
( m_intersectionMeasuredDepths[i] - m_intersectionMeasuredDepths[i - 1] ) * t;
|
|
|
|
|
resampledIntersectionMeasuredDepths.push_back( md );
|
|
|
|
|
resampledIntersectionMeasuredDepths.push_back( md );
|
|
|
|
|
|
|
|
|
|
const double tvd = m_intersectionTVDs[i - 1] + ( m_intersectionTVDs[i] - m_intersectionTVDs[i - 1] ) * t;
|
|
|
|
|
resampledIntersectionTVDs.push_back( tvd );
|
|
|
|
|
resampledIntersectionTVDs.push_back( tvd );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
resampledIntersections.push_back( p2 );
|
|
|
|
|
resampledIntersectedCellsGlobIdx.push_back( m_intersectedCellsGlobIdx[i] );
|
|
|
|
|
resampledIntersectedCellFaces.push_back( m_intersectedCellFaces[i] );
|
|
|
|
|
resampledIntersectionMeasuredDepths.push_back( m_intersectionMeasuredDepths[i] );
|
|
|
|
|
resampledIntersectionTVDs.push_back( m_intersectionTVDs[i] );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_intersectionMeasuredDepths = resampledIntersectionMeasuredDepths;
|
|
|
|
|
m_intersectionTVDs = resampledIntersectionTVDs;
|
|
|
|
|
m_intersections = resampledIntersections;
|
|
|
|
|
m_intersectedCellsGlobIdx = resampledIntersectedCellsGlobIdx;
|
|
|
|
|
m_intersectedCellFaces = resampledIntersectedCellFaces;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-04 10:08:30 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::optional<double> RigWellLogExtractor::averageMdForCell( size_t cellIndex ) const
|
|
|
|
|
{
|
|
|
|
|
std::vector<size_t> indicesForCell;
|
|
|
|
|
|
|
|
|
|
for ( size_t i = 0; i < m_intersectedCellsGlobIdx.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
if ( m_intersectedCellsGlobIdx[i] == cellIndex ) indicesForCell.emplace_back( i );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( indicesForCell.empty() ) return std::nullopt;
|
|
|
|
|
|
|
|
|
|
double sum = 0.0;
|
|
|
|
|
for ( const auto& i : indicesForCell )
|
|
|
|
|
{
|
|
|
|
|
sum += m_intersectionMeasuredDepths[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sum / static_cast<double>( indicesForCell.size() );
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-12 15:00:14 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2017-12-12 15:00:14 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-02-07 11:08:47 +01:00
|
|
|
const std::vector<size_t>& RigWellLogExtractor::intersectedCellsGlobIdx() const
|
2017-12-12 15:00:14 +01:00
|
|
|
{
|
|
|
|
|
return m_intersectedCellsGlobIdx;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-31 16:27:14 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
const std::vector<cvf::Vec3d>& RigWellLogExtractor::intersections() const
|
|
|
|
|
{
|
|
|
|
|
return m_intersections;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
const std::vector<cvf::StructGridInterface::FaceType>& RigWellLogExtractor::intersectedCellFaces() const
|
|
|
|
|
{
|
|
|
|
|
return m_intersectedCellFaces;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-04 11:40:21 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-10-06 12:37:16 +02:00
|
|
|
const RigWellPath* RigWellLogExtractor::wellPathGeometry() const
|
2018-09-04 11:40:21 +02:00
|
|
|
{
|
2020-10-06 12:37:16 +02:00
|
|
|
return m_wellPathGeometry.p();
|
2018-09-04 11:40:21 +02:00
|
|
|
}
|
|
|
|
|
|
2015-10-14 10:10:07 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2015-10-14 10:10:07 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2023-02-26 10:48:40 +01:00
|
|
|
void RigWellLogExtractor::insertIntersectionsInMap( const std::vector<HexIntersectionInfo>& intersections,
|
|
|
|
|
cvf::Vec3d p1,
|
|
|
|
|
double md1,
|
|
|
|
|
cvf::Vec3d p2,
|
|
|
|
|
double md2,
|
|
|
|
|
double tolerance,
|
2020-02-12 11:43:15 +01:00
|
|
|
std::map<RigMDCellIdxEnterLeaveKey, HexIntersectionInfo>* uniqueIntersections )
|
2015-10-14 10:10:07 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
for ( size_t intIdx = 0; intIdx < intersections.size(); ++intIdx )
|
2015-10-14 10:10:07 +02:00
|
|
|
{
|
2020-06-03 20:31:58 +00:00
|
|
|
double lengthAlongLineSegment1 = ( intersections[intIdx].m_intersectionPoint - p1 ).length();
|
|
|
|
|
double lengthAlongLineSegment2 = ( p2 - intersections[intIdx].m_intersectionPoint ).length();
|
2015-10-14 10:10:07 +02:00
|
|
|
double measuredDepthDiff = md2 - md1;
|
2020-06-03 20:31:58 +00:00
|
|
|
double lineLength = lengthAlongLineSegment1 + lengthAlongLineSegment2;
|
2015-10-14 10:10:07 +02:00
|
|
|
double measuredDepthOfPoint = 0.0;
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( lineLength > 0.00001 )
|
2015-10-14 10:10:07 +02:00
|
|
|
{
|
2020-06-03 20:31:58 +00:00
|
|
|
measuredDepthOfPoint = md1 + measuredDepthDiff * lengthAlongLineSegment1 / ( lineLength );
|
2015-10-14 10:10:07 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
measuredDepthOfPoint = md1;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-02 06:51:21 +02:00
|
|
|
uniqueIntersections->insert( std::make_pair( RigMDCellIdxEnterLeaveKey( measuredDepthOfPoint,
|
|
|
|
|
intersections[intIdx].m_hexIndex,
|
|
|
|
|
intersections[intIdx].m_isIntersectionEntering,
|
|
|
|
|
tolerance ),
|
|
|
|
|
intersections[intIdx] ) );
|
2015-10-14 10:10:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
2015-10-14 08:35:05 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
///
|
2015-10-14 08:35:05 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 10:40:57 +02:00
|
|
|
void RigWellLogExtractor::populateReturnArrays( std::map<RigMDCellIdxEnterLeaveKey, HexIntersectionInfo>& uniqueIntersections )
|
2015-10-14 08:35:05 +02:00
|
|
|
{
|
2020-10-22 08:17:25 +02:00
|
|
|
QStringList errorMessages;
|
2015-10-14 15:14:41 +02:00
|
|
|
// For same MD and same cell, remove enter/leave pairs, as they only touches the wellpath, and should not contribute.
|
2015-10-14 08:35:05 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
std::map<RigMDCellIdxEnterLeaveKey, HexIntersectionInfo>::iterator it1 = uniqueIntersections.begin();
|
|
|
|
|
std::map<RigMDCellIdxEnterLeaveKey, HexIntersectionInfo>::iterator it2 = uniqueIntersections.begin();
|
2015-10-14 08:35:05 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
std::vector<std::map<RigMDCellIdxEnterLeaveKey, HexIntersectionInfo>::iterator> iteratorsToIntersectonsToErase;
|
2015-10-14 08:35:05 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
while ( it2 != uniqueIntersections.end() )
|
2015-10-14 08:35:05 +02:00
|
|
|
{
|
|
|
|
|
++it2;
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( it2 != uniqueIntersections.end() )
|
2015-10-14 08:35:05 +02:00
|
|
|
{
|
2023-02-26 10:48:40 +01:00
|
|
|
if ( RigWellLogExtractionTools::isEqualDepth( it1->first.measuredDepth, it2->first.measuredDepth, it1->first.tolerance ) )
|
2015-10-14 08:35:05 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
if ( it1->first.hexIndex == it2->first.hexIndex )
|
2015-10-14 08:35:05 +02:00
|
|
|
{
|
|
|
|
|
// Remove the two from the map, as they just are a touch of the cell surface
|
2026-08-06 21:18:33 +02:00
|
|
|
CAF_ASSERT( !it1->first.isEnteringCell && it2->first.isEnteringCell );
|
2015-10-14 08:35:05 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
iteratorsToIntersectonsToErase.push_back( it1 );
|
|
|
|
|
iteratorsToIntersectonsToErase.push_back( it2 );
|
2015-10-14 08:35:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
++it1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Erase all the intersections that is not needed
|
2019-09-06 10:40:57 +02:00
|
|
|
for ( size_t erItIdx = 0; erItIdx < iteratorsToIntersectonsToErase.size(); ++erItIdx )
|
2015-10-14 08:35:05 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
uniqueIntersections.erase( iteratorsToIntersectonsToErase[erItIdx] );
|
2015-10-14 08:35:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Copy the map into a different sorting regime, with enter leave more significant than cell index
|
2015-10-14 15:14:41 +02:00
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
std::map<RigMDEnterLeaveCellIdxKey, HexIntersectionInfo> sortedUniqueIntersections;
|
2015-10-14 08:35:05 +02:00
|
|
|
{
|
2019-09-06 10:40:57 +02:00
|
|
|
std::map<RigMDCellIdxEnterLeaveKey, HexIntersectionInfo>::iterator it = uniqueIntersections.begin();
|
|
|
|
|
while ( it != uniqueIntersections.end() )
|
2015-10-14 08:35:05 +02:00
|
|
|
{
|
2023-02-26 10:48:40 +01:00
|
|
|
sortedUniqueIntersections.insert(
|
|
|
|
|
std::make_pair( RigMDEnterLeaveCellIdxKey( it->first.measuredDepth, it->first.isEnteringCell, it->first.hexIndex, it->first.tolerance ),
|
|
|
|
|
it->second ) );
|
2015-10-14 08:35:05 +02:00
|
|
|
++it;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-14 15:14:41 +02:00
|
|
|
// Add points for the endpoint of the wellpath, if it starts/ends inside a cell
|
2015-10-14 08:35:05 +02:00
|
|
|
{
|
|
|
|
|
// Add an intersection for the well startpoint that is inside the first cell
|
2019-09-06 10:40:57 +02:00
|
|
|
std::map<RigMDEnterLeaveCellIdxKey, HexIntersectionInfo>::iterator it = sortedUniqueIntersections.begin();
|
2020-02-12 11:43:15 +01:00
|
|
|
if ( it != sortedUniqueIntersections.end() && !it->first.isEnteringCell ) // Leaving a cell as first
|
|
|
|
|
// intersection. Well starts inside a
|
|
|
|
|
// cell.
|
2015-10-14 08:35:05 +02:00
|
|
|
{
|
|
|
|
|
// Needs wellpath start point in front
|
2019-09-06 10:40:57 +02:00
|
|
|
HexIntersectionInfo firstLeavingPoint = it->second;
|
2020-10-06 12:37:16 +02:00
|
|
|
firstLeavingPoint.m_intersectionPoint = m_wellPathGeometry->wellPathPoints()[0];
|
2019-09-06 10:40:57 +02:00
|
|
|
firstLeavingPoint.m_face = cvf::StructGridInterface::NO_FACE;
|
2017-12-12 16:34:42 +01:00
|
|
|
firstLeavingPoint.m_isIntersectionEntering = true;
|
2015-10-14 08:35:05 +02:00
|
|
|
|
2023-02-26 10:48:40 +01:00
|
|
|
sortedUniqueIntersections.insert( std::make_pair( RigMDEnterLeaveCellIdxKey( m_wellPathGeometry->measuredDepths()[0],
|
|
|
|
|
true,
|
|
|
|
|
firstLeavingPoint.m_hexIndex,
|
|
|
|
|
it->first.tolerance ),
|
|
|
|
|
firstLeavingPoint ) );
|
2015-10-14 08:35:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add an intersection for the well endpoint possibly inside the last cell.
|
2023-02-26 10:48:40 +01:00
|
|
|
std::map<RigMDEnterLeaveCellIdxKey, HexIntersectionInfo>::reverse_iterator rit = sortedUniqueIntersections.rbegin();
|
2020-02-12 11:43:15 +01:00
|
|
|
if ( rit != sortedUniqueIntersections.rend() && rit->first.isEnteringCell ) // Entering a cell as last
|
|
|
|
|
// intersection. Well ends inside a
|
|
|
|
|
// cell.
|
2015-10-14 08:35:05 +02:00
|
|
|
{
|
|
|
|
|
// Needs wellpath end point at end
|
2019-09-06 10:40:57 +02:00
|
|
|
HexIntersectionInfo lastEnterPoint = rit->second;
|
2020-10-06 12:37:16 +02:00
|
|
|
lastEnterPoint.m_intersectionPoint = m_wellPathGeometry->wellPathPoints().back();
|
2015-10-14 15:07:48 +02:00
|
|
|
lastEnterPoint.m_isIntersectionEntering = false;
|
2019-09-06 10:40:57 +02:00
|
|
|
lastEnterPoint.m_face = cvf::StructGridInterface::NO_FACE;
|
2015-10-14 08:35:05 +02:00
|
|
|
|
2023-02-26 10:48:40 +01:00
|
|
|
sortedUniqueIntersections.insert( std::make_pair( RigMDEnterLeaveCellIdxKey( m_wellPathGeometry->measuredDepths().back(),
|
|
|
|
|
false,
|
|
|
|
|
lastEnterPoint.m_hexIndex,
|
|
|
|
|
rit->first.tolerance ),
|
|
|
|
|
lastEnterPoint ) );
|
2015-10-14 08:35:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-04 16:58:42 +01:00
|
|
|
// Store the intersections pairwise as cell enter-leave pairs, see pairCellEnterLeavePoints()
|
2015-10-14 08:35:05 +02:00
|
|
|
{
|
2026-11-04 16:58:42 +01:00
|
|
|
std::vector<RigMDEnterLeaveCellIdxKey> sortedPoints;
|
|
|
|
|
std::vector<const HexIntersectionInfo*> sortedInfos;
|
|
|
|
|
for ( const auto& [key, info] : sortedUniqueIntersections )
|
|
|
|
|
{
|
|
|
|
|
sortedPoints.push_back( key );
|
|
|
|
|
sortedInfos.push_back( &info );
|
|
|
|
|
}
|
2015-10-14 08:35:05 +02:00
|
|
|
|
2026-11-04 16:58:42 +01:00
|
|
|
std::vector<size_t> discardedPoints;
|
|
|
|
|
for ( const auto& [enterIdx, leaveIdx] : pairCellEnterLeavePoints( sortedPoints, &discardedPoints ) )
|
2015-10-14 08:35:05 +02:00
|
|
|
{
|
2026-11-04 16:58:42 +01:00
|
|
|
appendIntersectionToArrays( sortedPoints[enterIdx].measuredDepth, *sortedInfos[enterIdx], &errorMessages );
|
|
|
|
|
appendIntersectionToArrays( sortedPoints[leaveIdx].measuredDepth, *sortedInfos[leaveIdx], &errorMessages );
|
|
|
|
|
}
|
2026-11-03 04:08:40 +01:00
|
|
|
|
2026-11-04 16:58:42 +01:00
|
|
|
for ( size_t idx : discardedPoints )
|
|
|
|
|
{
|
|
|
|
|
errorMessages += QString( "Well Log Extraction : " ) + QString::fromStdString( m_wellCaseErrorMsgName ) +
|
|
|
|
|
( " Discards a point at MD: " ) + QString::number( (double)( sortedPoints[idx].measuredDepth ) );
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-10-14 08:35:05 +02:00
|
|
|
|
2026-11-04 16:58:42 +01:00
|
|
|
bool reportErrorMessages = false;
|
|
|
|
|
if ( reportErrorMessages )
|
|
|
|
|
{
|
|
|
|
|
errorMessages.removeDuplicates();
|
|
|
|
|
for ( auto message : errorMessages )
|
2026-11-03 04:08:40 +01:00
|
|
|
{
|
2026-11-04 16:58:42 +01:00
|
|
|
RiaLogging::warning( message.toStdString() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-10-14 08:35:05 +02:00
|
|
|
|
2026-11-04 16:58:42 +01:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
/// Pairs the entering and leaving points of each cell. The points are sorted by RigMDEnterLeaveCellIdxKey. Returns index pairs
|
|
|
|
|
/// (enter, leave) in the order the leaving points are reached. Points without a match are returned in discardedPoints.
|
|
|
|
|
///
|
|
|
|
|
/// A leaving point is matched with the latest entering point of the same cell, so points without a match (touches along cell
|
|
|
|
|
/// edges, cells next to an LGR, overlapping cells at faults) are discarded without breaking the pairs around them. A pair is
|
|
|
|
|
/// discarded when more than maxPointsBetweenEnterAndLeave points lie between its two points, and when a pair already found
|
|
|
|
|
/// lies entirely inside it: writing it would make the measured depths go back and count the inner interval twice.
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
std::vector<std::pair<size_t, size_t>> RigWellLogExtractor::pairCellEnterLeavePoints( const std::vector<RigMDEnterLeaveCellIdxKey>& sortedPoints,
|
|
|
|
|
std::vector<size_t>* discardedPoints )
|
|
|
|
|
{
|
|
|
|
|
std::vector<std::pair<size_t, size_t>> pairs;
|
|
|
|
|
std::vector<size_t> discarded;
|
2026-11-03 04:08:40 +01:00
|
|
|
|
2026-11-04 16:58:42 +01:00
|
|
|
std::map<size_t, size_t> openEnterPoints; // cell index -> position of the latest entering point
|
|
|
|
|
std::optional<size_t> latestPairedEnterPoint;
|
2015-10-14 15:07:48 +02:00
|
|
|
|
2026-11-04 16:58:42 +01:00
|
|
|
for ( size_t position = 0; position < sortedPoints.size(); ++position )
|
|
|
|
|
{
|
|
|
|
|
const RigMDEnterLeaveCellIdxKey& point = sortedPoints[position];
|
|
|
|
|
auto openIt = openEnterPoints.find( point.hexIndex );
|
2015-10-14 15:07:48 +02:00
|
|
|
|
2026-11-04 16:58:42 +01:00
|
|
|
if ( point.isEnteringCell )
|
|
|
|
|
{
|
|
|
|
|
if ( openIt != openEnterPoints.end() ) discarded.push_back( openIt->second );
|
2026-11-03 04:08:40 +01:00
|
|
|
|
2026-11-04 16:58:42 +01:00
|
|
|
openEnterPoints[point.hexIndex] = position;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2026-11-03 04:08:40 +01:00
|
|
|
|
2026-11-04 16:58:42 +01:00
|
|
|
if ( openIt == openEnterPoints.end() )
|
|
|
|
|
{
|
|
|
|
|
discarded.push_back( position );
|
|
|
|
|
continue;
|
2026-11-03 04:08:40 +01:00
|
|
|
}
|
|
|
|
|
|
2026-11-04 16:58:42 +01:00
|
|
|
const size_t enterPosition = openIt->second;
|
|
|
|
|
openEnterPoints.erase( openIt );
|
|
|
|
|
|
|
|
|
|
const bool isClose = ( position - enterPosition - 1 ) <= maxPointsBetweenEnterAndLeave;
|
|
|
|
|
const bool isAroundPairedCell = latestPairedEnterPoint.has_value() && *latestPairedEnterPoint > enterPosition;
|
|
|
|
|
|
|
|
|
|
if ( isClose && !isAroundPairedCell && RigMDEnterLeaveCellIdxKey::isProperCellEnterLeavePair( sortedPoints[enterPosition], point ) )
|
2026-11-03 04:08:40 +01:00
|
|
|
{
|
2026-11-04 16:58:42 +01:00
|
|
|
pairs.emplace_back( enterPosition, position );
|
|
|
|
|
latestPairedEnterPoint = enterPosition;
|
|
|
|
|
continue;
|
2015-10-14 08:35:05 +02:00
|
|
|
}
|
2026-11-04 16:58:42 +01:00
|
|
|
|
|
|
|
|
discarded.push_back( enterPosition );
|
|
|
|
|
discarded.push_back( position );
|
2015-10-14 08:35:05 +02:00
|
|
|
}
|
2021-04-18 09:05:10 +02:00
|
|
|
|
2026-11-04 16:58:42 +01:00
|
|
|
for ( const auto& [cellIndex, enterPosition] : openEnterPoints )
|
2020-10-22 08:17:25 +02:00
|
|
|
{
|
2026-11-04 16:58:42 +01:00
|
|
|
discarded.push_back( enterPosition );
|
2020-10-22 08:17:25 +02:00
|
|
|
}
|
2026-11-04 16:58:42 +01:00
|
|
|
|
|
|
|
|
if ( discardedPoints )
|
|
|
|
|
{
|
|
|
|
|
std::sort( discarded.begin(), discarded.end() );
|
|
|
|
|
*discardedPoints = discarded;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pairs;
|
2015-10-14 08:35:05 +02:00
|
|
|
}
|
|
|
|
|
|
2023-03-31 16:27:14 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2026-06-20 11:49:52 +02:00
|
|
|
void RigWellLogExtractor::appendIntersectionToArrays( double measuredDepth, const HexIntersectionInfo& intersection, QStringList* errorMessages )
|
2015-10-14 15:07:48 +02:00
|
|
|
{
|
2021-02-12 13:37:05 +01:00
|
|
|
QString errorMessage; // This error message is currently not displayed anywhere, as the output caused noise in
|
|
|
|
|
// several situations https://github.com/OPM/ResInsight/issues/7126
|
|
|
|
|
|
2020-10-12 09:56:38 +02:00
|
|
|
if ( !m_intersectionMeasuredDepths.empty() && measuredDepth < m_intersectionMeasuredDepths.back() )
|
|
|
|
|
{
|
2020-12-07 14:59:40 +01:00
|
|
|
const double warningLimit = 0.01;
|
|
|
|
|
double diff = std::fabs( measuredDepth - m_intersectionMeasuredDepths.back() );
|
|
|
|
|
if ( diff > warningLimit )
|
|
|
|
|
{
|
2023-02-26 10:48:40 +01:00
|
|
|
errorMessage += QString( "Well Log Extraction : %1 does not have a monotonically increasing measured depth." )
|
|
|
|
|
.arg( QString::fromStdString( m_wellCaseErrorMsgName ) );
|
2020-12-07 14:59:40 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-29 10:53:52 +02:00
|
|
|
// Allow alterations of up to 0.1 percent as long as we keep the measured depth monotonically increasing.
|
2020-10-12 09:56:38 +02:00
|
|
|
const double tolerance = std::max( 1.0, measuredDepth ) * 1.0e-3;
|
|
|
|
|
if ( RigWellLogExtractionTools::isEqualDepth( measuredDepth, m_intersectionMeasuredDepths.back(), tolerance ) )
|
|
|
|
|
{
|
2020-12-07 14:59:40 +01:00
|
|
|
if ( diff > warningLimit )
|
|
|
|
|
{
|
|
|
|
|
errorMessage += "The well path has been slightly adjusted";
|
|
|
|
|
}
|
2020-10-12 09:56:38 +02:00
|
|
|
measuredDepth = m_intersectionMeasuredDepths.back();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-06 10:40:57 +02:00
|
|
|
m_intersectionMeasuredDepths.push_back( measuredDepth );
|
|
|
|
|
m_intersectionTVDs.push_back( fabs( intersection.m_intersectionPoint[2] ) );
|
|
|
|
|
m_intersections.push_back( intersection.m_intersectionPoint );
|
|
|
|
|
m_intersectedCellsGlobIdx.push_back( intersection.m_hexIndex );
|
|
|
|
|
m_intersectedCellFaces.push_back( intersection.m_face );
|
2015-10-14 15:07:48 +02:00
|
|
|
}
|