Refactoring as preparations for #1171, #1120, and #1209

This commit is contained in:
Jacob Støren 2017-02-17 11:13:27 +01:00
parent 03adf8f759
commit b00fe21726
6 changed files with 168 additions and 112 deletions

View File

@ -20,7 +20,10 @@
#include "RiaApplication.h"
#include "RigAccWellFlowCalculator.h"
#include "RigEclipseCaseData.h"
#include "RigFlowDiagResultAddress.h"
#include "RigFlowDiagResults.h"
#include "RigSimulationWellCenterLineCalculator.h"
#include "RigSimulationWellCoordsAndMD.h"
#include "RigSingleWellResultsData.h"
@ -32,22 +35,19 @@
#include "RimEclipseWell.h"
#include "RimEclipseWellCollection.h"
#include "RimFlowDiagSolution.h"
#include "RimProject.h"
#include "RimTotalWellAllocationPlot.h"
#include "RimWellFlowRateCurve.h"
#include "RimWellLogPlot.h"
#include "RimWellLogTrack.h"
#include "RimWellAllocationPlotLegend.h"
#include "RiuMainPlotWindow.h"
#include "RiuWellAllocationPlot.h"
#include "RigAccWellFlowCalculator.h"
#include "RimProject.h"
#include "RiuWellLogTrack.h"
#include "RimWellAllocationPlotLegend.h"
CAF_PDM_SOURCE_INIT(RimWellAllocationPlot, "WellAllocationPlot");
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -183,20 +183,20 @@ void RimWellAllocationPlot::updateFromWell()
pipeBranchesCLCoords,
pipeBranchesCellIds);
std::map<QString, const std::vector<double>* > tracerCellFractionValues = findRelevantTracerCellFractions(wellResults);
std::map<QString, const std::vector<double>* > tracerFractionCellValues = findRelevantTracerCellFractions(wellResults);
std::unique_ptr< RigAccWellFlowCalculator > wfCalculator;
double smallContributionThreshold = 0.0;
if (m_groupSmallContributions()) smallContributionThreshold = m_smallContributionsThreshold;
if ( tracerCellFractionValues.size() )
if ( tracerFractionCellValues.size() )
{
bool isProducer = wellResults->wellProductionType(m_timeStep) == RigWellResultFrame::PRODUCER ;
RigEclCellIndexCalculator cellIdxCalc(m_case->reservoirData()->mainGrid(), m_case->reservoirData()->activeCellInfo(RifReaderInterface::MATRIX_RESULTS));
wfCalculator.reset(new RigAccWellFlowCalculator(pipeBranchesCLCoords,
pipeBranchesCellIds,
tracerCellFractionValues,
tracerFractionCellValues,
cellIdxCalc,
smallContributionThreshold,
isProducer));

View File

@ -19,25 +19,46 @@
#include "RigAccWellFlowCalculator.h"
#include "RigSingleWellResultsData.h"
#include "RigMainGrid.h"
#include "RigActiveCellInfo.h"
#include "RigFlowDiagResults.h"
#define RIG_FLOW_TOTAL_NAME "Total"
#define RIG_RESERVOIR_TRACER_NAME "Reservoir"
#define RIG_TINY_TRACER_GROUP_NAME "Other"
//==================================================================================================
///
///
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigAccWellFlowCalculator::RigAccWellFlowCalculator(const std::vector< std::vector <cvf::Vec3d> >& pipeBranchesCLCoords,
const std::vector< std::vector <RigWellResultPoint> >& pipeBranchesCellIds,
const std::map<QString, const std::vector<double>* >& tracerCellFractionValues,
size_t RigEclCellIndexCalculator::resultCellIndex(size_t gridIndex, size_t gridCellIndex) const
{
const RigGridBase* grid = m_mainGrid->gridByIndex(gridIndex);
size_t reservoirCellIndex = grid->reservoirCellIndex(gridCellIndex);
return m_activeCellInfo->cellResultIndex(reservoirCellIndex);
}
//==================================================================================================
///
///
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigAccWellFlowCalculator::RigAccWellFlowCalculator(const std::vector< std::vector <cvf::Vec3d> >& pipeBranchesCLCoords,
const std::vector< std::vector <RigWellResultPoint> >& pipeBranchesCellIds,
const std::map<QString, const std::vector<double>* >& tracerCellFractionValues,
const RigEclCellIndexCalculator cellIndexCalculator,
double smallContribThreshold,
bool isProducer):
m_pipeBranchesCLCoords(pipeBranchesCLCoords),
m_pipeBranchesCellIds(pipeBranchesCellIds),
m_tracerCellFractionValues(&tracerCellFractionValues),
m_cellIndexCalculator(cellIndexCalculator),
m_smallContributionsThreshold(smallContribThreshold)
bool isProducer)
: m_pipeBranchesCLCoords(pipeBranchesCLCoords),
m_pipeBranchesCellIds(pipeBranchesCellIds),
m_tracerCellFractionValues(&tracerCellFractionValues),
m_cellIndexCalculator(cellIndexCalculator),
m_smallContributionsThreshold(smallContribThreshold)
{
m_accConnectionFlowPrBranch.resize(m_pipeBranchesCellIds.size());
@ -66,13 +87,13 @@ RigAccWellFlowCalculator::RigAccWellFlowCalculator(const std::vector< std::vecto
///
//--------------------------------------------------------------------------------------------------
RigAccWellFlowCalculator::RigAccWellFlowCalculator(const std::vector< std::vector <cvf::Vec3d> >& pipeBranchesCLCoords,
const std::vector< std::vector <RigWellResultPoint> >& pipeBranchesCellIds,
double smallContribThreshold ):
m_pipeBranchesCLCoords(pipeBranchesCLCoords),
m_pipeBranchesCellIds(pipeBranchesCellIds),
m_tracerCellFractionValues(nullptr),
m_cellIndexCalculator(RigEclCellIndexCalculator(nullptr, nullptr)),
m_smallContributionsThreshold(smallContribThreshold)
const std::vector< std::vector <RigWellResultPoint> >& pipeBranchesCellIds,
double smallContribThreshold)
: m_pipeBranchesCLCoords(pipeBranchesCLCoords),
m_pipeBranchesCellIds(pipeBranchesCellIds),
m_tracerCellFractionValues(nullptr),
m_cellIndexCalculator(RigEclCellIndexCalculator(nullptr, nullptr)),
m_smallContributionsThreshold(smallContribThreshold)
{
m_accConnectionFlowPrBranch.resize(m_pipeBranchesCellIds.size());
@ -86,9 +107,9 @@ RigAccWellFlowCalculator::RigAccWellFlowCalculator(const std::vector< std::vecto
//--------------------------------------------------------------------------------------------------
const std::vector<double>& RigAccWellFlowCalculator::accumulatedTotalFlowPrConnection(size_t branchIdx)
{
CVF_ASSERT(m_accConnectionFlowPrBranch[branchIdx].accConnFlowFractionsPrTracer.find(RIG_FLOW_TOTAL_NAME) != m_accConnectionFlowPrBranch[branchIdx].accConnFlowFractionsPrTracer.end());
CVF_ASSERT(m_accConnectionFlowPrBranch[branchIdx].accFlowPrTracer.find(RIG_FLOW_TOTAL_NAME) != m_accConnectionFlowPrBranch[branchIdx].accFlowPrTracer.end());
return m_accConnectionFlowPrBranch[branchIdx].accConnFlowFractionsPrTracer[RIG_FLOW_TOTAL_NAME];
return m_accConnectionFlowPrBranch[branchIdx].accFlowPrTracer[RIG_FLOW_TOTAL_NAME];
}
//--------------------------------------------------------------------------------------------------
@ -96,9 +117,9 @@ const std::vector<double>& RigAccWellFlowCalculator::accumulatedTotalFlowPrConne
//--------------------------------------------------------------------------------------------------
const std::vector<double>& RigAccWellFlowCalculator::accumulatedTracerFlowPrConnection(const QString& tracerName, size_t branchIdx)
{
CVF_ASSERT(m_accConnectionFlowPrBranch[branchIdx].accConnFlowFractionsPrTracer.find(tracerName) != m_accConnectionFlowPrBranch[branchIdx].accConnFlowFractionsPrTracer.end());
CVF_ASSERT(m_accConnectionFlowPrBranch[branchIdx].accFlowPrTracer.find(tracerName) != m_accConnectionFlowPrBranch[branchIdx].accFlowPrTracer.end());
return m_accConnectionFlowPrBranch[branchIdx].accConnFlowFractionsPrTracer[tracerName];
return m_accConnectionFlowPrBranch[branchIdx].accFlowPrTracer[tracerName];
}
//--------------------------------------------------------------------------------------------------
@ -150,6 +171,9 @@ std::vector<std::pair<QString, double> > RigAccWellFlowCalculator::totalTracerFr
return totalFlows;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RigAccWellFlowCalculator::isWellFlowConsistent( bool isProducer)
{
bool isConsistent = true;
@ -181,7 +205,7 @@ void RigAccWellFlowCalculator::calculateAccumulatedFlowPrConnection(size_t branc
size_t prevConnIndx = -1;
int clSegIdx = static_cast<int>(branchCells.size()) - 1;
std::map<QString, std::vector<double> >& accConnFlowFractionsPrTracer = m_accConnectionFlowPrBranch[branchIdx].accConnFlowFractionsPrTracer;
std::map<QString, std::vector<double> >& accConnFlowFractionsPrTracer = m_accConnectionFlowPrBranch[branchIdx].accFlowPrTracer;
std::vector<size_t>& connNumbersFromTop = m_accConnectionFlowPrBranch[branchIdx].connectionNumbersFromTop;
std::vector<double> accFlow;
@ -240,12 +264,12 @@ void RigAccWellFlowCalculator::calculateAccumulatedFlowPrConnection(size_t branc
if ( dsBidx != branchIdx && m_accConnectionFlowPrBranch[dsBidx].connectionNumbersFromTop.size() == 0 ) // Not this branch or already calculated
{
calculateAccumulatedFlowPrConnection(dsBidx, connNumFromTop);
BranchResult& accConnFlowFractionsDsBranch = m_accConnectionFlowPrBranch[dsBidx];
BranchFlowPrConnection& accConnFlowFractionsDsBranch = m_accConnectionFlowPrBranch[dsBidx];
size_t tracerIdx = 0;
for ( const auto & tracerName: m_tracerNames )
{
accFlow[tracerIdx] += accConnFlowFractionsDsBranch.accConnFlowFractionsPrTracer[tracerName].back();
accFlow[tracerIdx] += accConnFlowFractionsDsBranch.accFlowPrTracer[tracerName].back();
tracerIdx++;
}
}
@ -346,8 +370,11 @@ void RigAccWellFlowCalculator::sortTracers()
for (const QString& tracerName: m_tracerNames)
{
const std::vector<double>& mainBranchAccFlow = accumulatedTracerFlowPrConnection(tracerName, 0);
double totalFlow = 0.0;
if (mainBranchAccFlow.size()) totalFlow = - abs( mainBranchAccFlow.back() ); // Based on size in reverse order (biggest to least)
sortedTracers.insert({totalFlow, tracerName});
}
@ -359,61 +386,71 @@ void RigAccWellFlowCalculator::sortTracers()
}
//--------------------------------------------------------------------------------------------------
///
/// Concatenate small tracers into an "Other" group
//--------------------------------------------------------------------------------------------------
void RigAccWellFlowCalculator::groupSmallContributions()
{
// Concatenate small tracers into an "Other" group
if ( m_smallContributionsThreshold > 0.0 )
if ( ! (m_smallContributionsThreshold > 0.0) ) return;
// Find the tracers we need to group
std::vector<QString> tracersToGroup;
{
std::vector<std::pair<QString, double> > totalTracerFractions = this->totalTracerFractions();
if ( totalTracerFractions.size() < 5 ) return; // No grouping for few legend items
std::vector<QString> tracersToGroup;
for ( const auto& tracerPair : totalTracerFractions )
{
if ( abs(tracerPair.second) <= m_smallContributionsThreshold ) tracersToGroup.push_back(tracerPair.first);
}
if ( tracersToGroup.size() < 2 ) return; // Must at least group two ...
for ( BranchResult& brRes : m_accConnectionFlowPrBranch )
{
std::vector<double> groupedConnectionValues(brRes.connectionNumbersFromTop.size(), 0.0);
for ( const QString& tracername:tracersToGroup )
{
auto it = brRes.accConnFlowFractionsPrTracer.find(tracername);
if ( it != brRes.accConnFlowFractionsPrTracer.end() )
{
const std::vector<double>& tracerVals = it->second;
for ( size_t cIdx = 0; cIdx < groupedConnectionValues.size(); ++cIdx )
{
groupedConnectionValues[cIdx] += tracerVals[cIdx];
}
}
brRes.accConnFlowFractionsPrTracer.erase(it);
}
brRes.accConnFlowFractionsPrTracer[RIG_TINY_TRACER_GROUP_NAME] = groupedConnectionValues;
}
std::vector<QString> filteredTracernames;
for ( const QString& tracerName: m_tracerNames )
{
bool isDeleted = false;
for ( const QString& deletedTracerName: tracersToGroup )
{
if ( tracerName == deletedTracerName ) { isDeleted = true; break; }
}
if ( !isDeleted ) filteredTracernames.push_back(tracerName);
}
m_tracerNames.swap(filteredTracernames);
m_tracerNames.push_back(RIG_TINY_TRACER_GROUP_NAME);
}
if ( tracersToGroup.size() < 2 ) return; // Must at least group two ...
// Concatenate the values for each branch, erasing the tracers being grouped, replaced with the concatenated values
for ( BranchFlowPrConnection& brRes : m_accConnectionFlowPrBranch )
{
std::vector<double> groupedConnectionValues( brRes.connectionNumbersFromTop.size(), 0.0);
for ( const QString& tracername:tracersToGroup )
{
auto it = brRes.accFlowPrTracer.find(tracername);
if ( it != brRes.accFlowPrTracer.end() )
{
const std::vector<double>& tracerVals = it->second;
for ( size_t cIdx = 0; cIdx < groupedConnectionValues.size(); ++cIdx )
{
groupedConnectionValues[cIdx] += tracerVals[cIdx];
}
}
brRes.accFlowPrTracer.erase(it);
}
brRes.accFlowPrTracer[RIG_TINY_TRACER_GROUP_NAME] = groupedConnectionValues;
}
// Remove the grouped tracer names from the tracerName list, and replace with the "Others" name
std::vector<QString> filteredTracernames;
for ( const QString& tracerName: m_tracerNames )
{
bool isDeleted = false;
for ( const QString& deletedTracerName: tracersToGroup )
{
if ( tracerName == deletedTracerName ) { isDeleted = true; break; }
}
if ( !isDeleted ) filteredTracernames.push_back(tracerName);
}
m_tracerNames.swap(filteredTracernames);
m_tracerNames.push_back(RIG_TINY_TRACER_GROUP_NAME);
}

View File

@ -22,11 +22,9 @@
///
///
//==================================================================================================
#include "RigActiveCellInfo.h"
#include "RigMainGrid.h"
#include "RigFlowDiagResults.h"
struct RigWellResultPoint;
class RigMainGrid;
class RigActiveCellInfo;
class RigEclCellIndexCalculator
{
@ -35,13 +33,7 @@ public:
: m_mainGrid(mainGrid), m_activeCellInfo(activeCellInfo)
{}
size_t resultCellIndex(size_t gridIndex, size_t gridCellIndex) const
{
const RigGridBase* grid = m_mainGrid->gridByIndex(gridIndex);
size_t reservoirCellIndex = grid->reservoirCellIndex(gridCellIndex);
return m_activeCellInfo->cellResultIndex(reservoirCellIndex);
}
size_t resultCellIndex(size_t gridIndex, size_t gridCellIndex) const;
private:
const RigMainGrid* m_mainGrid;
@ -53,6 +45,14 @@ private:
///
//==================================================================================================
#include <vector>
#include <map>
#include <QString>
#include "cvfBase.h"
#include "cvfVector3.h"
struct RigWellResultPoint;
class RigAccWellFlowCalculator
{
@ -68,39 +68,52 @@ public:
const std::vector< std::vector <RigWellResultPoint> >& pipeBranchesCellIds,
double smallContribThreshold);
const std::vector<double>& accumulatedTotalFlowPrConnection( size_t branchIdx);// const;
const std::vector<double>& accumulatedTracerFlowPrConnection(const QString& tracerName, size_t branchIdx);// const;
const std::vector<size_t>& connectionNumbersFromTop(size_t branchIdx) const;
const std::vector<QString>& tracerNames() const { return m_tracerNames;}
const std::vector<double>& accumulatedTotalFlowPrConnection( size_t branchIdx);// const;
const std::vector<double>& accumulatedTracerFlowPrConnection(const QString& tracerName, size_t branchIdx);// const;
const std::vector<size_t>& connectionNumbersFromTop(size_t branchIdx) const;
const std::vector<QString>& tracerNames() const { return m_tracerNames;}
std::vector<std::pair<QString, double> > totalTracerFractions();
std::vector<std::pair<QString, double> > totalTracerFractions();
private:
bool isWellFlowConsistent(bool isProducer);
void calculateAccumulatedFlowPrConnection( size_t branchIdx, size_t startConnectionNumberFromTop);
std::vector<size_t> wrpToConnectionIndexFromBottom( const std::vector<RigWellResultPoint> &branchCells);
static size_t connectionIndexFromTop( const std::vector<size_t>& resPointToConnectionIndexFromBottom, size_t clSegIdx);
std::vector<size_t> findDownstreamBranchIdxs( const RigWellResultPoint& connectionPoint);
bool isWellFlowConsistent(bool isProducer);
void calculateAccumulatedFlowPrConnection( size_t branchIdx, size_t startConnectionNumberFromTop);
std::vector<size_t> wrpToConnectionIndexFromBottom( const std::vector<RigWellResultPoint> &branchCells);
static size_t connectionIndexFromTop( const std::vector<size_t>& resPointToConnectionIndexFromBottom, size_t clSegIdx);
std::vector<size_t> findDownstreamBranchIdxs( const RigWellResultPoint& connectionPoint);
std::vector<std::pair<QString, double> > totalWellFlowPrTracer() ;
void sortTracers();
std::vector<std::pair<QString, double> > totalWellFlowPrTracer() ;
void sortTracers();
void groupSmallContributions();
void groupSmallContributions();
const std::vector< std::vector <cvf::Vec3d> >& m_pipeBranchesCLCoords;
const std::vector< std::vector <RigWellResultPoint> >& m_pipeBranchesCellIds;
const std::map<QString, const std::vector<double>* >* m_tracerCellFractionValues;
RigEclCellIndexCalculator m_cellIndexCalculator;
std::vector<QString> m_tracerNames;
double m_smallContributionsThreshold;
const std::vector< std::vector <cvf::Vec3d> >& m_pipeBranchesCLCoords;
const std::vector< std::vector <RigWellResultPoint> >& m_pipeBranchesCellIds;
const std::map<QString, const std::vector<double>* >* m_tracerCellFractionValues;
RigEclCellIndexCalculator m_cellIndexCalculator;
std::vector<QString> m_tracerNames;
double m_smallContributionsThreshold;
struct BranchResult
struct BranchFlowPrConnection
{
std::vector<size_t> connectionNumbersFromTop;
std::map<QString, std::vector<double> > accConnFlowFractionsPrTracer;
};
std::vector<size_t> connectionNumbersFromTop;
std::map<QString, std::vector<double> > accFlowPrTracer;
std::map<QString, std::vector<double> > flowPrTracer;
};
std::vector< BranchFlowPrConnection > m_accConnectionFlowPrBranch;
struct BranchFlowPrDepth
{
std::vector<double> depthValueFromTop;
std::map<QString, std::vector<double> > accFlowPrTracer;
std::map<QString, std::vector<double> > flowPrTracer;
};
std::vector< BranchFlowPrDepth > m_accPseudoLengthFlowPrBranch;
std::vector< BranchFlowPrDepth > m_accTvdFlowPrBranch;
std::vector< BranchResult > m_accConnectionFlowPrBranch;
};

View File

@ -25,6 +25,10 @@
#define RIG_FLD_MAX_FRACTION_TRACER_RESNAME "MaxFractionTracer"
#define RIG_FLD_COMMUNICATION_RESNAME "Communication"
#define RIG_FLOW_TOTAL_NAME "Total"
#define RIG_RESERVOIR_TRACER_NAME "Reservoir"
#define RIG_TINY_TRACER_GROUP_NAME "Other"
class RigFlowDiagResultAddress
{

View File

@ -26,6 +26,8 @@
#include "RimEclipseCase.h"
#include "RimEclipseResultCase.h"
#include "RimFlowDiagSolution.h"
#include "RigFlowDiagResultFrames.h"
#include "RigStatisticsDataCache.h"
//--------------------------------------------------------------------------------------------------
///

View File

@ -26,11 +26,11 @@
#include <map>
#include <string>
#include "RigFlowDiagResultFrames.h"
#include "RigStatisticsDataCache.h"
#include "cafPdmPointer.h"
#include "RimFlowDiagSolution.h"
class RigFlowDiagResultFrames;
class RigStatisticsDataCache;
class RigFlowDiagSolverInterface;
class RigActiveCellInfo;