diff --git a/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake b/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake index 33f6106e01..4fa870d18c 100644 --- a/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake +++ b/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake @@ -37,6 +37,7 @@ ${CEE_CURRENT_LIST_DIR}RigTernaryResultAccessor2d.h ${CEE_CURRENT_LIST_DIR}RigEclipseNativeStatCalc.h ${CEE_CURRENT_LIST_DIR}RigEclipseMultiPropertyStatCalc.h ${CEE_CURRENT_LIST_DIR}RigWellLogCurveData.h +${CEE_CURRENT_LIST_DIR}RigTimeHistoryResultAccessor.h ) set (SOURCE_GROUP_SOURCE_FILES @@ -68,6 +69,7 @@ ${CEE_CURRENT_LIST_DIR}RigTernaryResultAccessor2d.cpp ${CEE_CURRENT_LIST_DIR}RigEclipseNativeStatCalc.cpp ${CEE_CURRENT_LIST_DIR}RigEclipseMultiPropertyStatCalc.cpp ${CEE_CURRENT_LIST_DIR}RigWellLogCurveData.cpp +${CEE_CURRENT_LIST_DIR}RigTimeHistoryResultAccessor.cpp ) list(APPEND CODE_HEADER_FILES diff --git a/ApplicationCode/ReservoirDataModel/RigTimeHistoryResultAccessor.cpp b/ApplicationCode/ReservoirDataModel/RigTimeHistoryResultAccessor.cpp new file mode 100644 index 0000000000..3b0f7283ee --- /dev/null +++ b/ApplicationCode/ReservoirDataModel/RigTimeHistoryResultAccessor.cpp @@ -0,0 +1,118 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Statoil ASA +// Copyright (C) Ceetron Solutions AS +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#include "RigTimeHistoryResultAccessor.h" + +#include // Needed for HUGE_VAL on Linux + +#include "RigCaseData.h" +#include "RigResultAccessor.h" +#include "RigResultAccessorFactory.h" +#include "RigCaseCellResultsData.h" + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RigTimeHistoryResultAccessor::RigTimeHistoryResultAccessor(RigCaseData* eclipseCaseData, size_t gridIndex, size_t cellIndex, size_t scalarResultIndex, RifReaderInterface::PorosityModelResultType porosityModel) + : m_eclipseCaseData(eclipseCaseData), + m_gridIndex(gridIndex), + m_cellIndex(cellIndex), + m_scalarResultIndex(scalarResultIndex), + m_porosityModel(porosityModel) +{ + m_face = cvf::StructGridInterface::NO_FACE; + m_nncIndex = cvf::UNDEFINED_SIZE_T; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigTimeHistoryResultAccessor::setFace(cvf::StructGridInterface::FaceType face) +{ + m_face = face; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigTimeHistoryResultAccessor::setNncIndex(size_t nncIndex) +{ + m_nncIndex = nncIndex; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RigTimeHistoryResultAccessor::yValues() const +{ + return m_yValues; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RigTimeHistoryResultAccessor::topologyText() +{ + QString text; + + if (m_eclipseCaseData) + { + if (m_cellIndex != cvf::UNDEFINED_SIZE_T) + { + size_t i = 0; + size_t j = 0; + size_t k = 0; + if (m_eclipseCaseData->grid(m_gridIndex)->ijkFromCellIndex(m_cellIndex, &i, &j, &k)) + { + // Adjust to 1-based Eclipse indexing + i++; + j++; + k++; + + cvf::StructGridInterface::FaceEnum faceEnum(m_face); + + text += QString("Cell : [%1, %2, %3]").arg(i).arg(j).arg(k); + } + } + } + + return text; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigTimeHistoryResultAccessor::computeCurveData() +{ + if (m_yValues.size() != 0) return; + + if (m_eclipseCaseData) + { + size_t timeStepCount = m_eclipseCaseData->results(m_porosityModel)->timeStepCount(m_scalarResultIndex); + + for (size_t i = 0; i < timeStepCount; i++) + { + cvf::ref resultAccessor = RigResultAccessorFactory::createResultAccessor(m_eclipseCaseData, m_gridIndex, m_porosityModel, i, m_scalarResultIndex); + + m_yValues.push_back(resultAccessor->cellScalar(m_cellIndex)); + } + } +} + diff --git a/ApplicationCode/ReservoirDataModel/RigTimeHistoryResultAccessor.h b/ApplicationCode/ReservoirDataModel/RigTimeHistoryResultAccessor.h new file mode 100644 index 0000000000..928a627741 --- /dev/null +++ b/ApplicationCode/ReservoirDataModel/RigTimeHistoryResultAccessor.h @@ -0,0 +1,58 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) Statoil ASA +// Copyright (C) Ceetron Solutions AS +// +// 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 +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include "cvfStructGrid.h" +#include "RifReaderInterface.h" + +class RigCaseData; + + +class RigTimeHistoryResultAccessor +{ +public: + RigTimeHistoryResultAccessor(RigCaseData* eclipseCaseData, size_t gridIndex, size_t cellIndex, size_t scalarResultIndex, RifReaderInterface::PorosityModelResultType porosityModel); + + void setFace(cvf::StructGridInterface::FaceType face); + void setNncIndex(size_t nncIndex); + + void computeCurveData(); + QString topologyText(); + + QString curveName() const; + std::vector yValues() const; + +private: + + +private: + RigCaseData* m_eclipseCaseData; + + size_t m_gridIndex; + size_t m_cellIndex; + size_t m_nncIndex; + size_t m_scalarResultIndex; + + cvf::StructGridInterface::FaceType m_face; + RifReaderInterface::PorosityModelResultType m_porosityModel; + + std::vector m_yValues; +}; + diff --git a/ApplicationCode/UserInterface/RiuMainWindow.cpp b/ApplicationCode/UserInterface/RiuMainWindow.cpp index 3dc6efce43..5e5f3c0d8b 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationCode/UserInterface/RiuMainWindow.cpp @@ -1165,6 +1165,14 @@ QMdiSubWindow* RiuMainWindow::findMdiSubWindow(QWidget* viewer) return NULL; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiuTimeHistoryQwtPlot* RiuMainWindow::timeHistoryPlot() +{ + return m_timeHistoryQwtPlot; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/UserInterface/RiuMainWindow.h b/ApplicationCode/UserInterface/RiuMainWindow.h index ea0553c699..d2755cffd5 100644 --- a/ApplicationCode/UserInterface/RiuMainWindow.h +++ b/ApplicationCode/UserInterface/RiuMainWindow.h @@ -113,6 +113,8 @@ public: bool isAnyMdiSubWindowVisible(); QMdiSubWindow* findMdiSubWindow(QWidget* viewer); + RiuTimeHistoryQwtPlot* timeHistoryPlot(); + protected: virtual void closeEvent(QCloseEvent* event); diff --git a/ApplicationCode/UserInterface/RiuTimeHistoryQwtPlot.cpp b/ApplicationCode/UserInterface/RiuTimeHistoryQwtPlot.cpp index c75a047e28..40f9151a10 100644 --- a/ApplicationCode/UserInterface/RiuTimeHistoryQwtPlot.cpp +++ b/ApplicationCode/UserInterface/RiuTimeHistoryQwtPlot.cpp @@ -25,6 +25,8 @@ #include "qwt_plot_curve.h" #include "qwt_plot_layout.h" #include "qwt_scale_engine.h" +#include "qwt_date_scale_draw.h" +#include "qwt_date_scale_engine.h" //-------------------------------------------------------------------------------------------------- /// @@ -32,25 +34,7 @@ RiuTimeHistoryQwtPlot::RiuTimeHistoryQwtPlot(QWidget* parent) : QwtPlot(parent) { -/* - setFocusPolicy(Qt::ClickFocus); -*/ setDefaults(); - - std::vector xValues; - std::vector yValues; - - xValues.push_back(1); - xValues.push_back(2); - xValues.push_back(3); - xValues.push_back(4); - - yValues.push_back(10); - yValues.push_back(12); - yValues.push_back(15); - yValues.push_back(11); - - addCurve("Test", xValues, yValues); } //-------------------------------------------------------------------------------------------------- @@ -64,16 +48,28 @@ RiuTimeHistoryQwtPlot::~RiuTimeHistoryQwtPlot() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiuTimeHistoryQwtPlot::addCurve(const QString& curveName, const std::vector& xValues, const std::vector& yValues) +void RiuTimeHistoryQwtPlot::addCurve(const QString& curveName, const std::vector& dateTimes, const std::vector& yValues) { - CVF_ASSERT(xValues.size() == yValues.size()); + CVF_ASSERT(dateTimes.size() == yValues.size()); QwtPlotCurve* plotCurve = new QwtPlotCurve("Curve 1"); - plotCurve->setSamples(xValues.data(), yValues.data(), (int) xValues.size()); + + QPolygonF points; + for (int i = 0; i < dateTimes.size(); i++) + { + double milliSecSinceEpoch = QwtDate::toDouble(dateTimes[i]); + points << QPointF(milliSecSinceEpoch, yValues[i]); + } + + plotCurve->setSamples(points); plotCurve->setTitle(curveName); plotCurve->attach(this); m_plotCurves.push_back(plotCurve); + + this->setAxisScale( QwtPlot::xTop, QwtDate::toDouble(dateTimes.front()), QwtDate::toDouble(dateTimes.back())); + + this->replot(); } //-------------------------------------------------------------------------------------------------- @@ -111,30 +107,23 @@ void RiuTimeHistoryQwtPlot::setDefaults() canvas()->setMouseTracking(true); canvas()->installEventFilter(this); -/* - QPen gridPen(Qt::SolidLine); - gridPen.setColor(Qt::lightGray); - m_grid->setPen(gridPen); -*/ - - enableAxis(QwtPlot::xTop, true); + enableAxis(QwtPlot::xBottom, true); enableAxis(QwtPlot::yLeft, true); - enableAxis(QwtPlot::xBottom, false); + enableAxis(QwtPlot::xTop, false); enableAxis(QwtPlot::yRight, false); plotLayout()->setAlignCanvasToScales(true); - axisScaleEngine(QwtPlot::yLeft)->setAttribute(QwtScaleEngine::Inverted, true); + QwtDateScaleDraw* scaleDraw = new QwtDateScaleDraw(Qt::UTC); + scaleDraw->setDateFormat(QwtDate::Year, QString("dd-MM-yyyy")); + + QwtDateScaleEngine* scaleEngine = new QwtDateScaleEngine(Qt::UTC); + setAxisScaleEngine(QwtPlot::xBottom, scaleEngine); + setAxisScaleDraw(QwtPlot::xBottom, scaleDraw); - // Align the canvas with the actual min and max values of the curves - axisScaleEngine(QwtPlot::xTop)->setAttribute(QwtScaleEngine::Floating, true); - axisScaleEngine(QwtPlot::yLeft)->setAttribute(QwtScaleEngine::Floating, true); - setAxisScale(QwtPlot::yLeft, 1000, 0); - setAxisScale(QwtPlot::xTop, -10, 100); - - QFont xAxisFont = axisFont(QwtPlot::xTop); + QFont xAxisFont = axisFont(QwtPlot::xBottom); xAxisFont.setPixelSize(9); - setAxisFont(QwtPlot::xTop, xAxisFont); + setAxisFont(QwtPlot::xBottom, xAxisFont); QFont yAxisFont = axisFont(QwtPlot::yLeft); yAxisFont.setPixelSize(9); @@ -149,9 +138,7 @@ void RiuTimeHistoryQwtPlot::setDefaults() setAxisTitle(QwtPlot::yLeft, axisTitleY); - QwtLegend* legend = new QwtLegend(this); - // The legend will be deleted in the destructor of the plot or when // another legend is inserted. this->insertLegend(legend, BottomLegend); diff --git a/ApplicationCode/UserInterface/RiuTimeHistoryQwtPlot.h b/ApplicationCode/UserInterface/RiuTimeHistoryQwtPlot.h index af3073e3ed..95323c9d88 100644 --- a/ApplicationCode/UserInterface/RiuTimeHistoryQwtPlot.h +++ b/ApplicationCode/UserInterface/RiuTimeHistoryQwtPlot.h @@ -34,7 +34,7 @@ public: RiuTimeHistoryQwtPlot(QWidget* parent = NULL); virtual ~RiuTimeHistoryQwtPlot(); - void addCurve(const QString& curveName, const std::vector& xValues, const std::vector& yValues); + void addCurve(const QString& curveName, const std::vector& dateTimes, const std::vector& yValues); void deleteAllCurves(); private: diff --git a/ApplicationCode/UserInterface/RiuViewerCommands.cpp b/ApplicationCode/UserInterface/RiuViewerCommands.cpp index 6a9735e731..f246365420 100644 --- a/ApplicationCode/UserInterface/RiuViewerCommands.cpp +++ b/ApplicationCode/UserInterface/RiuViewerCommands.cpp @@ -26,9 +26,11 @@ #include "Commands/WellLogCommands/RicNewWellLogCurveExtractionFeature.h" #include "RigCaseData.h" +#include "RigCaseCellResultsData.h" #include "RigFemPartCollection.h" #include "RigFemPartGrid.h" #include "RigGeoMechCaseData.h" +#include "RigTimeHistoryResultAccessor.h" #include "RimCellRangeFilter.h" #include "RimCellRangeFilterCollection.h" @@ -55,6 +57,7 @@ #include "RiuFemResultTextBuilder.h" #include "RiuMainWindow.h" #include "RiuResultTextBuilder.h" +#include "RiuTimeHistoryQwtPlot.h" #include "RiuViewer.h" #include "RivFemPartGeometryGenerator.h" @@ -489,6 +492,13 @@ void RiuViewerCommands::handlePickAction(int winPosX, int winPosY) resultInfo = textBuilder.mainResultText(); pickInfo = textBuilder.topologyText(", "); + + if (eclipseView->cellResult()->hasDynamicResult() && + eclipseView->eclipseCase() && + eclipseView->eclipseCase()->reservoirData()) + { + addTimeHistoryCurve(eclipseView, gridIndex, cellIndex); + } } else if (geomView) { @@ -517,6 +527,34 @@ void RiuViewerCommands::handlePickAction(int winPosX, int winPosY) mainWnd->setResultInfo(resultInfo); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RiuViewerCommands::addTimeHistoryCurve(RimEclipseView* eclipseView, size_t gridIndex, size_t cellIndex) +{ + RifReaderInterface::PorosityModelResultType porosityModel = RigCaseCellResultsData::convertFromProjectModelPorosityModel(eclipseView->cellResult()->porosityModel()); + + std::vector timeStepDates = eclipseView->eclipseCase()->reservoirData()->results(porosityModel)->timeStepDates(eclipseView->cellResult()->scalarResultIndex()); + + RigTimeHistoryResultAccessor timeHistResultAccessor(eclipseView->eclipseCase()->reservoirData(), gridIndex, cellIndex, eclipseView->cellResult()->scalarResultIndex(), porosityModel); + timeHistResultAccessor.computeCurveData(); + + QString curveName = eclipseView->eclipseCase()->caseUserDescription(); + curveName += " - Result : "; + curveName += eclipseView->cellResult()->resultVariable(); + curveName += " - "; + curveName += timeHistResultAccessor.topologyText(); + + std::vector yValues = timeHistResultAccessor.yValues(); + + CVF_ASSERT(timeStepDates.size() == yValues.size()); + + RiuMainWindow* mainWnd = RiuMainWindow::instance(); + + mainWnd->timeHistoryPlot()->deleteAllCurves(); + mainWnd->timeHistoryPlot()->addCurve(curveName, timeStepDates, yValues); +} + //-------------------------------------------------------------------------------------------------- /// Perform picking and return the index of the face that was hit, if a drawable geo was hit //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/UserInterface/RiuViewerCommands.h b/ApplicationCode/UserInterface/RiuViewerCommands.h index edb0bff949..856079754c 100644 --- a/ApplicationCode/UserInterface/RiuViewerCommands.h +++ b/ApplicationCode/UserInterface/RiuViewerCommands.h @@ -49,6 +49,7 @@ public: void displayContextMenu(QMouseEvent* event); void handlePickAction(int winPosX, int winPosY); + private slots: void slotRangeFilterI(); void slotRangeFilterJ(); @@ -62,6 +63,7 @@ private: void createSliceRangeFilter(int ijOrk); void extractIntersectionData(const cvf::HitItemCollection& hitItems, cvf::Vec3d* localIntersectionPoint, cvf::Part** firstPart, uint* firstPartFaceHit, cvf::Part** nncPart, uint* nncPartFaceHit); void updateSelectionFromPickedPart(cvf::Part* part); + void addTimeHistoryCurve(RimEclipseView* eclipseView, size_t gridIndex, size_t cellIndex); size_t m_currentGridIdx; size_t m_currentCellIndex;