2021-04-13 00:22:56 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2021- Equinor ASA
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2021-02-26 07:27:59 -06:00
|
|
|
#include "RicMswBranch.h"
|
2018-12-06 04:32:59 -06:00
|
|
|
|
2021-02-26 07:27:59 -06:00
|
|
|
#include "RicMswCompletions.h"
|
|
|
|
#include "RicMswSegment.h"
|
|
|
|
|
|
|
|
#include "RimWellPath.h"
|
2018-12-06 04:32:59 -06:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
RicMswBranch::RicMswBranch( const QString& label, const RimWellPath* wellPath, double initialMD, double initialTVD )
|
|
|
|
: RicMswItem( label )
|
|
|
|
, m_initialMD( initialMD )
|
|
|
|
, m_initialTVD( initialTVD )
|
|
|
|
, m_branchNumber( -1 )
|
|
|
|
, m_wellPath( wellPath )
|
2018-12-06 04:32:59 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
void RicMswBranch::addSegment( std::unique_ptr<RicMswSegment> segment )
|
2018-12-06 04:32:59 -06:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
m_segments.push_back( std::move( segment ) );
|
2018-12-06 04:32:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
void RicMswBranch::insertAfterSegment( const RicMswSegment* insertAfter, std::unique_ptr<RicMswSegment> insertItem )
|
2018-12-06 04:32:59 -06:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
auto it = std::find_if( m_segments.begin(), m_segments.end(), [insertAfter]( auto& item ) {
|
|
|
|
return item.get() == insertAfter;
|
|
|
|
} );
|
|
|
|
|
|
|
|
m_segments.insert( it, std::move( insertItem ) );
|
2018-12-06 04:32:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
void RicMswBranch::sortSegments()
|
2018-12-06 04:32:59 -06:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
std::stable_sort( m_segments.begin(),
|
|
|
|
m_segments.end(),
|
|
|
|
[]( const std::unique_ptr<RicMswSegment>& lhs, const std::unique_ptr<RicMswSegment>& rhs ) {
|
|
|
|
return *lhs < *rhs;
|
|
|
|
} );
|
2018-12-06 04:32:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
const RimWellPath* RicMswBranch::wellPath() const
|
2018-12-06 04:32:59 -06:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
return m_wellPath;
|
2018-12-06 04:32:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
double RicMswBranch::startMD() const
|
2018-12-06 04:32:59 -06:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
return m_initialMD;
|
2018-12-06 04:32:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
double RicMswBranch::startTVD() const
|
2018-12-06 04:32:59 -06:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
return m_initialTVD;
|
2018-12-06 04:32:59 -06:00
|
|
|
}
|
|
|
|
|
2018-12-12 02:44:00 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
double RicMswBranch::endMD() const
|
2018-12-12 02:44:00 -06:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
if ( !m_segments.empty() )
|
|
|
|
{
|
|
|
|
return m_segments.back()->endMD();
|
|
|
|
}
|
|
|
|
return m_initialMD;
|
2018-12-12 02:44:00 -06:00
|
|
|
}
|
|
|
|
|
2018-12-06 04:32:59 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
double RicMswBranch::endTVD() const
|
2018-12-06 04:32:59 -06:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
if ( !m_segments.empty() )
|
|
|
|
{
|
|
|
|
return m_segments.back()->endTVD();
|
|
|
|
}
|
|
|
|
return m_initialTVD;
|
2018-12-06 04:32:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
int RicMswBranch::branchNumber() const
|
2018-12-06 04:32:59 -06:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
return m_branchNumber;
|
2018-12-06 04:32:59 -06:00
|
|
|
}
|
|
|
|
|
2018-12-12 02:44:00 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
void RicMswBranch::setBranchNumber( int branchNumber )
|
2018-12-12 02:44:00 -06:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
m_branchNumber = branchNumber;
|
2018-12-12 02:44:00 -06:00
|
|
|
}
|
|
|
|
|
2018-12-06 04:32:59 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
std::vector<const RicMswSegment*> RicMswBranch::segments() const
|
2018-12-06 04:32:59 -06:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
std::vector<const RicMswSegment*> allSegments;
|
|
|
|
for ( const auto& segment : m_segments )
|
|
|
|
{
|
|
|
|
allSegments.push_back( segment.get() );
|
|
|
|
}
|
|
|
|
return allSegments;
|
2018-12-06 04:32:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
std::vector<RicMswSegment*> RicMswBranch::segments()
|
2018-12-06 04:32:59 -06:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
std::vector<RicMswSegment*> allSegments;
|
|
|
|
for ( auto& segment : m_segments )
|
|
|
|
{
|
|
|
|
allSegments.push_back( segment.get() );
|
|
|
|
}
|
|
|
|
return allSegments;
|
2018-12-06 04:32:59 -06:00
|
|
|
}
|
|
|
|
|
2021-04-13 00:22:56 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-19 07:04:28 -05:00
|
|
|
/// TODO: Marked as obsolete, delete if lowerMD variant works as expected
|
2021-04-13 00:22:56 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-04-19 07:04:28 -05:00
|
|
|
RicMswSegment* RicMswBranch::findClosestSegmentByMidpoint_obsolete( double measuredDepthLocation )
|
2021-04-13 00:22:56 -05:00
|
|
|
{
|
|
|
|
if ( measuredDepthLocation < startMD() )
|
|
|
|
{
|
|
|
|
return segmentCount() > 0 ? segments().front() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( measuredDepthLocation > endMD() )
|
|
|
|
{
|
|
|
|
return segmentCount() > 0 ? segments().back() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RicMswSegment* closestSegment = nullptr;
|
|
|
|
double smallestDistance = std::numeric_limits<double>::infinity();
|
|
|
|
|
|
|
|
for ( auto seg : segments() )
|
|
|
|
{
|
2021-04-19 07:04:28 -05:00
|
|
|
// WELSEGS is reported as the midpoint of the segment
|
2021-04-13 00:22:56 -05:00
|
|
|
double midpointMD = 0.5 * ( seg->startMD() + seg->endMD() );
|
|
|
|
|
|
|
|
double candidateDistance = std::abs( midpointMD - measuredDepthLocation );
|
|
|
|
if ( candidateDistance < smallestDistance )
|
|
|
|
{
|
|
|
|
closestSegment = seg;
|
|
|
|
smallestDistance = candidateDistance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return closestSegment;
|
|
|
|
}
|
|
|
|
|
2021-04-19 07:04:28 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RicMswSegment* RicMswBranch::findClosestSegmentWithLowerMD( double measuredDepthLocation )
|
|
|
|
{
|
|
|
|
if ( measuredDepthLocation < startMD() )
|
|
|
|
{
|
|
|
|
return segmentCount() > 0 ? segments().front() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( measuredDepthLocation > endMD() )
|
|
|
|
{
|
|
|
|
return segmentCount() > 0 ? segments().back() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RicMswSegment* closestSegment = nullptr;
|
|
|
|
double smallestDistance = std::numeric_limits<double>::infinity();
|
|
|
|
|
|
|
|
for ( auto seg : segments() )
|
|
|
|
{
|
|
|
|
// WELSEGS is reported as the midpoint of the segment
|
|
|
|
double midpointMD = 0.5 * ( seg->startMD() + seg->endMD() );
|
|
|
|
|
|
|
|
double candidateDistance = measuredDepthLocation - midpointMD;
|
|
|
|
if ( candidateDistance > 0.0 && candidateDistance < smallestDistance )
|
|
|
|
{
|
|
|
|
closestSegment = seg;
|
|
|
|
smallestDistance = candidateDistance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return closestSegment;
|
|
|
|
}
|
|
|
|
|
2018-12-06 04:32:59 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
size_t RicMswBranch::segmentCount() const
|
2018-12-06 04:32:59 -06:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
return m_segments.size();
|
2018-12-06 04:32:59 -06:00
|
|
|
}
|
2021-02-26 07:27:59 -06:00
|
|
|
|
2018-12-06 04:32:59 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
std::vector<const RicMswBranch*> RicMswBranch::branches() const
|
2018-12-06 04:32:59 -06:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
std::vector<const RicMswBranch*> branches;
|
|
|
|
for ( const auto& branch : m_branches )
|
|
|
|
{
|
|
|
|
branches.push_back( branch.get() );
|
|
|
|
}
|
|
|
|
return branches;
|
2018-12-06 04:32:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
std::vector<RicMswBranch*> RicMswBranch::branches()
|
2018-12-06 04:32:59 -06:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
std::vector<RicMswBranch*> branches;
|
|
|
|
for ( auto& branch : m_branches )
|
|
|
|
{
|
|
|
|
branches.push_back( branch.get() );
|
|
|
|
}
|
|
|
|
return branches;
|
2018-12-06 04:32:59 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2021-02-26 07:27:59 -06:00
|
|
|
void RicMswBranch::addChildBranch( std::unique_ptr<RicMswBranch> branch )
|
2018-12-06 04:32:59 -06:00
|
|
|
{
|
2021-02-26 07:27:59 -06:00
|
|
|
m_branches.push_back( std::move( branch ) );
|
2018-12-06 04:32:59 -06:00
|
|
|
}
|
2021-05-14 05:16:59 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
std::vector<RicMswSegment*> RicMswBranch::allSegmentsRecursively()
|
|
|
|
{
|
|
|
|
std::vector<RicMswSegment*> allSegments;
|
|
|
|
|
|
|
|
{
|
|
|
|
std::vector<RicMswSegment*> branchSegments = segments();
|
|
|
|
allSegments.insert( allSegments.begin(), branchSegments.begin(), branchSegments.end() );
|
|
|
|
|
|
|
|
for ( auto seg : branchSegments )
|
|
|
|
{
|
|
|
|
for ( auto completion : seg->completions() )
|
|
|
|
{
|
|
|
|
std::vector<RicMswSegment*> completionSegments = completion->allSegmentsRecursively();
|
|
|
|
|
|
|
|
allSegments.insert( allSegments.begin(), completionSegments.begin(), completionSegments.end() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for ( auto subBranch : branches() )
|
|
|
|
{
|
|
|
|
auto subBranchSegments = subBranch->allSegmentsRecursively();
|
|
|
|
|
|
|
|
allSegments.insert( allSegments.begin(), subBranchSegments.begin(), subBranchSegments.end() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return allSegments;
|
|
|
|
}
|
|
|
|
}
|