Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 93 additions & 9 deletions ApplicationLibCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "RigEclipseCaseDataTools.h"
#include "RigFlowDiagResultAddress.h"
#include "RigFlowDiagResults.h"
#include "RigMainGrid.h"
#include "Well/RigAccWellFlowCalculator.h"
#include "Well/RigSimWellData.h"
#include "Well/RigSimulationWellCenterLineCalculator.h"
Expand Down Expand Up @@ -76,6 +77,17 @@ void AppEnum<RimWellAllocationPlot::FlowType>::setUp()
addItem( RimWellAllocationPlot::INFLOW, "INFLOW", "Inflow Rates" );
setDefault( RimWellAllocationPlot::INFLOW );
}

template <>
void AppEnum<RimWellAllocationPlot::ConnectionLabelType>::setUp()
{
addItem( RimWellAllocationPlot::ConnectionLabelType::CONNECTION_NUMBER, "CONNECTION_NUMBER", "Connection Number" );
addItem( RimWellAllocationPlot::ConnectionLabelType::CELL_IJK, "CELL_IJK", "Cell (I, J, K)" );
addItem( RimWellAllocationPlot::ConnectionLabelType::CONNECTION_NUMBER_AND_CELL_IJK,
"CONNECTION_NUMBER_AND_CELL_IJK",
"Connection Number and Cell (I, J, K)" );
setDefault( RimWellAllocationPlot::ConnectionLabelType::CONNECTION_NUMBER_AND_CELL_IJK );
}
} // namespace caf

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -105,6 +117,19 @@ RimWellAllocationPlot::RimWellAllocationPlot()
CAF_PDM_InitField( &m_wellName, "WellName", RiaDefines::selectionTextNone(), "Well" );
CAF_PDM_InitFieldNoDefault( &m_flowDiagSolution, "FlowDiagSolution", "Plot Type" );
CAF_PDM_InitFieldNoDefault( &m_flowType, "FlowType", "Flow Type" );
CAF_PDM_InitFieldNoDefault( &m_connectionLabelType,
"ConnectionLabelType",
"Connection Labels",
"",
"Label the connections on the depth axis by connection number and/or grid cell (I, J, K)",
"" );
CAF_PDM_InitField( &m_showAllConnections,
"ShowAllConnections",
false,
"Show All Connections",
Comment thread
magnesj marked this conversation as resolved.
Resolved
"",
"Show a tick and label for every connection on the depth axis",
"" );
CAF_PDM_InitField( &m_groupSmallContributions, "GroupSmallContributions", true, "Group Small Contributions" );
CAF_PDM_InitField( &m_smallContributionsThreshold, "SmallContributionsThreshold", 0.005, "Threshold" );
CAF_PDM_InitFieldNoDefault( &m_accumulatedWellFlowPlot, "AccumulatedWellFlowPlot", "Accumulated Well Flow" );
Expand Down Expand Up @@ -369,6 +394,11 @@ void RimWellAllocationPlot::updateFromWell()

