#1048 Added derived result: Injector Producer communication

This commit is contained in:
Jacob Støren 2017-01-02 14:46:12 +01:00
parent a9b1cb4849
commit 7c24522478
2 changed files with 140 additions and 89 deletions

View File

@ -160,39 +160,24 @@ std::vector<double>* RigFlowDiagResults::calculateDerivedResult(const RigFlowDia
{
if (resVarAddr.isNativeResult()) return nullptr;
size_t activeCellCount = this->activeCellInfo(resVarAddr)->reservoirActiveCellCount();
if (resVarAddr.variableName == RIG_FLD_TOF_RESNAME)
{
std::vector<const std::vector<double>* > injectorTOFs;
std::vector<const std::vector<double>* > injectorFractions;
std::vector<const std::vector<double>* > injectorTOFs = findResultsForSelectedTracers(resVarAddr, frameIndex,
RIG_FLD_TOF_RESNAME, RimFlowDiagSolution::INJECTOR);
std::vector<const std::vector<double>* > injectorFractions = findResultsForSelectedTracers(resVarAddr, frameIndex,
RIG_FLD_CELL_FRACTION_RESNAME, RimFlowDiagSolution::INJECTOR);
std::vector<const std::vector<double>* > producerTOFs;
std::vector<const std::vector<double>* > producerFractions;
for (const std::string& tracerName: resVarAddr.selectedTracerNames)
{
RimFlowDiagSolution::TracerStatusType tracerType = m_flowDiagSolution->tracerStatusInTimeStep(QString::fromStdString(tracerName), frameIndex);
if ( tracerType == RimFlowDiagSolution::INJECTOR )
{
injectorTOFs.push_back( findOrCalculateResult(RigFlowDiagResultAddress(RIG_FLD_TOF_RESNAME, tracerName), frameIndex));
injectorFractions.push_back(findOrCalculateResult(RigFlowDiagResultAddress(RIG_FLD_CELL_FRACTION_RESNAME, tracerName), frameIndex));
}
else if ( tracerType == RimFlowDiagSolution::PRODUCER )
{
producerTOFs.push_back(findOrCalculateResult(RigFlowDiagResultAddress(RIG_FLD_TOF_RESNAME, tracerName), frameIndex));
producerFractions.push_back(findOrCalculateResult(RigFlowDiagResultAddress(RIG_FLD_CELL_FRACTION_RESNAME, tracerName), frameIndex));
}
}
size_t activeCellCount = this->activeCellInfo(resVarAddr)->reservoirActiveCellCount();
std::vector<const std::vector<double>* > producerTOFs = findResultsForSelectedTracers(resVarAddr, frameIndex,
RIG_FLD_TOF_RESNAME, RimFlowDiagSolution::PRODUCER);
std::vector<const std::vector<double>* > producerFractions = findResultsForSelectedTracers(resVarAddr, frameIndex,
RIG_FLD_CELL_FRACTION_RESNAME, RimFlowDiagSolution::PRODUCER);
std::vector<double> injectorTotalFractions;
std::vector<double> injectorFractMultTof;
calculateSumOfFractionAndFractionMultTOF(activeCellCount, injectorFractions, injectorTOFs, &injectorTotalFractions, &injectorFractMultTof);
std::vector<double> producerTotalFractions;
std::vector<double> producerFractMultTof;
calculateSumOfFractionAndFractionMultTOF(activeCellCount, producerFractions, producerTOFs, &producerTotalFractions, &producerFractMultTof);
@ -220,40 +205,77 @@ std::vector<double>* RigFlowDiagResults::calculateDerivedResult(const RigFlowDia
}
else if (resVarAddr.variableName == RIG_FLD_CELL_FRACTION_RESNAME)
{
std::vector<const std::vector<double>* > fractions;
for ( const std::string& tracerName: resVarAddr.selectedTracerNames )
{
fractions.push_back(findOrCalculateResult(RigFlowDiagResultAddress(RIG_FLD_CELL_FRACTION_RESNAME, tracerName), frameIndex));
}
size_t activeCellCount = this->activeCellInfo(resVarAddr)->reservoirActiveCellCount();
std::vector<const std::vector<double>* > fractions = findResultsForSelectedTracers(resVarAddr,
frameIndex,
RIG_FLD_CELL_FRACTION_RESNAME,
RimFlowDiagSolution::UNDEFINED);
RigFlowDiagResultFrames* sumOfFractionsFrames = this->createScalarResult(resVarAddr);
std::vector<double>& sumOfFractions = sumOfFractionsFrames->frameData(frameIndex);
sumOfFractions.resize(activeCellCount, HUGE_VAL);
for ( size_t iIdx = 0; iIdx < fractions.size() ; ++iIdx )
{
const std::vector<double> * frInj = fractions[iIdx];
if ( ! (frInj) ) continue;
for ( size_t acIdx = 0 ; acIdx < activeCellCount; ++acIdx )
{
if ( (*frInj)[acIdx] == HUGE_VAL ) continue;
if ((sumOfFractions)[acIdx] == HUGE_VAL) (sumOfFractions)[acIdx] = 0.0;
(sumOfFractions)[acIdx] += (*frInj)[acIdx];
}
}
calculateSumOfFractions(fractions, activeCellCount, &sumOfFractions);
return &sumOfFractions;
}
else if ( resVarAddr.variableName == RIG_FLD_COMMUNICATION_RESNAME )
{
std::vector<const std::vector<double>* > injectorFractions = findResultsForSelectedTracers(resVarAddr,
frameIndex,
RIG_FLD_CELL_FRACTION_RESNAME,
RimFlowDiagSolution::INJECTOR);
std::vector<const std::vector<double>* > producerFractions = findResultsForSelectedTracers(resVarAddr,
frameIndex,
RIG_FLD_CELL_FRACTION_RESNAME,
RimFlowDiagSolution::PRODUCER);
std::vector<double> sumOfInjectorFractions;
calculateSumOfFractions(injectorFractions, activeCellCount, &sumOfInjectorFractions);
std::vector<double> sumOfProducerFractions;
calculateSumOfFractions(producerFractions, activeCellCount, &sumOfProducerFractions);
RigFlowDiagResultFrames* commFrames = this->createScalarResult(resVarAddr);
std::vector<double>& commPI = commFrames->frameData(frameIndex);
commPI.resize(activeCellCount, HUGE_VAL);
for ( size_t acIdx = 0 ; acIdx < activeCellCount; ++acIdx )
{
if ( (sumOfInjectorFractions)[acIdx] == HUGE_VAL ) continue;
if ( (sumOfProducerFractions)[acIdx] == HUGE_VAL ) continue;
(commPI)[acIdx] = (sumOfInjectorFractions)[acIdx] * (sumOfProducerFractions)[acIdx];
}
return &commPI;
}
return nullptr; // Todo
}
std::vector<const std::vector<double>* > RigFlowDiagResults::findResultsForSelectedTracers(const RigFlowDiagResultAddress& resVarAddr,
size_t frameIndex,
const std::string& nativeResultName,
RimFlowDiagSolution::TracerStatusType wantedTracerType)
{
std::vector<const std::vector<double>* > selectedTracersResults;
for ( const std::string& tracerName: resVarAddr.selectedTracerNames )
{
RimFlowDiagSolution::TracerStatusType tracerType = m_flowDiagSolution->tracerStatusInTimeStep(QString::fromStdString(tracerName), frameIndex);
if ( tracerType == wantedTracerType || wantedTracerType == RimFlowDiagSolution::UNDEFINED )
{
selectedTracersResults.push_back(findOrCalculateResult(RigFlowDiagResultAddress(nativeResultName, tracerName), frameIndex));
}
}
return selectedTracersResults;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -299,6 +321,32 @@ RigStatisticsDataCache* RigFlowDiagResults::statistics(const RigFlowDiagResultAd
return statCache;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigFlowDiagResults::calculateSumOfFractions(const std::vector<const std::vector<double> *> &fractions,
size_t activeCellCount,
std::vector<double>* sumOfFractions)
{
sumOfFractions->resize(activeCellCount, HUGE_VAL);
for ( size_t iIdx = 0; iIdx < fractions.size() ; ++iIdx )
{
const std::vector<double> * fraction = fractions[iIdx];
if ( ! (fraction) ) continue;
for ( size_t acIdx = 0 ; acIdx < activeCellCount; ++acIdx )
{
if ( (*fraction)[acIdx] == HUGE_VAL ) continue;
if ( (*sumOfFractions)[acIdx] == HUGE_VAL ) (*sumOfFractions)[acIdx] = 0.0;
(*sumOfFractions)[acIdx] += (*fraction)[acIdx];
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -29,9 +29,9 @@
#include "RigFlowDiagResultFrames.h"
#include "RigStatisticsDataCache.h"
#include "cafPdmPointer.h"
#include "RimFlowDiagSolution.h"
class RigFlowDiagSolverInterface;
class RimFlowDiagSolution;
class RigActiveCellInfo;
class RigFlowDiagResults: public cvf::Object
@ -40,59 +40,62 @@ public:
RigFlowDiagResults(RimFlowDiagSolution* flowSolution, size_t timeStepCount);
virtual ~RigFlowDiagResults();
const std::vector<double>* resultValues(const RigFlowDiagResultAddress& resVarAddr, size_t frameIndex);
size_t timeStepCount() { return m_timeStepCount; }
const RigActiveCellInfo * activeCellInfo(const RigFlowDiagResultAddress& resVarAddr);
const std::vector<double>* resultValues(const RigFlowDiagResultAddress& resVarAddr, size_t frameIndex);
size_t timeStepCount() { return m_timeStepCount; }
const RigActiveCellInfo * activeCellInfo(const RigFlowDiagResultAddress& resVarAddr);
void minMaxScalarValues (const RigFlowDiagResultAddress& resVarAddr, int frameIndex, double* localMin, double* localMax);
void minMaxScalarValues (const RigFlowDiagResultAddress& resVarAddr, double* globalMin, double* globalMax);
void posNegClosestToZero(const RigFlowDiagResultAddress& resVarAddr, int frameIndex, double* localPosClosestToZero, double* localNegClosestToZero);
void posNegClosestToZero(const RigFlowDiagResultAddress& resVarAddr, double* globalPosClosestToZero, double* globalNegClosestToZero);
void meanScalarValue(const RigFlowDiagResultAddress& resVarAddr, double* meanValue);
void meanScalarValue(const RigFlowDiagResultAddress& resVarAddr, int frameIndex, double* meanValue);
void p10p90ScalarValues(const RigFlowDiagResultAddress& resVarAddr, double* p10, double* p90);
void p10p90ScalarValues(const RigFlowDiagResultAddress& resVarAddr, int frameIndex, double* p10, double* p90);
void sumScalarValue(const RigFlowDiagResultAddress& resVarAddr, double* sum);
void sumScalarValue(const RigFlowDiagResultAddress& resVarAddr, int frameIndex, double* sum);
const std::vector<size_t>& scalarValuesHistogram(const RigFlowDiagResultAddress& resVarAddr);
const std::vector<size_t>& scalarValuesHistogram(const RigFlowDiagResultAddress& resVarAddr, int frameIndex);
const std::vector<int>& uniqueCellScalarValues(const RigFlowDiagResultAddress& resVarAddr);
const std::vector<int>& uniqueCellScalarValues(const RigFlowDiagResultAddress& resVarAddr, int frameIndex);
void minMaxScalarValues (const RigFlowDiagResultAddress& resVarAddr, int frameIndex, double* localMin, double* localMax);
void minMaxScalarValues (const RigFlowDiagResultAddress& resVarAddr, double* globalMin, double* globalMax);
void posNegClosestToZero(const RigFlowDiagResultAddress& resVarAddr, int frameIndex, double* localPosClosestToZero, double* localNegClosestToZero);
void posNegClosestToZero(const RigFlowDiagResultAddress& resVarAddr, double* globalPosClosestToZero, double* globalNegClosestToZero);
void meanScalarValue(const RigFlowDiagResultAddress& resVarAddr, double* meanValue);
void meanScalarValue(const RigFlowDiagResultAddress& resVarAddr, int frameIndex, double* meanValue);
void p10p90ScalarValues(const RigFlowDiagResultAddress& resVarAddr, double* p10, double* p90);
void p10p90ScalarValues(const RigFlowDiagResultAddress& resVarAddr, int frameIndex, double* p10, double* p90);
void sumScalarValue(const RigFlowDiagResultAddress& resVarAddr, double* sum);
void sumScalarValue(const RigFlowDiagResultAddress& resVarAddr, int frameIndex, double* sum);
const std::vector<size_t>& scalarValuesHistogram(const RigFlowDiagResultAddress& resVarAddr);
const std::vector<size_t>& scalarValuesHistogram(const RigFlowDiagResultAddress& resVarAddr, int frameIndex);
const std::vector<int>& uniqueCellScalarValues(const RigFlowDiagResultAddress& resVarAddr);
const std::vector<int>& uniqueCellScalarValues(const RigFlowDiagResultAddress& resVarAddr, int frameIndex);
private:
const std::vector<double>* findOrCalculateResult (const RigFlowDiagResultAddress& resVarAddr, size_t frameIndex);
std::vector<double>* calculateDerivedResult(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 calculateSumOfFractionAndFractionMultTOF(size_t activeCellCount,
const std::vector<const std::vector<double> *>& injectorFractions,
const std::vector<const std::vector<double> *>& injectorTOFs,
std::vector<double> *injectorTotalFractions,
std::vector<double> *injectorFractMultTof);
RigStatisticsDataCache* statistics(const RigFlowDiagResultAddress& resVarAddr);
std::vector<const std::vector<double>* > findResultsForSelectedTracers(const RigFlowDiagResultAddress& resVarAddr,
size_t frameIndex,
const std::string& nativeResultName,
RimFlowDiagSolution::TracerStatusType wantedTracerType);
void calculateSumOfFractionAndFractionMultTOF(size_t activeCellCount,
const std::vector<const std::vector<double> *>& injectorFractions,
const std::vector<const std::vector<double> *>& injectorTOFs,
std::vector<double> *injectorTotalFractions,
std::vector<double> *injectorFractMultTof);
void calculateFractionWeightedTOF (size_t timeStepIdx, std::set<std::string> selectedTracerNames);
void calculateSumOfFractions ( size_t timeStepIdx, std::set<std::string> selectedTracerNames);
void calculateTracerWithMaxFraction( size_t timeStepIdx, std::set<std::string> selectedTracerNames); // Needs a tracer index
void calculateCommunication ( size_t timeStepIdx, std::set<std::string> selectedTracerNames);
RigFlowDiagResultFrames* createScalarResult(const RigFlowDiagResultAddress& resVarAddr);
RigFlowDiagResultFrames* findScalarResult (const RigFlowDiagResultAddress& resVarAddr) ;
std::vector<double>* findScalarResultFrame (const RigFlowDiagResultAddress& resVarAddr, size_t frameIndex);
void calculateSumOfFractions(const std::vector<const std::vector<double> *> &fractions,
size_t activeCellCount,
std::vector<double>* sumOfFractions);
//void deleteScalarResult(const RigFlowDiagResultAddress& resVarAddr);
RigStatisticsDataCache* statistics(const RigFlowDiagResultAddress& resVarAddr);
RigFlowDiagResultFrames* createScalarResult(const RigFlowDiagResultAddress& resVarAddr);
RigFlowDiagResultFrames* findScalarResult (const RigFlowDiagResultAddress& resVarAddr) ;
std::vector<double>* findScalarResultFrame (const RigFlowDiagResultAddress& resVarAddr, size_t frameIndex);
size_t m_timeStepCount;
//void deleteScalarResult(const RigFlowDiagResultAddress& resVarAddr);
RigFlowDiagSolverInterface* solverInterface();
size_t m_timeStepCount;
caf::PdmPointer<RimFlowDiagSolution> m_flowDiagSolution;
std::vector<bool> m_hasAtemptedNativeResults;
std::map< RigFlowDiagResultAddress, cvf::ref<RigFlowDiagResultFrames> > m_resultSets;
std::map< RigFlowDiagResultAddress, cvf::ref<RigStatisticsDataCache> > m_resultStatistics;
RigFlowDiagSolverInterface* solverInterface();
caf::PdmPointer<RimFlowDiagSolution> m_flowDiagSolution;
std::vector<bool> m_hasAtemptedNativeResults;
};