2015-09-04 08:30:04 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) Statoil ASA
|
|
|
|
// Copyright (C) Ceetron Solutions AS
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2015-09-04 08:30:04 -05: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 03:40:57 -05:00
|
|
|
//
|
2015-09-04 08:30:04 -05: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 03:40:57 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2015-09-04 08:30:04 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#pragma once
|
2020-10-12 02:56:38 -05:00
|
|
|
|
|
|
|
#include <algorithm>
|
2017-06-14 07:34:52 -05:00
|
|
|
#include <cmath>
|
2015-09-04 08:30:04 -05:00
|
|
|
|
|
|
|
//==================================================================================================
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2020-10-12 02:56:38 -05:00
|
|
|
/// Default tolerance is 0.1 meters to handle inaccuracies across faults
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2015-09-04 08:30:04 -05:00
|
|
|
//==================================================================================================
|
|
|
|
|
2017-06-14 07:15:29 -05:00
|
|
|
struct RigWellLogExtractionTools
|
2015-09-04 08:30:04 -05:00
|
|
|
{
|
2020-10-12 02:56:38 -05:00
|
|
|
static bool isEqualDepth( double d1, double d2, const double tolerance = 0.1 )
|
2017-05-15 08:49:49 -05:00
|
|
|
{
|
2015-10-14 01:08:13 -05:00
|
|
|
double depthDiff = d1 - d2;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
return ( fabs( depthDiff ) < tolerance ); // Equal depth
|
2015-10-14 01:08:13 -05:00
|
|
|
}
|
2015-09-04 08:30:04 -05:00
|
|
|
};
|
|
|
|
|
2015-10-14 01:08:13 -05:00
|
|
|
//==================================================================================================
|
|
|
|
/// Class used to sort the intersections along the wellpath,
|
|
|
|
/// Use as key in a map
|
|
|
|
/// Sorting according to MD first, then Cell Idx, then Leaving before entering cell
|
|
|
|
//==================================================================================================
|
|
|
|
|
2015-10-14 05:40:31 -05:00
|
|
|
struct RigMDCellIdxEnterLeaveKey
|
2015-10-14 01:08:13 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
RigMDCellIdxEnterLeaveKey( double md, size_t cellIdx, bool entering )
|
|
|
|
: measuredDepth( md )
|
|
|
|
, hexIndex( cellIdx )
|
|
|
|
, isEnteringCell( entering )
|
2018-02-23 15:38:08 -06:00
|
|
|
{
|
|
|
|
}
|
2015-10-14 01:08:13 -05:00
|
|
|
|
|
|
|
double measuredDepth;
|
|
|
|
size_t hexIndex;
|
|
|
|
bool isEnteringCell; // As opposed to leaving.
|
2020-02-12 04:13:38 -06:00
|
|
|
bool isLeavingCell() const { return !isEnteringCell; }
|
2015-10-14 01:08:13 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
bool operator<( const RigMDCellIdxEnterLeaveKey& other ) const
|
2015-10-14 01:08:13 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( RigWellLogExtractionTools::isEqualDepth( measuredDepth, other.measuredDepth ) )
|
2015-09-04 08:30:04 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( hexIndex == other.hexIndex )
|
2015-10-14 01:08:13 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( isEnteringCell == other.isEnteringCell )
|
2015-10-14 01:08:13 -05:00
|
|
|
{
|
|
|
|
// Completely equal: intersections at cell edges or corners or edges of the face triangles
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !isEnteringCell; // Sort Leaving cell before (less than) entering cell
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
return ( hexIndex < other.hexIndex );
|
2015-09-04 08:30:04 -05:00
|
|
|
}
|
2015-10-14 01:08:13 -05:00
|
|
|
|
|
|
|
// The depths are not equal
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
return ( measuredDepth < other.measuredDepth );
|
2015-10-14 01:08:13 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
//==================================================================================================
|
|
|
|
/// Class used to sort the intersections along the wellpath,
|
|
|
|
/// Use as key in a map
|
2019-09-06 03:40:57 -05:00
|
|
|
/// Sorting according to MD first,then Leaving before entering cell, then Cell Idx,
|
2015-10-14 01:08:13 -05:00
|
|
|
//==================================================================================================
|
|
|
|
|
2015-10-14 05:40:31 -05:00
|
|
|
struct RigMDEnterLeaveCellIdxKey
|
2015-10-14 01:08:13 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
RigMDEnterLeaveCellIdxKey( double md, bool entering, size_t cellIdx )
|
|
|
|
: measuredDepth( md )
|
|
|
|
, isEnteringCell( entering )
|
|
|
|
, hexIndex( cellIdx )
|
2018-02-23 15:38:08 -06:00
|
|
|
{
|
|
|
|
}
|
2015-10-14 01:08:13 -05:00
|
|
|
|
|
|
|
double measuredDepth;
|
|
|
|
bool isEnteringCell; // As opposed to leaving.
|
2020-02-12 04:13:38 -06:00
|
|
|
bool isLeavingCell() const { return !isEnteringCell; }
|
2015-10-14 01:08:13 -05:00
|
|
|
size_t hexIndex;
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
bool operator<( const RigMDEnterLeaveCellIdxKey& other ) const
|
2015-10-14 01:08:13 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( RigWellLogExtractionTools::isEqualDepth( measuredDepth, other.measuredDepth ) )
|
2015-09-04 08:30:04 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( isEnteringCell == other.isEnteringCell )
|
2015-10-14 01:08:13 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( hexIndex == other.hexIndex )
|
2015-10-14 01:08:13 -05:00
|
|
|
{
|
|
|
|
// Completely equal: intersections at cell edges or corners or edges of the face triangles
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
return ( hexIndex < other.hexIndex );
|
2015-10-14 01:08:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return isLeavingCell(); // Sort Leaving cell before (less than) entering cell
|
2015-09-04 08:30:04 -05:00
|
|
|
}
|
|
|
|
|
2015-10-14 01:08:13 -05:00
|
|
|
// The depths are not equal
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
return ( measuredDepth < other.measuredDepth );
|
2015-10-14 01:08:13 -05:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
static bool isProperCellEnterLeavePair( const RigMDEnterLeaveCellIdxKey& key1, const RigMDEnterLeaveCellIdxKey& key2 )
|
2015-10-14 01:08:13 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
return ( key1.hexIndex == key2.hexIndex && key1.isEnteringCell && key2.isLeavingCell() &&
|
|
|
|
!RigWellLogExtractionTools::isEqualDepth( key1.measuredDepth, key2.measuredDepth ) );
|
2015-09-04 08:30:04 -05:00
|
|
|
}
|
|
|
|
};
|