if ( !depthValues.empty() )
{
if ( depthType == RiaDefines::DepthType::CONNECTION_NUMBER )
{
updateConnectionTickLabels( plotTrack, *wfCalculator, brIdx );
}

std::vector<QString> tracerNames = wfCalculator->tracerNames();
for ( const QString& tracerName : tracerNames )
{
Expand All @@ -381,20 +411,16 @@ void RimWellAllocationPlot::updateFromWell()

if ( !accFlow.empty() )
{
// Add a dummy zero connection number at the end to make the curve reach the y-axis when showing in flow rate. The
// lowest connection number is 1.0, so adding a zero value will not cause any issue when showing in accumulated flow.
// Add a dummy zero connection number at the end to make the curve reach the y-axis. The lowest connection number
// is 1.0, so the dummy point (shifted to 0.5 below) stays before the first connection in both flow types.
accFlow.push_back( accFlow.back() );
curveDepthValues.push_back( 0.0 );
}

// Shift the "bars" to make connection number tick at the midpoint of the constant value
Comment thread
magnesj marked this conversation as resolved.
Resolved
// when showing in flow rate
if ( m_flowType == INFLOW )
for ( double& connNum : curveDepthValues )
{
for ( double& connNum : curveDepthValues )
{
connNum += 0.5;
}
connNum += 0.5;
}
Comment thread
magnesj marked this conversation as resolved.
Resolved
}
else if ( depthType == RiaDefines::DepthType::PSEUDO_LENGTH || depthType == RiaDefines::DepthType::TRUE_VERTICAL_DEPTH )
Expand Down Expand Up @@ -477,6 +503,7 @@ void RimWellAllocationPlot::updateFromWell()
m_totalWellAllocationPlot->updateConnectedEditors();

accumulatedWellFlowPlot()->updateConnectedEditors();
updateConnectedEditors();
m_tofAccumulatedPhaseFractionsPlot->reloadFromWell();
m_tofAccumulatedPhaseFractionsPlot->updateConnectedEditors();

Expand All @@ -496,6 +523,58 @@ void RimWellAllocationPlot::updateWellFlowPlotXAxisTitle( RimWellLogTrack* plotT
plotTrack->setPropertyValueAxisTitle( axisTitle );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimWellAllocationPlot::updateConnectionTickLabels( RimWellLogTrack* plotTrack,
const RigAccWellFlowCalculator& wfCalculator,
size_t branchIdx ) const
{
std::map<int, QString> cellTexts;

if ( m_case && m_case->eclipseCaseData() )
{
const RigMainGrid* mainGrid = m_case->eclipseCaseData()->mainGrid();

const std::vector<double> connectionNumbers = wfCalculator.connectionNumbersFromTop( branchIdx );
const std::vector<RigWellResultPoint>& resultPoints = wfCalculator.connectionWellResultPoints( branchIdx );
CAF_ASSERT( connectionNumbers.size() == resultPoints.size() );

for ( size_t i = 0; i < std::min( connectionNumbers.size(), resultPoints.size() ); ++i )
{
const RigWellResultPoint& resultPoint = resultPoints[i];
if ( !mainGrid || !resultPoint.isCell() || resultPoint.gridIndex() >= mainGrid->gridCount() ) continue;

const RigGridBase* grid = mainGrid->gridByIndex( resultPoint.gridIndex() );
const auto ijk = grid ? grid->ijkFromCellIndex( resultPoint.cellIndex() ) : std::nullopt;
if ( !ijk ) continue;

const auto ijk1 = ijk->toOneBased();

QString cellText = QString( "(%1, %2, %3)" ).arg( ijk1.x() ).arg( ijk1.y() ).arg( ijk1.z() );
if ( grid != mainGrid ) cellText = QString::fromStdString( grid->gridName() ) + " " + cellText;

const int connectionNumber = std::lround( connectionNumbers[i] );
cellTexts[connectionNumber] = cellText;
}
}

std::map<int, QString> tickLabels;
if ( m_connectionLabelType() != ConnectionLabelType::CONNECTION_NUMBER )
{
for ( const auto& [connectionNumber, cellText] : cellTexts )
{
tickLabels[connectionNumber] = m_connectionLabelType() == ConnectionLabelType::CELL_IJK
? cellText
: QString( "%1 %2" ).arg( connectionNumber ).arg( cellText );
}
}

plotTrack->setConnectionCellTexts( cellTexts );
plotTrack->setDepthAxisTickLabels( tickLabels );
plotTrack->setDepthAxisIntegerTicks( true, m_showAllConnections() );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -804,7 +883,7 @@ void RimWellAllocationPlot::fieldChangedByUi( const caf::PdmFieldHandle* changed
}
else if ( changedField == &m_wellName || changedField == &m_timeStep || changedField == &m_flowDiagSolution ||
changedField == &m_groupSmallContributions || changedField == &m_smallContributionsThreshold || changedField == &m_flowType ||
changedField == &m_branchDetection )
changedField == &m_branchDetection || changedField == &m_connectionLabelType || changedField == &m_showAllConnections )
Comment thread
magnesj marked this conversation as resolved.
Resolved
{
onLoadDataAndUpdate();
}
Expand Down Expand Up @@ -839,6 +918,11 @@ void RimWellAllocationPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOr
caf::PdmUiGroup& optionGroup = *uiOrdering.addNewGroup( "Options" );
optionGroup.add( &m_flowDiagSolution );
optionGroup.add( &m_flowType );
if ( m_accumulatedWellFlowPlot && m_accumulatedWellFlowPlot->depthType() == RiaDefines::DepthType::CONNECTION_NUMBER )
{
optionGroup.add( &m_connectionLabelType );
optionGroup.add( &m_showAllConnections );
}
Comment thread
magnesj marked this conversation as resolved.
Resolved
optionGroup.add( &m_groupSmallContributions );
optionGroup.add( &m_smallContributionsThreshold );
m_smallContributionsThreshold.uiCapability()->setUiReadOnly( !m_groupSmallContributions() );
Expand Down
12 changes: 12 additions & 0 deletions ApplicationLibCode/ProjectDataModel/Flow/RimWellAllocationPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <QPointer>

class RigAccWellFlowCalculator;
class RigSimWellData;
class RimEclipseResultCase;
class RimFlowDiagSolution;
Expand Down Expand Up @@ -62,6 +63,13 @@ class RimWellAllocationPlot : public RimViewWindow
INFLOW
};

enum class ConnectionLabelType
{
CONNECTION_NUMBER,
CELL_IJK,
CONNECTION_NUMBER_AND_CELL_IJK
};

public:
RimWellAllocationPlot();
~RimWellAllocationPlot() override;
Expand Down Expand Up @@ -110,6 +118,7 @@ class RimWellAllocationPlot : public RimViewWindow
void setCase( RimEclipseResultCase* eclipseCase );
void updateFromWell();
void updateWellFlowPlotXAxisTitle( RimWellLogTrack* plotTrack );
void updateConnectionTickLabels( RimWellLogTrack* plotTrack, const RigAccWellFlowCalculator& wfCalculator, size_t branchIdx ) const;

void addStackedCurve( const QString& tracerName,
RiaDefines::DepthType depthType,
Expand Down Expand Up @@ -145,6 +154,9 @@ class RimWellAllocationPlot : public RimViewWindow
caf::PdmField<double> m_smallContributionsThreshold;
caf::PdmField<caf::AppEnum<FlowType>> m_flowType;

caf::PdmField<caf::AppEnum<ConnectionLabelType>> m_connectionLabelType;
caf::PdmField<bool> m_showAllConnections;

QPointer<RiuWellAllocationPlot> m_wellAllocationPlotWidget;

caf::PdmChildField<RimWellLogPlot*> m_accumulatedWellFlowPlot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,16 +803,11 @@ QString RimWellLogTrack::asciiDataForPlotExport() const
std::vector<double> curveDepths;
std::vector<std::vector<double>> curvesPlotXValues;

auto depthType = parentWellLogPlot()->depthType();
auto depthUnit = parentWellLogPlot()->depthUnit();
bool isWellAllocInflowPlot = false;
{
auto wapl = parentWellLogPlot()->firstAncestorOfType<RimWellAllocationPlot>();
if ( wapl )
{
isWellAllocInflowPlot = ( wapl->flowType() == RimWellAllocationPlot::INFLOW );
}
}
auto depthType = parentWellLogPlot()->depthType();
auto depthUnit = parentWellLogPlot()->depthUnit();
bool isWellAllocPlot = parentWellLogPlot()->firstAncestorOfType<RimWellAllocationPlot>() != nullptr;

const bool exportCellTexts = depthType == RiaDefines::DepthType::CONNECTION_NUMBER && !m_connectionCellTexts.empty();

RiaWellLogCurveMerger curveMerger;
bool foundNonMatchingDepths = false;
Expand Down Expand Up @@ -857,6 +852,7 @@ QString RimWellLogTrack::asciiDataForPlotExport() const
if ( depthType == RiaDefines::DepthType::CONNECTION_NUMBER )
{
out += "Connection";
if ( exportCellTexts ) out += " \tCell (I, J, K)";
}
else if ( depthType == RiaDefines::DepthType::MEASURED_DEPTH )
{
Expand Down Expand Up @@ -922,13 +918,18 @@ QString RimWellLogTrack::asciiDataForPlotExport() const

curveDepth = curveDepths[i];

if ( isWellAllocInflowPlot )
if ( isWellAllocPlot )
{
curveDepth -= 0.5; // To shift the values that was shifted to get the numbers between the changes
}
}

out += QString::number( curveDepth, 'f', 3 );
if ( exportCellTexts )
{
auto it = m_connectionCellTexts.find( std::lround( curveDepth ) );
out += " \t" + ( it != m_connectionCellTexts.end() ? it->second : QString( "-" ) );
}
for ( std::vector<double> plotVector : curvesPlotXValues )
{
out += QString( " \t%1" ).arg( QString::number( plotVector[i], 'f', 3 ), 12 );
Expand Down Expand Up @@ -1422,6 +1423,35 @@ QString RimWellLogTrack::depthAxisTitle() const
return "";
}

//--------------------------------------------------------------------------------------------------
/// Custom text for depth axis ticks at integer depth values, e.g. cell IJK for connection numbers
//--------------------------------------------------------------------------------------------------
void RimWellLogTrack::setDepthAxisTickLabels( const std::map<int, QString>& tickLabels )
{
m_depthAxisTickLabels = tickLabels;

if ( m_plotWidget ) m_plotWidget->setDepthAxisTickLabels( m_depthAxisTickLabels );
}

//--------------------------------------------------------------------------------------------------
/// Grid cell text for each connection number, included in the plot data export
//--------------------------------------------------------------------------------------------------
void RimWellLogTrack::setConnectionCellTexts( const std::map<int, QString>& cellTexts )
{
m_connectionCellTexts = cellTexts;
}

//--------------------------------------------------------------------------------------------------
/// Place depth axis ticks at integer values only, optionally with a major tick at every integer
//--------------------------------------------------------------------------------------------------
void RimWellLogTrack::setDepthAxisIntegerTicks( bool enabled, bool tickAtEveryInteger )
{
m_depthAxisIntegerTicks = enabled;
m_depthAxisTickAtEveryInteger = tickAtEveryInteger;

if ( m_plotWidget ) m_plotWidget->setDepthAxisIntegerTicks( m_depthAxisIntegerTicks, m_depthAxisTickAtEveryInteger );
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1538,6 +1568,8 @@ RiuPlotWidget* RimWellLogTrack::doCreatePlotViewWidget( QWidget* mainWindowParen
{
m_plotWidget = new RiuWellLogTrack( this, mainWindowParent );
updateAxisScaleEngine();
if ( !m_depthAxisTickLabels.empty() ) m_plotWidget->setDepthAxisTickLabels( m_depthAxisTickLabels );
if ( m_depthAxisIntegerTicks ) m_plotWidget->setDepthAxisIntegerTicks( m_depthAxisIntegerTicks, m_depthAxisTickAtEveryInteger );

for ( size_t cIdx = 0; cIdx < m_curves.size(); ++cIdx )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ class RimWellLogTrack : public RimPlot
void setPropertyValueAxisTitle( const QString& text );
QString depthAxisTitle() const;

void setDepthAxisTickLabels( const std::map<int, QString>& tickLabels );
void setConnectionCellTexts( const std::map<int, QString>& cellTexts );
void setDepthAxisIntegerTicks( bool enabled, bool tickAtEveryInteger );

void setFormationWellPath( RimWellPath* wellPath );
RimWellPath* formationWellPath() const;
void setFormationSimWellName( const QString& simWellName );
Expand Down Expand Up @@ -405,4 +409,9 @@ class RimWellLogTrack : public RimPlot
double m_availablePropertyValueRangeMax;
double m_availableDepthRangeMin;
double m_availableDepthRangeMax;

std::map<int, QString> m_depthAxisTickLabels;
std::map<int, QString> m_connectionCellTexts;
bool m_depthAxisIntegerTicks = false;
bool m_depthAxisTickAtEveryInteger = false;
};
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ std::vector<double> RigAccWellFlowCalculator::connectionNumbersFromTop( size_t b
return result;
}

//--------------------------------------------------------------------------------------------------
/// The well result points of the connections, in the same order as connectionNumbersFromTop()
//--------------------------------------------------------------------------------------------------
const std::vector<RigWellResultPoint>& RigAccWellFlowCalculator::connectionWellResultPoints( size_t branchIdx ) const
{
return m_connectionFlowPrBranch[branchIdx].wellResultPoints;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -485,6 +493,7 @@ void RigAccWellFlowCalculator::calculateAccumulatedFlowPrConnection( size_t bran
BranchFlow& branchFlow = m_connectionFlowPrBranch[branchIdx];

storeFlowOnDepth( &branchFlow, connNumFromTop, accFlowPrTracer, flowPrTracer );
branchFlow.wellResultPoints.push_back( wellCell );

--clSegIdx;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class RigEclCellIndexCalculator

#include <QString>

#include "cvfVector3.h"
#include "RigWellResultPoint.h"

struct RigWellResultPoint;
#include "cvfVector3.h"

class RigAccWellFlowCalculator
{
Expand All @@ -81,9 +81,10 @@ class RigAccWellFlowCalculator
const std::vector<double>& pipeBranchMeasuredDepths,
bool totalFlowOnly );

std::vector<double> connectionNumbersFromTop( size_t branchIdx ) const;
const std::vector<double>& accumulatedTracerFlowPrConnection( const QString& tracerName, size_t branchIdx ) const;
const std::vector<double>& tracerFlowPrConnection( const QString& tracerName, size_t branchIdx ) const;
std::vector<double> connectionNumbersFromTop( size_t branchIdx ) const;
const std::vector<RigWellResultPoint>& connectionWellResultPoints( size_t branchIdx ) const;
const std::vector<double>& accumulatedTracerFlowPrConnection( const QString& tracerName, size_t branchIdx ) const;
const std::vector<double>& tracerFlowPrConnection( const QString& tracerName, size_t branchIdx ) const;

const std::vector<double>& pseudoLengthFromTop( size_t branchIdx ) const;
const std::vector<double>& trueVerticalDepth( size_t branchIdx ) const;
Expand Down Expand Up @@ -134,6 +135,7 @@ class RigAccWellFlowCalculator
{
std::vector<double> depthValuesFromTop;
std::vector<double> trueVerticalDepth;
std::vector<RigWellResultPoint> wellResultPoints; // Only populated for connection based flow
std::map<QString, std::vector<double>> accFlowPrTracer;
std::map<QString, std::vector<double>> flowPrTracer;
};
Expand Down
1 change: 1 addition & 0 deletions ApplicationLibCode/UnitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ set(SOURCE_UNITTEST_FILES
${CMAKE_CURRENT_LIST_DIR}/RifCaseRealizationParametersReader-Test.cpp
${CMAKE_CURRENT_LIST_DIR}/RigWellLogExtractor-Test.cpp
${CMAKE_CURRENT_LIST_DIR}/RigWellPath-Test.cpp
${CMAKE_CURRENT_LIST_DIR}/RigAccWellFlowCalculator-Test.cpp
${CMAKE_CURRENT_LIST_DIR}/RigWellPathGeometryTools-Test.cpp
${CMAKE_CURRENT_LIST_DIR}/RifEclipseSummaryAddress-Test.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaTimeHistoryCurveTools-Test.cpp
Expand Down
Loading