From eee43ccf0fd16cd905f3026a316312fc69553b44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Thu, 2 Feb 2017 11:22:02 +0100 Subject: [PATCH] #1108, #1110, #1116 Pie chart Well Allocation Factors now working. --- .../Flow/RimTotalWellAllocationPlot.cpp | 132 ++++-------------- .../Flow/RimTotalWellAllocationPlot.h | 28 ++-- .../Flow/RimWellAllocationPlot.cpp | 87 ++++++++---- .../Flow/RimWellAllocationPlot.h | 6 + 4 files changed, 103 insertions(+), 150 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.cpp index 25c8a01bdf..1d2a2aecc0 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.cpp @@ -32,6 +32,7 @@ #include "RiuMainPlotWindow.h" #include "RiuNightchartsWidget.h" #include "RiuWellAllocationPlot.h" +#include "cvfColor3.h" CAF_PDM_SOURCE_INIT(RimTotalWellAllocationPlot, "TotalWellAllocationPlot"); @@ -48,7 +49,6 @@ RimTotalWellAllocationPlot::RimTotalWellAllocationPlot() m_userName.uiCapability()->setUiReadOnly(true); CAF_PDM_InitField(&m_showPlotTitle, "ShowPlotTitle", true, "Show Plot Title", "", "", ""); - CAF_PDM_InitFieldNoDefault(&m_simulationWell, "SimulationWell", "Simulation Well", "", "", ""); } @@ -62,15 +62,6 @@ RimTotalWellAllocationPlot::~RimTotalWellAllocationPlot() deleteViewWidget(); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimTotalWellAllocationPlot::setSimulationWell(RimEclipseWell* simWell) -{ - m_simulationWell = simWell; - - updateFromWell(); -} //-------------------------------------------------------------------------------------------------- /// @@ -84,60 +75,6 @@ void RimTotalWellAllocationPlot::deleteViewWidget() } } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimTotalWellAllocationPlot::updateFromWell() -{ -/* - QString simName = "None"; - int branchCount = 0; - - const RigWellResultFrame* wellResultFrame = nullptr; - - if (m_simulationWell && m_simulationWell->wellResults() )// && Timestep Ok ) - { - simName = m_simulationWell->name(); - wellResultFrame = &(m_simulationWell->wellResults()->wellResultFrame(1)); - branchCount = static_cast( wellResultFrame->m_wellResultBranches.size()); - // // Todo : Use this instead, and use to calculate accumulated flow - // - // size_t timeStep = 0; // make field - // std::vector< std::vector > pipeBranchesCLCoords; - // std::vector< std::vector > pipeBranchesCellIds; - // m_simulationWell->calculateWellPipeDynamicCenterLine(timeStep, pipeBranchesCLCoords, pipeBranchesCellIds); - // branchCount = static_cast( pipeBranchesCLCoords.size()); - } - - int existingTrackCount = static_cast(accumulatedWellFlowPlot()->trackCount()); - accumulatedWellFlowPlot()->setDescription("Accumulated Well Flow (" + simName + ")"); - - int neededExtraTrackCount = branchCount - existingTrackCount; - for (int etc = 0; etc < neededExtraTrackCount; ++etc) - { - RimWellLogTrack* plotTrack = new RimWellLogTrack(); - accumulatedWellFlowPlot()->addTrack(plotTrack); - } - - for (int etc = branchCount; etc < existingTrackCount; ++etc) - { - accumulatedWellFlowPlot()->removeTrackByIndex(accumulatedWellFlowPlot()->trackCount()- 1); - } - - - for (size_t brIdx = 0; brIdx < branchCount; ++brIdx) - { - RimWellLogTrack* plotTrack = accumulatedWellFlowPlot()->trackByIndex(brIdx); - - plotTrack->setDescription(QString("Branch %1").arg(brIdx+1)); - - } - - setDescription("Well Allocation (" + simName + ")"); - accumulatedWellFlowPlot()->updateConnectedEditors(); -*/ -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -153,39 +90,6 @@ void RimTotalWellAllocationPlot::zoomAll() { } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -QList RimTotalWellAllocationPlot::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) -{ - QList options; - - if (fieldNeedingOptions == &m_simulationWell) - { - RimView* activeView = RiaApplication::instance()->activeReservoirView(); - RimEclipseView* eclView = dynamic_cast(activeView); - - if (eclView && eclView->wellCollection()) - { - RimEclipseWellCollection* coll = eclView->wellCollection(); - - caf::PdmChildArrayField& eclWells = coll->wells; - - QIcon simWellIcon(":/Well.png"); - for (RimEclipseWell* eclWell : eclWells) - { - options.push_back(caf::PdmOptionItemInfo(eclWell->name(), eclWell, false, simWellIcon)); - } - } - - if (options.size() == 0) - { - options.push_front(caf::PdmOptionItemInfo("None", nullptr)); - } - } - - return options; -} //-------------------------------------------------------------------------------------------------- /// @@ -199,10 +103,7 @@ void RimTotalWellAllocationPlot::fieldChangedByUi(const caf::PdmFieldHandle* cha { updateMdiWindowTitle(); } - else if (changedField == &m_simulationWell) - { - updateFromWell(); - } + } @@ -235,13 +136,34 @@ QString RimTotalWellAllocationPlot::description() const return m_userName(); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimTotalWellAllocationPlot::addSlice(const QString& name, const cvf::Color3f& color, float value) +{ + QColor sliceColor(color.rByte(), color.gByte(), color.bByte()); + + m_wellTotalAllocationPlotWidget->addItem(name, sliceColor, value); + m_wellTotalAllocationPlotWidget->update(); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimTotalWellAllocationPlot::clearSlices() +{ + m_wellTotalAllocationPlotWidget->clear(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimTotalWellAllocationPlot::loadDataAndUpdate() { updateMdiWindowVisibility(); - updateFromWell(); + } //-------------------------------------------------------------------------------------------------- @@ -250,12 +172,6 @@ void RimTotalWellAllocationPlot::loadDataAndUpdate() QWidget* RimTotalWellAllocationPlot::createViewWidget(QWidget* mainWindowParent) { m_wellTotalAllocationPlotWidget = new RiuNightchartsWidget(mainWindowParent); - m_wellTotalAllocationPlotWidget->addItem("Item1", QColor(200, 10, 50), 34); - m_wellTotalAllocationPlotWidget->addItem("Item2", Qt::green, 27); - m_wellTotalAllocationPlotWidget->addItem("Item3", Qt::cyan, 14); - m_wellTotalAllocationPlotWidget->addItem("Item4", Qt::yellow, 7); - m_wellTotalAllocationPlotWidget->addItem("Item5", Qt::blue, 4); - return m_wellTotalAllocationPlotWidget; } diff --git a/ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.h b/ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.h index 8bca8116ea..5cf541f367 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.h +++ b/ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.h @@ -36,6 +36,10 @@ namespace caf { class PdmOptionItemInfo; } +namespace cvf { + class cvf::Color3f; +} + //================================================================================================== /// @@ -49,39 +53,31 @@ class RimTotalWellAllocationPlot : public RimViewWindow RimTotalWellAllocationPlot(); virtual ~RimTotalWellAllocationPlot(); - void setSimulationWell(RimEclipseWell* simWell); - void setDescription(const QString& description); QString description() const; - void loadDataAndUpdate(); + void addSlice(const QString& name, const cvf::Color3f& color, float value); + void clearSlices(); + // RimViewWindow overrides virtual QWidget* viewWidget() override; virtual void zoomAll() override; - - virtual QList calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly) override; - - // RimViewWindow overrides - virtual QWidget* createViewWidget(QWidget* mainWindowParent) override; virtual void deleteViewWidget() override; protected: - // Overridden PDM methods - virtual caf::PdmFieldHandle* userDescriptionField() { return &m_userName; } - virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; + // RimViewWindow overrides + virtual void loadDataAndUpdate() override; virtual QImage snapshotWindowContent() override; -private: - void updateFromWell(); - + // Overridden PDM methods + virtual caf::PdmFieldHandle* userDescriptionField() { return &m_userName; } + virtual void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; private: caf::PdmField m_showPlotTitle; caf::PdmField m_userName; - caf::PdmPtrField m_simulationWell; - QPointer m_wellTotalAllocationPlotWidget; }; diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp index 13b1fc891b..edd02b7abe 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp @@ -225,53 +225,88 @@ void RimWellAllocationPlot::updateFromWell() accumulatedWellFlowPlot()->addTrack(plotTrack); - if ( m_flowDiagSolution ) + std::vector connNumbers; { - std::vector connNumbers; - { - const std::vector& connNumbersSize_t = wfCalculator->connectionNumbersFromTop(brIdx); - for ( size_t conNumb : connNumbersSize_t ) connNumbers.push_back(static_cast(conNumb)); - } + const std::vector& connNumbersSize_t = wfCalculator->connectionNumbersFromTop(brIdx); + for ( size_t conNumb : connNumbersSize_t ) connNumbers.push_back(static_cast(conNumb)); + } + if ( m_flowDiagSolution ) + { std::vector tracerNames = wfCalculator->tracerNames(); for (const QString& tracerName: tracerNames) { const std::vector& accFlow = wfCalculator->accumulatedTracerFlowPrConnection(tracerName, brIdx); - - RimWellFlowRateCurve* curve = new RimWellFlowRateCurve; - curve->setFlowValues(tracerName, connNumbers, accFlow); - curve->setColor( m_flowDiagSolution->tracerColor(tracerName)); - - plotTrack->addCurve(curve); - - curve->loadDataAndUpdate(); + addStackedCurve(tracerName, connNumbers, accFlow, plotTrack); } } else { - std::vector connNumbers; - { - const std::vector& connNumbersSize_t = wfCalculator->connectionNumbersFromTop(brIdx); - for ( size_t conNumb : connNumbersSize_t ) connNumbers.push_back(static_cast(conNumb)); - } - const std::vector& accFlow = wfCalculator->accumulatedTotalFlowPrConnection(brIdx); + addStackedCurve("Total", connNumbers, accFlow, plotTrack); + } - RimWellFlowRateCurve* curve = new RimWellFlowRateCurve; - curve->setFlowValues("Total", connNumbers, accFlow); - curve->setColor( cvf::Color3f::DARK_GRAY); + } - plotTrack->addCurve(curve); + /// Pie chart - curve->loadDataAndUpdate(); - } + m_totalWellAllocationPlot->clearSlices(); + std::vector tracerNames = wfCalculator->tracerNames(); + std::vector > tracerWithValues; + + for (const QString& tracerName: tracerNames) + { + const std::vector& accFlow = wfCalculator->accumulatedTracerFlowPrConnection(tracerName, 0); + tracerWithValues.push_back(std::make_pair(tracerName, accFlow.back())); + } + + float sumTracerVals = 0.0f; + for ( const auto& tracerVal:tracerWithValues) + { + sumTracerVals += tracerVal.second; + } + + if ( sumTracerVals != 0.0f ) + { + for ( const auto& tracerVal:tracerWithValues ) + { + cvf::Color3f color; + if ( m_flowDiagSolution ) + color = m_flowDiagSolution->tracerColor(tracerVal.first); + else + color = cvf::Color3f::DARK_GRAY; + m_totalWellAllocationPlot->addSlice(tracerVal.first, color, 100*tracerVal.second/sumTracerVals); + } } + m_totalWellAllocationPlot->updateConnectedEditors(); + setDescription("Well Allocation (" + m_wellName + ")"); accumulatedWellFlowPlot()->updateConnectedEditors(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimWellAllocationPlot::addStackedCurve(const QString& tracerName, + const std::vector& connNumbers, + const std::vector& accFlow, + RimWellLogTrack* plotTrack) +{ + RimWellFlowRateCurve* curve = new RimWellFlowRateCurve; + curve->setFlowValues(tracerName, connNumbers, accFlow); + + if ( m_flowDiagSolution ) + curve->setColor(m_flowDiagSolution->tracerColor(tracerName)); + else + curve->setColor(cvf::Color3f::DARK_GRAY); + + plotTrack->addCurve(curve); + + curve->loadDataAndUpdate(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h index c361a00eb4..f94c98c512 100644 --- a/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h +++ b/ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h @@ -33,6 +33,7 @@ class RimFlowDiagSolution; class RimTotalWellAllocationPlot; class RimWellLogPlot; class RiuWellAllocationPlot; +class RimWellLogTrack; namespace caf { class PdmOptionItemInfo; @@ -80,6 +81,11 @@ class RimWellAllocationPlot : public RimViewWindow private: void updateFromWell(); + void addStackedCurve(const QString& tracerName, + const std::vector& connNumbers, + const std::vector& accFlow, + RimWellLogTrack* plotTrack); + // RimViewWindow overrides virtual QWidget* createViewWidget(QWidget* mainWindowParent) override;