Files
ResInsight/ApplicationLibCode/FileInterface/RifReaderRftInterface.cpp
T
Magne Sjaastad 387b19ef62 #12276 Add RFT correlation report plot with cross-plot and tornado plot
* Fix defensive guards and TVD interpolation

Guard against out-of-bounds IJK and invalid cells in RifReaderRftInterface.
Guard against null eclCase in RimDataSourceForRftPlt::address.
Guard against null plot widgets in RiuMultiPlotPage.
Fix interpolateMdFromTvd corrupting valid entries after infinity TVD values
by skipping infinity entries in the first pass and tracking only the last
two valid MD values for the startMD adjustment.

* Add RiuQwtCurveSelectorFilter for click-to-select realization in Qwt plots

New shared event filter class that installs on a QwtPlot canvas and calls a
user-supplied callback with the closest data point on each click.

Migrate the local CurveSelectorFilter in RimParameterResultCrossPlot to use
the new shared class. Add Z_HIGHLIGHTED_CURVE to ZIndex enum and replace all
raw z-order integers in RiuQwtPlotCurveDefines with named constants.

* Add RFT correlation report plot with cross-plot and tornado plot

New classes:
- RimRftCorrelationReportPlot: composite plot showing an RFT well log track
  alongside a parameter cross-plot and a tornado plot sub-plot.
- RimParameterRftCrossPlot: cross-plot of ensemble parameters vs RFT-derived
  measured depth values, with click-to-select realization support.
- RimRftTornadoPlot: tornado plot with correlation-sorted parameter list and
  click-to-select realization support.
- RicCreateRftCorrelationReportFeature: context menu command on RimWellRftPlot
  that creates a RimRftCorrelationReportPlot in the correlation plot collection.

Wire up in RimCorrelationPlotCollection and RimContextCommandBuilder.

* Add click-to-select and highlight selected realization in RFT plots

Install RiuQwtCurveSelectorFilter on RimWellRftPlot canvas to support
click-to-select realization. Highlight the selected realization using a
contrast color (orange-red) and increased line thickness. React to both
click-to-select in the plot and selection changes in the Data Sources panel.

Add Z_HIGHLIGHTED_CURVE z-order and replace raw z-order integers with
named constants in RimWellRftPlot.

Highlight selected realization with XCROSS symbol in RimParameterRftCrossPlot
via RimSummaryEnsembleTools::findSummaryCase.

* RimWellRftPlot: add Create RFT Correlation Report to canvas right-click menu

Override appendMenuItems in RimWellRftPlot to add RicCreateRftCorrelationReportFeature.
Call appendMenuItems from RiuMultiPlotPage::contextMenuEvent so any plot type
can contribute canvas menu items without modifying RiuMultiPlotPage.

* RicShowPlotDataFeature: support RimRftCorrelationReportPlot

Add RimRftCorrelationReportPlot to the isCommandEnabled check and expand
it into its cross-plot and tornado sub-plots in onActionTriggered, matching
the pattern used for RimCorrelationReportPlot.
2026-04-16 16:45:44 +02:00

