diff --git a/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp b/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp index 3570d0f320..a44cee7f38 100644 --- a/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp +++ b/ApplicationCode/ProjectDataModel/Rim3dOverlayInfoConfig.cpp @@ -292,6 +292,7 @@ Rim3dOverlayInfoConfig::HistogramData Rim3dOverlayInfoConfig::histogramData(RimE fldResults->p10p90ScalarValues(resAddr, currentTimeStep, &histData.p10, &histData.p90); fldResults->meanScalarValue(resAddr, currentTimeStep, &histData.mean); fldResults->sumScalarValue(resAddr, currentTimeStep, &histData.sum); + fldResults->mobileVolumeWeightedMean(resAddr, currentTimeStep, &histData.weightedMean); histData.histogram = &(fldResults->scalarValuesHistogram(resAddr, currentTimeStep)); } diff --git a/ApplicationCode/ReservoirDataModel/RigEclipseNativeVisibleCellsStatCalc.cpp b/ApplicationCode/ReservoirDataModel/RigEclipseNativeVisibleCellsStatCalc.cpp index e227eac308..735803dd8e 100644 --- a/ApplicationCode/ReservoirDataModel/RigEclipseNativeVisibleCellsStatCalc.cpp +++ b/ApplicationCode/ReservoirDataModel/RigEclipseNativeVisibleCellsStatCalc.cpp @@ -112,6 +112,6 @@ void RigEclipseNativeVisibleCellsStatCalc::mobileVolumeWeightedMean(size_t timeS const RigActiveCellInfo* actCellInfo = m_caseData->activeCellInfo(); - RigWeightedMeanCalc::weightedMeanOverCells(&weights, &values, m_cellVisibilities.p(), actCellInfo, m_caseData->isUsingGlobalActiveIndex(m_scalarResultIndex), &result); + RigWeightedMeanCalc::weightedMeanOverCells(&weights, &values, m_cellVisibilities.p(), true, actCellInfo, m_caseData->isUsingGlobalActiveIndex(m_scalarResultIndex), &result); } diff --git a/ApplicationCode/ReservoirDataModel/RigFlowDiagResults.cpp b/ApplicationCode/ReservoirDataModel/RigFlowDiagResults.cpp index f15b8c3cf3..8802675fd8 100644 --- a/ApplicationCode/ReservoirDataModel/RigFlowDiagResults.cpp +++ b/ApplicationCode/ReservoirDataModel/RigFlowDiagResults.cpp @@ -665,6 +665,14 @@ const std::vector& RigFlowDiagResults::uniqueCellScalarValues(const RigFlow return this->statistics(resVarAddr)->uniqueCellScalarValues(timeStepIndex); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigFlowDiagResults::mobileVolumeWeightedMean(const RigFlowDiagResultAddress& resVarAddr, int timeStepIndex, double* mean) +{ + this->statistics(resVarAddr)->mobileVolumeWeightedMean(timeStepIndex, *mean); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ReservoirDataModel/RigFlowDiagResults.h b/ApplicationCode/ReservoirDataModel/RigFlowDiagResults.h index f7d3ceb1c4..14f855dfdb 100644 --- a/ApplicationCode/ReservoirDataModel/RigFlowDiagResults.h +++ b/ApplicationCode/ReservoirDataModel/RigFlowDiagResults.h @@ -74,6 +74,7 @@ public: const std::vector& scalarValuesHistogram(const RigFlowDiagResultAddress& resVarAddr, int timeStepIndex); const std::vector& uniqueCellScalarValues(const RigFlowDiagResultAddress& resVarAddr); const std::vector& uniqueCellScalarValues(const RigFlowDiagResultAddress& resVarAddr, int timeStepIndex); + void mobileVolumeWeightedMean(const RigFlowDiagResultAddress& resVarAddr, int timeStepIndex, double* mean); std::pair injectorProducerPairFluxes(const std::string& injTracername, const std::string& prodTracerName, int timeStepIndex); double maxAbsPairFlux(int timeStepIndex); diff --git a/ApplicationCode/ReservoirDataModel/RigFlowDiagStatCalc.cpp b/ApplicationCode/ReservoirDataModel/RigFlowDiagStatCalc.cpp index 724d026ebd..51ea27d4ab 100644 --- a/ApplicationCode/ReservoirDataModel/RigFlowDiagStatCalc.cpp +++ b/ApplicationCode/ReservoirDataModel/RigFlowDiagStatCalc.cpp @@ -18,10 +18,15 @@ ///////////////////////////////////////////////////////////////////////////////// #include "RigFlowDiagStatCalc.h" + +#include "RigCaseCellResultsData.h" #include "RigFlowDiagResults.h" +#include "RigStatisticsMath.h" +#include "RigWeightedMeanCalc.h" + +#include "RimEclipseResultCase.h" #include -#include "RigStatisticsMath.h" //-------------------------------------------------------------------------------------------------- /// @@ -104,4 +109,24 @@ size_t RigFlowDiagStatCalc::timeStepCount() return m_resultsData->timeStepCount(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigFlowDiagStatCalc::mobileVolumeWeightedMean(size_t timeStepIndex, double& mean) +{ + RimEclipseResultCase* eclCase = nullptr; + m_resultsData->flowDiagSolution()->firstAncestorOrThisOfType(eclCase); + if (!eclCase) return; + + RigCaseCellResultsData* caseCellResultsData = eclCase->results(RiaDefines::MATRIX_MODEL); + + size_t mobPVResultIndex = caseCellResultsData->findOrLoadScalarResult(RiaDefines::ResultCatType::STATIC_NATIVE, RiaDefines::mobilePoreVolumeName()); + + const std::vector& weights = caseCellResultsData->cellScalarResults(mobPVResultIndex, 0); + const std::vector* values = m_resultsData->resultValues(m_resVarAddr, timeStepIndex); + + const RigActiveCellInfo* actCellInfo = m_resultsData->activeCellInfo(m_resVarAddr); + + RigWeightedMeanCalc::weightedMeanOverCells(&weights, values, nullptr, false, actCellInfo, true, &mean); +} diff --git a/ApplicationCode/ReservoirDataModel/RigFlowDiagStatCalc.h b/ApplicationCode/ReservoirDataModel/RigFlowDiagStatCalc.h index bd145c43d2..14993cd7d5 100644 --- a/ApplicationCode/ReservoirDataModel/RigFlowDiagStatCalc.h +++ b/ApplicationCode/ReservoirDataModel/RigFlowDiagStatCalc.h @@ -19,8 +19,8 @@ #pragma once -#include "RigStatisticsCalculator.h" #include "RigFlowDiagResultAddress.h" +#include "RigStatisticsCalculator.h" class RigHistogramCalculator; class RigFlowDiagResults; @@ -32,7 +32,7 @@ class RigFlowDiagResults; class RigFlowDiagStatCalc : public RigStatisticsCalculator { public: - RigFlowDiagStatCalc(RigFlowDiagResults* femResultCollection, const RigFlowDiagResultAddress& resVarAddr); + RigFlowDiagStatCalc(RigFlowDiagResults* flowDiagResults, const RigFlowDiagResultAddress& resVarAddr); virtual void minMaxCellScalarValues(size_t timeStepIndex, double& min, double& max); virtual void posNegClosestToZero(size_t timeStepIndex, double& pos, double& neg); @@ -40,6 +40,7 @@ public: virtual void addDataToHistogramCalculator(size_t timeStepIndex, RigHistogramCalculator& histogramCalculator); virtual void uniqueValues(size_t timeStepIndex, std::set& values); virtual size_t timeStepCount(); + virtual void mobileVolumeWeightedMean(size_t timeStepIndex, double& mean); private: RigFlowDiagResults* m_resultsData; diff --git a/ApplicationCode/ReservoirDataModel/RigFlowDiagVisibleCellsStatCalc.cpp b/ApplicationCode/ReservoirDataModel/RigFlowDiagVisibleCellsStatCalc.cpp index 9abdf4aa70..da57faf89c 100644 --- a/ApplicationCode/ReservoirDataModel/RigFlowDiagVisibleCellsStatCalc.cpp +++ b/ApplicationCode/ReservoirDataModel/RigFlowDiagVisibleCellsStatCalc.cpp @@ -116,6 +116,6 @@ void RigFlowDiagVisibleCellsStatCalc::mobileVolumeWeightedMean(size_t timeStepIn const RigActiveCellInfo* actCellInfo = m_resultsData->activeCellInfo(m_resVarAddr); - RigWeightedMeanCalc::weightedMeanOverCells(&weights, values, m_cellVisibilities.p(), actCellInfo, true, &result); + RigWeightedMeanCalc::weightedMeanOverCells(&weights, values, m_cellVisibilities.p(), true, actCellInfo, true, &result); } diff --git a/ApplicationCode/ReservoirDataModel/RigWeightedMeanCalc.cpp b/ApplicationCode/ReservoirDataModel/RigWeightedMeanCalc.cpp index 4530e18380..dde8819049 100644 --- a/ApplicationCode/ReservoirDataModel/RigWeightedMeanCalc.cpp +++ b/ApplicationCode/ReservoirDataModel/RigWeightedMeanCalc.cpp @@ -28,71 +28,48 @@ //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RigWeightedMeanCalc::weightedMeanOverCells(const std::vector* weights, - const std::vector* values, - const cvf::UByteArray* cellVisibilities, +void RigWeightedMeanCalc::weightedMeanOverCells(const std::vector* weights, + const std::vector* values, + const cvf::UByteArray* cellVisibilities, + bool isUsingVisibleCells, const RigActiveCellInfo* actCellInfo, bool isUsingActiveIndex, double *result) { - if (!(weights && values && cellVisibilities && result)) return; + if (!(weights && values && result)) return; + if (!cellVisibilities && isUsingVisibleCells) return; if (!actCellInfo && isUsingActiveIndex) return; if (weights->empty() || values->empty()) return; - if (weights->size() != values->size()) return; double weightedSum = 0.0; double weightSum = 0.0; - for (size_t cIdx = 0; cIdx < cellVisibilities->size(); ++cIdx) + for (size_t cIdx = 0; cIdx < actCellInfo->reservoirCellCount(); ++cIdx) { - if (!(*cellVisibilities)[cIdx]) continue; + if (isUsingVisibleCells) + { + if (!(*cellVisibilities)[cIdx]) continue; + } + + size_t cellResultIndex = actCellInfo->cellResultIndex(cIdx); + if (cellResultIndex == cvf::UNDEFINED_SIZE_T || cellResultIndex > weights->size()) + { + continue; + } + + double value; - size_t cellResultIndex = cIdx; if (isUsingActiveIndex) { - cellResultIndex = actCellInfo->cellResultIndex(cIdx); + value = (*values)[cellResultIndex]; + } + else + { + value = (*values)[cIdx]; } - - if (cellResultIndex == cvf::UNDEFINED_SIZE_T || cellResultIndex > values->size()) continue; double weight = (*weights)[cellResultIndex]; - double value = (*values)[cellResultIndex]; - - if (weight == HUGE_VAL || value == HUGE_VAL) - { - continue; - } - - weightedSum += weight * value; - weightSum += weight; - } - - if (weightSum != 0) - { - *result = weightedSum / weightSum; - } - else - { - *result = HUGE_VAL; - } -} - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigWeightedMeanCalc::weightedMean(const std::vector* weights, const std::vector* values, double* result) -{ - if (!weights || !values) return; - if (weights->size() != values->size()) return; - - double weightedSum = 0; - double weightSum = 0; - - for (size_t i = 0; i < values->size(); i++) - { - double weight = weights->at(i); - double value = values->at(i); if (weight == HUGE_VAL || value == HUGE_VAL) { diff --git a/ApplicationCode/ReservoirDataModel/RigWeightedMeanCalc.h b/ApplicationCode/ReservoirDataModel/RigWeightedMeanCalc.h index 138067a9dd..c3f58e6902 100644 --- a/ApplicationCode/ReservoirDataModel/RigWeightedMeanCalc.h +++ b/ApplicationCode/ReservoirDataModel/RigWeightedMeanCalc.h @@ -31,9 +31,8 @@ public: static void weightedMeanOverCells(const std::vector* weights, const std::vector* values, const cvf::UByteArray* cellVisibilities, + bool isUsingVisibleCells, const RigActiveCellInfo* actCellInfo, bool isUsingActiveIndex, double *result); - - static void weightedMean(const std::vector* weights, const std::vector* values, double *result); }; diff --git a/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.cpp b/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.cpp index c9f530435a..fe19cd8b4d 100644 --- a/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.cpp +++ b/ApplicationCode/ResultStatisticsCache/RigStatisticsDataCache.cpp @@ -280,6 +280,11 @@ const std::vector& RigStatisticsDataCache::uniqueCellScalarValues(size_t ti //-------------------------------------------------------------------------------------------------- void RigStatisticsDataCache::mobileVolumeWeightedMean(size_t timeStepIndex, double& mean) { + if (timeStepIndex >= m_statsPrTs.size()) + { + m_statsPrTs.resize(timeStepIndex + 1); + } + if (!m_statsPrTs[timeStepIndex].m_isVolumeWeightedMeanCalculated) { m_statisticsCalculator->mobileVolumeWeightedMean(timeStepIndex, m_statsPrTs[timeStepIndex].m_volumeWeightedMean);