diff --git a/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.cpp b/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.cpp index 0902374ca5..3a1bbb490c 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.cpp +++ b/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.cpp @@ -19,27 +19,41 @@ #include "RimWellLogRftCurve.h" +#include "RiaApplication.h" #include "RiaEclipseUnitTools.h" #include "RimEclipseResultCase.h" +#include "RimMainPlotCollection.h" +#include "RimProject.h" #include "RimTools.h" #include "RimWellLogPlot.h" +#include "RimWellLogPlotCollection.h" +#include "RimWellPath.h" #include "RigEclipseCaseData.h" +#include "RigEclipseWellLogExtractor.h" +#include "RigMainGrid.h" #include "RigWellLogCurveData.h" +#include "RigWellPath.h" +#include "RigWellPathIntersectionTools.h" #include "RiuLineSegmentQwtPlotCurve.h" -#include "RifReaderEclipseRft.h" #include "RifEclipseRftAddress.h" +#include "RifReaderEclipseRft.h" #include "cafPdmObject.h" +#include "cafVecIjk.h" + #include "cvfAssert.h" #include #include +#include +#include + namespace caf { template<> @@ -249,14 +263,14 @@ void RimWellLogRftCurve::onLoadDataAndUpdate(bool updateParentPlot) CVF_ASSERT(wellLogPlot); std::vector values = xValues(); - std::vector depthVector = depthValues(); + std::vector tvDepthVector = tvDepthValues(); + std::vector measuredDepthVector = measuredDepthValues(); - if (values.empty() || depthVector.empty()) return; - - if (values.size() == depthVector.size()) - { - m_curveData->setValuesAndMD(values, depthVector, RiaEclipseUnitTools::depthUnit(m_eclipseResultCase->eclipseCaseData()->unitsType()), false); - } + if (values.empty()) return; + if (values.size() != tvDepthVector.size()) return; + if (values.size() != measuredDepthVector.size()) return; + + m_curveData->setValuesWithTVD(values, measuredDepthVector, tvDepthVector, RiaEclipseUnitTools::depthUnit(m_eclipseResultCase->eclipseCaseData()->unitsType()), false); RiaDefines::DepthUnitType displayUnit = RiaDefines::UNIT_METER; if (wellLogPlot) @@ -264,7 +278,15 @@ void RimWellLogRftCurve::onLoadDataAndUpdate(bool updateParentPlot) displayUnit = wellLogPlot->depthUnit(); } - m_qwtPlotCurve->setSamples(m_curveData->xPlotValues().data(), m_curveData->measuredDepthPlotValues(displayUnit).data(), static_cast(m_curveData->xPlotValues().size())); + if (wellLogPlot->depthType() == RimWellLogPlot::MEASURED_DEPTH) + { + m_qwtPlotCurve->setSamples(m_curveData->xPlotValues().data(), m_curveData->measuredDepthPlotValues(displayUnit).data(), static_cast(m_curveData->xPlotValues().size())); + } + else + { + m_qwtPlotCurve->setSamples(m_curveData->xPlotValues().data(), m_curveData->trueDepthPlotValues(displayUnit).data(), static_cast(m_curveData->xPlotValues().size())); + } + m_qwtPlotCurve->setLineSegmentStartStopIndices(m_curveData->polylineStartStopIndices()); updateZoomInParentPlot(); @@ -413,16 +435,76 @@ std::vector RimWellLogRftCurve::xValues() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RimWellLogRftCurve::depthValues() const +std::vector RimWellLogRftCurve::tvDepthValues() const { RifReaderEclipseRft* reader = rftReader(); - std::vector values; + std::vector tvDepthValues; - if (!reader) return values; + if (!reader) return tvDepthValues; - RifEclipseRftAddress address(m_wellName(), m_timeStep, RifEclipseRftAddress::DEPTH); + RifEclipseRftAddress depthAddress(m_wellName(), m_timeStep, RifEclipseRftAddress::DEPTH); - reader->values(address, &values); + reader->values(depthAddress, &tvDepthValues); + return tvDepthValues; +} +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RimWellLogRftCurve::measuredDepthValues() const +{ + std::vector measuredDepthForCells; + + RifReaderEclipseRft* reader = rftReader(); + if (!reader) return measuredDepthForCells; - return values; -} \ No newline at end of file + + RimMainPlotCollection* mainPlotCollection; + this->firstAncestorOrThisOfTypeAsserted(mainPlotCollection); + + RimWellLogPlotCollection* wellLogCollection = mainPlotCollection->wellLogPlotCollection(); + if (!wellLogCollection) return measuredDepthForCells; + + RigEclipseWellLogExtractor* eclExtractor = nullptr; + + RimProject* proj = RiaApplication::instance()->project(); + RimWellPath* wellPath = proj->wellPathFromSimulationWell(m_wellName()); + eclExtractor = wellLogCollection->findOrCreateExtractor(wellPath, m_eclipseResultCase); + + if (!eclExtractor) + { + std::vector wellPaths = proj->simulationWellBranches(m_wellName()); + if (wellPaths.size() == 0) return measuredDepthForCells; + + eclExtractor = wellLogCollection->findOrCreateSimWellExtractor(m_wellName(), QString("Find or create sim well extractor"), wellPaths[0], m_eclipseResultCase->eclipseCaseData()); + } + + if (!eclExtractor) return measuredDepthForCells; + + std::vector measuredDepthForIntersections = eclExtractor->measuredDepth(); + + std::vector< size_t> globCellIndices = eclExtractor->intersectedCellsGlobIdx(); + + std::map> globCellIdToIntersectionDepthsMap; + + for (size_t iIdx = 0; iIdx < measuredDepthForIntersections.size(); ++iIdx) + { + globCellIdToIntersectionDepthsMap[globCellIndices[iIdx]].push_back(measuredDepthForIntersections[iIdx]); + } + + const RigMainGrid* mainGrid = eclExtractor->caseData()->mainGrid(); + + RifEclipseRftAddress depthAddress(m_wellName(), m_timeStep, RifEclipseRftAddress::DEPTH); + std::vector indices; + rftReader()->cellIndices(depthAddress, &indices); + + for (const caf::VecIjk& ijkIndex : indices) + { + size_t globalCellIndex = mainGrid->cellIndexFromIJK(ijkIndex.i(), ijkIndex.j(), ijkIndex.k()); + + double sum = std::accumulate(globCellIdToIntersectionDepthsMap[globalCellIndex].begin(), globCellIdToIntersectionDepthsMap[globalCellIndex].end(), 0); + + measuredDepthForCells.push_back(sum / (double)globCellIdToIntersectionDepthsMap[globalCellIndex].size()); + } + + return measuredDepthForCells; +} diff --git a/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.h b/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.h index 94d218a7cc..59d6f2d615 100644 --- a/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.h +++ b/ApplicationCode/ProjectDataModel/RimWellLogRftCurve.h @@ -23,13 +23,15 @@ #include "RifEclipseRftAddress.h" +#include "cafAppEnum.h" #include "cafPdmField.h" #include "cafPdmPtrField.h" + #include "cvfObject.h" -#include "cafAppEnum.h" class RifReaderEclipseRft; class RimEclipseResultCase; +class RimWellPath; //================================================================================================== /// @@ -43,22 +45,22 @@ public: RimWellLogRftCurve(); virtual ~RimWellLogRftCurve(); - virtual QString wellName() const override; - virtual QString wellLogChannelName() const override; + virtual QString wellName() const override; + virtual QString wellLogChannelName() const override; - void setEclipseResultCase(RimEclipseResultCase* eclipseResultCase); - RimEclipseResultCase* eclipseResultCase() const; + void setEclipseResultCase(RimEclipseResultCase* eclipseResultCase); + RimEclipseResultCase* eclipseResultCase() const; - void setRftAddress(RifEclipseRftAddress address); - RifEclipseRftAddress rftAddress() const; + void setRftAddress(RifEclipseRftAddress address); + RifEclipseRftAddress rftAddress() const; - void setDefaultAddress(QString wellName); - void updateWellChannelNameAndTimeStep(); + void setDefaultAddress(QString wellName); + void updateWellChannelNameAndTimeStep(); protected: // Overrides from RimWellLogPlotCurve - virtual QString createCurveAutoName() override; - virtual void onLoadDataAndUpdate(bool updateParentPlot) override; + virtual QString createCurveAutoName() override; + virtual void onLoadDataAndUpdate(bool updateParentPlot) override; // Pdm overrrides virtual void defineUiOrdering(QString uiConfigName, caf::PdmUiOrdering& uiOrdering) override; @@ -69,7 +71,8 @@ private: RifReaderEclipseRft* rftReader() const; std::vector xValues() const; - std::vector depthValues() const; + std::vector tvDepthValues() const; + std::vector measuredDepthValues() const; private: caf::PdmPtrField m_eclipseResultCase; diff --git a/ApplicationCode/ReservoirDataModel/RigWellLogCurveData.cpp b/ApplicationCode/ReservoirDataModel/RigWellLogCurveData.cpp index 365f0c8361..06835e8a0b 100644 --- a/ApplicationCode/ReservoirDataModel/RigWellLogCurveData.cpp +++ b/ApplicationCode/ReservoirDataModel/RigWellLogCurveData.cpp @@ -82,7 +82,6 @@ void RigWellLogCurveData::setValuesWithTVD(const std::vector& xValues, m_tvDepths = tvDepths; m_depthUnit = depthUnit; - // Always use value filtering when TVD is present m_isExtractionCurve = isExtractionCurve; calculateIntervalsOfContinousValidValues(); diff --git a/ApplicationCode/ReservoirDataModel/RigWellLogCurveData.h b/ApplicationCode/ReservoirDataModel/RigWellLogCurveData.h index f631b57045..c2a355deeb 100644 --- a/ApplicationCode/ReservoirDataModel/RigWellLogCurveData.h +++ b/ApplicationCode/ReservoirDataModel/RigWellLogCurveData.h @@ -45,7 +45,8 @@ public: void setValuesWithTVD(const std::vector& xValues, const std::vector& measuredDepths, const std::vector& tvDepths, - RiaDefines::DepthUnitType depthUnit); + RiaDefines::DepthUnitType depthUnit, + bool isExtractionCurve); const std::vector& xValues() const; const std::vector& measuredDepths() const;