Skip to content

Commit

Permalink
#1108, #1110, #1116 Pie chart Well Allocation Factors now working.
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobStoren committed Feb 2, 2017
1 parent 7abdc38 commit eee43cc
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 150 deletions.
132 changes: 24 additions & 108 deletions ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "RiuMainPlotWindow.h"
#include "RiuNightchartsWidget.h"
#include "RiuWellAllocationPlot.h"
#include "cvfColor3.h"


CAF_PDM_SOURCE_INIT(RimTotalWellAllocationPlot, "TotalWellAllocationPlot");
Expand All @@ -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", "", "", "");

}

Expand All @@ -62,15 +62,6 @@ RimTotalWellAllocationPlot::~RimTotalWellAllocationPlot()
deleteViewWidget();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimTotalWellAllocationPlot::setSimulationWell(RimEclipseWell* simWell)
{
m_simulationWell = simWell;

updateFromWell();
}

//--------------------------------------------------------------------------------------------------
///
Expand All @@ -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<int>( wellResultFrame->m_wellResultBranches.size());
// // Todo : Use this instead, and use to calculate accumulated flow
//
// size_t timeStep = 0; // make field
// std::vector< std::vector <cvf::Vec3d> > pipeBranchesCLCoords;
// std::vector< std::vector <RigWellResultPoint> > pipeBranchesCellIds;
// m_simulationWell->calculateWellPipeDynamicCenterLine(timeStep, pipeBranchesCLCoords, pipeBranchesCellIds);
// branchCount = static_cast<int>( pipeBranchesCLCoords.size());
}
int existingTrackCount = static_cast<int>(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();
*/
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand All @@ -153,39 +90,6 @@ void RimTotalWellAllocationPlot::zoomAll()
{
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QList<caf::PdmOptionItemInfo> RimTotalWellAllocationPlot::calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool * useOptionsOnly)
{
QList<caf::PdmOptionItemInfo> options;

if (fieldNeedingOptions == &m_simulationWell)
{
RimView* activeView = RiaApplication::instance()->activeReservoirView();
RimEclipseView* eclView = dynamic_cast<RimEclipseView*>(activeView);

if (eclView && eclView->wellCollection())
{
RimEclipseWellCollection* coll = eclView->wellCollection();

caf::PdmChildArrayField<RimEclipseWell*>& 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;
}

//--------------------------------------------------------------------------------------------------
///
Expand All @@ -199,10 +103,7 @@ void RimTotalWellAllocationPlot::fieldChangedByUi(const caf::PdmFieldHandle* cha
{
updateMdiWindowTitle();
}
else if (changedField == &m_simulationWell)
{
updateFromWell();
}

}


Expand Down Expand Up @@ -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();

}

//--------------------------------------------------------------------------------------------------
Expand All @@ -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;
}

Expand Down
28 changes: 12 additions & 16 deletions ApplicationCode/ProjectDataModel/Flow/RimTotalWellAllocationPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ namespace caf {
class PdmOptionItemInfo;
}

namespace cvf {
class cvf::Color3f;
}


//==================================================================================================
///
Expand All @@ -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<caf::PdmOptionItemInfo> 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<bool> m_showPlotTitle;
caf::PdmField<QString> m_userName;

caf::PdmPtrField<RimEclipseWell*> m_simulationWell;

QPointer<RiuNightchartsWidget> m_wellTotalAllocationPlotWidget;
};
87 changes: 61 additions & 26 deletions ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,53 +225,88 @@ void RimWellAllocationPlot::updateFromWell()

accumulatedWellFlowPlot()->addTrack(plotTrack);

if ( m_flowDiagSolution )
std::vector<double> connNumbers;
{
std::vector<double> connNumbers;
{
const std::vector<size_t>& connNumbersSize_t = wfCalculator->connectionNumbersFromTop(brIdx);
for ( size_t conNumb : connNumbersSize_t ) connNumbers.push_back(static_cast<double>(conNumb));
}
const std::vector<size_t>& connNumbersSize_t = wfCalculator->connectionNumbersFromTop(brIdx);
for ( size_t conNumb : connNumbersSize_t ) connNumbers.push_back(static_cast<double>(conNumb));
}

if ( m_flowDiagSolution )
{
std::vector<QString> tracerNames = wfCalculator->tracerNames();
for (const QString& tracerName: tracerNames)
{
const std::vector<double>& 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<double> connNumbers;
{
const std::vector<size_t>& connNumbersSize_t = wfCalculator->connectionNumbersFromTop(brIdx);
for ( size_t conNumb : connNumbersSize_t ) connNumbers.push_back(static_cast<double>(conNumb));
}

const std::vector<double>& 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<QString> tracerNames = wfCalculator->tracerNames();
std::vector<std::pair<QString, double> > tracerWithValues;

for (const QString& tracerName: tracerNames)
{
const std::vector<double>& 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<double>& connNumbers,
const std::vector<double>& 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();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions ApplicationCode/ProjectDataModel/Flow/RimWellAllocationPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class RimFlowDiagSolution;
class RimTotalWellAllocationPlot;
class RimWellLogPlot;
class RiuWellAllocationPlot;
class RimWellLogTrack;

namespace caf {
class PdmOptionItemInfo;
Expand Down Expand Up @@ -80,6 +81,11 @@ class RimWellAllocationPlot : public RimViewWindow
private:
void updateFromWell();

void addStackedCurve(const QString& tracerName,
const std::vector<double>& connNumbers,
const std::vector<double>& accFlow,
RimWellLogTrack* plotTrack);

// RimViewWindow overrides

virtual QWidget* createViewWidget(QWidget* mainWindowParent) override;
Expand Down

0 comments on commit eee43cc

Please sign in to comment.