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

View File

@ -19,10 +19,31 @@
#include "RigAccWellFlowCalculator.h" #include "RigAccWellFlowCalculator.h"
#include "RigSingleWellResultsData.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" ///
//==================================================================================================
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
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);
}
//==================================================================================================
///
///
//==================================================================================================
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// ///
@ -32,8 +53,8 @@ RigAccWellFlowCalculator::RigAccWellFlowCalculator(const std::vector< std::vecto
const std::map<QString, const std::vector<double>* >& tracerCellFractionValues, const std::map<QString, const std::vector<double>* >& tracerCellFractionValues,
const RigEclCellIndexCalculator cellIndexCalculator, const RigEclCellIndexCalculator cellIndexCalculator,
double smallContribThreshold, double smallContribThreshold,
bool isProducer): bool isProducer)
m_pipeBranchesCLCoords(pipeBranchesCLCoords), : m_pipeBranchesCLCoords(pipeBranchesCLCoords),
m_pipeBranchesCellIds(pipeBranchesCellIds), m_pipeBranchesCellIds(pipeBranchesCellIds),
m_tracerCellFractionValues(&tracerCellFractionValues), m_tracerCellFractionValues(&tracerCellFractionValues),
m_cellIndexCalculator(cellIndexCalculator), m_cellIndexCalculator(cellIndexCalculator),
@ -67,8 +88,8 @@ RigAccWellFlowCalculator::RigAccWellFlowCalculator(const std::vector< std::vecto
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RigAccWellFlowCalculator::RigAccWellFlowCalculator(const std::vector< std::vector <cvf::Vec3d> >& pipeBranchesCLCoords, RigAccWellFlowCalculator::RigAccWellFlowCalculator(const std::vector< std::vector <cvf::Vec3d> >& pipeBranchesCLCoords,
const std::vector< std::vector <RigWellResultPoint> >& pipeBranchesCellIds, const std::vector< std::vector <RigWellResultPoint> >& pipeBranchesCellIds,
double smallContribThreshold ): double smallContribThreshold)
m_pipeBranchesCLCoords(pipeBranchesCLCoords), : m_pipeBranchesCLCoords(pipeBranchesCLCoords),
m_pipeBranchesCellIds(pipeBranchesCellIds), m_pipeBranchesCellIds(pipeBranchesCellIds),
m_tracerCellFractionValues(nullptr), m_tracerCellFractionValues(nullptr),
m_cellIndexCalculator(RigEclCellIndexCalculator(nullptr, nullptr)), m_cellIndexCalculator(RigEclCellIndexCalculator(nullptr, nullptr)),
@ -86,9 +107,9 @@ RigAccWellFlowCalculator::RigAccWellFlowCalculator(const std::vector< std::vecto
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
const std::vector<double>& RigAccWellFlowCalculator::accumulatedTotalFlowPrConnection(size_t branchIdx) 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) 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; return totalFlows;
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RigAccWellFlowCalculator::isWellFlowConsistent( bool isProducer) bool RigAccWellFlowCalculator::isWellFlowConsistent( bool isProducer)
{ {
bool isConsistent = true; bool isConsistent = true;
@ -181,7 +205,7 @@ void RigAccWellFlowCalculator::calculateAccumulatedFlowPrConnection(size_t branc
size_t prevConnIndx = -1; size_t prevConnIndx = -1;
int clSegIdx = static_cast<int>(branchCells.size()) - 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<size_t>& connNumbersFromTop = m_accConnectionFlowPrBranch[branchIdx].connectionNumbersFromTop;
std::vector<double> accFlow; 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 if ( dsBidx != branchIdx && m_accConnectionFlowPrBranch[dsBidx].connectionNumbersFromTop.size() == 0 ) // Not this branch or already calculated
{ {
calculateAccumulatedFlowPrConnection(dsBidx, connNumFromTop); calculateAccumulatedFlowPrConnection(dsBidx, connNumFromTop);
BranchResult& accConnFlowFractionsDsBranch = m_accConnectionFlowPrBranch[dsBidx]; BranchFlowPrConnection& accConnFlowFractionsDsBranch = m_accConnectionFlowPrBranch[dsBidx];
size_t tracerIdx = 0; size_t tracerIdx = 0;
for ( const auto & tracerName: m_tracerNames ) for ( const auto & tracerName: m_tracerNames )
{ {
accFlow[tracerIdx] += accConnFlowFractionsDsBranch.accConnFlowFractionsPrTracer[tracerName].back(); accFlow[tracerIdx] += accConnFlowFractionsDsBranch.accFlowPrTracer[tracerName].back();
tracerIdx++; tracerIdx++;
} }
} }
@ -346,8 +370,11 @@ void RigAccWellFlowCalculator::sortTracers()
for (const QString& tracerName: m_tracerNames) for (const QString& tracerName: m_tracerNames)
{ {
const std::vector<double>& mainBranchAccFlow = accumulatedTracerFlowPrConnection(tracerName, 0); const std::vector<double>& mainBranchAccFlow = accumulatedTracerFlowPrConnection(tracerName, 0);
double totalFlow = 0.0; double totalFlow = 0.0;
if (mainBranchAccFlow.size()) totalFlow = - abs( mainBranchAccFlow.back() ); // Based on size in reverse order (biggest to least) if (mainBranchAccFlow.size()) totalFlow = - abs( mainBranchAccFlow.back() ); // Based on size in reverse order (biggest to least)
sortedTracers.insert({totalFlow, tracerName}); sortedTracers.insert({totalFlow, tracerName});
} }
@ -359,34 +386,41 @@ void RigAccWellFlowCalculator::sortTracers()
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// /// Concatenate small tracers into an "Other" group
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
void RigAccWellFlowCalculator::groupSmallContributions() 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(); std::vector<std::pair<QString, double> > totalTracerFractions = this->totalTracerFractions();
if ( totalTracerFractions.size() < 5 ) return; // No grouping for few legend items if ( totalTracerFractions.size() < 5 ) return; // No grouping for few legend items
std::vector<QString> tracersToGroup;
for ( const auto& tracerPair : totalTracerFractions ) for ( const auto& tracerPair : totalTracerFractions )
{ {
if ( abs(tracerPair.second) <= m_smallContributionsThreshold ) tracersToGroup.push_back(tracerPair.first); if ( abs(tracerPair.second) <= m_smallContributionsThreshold ) tracersToGroup.push_back(tracerPair.first);
} }
}
if ( tracersToGroup.size() < 2 ) return; // Must at least group two ... if ( tracersToGroup.size() < 2 ) return; // Must at least group two ...
for ( BranchResult& brRes : m_accConnectionFlowPrBranch ) // 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); std::vector<double> groupedConnectionValues( brRes.connectionNumbersFromTop.size(), 0.0);
for ( const QString& tracername:tracersToGroup ) for ( const QString& tracername:tracersToGroup )
{ {
auto it = brRes.accConnFlowFractionsPrTracer.find(tracername); auto it = brRes.accFlowPrTracer.find(tracername);
if ( it != brRes.accConnFlowFractionsPrTracer.end() )
if ( it != brRes.accFlowPrTracer.end() )
{ {
const std::vector<double>& tracerVals = it->second; const std::vector<double>& tracerVals = it->second;
for ( size_t cIdx = 0; cIdx < groupedConnectionValues.size(); ++cIdx ) for ( size_t cIdx = 0; cIdx < groupedConnectionValues.size(); ++cIdx )
@ -394,12 +428,15 @@ void RigAccWellFlowCalculator::groupSmallContributions()
groupedConnectionValues[cIdx] += tracerVals[cIdx]; groupedConnectionValues[cIdx] += tracerVals[cIdx];
} }
} }
brRes.accConnFlowFractionsPrTracer.erase(it);
brRes.accFlowPrTracer.erase(it);
} }
brRes.accConnFlowFractionsPrTracer[RIG_TINY_TRACER_GROUP_NAME] = groupedConnectionValues; 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; std::vector<QString> filteredTracernames;
for ( const QString& tracerName: m_tracerNames ) for ( const QString& tracerName: m_tracerNames )
{ {
@ -414,6 +451,6 @@ void RigAccWellFlowCalculator::groupSmallContributions()
m_tracerNames.swap(filteredTracernames); m_tracerNames.swap(filteredTracernames);
m_tracerNames.push_back(RIG_TINY_TRACER_GROUP_NAME); 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 class RigEclCellIndexCalculator
{ {
@ -35,13 +33,7 @@ public:
: m_mainGrid(mainGrid), m_activeCellInfo(activeCellInfo) : m_mainGrid(mainGrid), m_activeCellInfo(activeCellInfo)
{} {}
size_t resultCellIndex(size_t gridIndex, size_t gridCellIndex) const 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);
}
private: private:
const RigMainGrid* m_mainGrid; 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 class RigAccWellFlowCalculator
{ {
@ -74,6 +74,7 @@ public:
const std::vector<QString>& tracerNames() const { return m_tracerNames;} const std::vector<QString>& tracerNames() const { return m_tracerNames;}
std::vector<std::pair<QString, double> > totalTracerFractions(); std::vector<std::pair<QString, double> > totalTracerFractions();
private: private:
bool isWellFlowConsistent(bool isProducer); bool isWellFlowConsistent(bool isProducer);
@ -94,13 +95,25 @@ private:
std::vector<QString> m_tracerNames; std::vector<QString> m_tracerNames;
double m_smallContributionsThreshold; double m_smallContributionsThreshold;
struct BranchResult struct BranchFlowPrConnection
{ {
std::vector<size_t> connectionNumbersFromTop; std::vector<size_t> connectionNumbersFromTop;
std::map<QString, std::vector<double> > accConnFlowFractionsPrTracer; std::map<QString, std::vector<double> > accFlowPrTracer;
std::map<QString, std::vector<double> > flowPrTracer;
}; };
std::vector< BranchResult > m_accConnectionFlowPrBranch; 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;
}; };

View File

@ -25,6 +25,10 @@
#define RIG_FLD_MAX_FRACTION_TRACER_RESNAME "MaxFractionTracer" #define RIG_FLD_MAX_FRACTION_TRACER_RESNAME "MaxFractionTracer"
#define RIG_FLD_COMMUNICATION_RESNAME "Communication" #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 class RigFlowDiagResultAddress
{ {

View File

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

View File

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