#1035 Implemented Flow Diag access and caching system down to solver

This commit is contained in:
Jacob Støren 2016-12-17 10:46:57 +01:00
parent 7222d50645
commit 8f145da725
5 changed files with 130 additions and 18 deletions

View File

@ -35,7 +35,7 @@ RimFlowDiagSolution::RimFlowDiagSolution(void)
CAF_PDM_InitField(&m_userDescription, "UserDescription", QString("All Wells") ,"Description", "", "","");
m_flowDiagResults = new RigFlowDiagResults(this);
}
@ -52,6 +52,22 @@ RimFlowDiagSolution::~RimFlowDiagSolution(void)
//--------------------------------------------------------------------------------------------------
RigFlowDiagResults* RimFlowDiagSolution::flowDiagResults()
{
if ( m_flowDiagResults.isNull() )
{
size_t timeStepCount;
{
RimEclipseResultCase* eclCase;
this->firstAncestorOrThisOfType(eclCase);
CVF_ASSERT(eclCase && eclCase->reservoirData() && eclCase->reservoirData() );
timeStepCount = eclCase->reservoirData()->results(RifReaderInterface::MATRIX_RESULTS)->maxTimeStepCount();
}
m_flowDiagResults = new RigFlowDiagResults(this, timeStepCount);
}
return m_flowDiagResults.p();
}

View File