161 lines
6.6 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2019- 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.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RifReaderRftInterface.h"
#include "RigEclipseCaseData.h"
#include "RigMainGrid.h"
#include "Well/RigEclipseWellLogExtractor.h"
#include "Well/RigWellPath.h"
#include "Well/RigWellPathGeometryTools.h"
#include "cafVecIjk.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RifReaderRftInterface::~RifReaderRftInterface() = default;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::set<RifEclipseRftAddress> RifReaderRftInterface::eclipseRftAddresses( const QString& wellName, const QDateTime& timeStep )
{
std::set<RifEclipseRftAddress> matchingAddresses;
std::set<RifEclipseRftAddress> allAddresses = eclipseRftAddresses();
for ( const RifEclipseRftAddress& address : allAddresses )
{
if ( address.wellName() == wellName && address.timeStep() == timeStep )
{
matchingAddresses.insert( address );
}
}
return matchingAddresses;
}
//--------------------------------------------------------------------------------------------------
// Compute average measured depth for cell based on grid intersections for cells. If the well path geometry do not contain measured depth
// for a grid cell, the measured depth is estimated based on existing geometry for the well path.
//--------------------------------------------------------------------------------------------------
std::vector<double>
RifReaderRftInterface::computeMeasuredDepth( const QString& wellName, const QDateTime& timeStep, RigEclipseWellLogExtractor* eclExtractor )
{
if ( !eclExtractor ) return {};
if ( !eclExtractor->caseData() ) return {};
if ( eclExtractor->cellIntersectionMDs().empty() ) return {};
auto mainGrid = eclExtractor->caseData()->mainGrid();
if ( !mainGrid ) return {};
std::vector<double> avgMeasuredDepthForCells;
std::vector<double> tvdValuesToEstimate;
auto cellIjk = cellIndices( wellName, timeStep );
for ( const caf::VecIjk0& ijk : cellIjk )
{
if ( ijk.i() >= mainGrid->cellCountI() || ijk.j() >= mainGrid->cellCountJ() || ijk.k() >= mainGrid->cellCountK() ) continue;
auto globalCellIndex = mainGrid->cellIndexFromIJK( ijk.i(), ijk.j(), ijk.k() );
auto avgMd = eclExtractor->averageMdForCell( globalCellIndex );
if ( avgMd.has_value() )
{
avgMeasuredDepthForCells.push_back( avgMd.value() );
}
else
{
// The RFT cell is not part of cells intersected by well path
// Use the TVD of cell center to estimate measured depth
avgMeasuredDepthForCells.push_back( std::numeric_limits<double>::infinity() );
const RigCell& cell = mainGrid->cell( globalCellIndex );
if ( cell.isInvalid() )
{
tvdValuesToEstimate.push_back( std::numeric_limits<double>::infinity() );
}
else
{
tvdValuesToEstimate.push_back( -cell.center().z() );
}
}
}
if ( !tvdValuesToEstimate.empty() )
{
auto wellPathMd = eclExtractor->wellPathGeometry()->measuredDepths();
auto wellPathTvd = eclExtractor->wellPathGeometry()->trueVerticalDepths();
// Estimate measured depth for cells that do not have measured depth
auto estimatedMeasuredDepth = RigWellPathGeometryTools::interpolateMdFromTvd( wellPathMd, wellPathTvd, tvdValuesToEstimate );
double previousMd = std::numeric_limits<double>::infinity();
// Replace infinity MD values with estimated MD values based on well path geometry
// previousMd contains the last known measured depth value as we move along the well path
size_t estimatedIndex = 0;
for ( auto& measuredDepth : avgMeasuredDepthForCells )
{
if ( measuredDepth == std::numeric_limits<double>::infinity() )
{
// No measured depth for cell is found, try to estimate MD based on MD for previous cell
if ( estimatedIndex < estimatedMeasuredDepth.size() )
{
double estimatedMd = estimatedMeasuredDepth[estimatedIndex++];
if ( previousMd != std::numeric_limits<double>::infinity() )
{
if ( previousMd < estimatedMd )
{
// The estimated MD is larger than previous MD, use the estimated MD
measuredDepth = estimatedMd;
}
else
{
// The estimated MD is smaller than previous MD, use the previous MD + 1.0
measuredDepth = previousMd + 1.0;
}
}
else
{
// We do not have a valid previous MD, use the estimated MD
measuredDepth = estimatedMd;
}
}
else
{
measuredDepth = previousMd + 1.0;
}
}
// Assign the current MD as previous MD to be used for next estimated MD
previousMd = measuredDepth;
}
}
return avgMeasuredDepthForCells;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<caf::VecIjk0> RifReaderRftInterface::cellIndices( const QString& wellName, const QDateTime& timeStep )
{
return {};
}