@ -23,10 +23,14 @@
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigFlowDiagResults::RigFlowDiagResults(RimFlowDiagSolution* flowSolution)
RigFlowDiagResults::RigFlowDiagResults(RimFlowDiagSolution* flowSolution, size_t timeStepCount)
: m_flowDiagSolution()
{
m_flowDagSolverInterface = new RigFlowDiagSolverInterface(flowSolution);
m_timeStepCount = timeStepCount;
m_hasAtemptedNativeResults.resize(timeStepCount, false);
}
//--------------------------------------------------------------------------------------------------
@ -37,11 +41,96 @@ RigFlowDiagResults::~RigFlowDiagResults()
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const std::vector<double>* RigFlowDiagResults::resultValues(const RigFlowDiagResultAddress& resVarAddr, size_t frameIndex)
{
return nullptr; // Todo
CVF_ASSERT(m_timeStepCount != cvf::UNDEFINED_SIZE_T); // Forgotten to call init
return findOrCalculateResult(resVarAddr, frameIndex);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const std::vector<double>* RigFlowDiagResults::findOrCalculateResult(const RigFlowDiagResultAddress& resVarAddr, size_t frameIndex)
{
std::vector<double>* frameData = findScalarResultFrame(resVarAddr, frameIndex);
if ( frameData ) return frameData;
frameData = calculateDerivedResult(resVarAddr, frameIndex);
if ( frameData ) return frameData;
// We need to access the native data from the opm solver
if (!m_hasAtemptedNativeResults[frameIndex])
{
RigFlowDiagTimeStepResult nativeTimestepResults = m_flowDagSolverInterface->calculate(frameIndex);
std::map<RigFlowDiagResultAddress, std::vector<double> >& nativeResults = nativeTimestepResults.nativeResults();
for ( auto& resIt: nativeResults )
{
RigFlowDiagResultFrames* nativeResFrames = findScalarResult(resIt.first);
if ( !nativeResFrames ) nativeResFrames = createScalarResult(resIt.first);
nativeResFrames->frameData(frameIndex).swap(resIt.second);
}
m_hasAtemptedNativeResults[frameIndex] = true;
}
return findScalarResultFrame(resVarAddr, frameIndex);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<double>* RigFlowDiagResults::findScalarResultFrame(const RigFlowDiagResultAddress& resVarAddr, size_t frameIndex)
{
RigFlowDiagResultFrames* resFrames = findScalarResult (resVarAddr);
if ( resFrames )
{
std::vector<double>& frame = resFrames->frameData(frameIndex);
if ( frame.size() ) return(&frame);
}
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigFlowDiagResultFrames* RigFlowDiagResults::createScalarResult(const RigFlowDiagResultAddress& resVarAddr)
{
cvf::ref<RigFlowDiagResultFrames> newFrameSet = new RigFlowDiagResultFrames(m_timeStepCount);
m_resultSets[resVarAddr] = newFrameSet;
return newFrameSet.p();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigFlowDiagResultFrames* RigFlowDiagResults::findScalarResult(const RigFlowDiagResultAddress& resVarAddr)
{
decltype(m_resultSets)::iterator it = m_resultSets.find(resVarAddr);
if ( it == m_resultSets.end() ) return nullptr;
return it->second.p();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<double>* RigFlowDiagResults::calculateDerivedResult(const RigFlowDiagResultAddress& resVarAddr, size_t frameIndex)
{
return nullptr; // Todo
}

View File

@ -36,15 +36,13 @@ class RimFlowDiagSolution;
class RigFlowDiagResults: public cvf::Object
{
public:
RigFlowDiagResults(RimFlowDiagSolution* flowSolution);
RigFlowDiagResults(RimFlowDiagSolution* flowSolution, size_t timeStepCount);
virtual ~RigFlowDiagResults();
void initResultSteps(size_t timeStepCount);
const std::vector<double>* resultValues(const RigFlowDiagResultAddress& resVarAddr, size_t frameIndex);
private:
std::vector<double>* findOrCalculateResult (const RigFlowDiagResultAddress& resVarAddr, size_t frameIndex);
const std::vector<double>* findOrCalculateResult (const RigFlowDiagResultAddress& resVarAddr, size_t frameIndex);
std::vector<double>* calculateDerivedResult(const RigFlowDiagResultAddress& resVarAddr, size_t frameIndex);
void calculateFractionWeightedTOF ( size_t timeStepIdx, std::set<std::string> selectedTracerNames);
void calculateSumOfFractions ( size_t timeStepIdx, std::set<std::string> selectedTracerNames);
@ -52,10 +50,13 @@ private:
void calculateCommunication ( size_t timeStepIdx, std::set<std::string> selectedTracerNames);
RigFlowDiagResultFrames* createScalarResult(const RigFlowDiagResultAddress& resVarAddr);
RigFlowDiagResultFrames* findScalarResult (const RigFlowDiagResultAddress& resVarAddr);
void deleteScalarResult(const RigFlowDiagResultAddress& resVarAddr);
RigFlowDiagResultFrames* findScalarResult (const RigFlowDiagResultAddress& resVarAddr) ;
std::vector<double>* findScalarResultFrame (const RigFlowDiagResultAddress& resVarAddr, size_t frameIndex);
//void deleteScalarResult(const RigFlowDiagResultAddress& resVarAddr);
size_t m_timeStepCount;
std::map< RigFlowDiagResultAddress, cvf::ref<RigFlowDiagResultFrames> > m_resultSets;
std::map< RigFlowDiagResultAddress, cvf::ref<RigStatisticsDataCache> > m_resultStatistics;
@ -63,6 +64,7 @@ private:
caf::PdmPointer<RimFlowDiagSolution> m_flowDiagSolution;
std::vector<bool> m_hasAtemptedNativeResults;
};

View File

@ -17,6 +17,7 @@
/////////////////////////////////////////////////////////////////////////////////
#include "RigFlowDiagSolverInterface.h"
#include "RimFlowDiagSolution.h"
//--------------------------------------------------------------------------------------------------
///
@ -30,7 +31,8 @@ RigFlowDiagTimeStepResult::RigFlowDiagTimeStepResult(size_t activeCellCount)
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigFlowDiagSolverInterface::RigFlowDiagSolverInterface(RimEclipseResultCase* eclCase)
RigFlowDiagSolverInterface::RigFlowDiagSolverInterface(RimFlowDiagSolution* flowSol)
: m_flowDiagSolution(flowSol)
{
}
@ -46,8 +48,10 @@ RigFlowDiagSolverInterface::~RigFlowDiagSolverInterface()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<RigFlowDiagTimeStepResult> RigFlowDiagSolverInterface::calculate(size_t timestep, const std::vector<RigTracerCells > & allTracerData)
RigFlowDiagTimeStepResult RigFlowDiagSolverInterface::calculate(size_t timestep)
{
return new RigFlowDiagTimeStepResult(0);
std::vector<RigTracerCells > allTracerData;
return RigFlowDiagTimeStepResult(0); // Relying on implicit move constructor
}

View File

@ -27,6 +27,7 @@
#include <map>
class RimEclipseResultCase;
class RimFlowDiagSolution;
struct RigTracerCells
{
@ -36,7 +37,7 @@ struct RigTracerCells
class RigFlowDiagTimeStepResult: public cvf::Object
class RigFlowDiagTimeStepResult
{
public:
RigFlowDiagTimeStepResult(size_t activeCellCount);
@ -46,8 +47,8 @@ public:
void setProducerTracerTOF (const std::string& tracerName, const std::map<int, double>& cellValues);
void setProducerTracerFraction(const std::string& tracerName, const std::map<int, double>& cellValues);
std::vector<double>& nativeResult(const RigFlowDiagResultAddress& resAddr); // Use to "steal" the data from this one using swap
// Use to "steal" the data from this one using swap
std::map<RigFlowDiagResultAddress, std::vector<double> >& nativeResults() { return m_nativeResults; }
private:
void addResult(const RigFlowDiagResultAddress& resAddr, const std::map<int, double>& cellValues);
@ -61,13 +62,13 @@ private:
class RigFlowDiagSolverInterface : public cvf::Object
{
public:
RigFlowDiagSolverInterface(RimEclipseResultCase* eclCase);
RigFlowDiagSolverInterface(RimFlowDiagSolution* flowSol);
virtual ~RigFlowDiagSolverInterface();
cvf::ref<RigFlowDiagTimeStepResult> calculate(size_t timestep, const std::vector<RigTracerCells > & allTracerData);
RigFlowDiagTimeStepResult calculate(size_t timestep);
private:
caf::PdmPointer<RimEclipseResultCase> m_eclipseCase;
caf::PdmPointer<RimFlowDiagSolution> m_flowDiagSolution;
};