From e3e4e79340fedf8f32d832106170ea3934b993d2 Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Tue, 19 Jun 2018 13:20:15 +0200 Subject: [PATCH] Improve encapsulation of RigEclipseResultInfo * To make it more suitable for looking up results. --- .../RimIdenticalGridCaseGroup.cpp | 8 +- .../RimReservoirCellResultsStorage.cpp | 16 +-- .../RigCaseCellResultsData.cpp | 69 +++++++----- .../RigCaseCellResultsData.h | 1 + .../RigEclipseResultInfo.cpp | 104 +++++++++++++++++- .../ReservoirDataModel/RigEclipseResultInfo.h | 29 ++++- 6 files changed, 175 insertions(+), 52 deletions(-) diff --git a/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp b/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp index d88876c537..af8c77915e 100644 --- a/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp +++ b/ApplicationCode/ProjectDataModel/RimIdenticalGridCaseGroup.cpp @@ -251,10 +251,10 @@ void RimIdenticalGridCaseGroup::loadMainCaseAndActiveCellInfo() for (size_t resIdx = 0; resIdx < resultInfos.size(); resIdx++) { - RiaDefines::ResultCatType resultType = resultInfos[resIdx].m_resultType; - QString resultName = resultInfos[resIdx].m_resultName; - bool needsToBeStored = resultInfos[resIdx].m_needsToBeStored; - bool mustBeCalculated = resultInfos[resIdx].m_mustBeCalculated; + RiaDefines::ResultCatType resultType = resultInfos[resIdx].resultType(); + QString resultName = resultInfos[resIdx].resultName(); + bool needsToBeStored = resultInfos[resIdx].needsToBeStored(); + bool mustBeCalculated = resultInfos[resIdx].mustBeCalculated(); size_t scalarResultIndex = cellResultsStorage->findScalarResultIndex(resultType, resultName); if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) diff --git a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp index e366396acd..e4c3229587 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp +++ b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp @@ -96,7 +96,7 @@ void RimReservoirCellResultsStorage::setupBeforeSave() bool hasResultsToStore = false; for (size_t rIdx = 0; rIdx < resInfo.size(); ++rIdx) { - if (resInfo[rIdx].m_needsToBeStored) + if (resInfo[rIdx].needsToBeStored()) { hasResultsToStore = true; break; @@ -128,18 +128,18 @@ void RimReservoirCellResultsStorage::setupBeforeSave() { // If there is no data, we do not store anything for the current result variable // (Even not the metadata, of cause) - size_t timestepCount = m_cellResults->cellScalarResults(resInfo[rIdx].m_gridScalarResultIndex).size(); + size_t timestepCount = m_cellResults->cellScalarResults(resInfo[rIdx].gridScalarResultIndex()).size(); - if (timestepCount && resInfo[rIdx].m_needsToBeStored) + if (timestepCount && resInfo[rIdx].needsToBeStored()) { - progInfo.setProgressDescription(resInfo[rIdx].m_resultName); + progInfo.setProgressDescription(resInfo[rIdx].resultName()); // Create and setup the cache information for this result RimReservoirCellResultsStorageEntryInfo* cacheEntry = new RimReservoirCellResultsStorageEntryInfo; m_resultCacheMetaData.push_back(cacheEntry); - cacheEntry->m_resultType = resInfo[rIdx].m_resultType; - cacheEntry->m_resultName = resInfo[rIdx].m_resultName; + cacheEntry->m_resultType = resInfo[rIdx].resultType(); + cacheEntry->m_resultName = resInfo[rIdx].resultName(); cacheEntry->m_timeStepDates = resInfo[rIdx].dates(); cacheEntry->m_daysSinceSimulationStart = resInfo[rIdx].daysSinceSimulationStarts(); @@ -153,7 +153,7 @@ void RimReservoirCellResultsStorage::setupBeforeSave() const std::vector* data = nullptr; if (tsIdx < timestepCount) { - data = &(m_cellResults->cellScalarResults(resInfo[rIdx].m_gridScalarResultIndex, tsIdx)); + data = &(m_cellResults->cellScalarResults(resInfo[rIdx].gridScalarResultIndex(), tsIdx)); } if (data && data->size()) @@ -271,7 +271,7 @@ void RimReservoirCellResultsStorage::setCellResults(RigCaseCellResultsData* cell for (size_t rIdx = 0; rIdx < m_resultCacheMetaData.size(); ++rIdx) { RimReservoirCellResultsStorageEntryInfo* resInfo = m_resultCacheMetaData[rIdx]; - size_t resultIndex = m_cellResults->findOrCreateScalarResultIndex(resInfo->m_resultType(), resInfo->m_resultName(), true); + size_t resultIndex = m_cellResults->findOrCreateScalarResultIndex(resInfo->m_resultType(), resInfo->m_resultName, true); std::vector reportNumbers; // Hack: Using no report step numbers. Not really used except for Flow Diagnostics... reportNumbers.resize(resInfo->m_timeStepDates().size()); diff --git a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp index f7bbe9defe..62c33b5b6c 100644 --- a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp +++ b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp @@ -238,9 +238,9 @@ size_t RigCaseCellResultsData::findScalarResultIndex(RiaDefines::ResultCatType t std::vector::const_iterator it; for (it = m_resultInfos.begin(); it != m_resultInfos.end(); ++it) { - if (it->m_resultType == type && it->m_resultName == resultName) + if (it->resultType() == type && it->resultName() == resultName) { - return it->m_gridScalarResultIndex; + return it->gridScalarResultIndex(); } } @@ -301,7 +301,7 @@ size_t RigCaseCellResultsData::findOrCreateScalarResultIndex(RiaDefines::ResultC scalarResultIndex = this->resultCount(); m_cellScalarResults.push_back(std::vector >()); - RigEclipseResultInfo resInfo(type, needsToBeStored, false, resultName, scalarResultIndex); + RigEclipseResultInfo resInfo(type, resultName, needsToBeStored, false, scalarResultIndex); m_resultInfos.push_back(resInfo); // Create statistics calculator and add statistics cache object @@ -409,9 +409,9 @@ QStringList RigCaseCellResultsData::resultNames(RiaDefines::ResultCatType resTyp std::vector::const_iterator it; for (it = m_resultInfos.begin(); it != m_resultInfos.end(); ++it) { - if (it->m_resultType == resType ) + if (it->resultType() == resType ) { - varList.push_back(it->m_resultName); + varList.push_back(it->resultName()); } } return varList; @@ -475,8 +475,8 @@ std::vector RigCaseCellResultsData::allTimeStepDatesFromEclipseReader //-------------------------------------------------------------------------------------------------- QDateTime RigCaseCellResultsData::timeStepDate(size_t scalarResultIndex, size_t timeStepIndex) const { - if (scalarResultIndex < m_resultInfos.size() && m_resultInfos[scalarResultIndex].m_timeStepInfos.size() > timeStepIndex) - return m_resultInfos[scalarResultIndex].m_timeStepInfos[timeStepIndex].m_date; + if (scalarResultIndex < m_resultInfos.size() && m_resultInfos[scalarResultIndex].timeStepInfos().size() > timeStepIndex) + return m_resultInfos[scalarResultIndex].timeStepInfos()[timeStepIndex].m_date; else return QDateTime(); } @@ -536,8 +536,8 @@ std::vector RigCaseCellResultsData::daysSinceSimulationStart(size_t scal //-------------------------------------------------------------------------------------------------- int RigCaseCellResultsData::reportStepNumber(size_t scalarResultIndex, size_t timeStepIndex) const { - if (scalarResultIndex < m_resultInfos.size() && m_resultInfos[scalarResultIndex].m_timeStepInfos.size() > timeStepIndex) - return m_resultInfos[scalarResultIndex].m_timeStepInfos[timeStepIndex].m_reportNumber; + if (scalarResultIndex < m_resultInfos.size() && m_resultInfos[scalarResultIndex].timeStepInfos().size() > timeStepIndex) + return m_resultInfos[scalarResultIndex].timeStepInfos()[timeStepIndex].m_reportNumber; else return -1; } @@ -559,7 +559,7 @@ std::vector RigCaseCellResultsData::reportStepNumbers(size_t scalarResultIn std::vector RigCaseCellResultsData::timeStepInfos(size_t scalarResultIndex) const { if (scalarResultIndex < m_resultInfos.size()) - return m_resultInfos[scalarResultIndex].m_timeStepInfos; + return m_resultInfos[scalarResultIndex].timeStepInfos(); else return std::vector(); } @@ -571,7 +571,7 @@ void RigCaseCellResultsData::setTimeStepInfos(size_t scalarResultIndex, const st { CVF_ASSERT(scalarResultIndex < m_resultInfos.size() ); - m_resultInfos[scalarResultIndex].m_timeStepInfos = timeStepInfos; + m_resultInfos[scalarResultIndex].setTimeStepInfos(timeStepInfos); std::vector< std::vector >& dataValues = this->cellScalarResults(scalarResultIndex); dataValues.resize(timeStepInfos.size()); @@ -587,9 +587,9 @@ size_t RigCaseCellResultsData::maxTimeStepCount(size_t* scalarResultIndexWithMos for (size_t i = 0; i < m_resultInfos.size(); i++) { - if (m_resultInfos[i].m_timeStepInfos.size() > maxTsCount) + if (m_resultInfos[i].timeStepInfos().size() > maxTsCount) { - maxTsCount = m_resultInfos[i].m_timeStepInfos.size(); + maxTsCount = m_resultInfos[i].timeStepInfos().size(); scalarResultIndexWithMaxTsCount = i; } } @@ -632,10 +632,19 @@ void RigCaseCellResultsData::clearScalarResult(RiaDefines::ResultCatType type, c size_t scalarResultIndex = this->findScalarResultIndex(type, resultName); if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) return; - m_cellScalarResults[scalarResultIndex].clear(); + std::vector> empty; + m_cellScalarResults[scalarResultIndex].swap(empty); recalculateStatistics(scalarResultIndex); - //m_resultInfos[scalarResultIndex].m_resultType = RiaDefines::REMOVED; + //m_resultInfos[scalarResultIndex].type() = RiaDefines::REMOVED; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigCaseCellResultsData::clearScalarResult(const RigEclipseResultInfo& resultInfo) +{ + clearScalarResult(resultInfo.resultType(), resultInfo.resultName()); } //-------------------------------------------------------------------------------------------------- @@ -688,10 +697,10 @@ bool RigCaseCellResultsData::updateResultName(RiaDefines::ResultCatType resultTy for (auto& it : m_resultInfos) { - if (it.m_resultType == resultType && it.m_resultName == oldName) + if (it.resultType() == resultType && it.resultName() == oldName) { anyNameUpdated = true; - it.m_resultName = newName; + it.setResultName(newName); } } @@ -742,9 +751,9 @@ bool RigCaseCellResultsData::mustBeCalculated(size_t scalarResultIndex) const std::vector::const_iterator it; for (it = m_resultInfos.begin(); it != m_resultInfos.end(); ++it) { - if (it->m_gridScalarResultIndex == scalarResultIndex) + if (it->gridScalarResultIndex() == scalarResultIndex) { - return it->m_mustBeCalculated; + return it->mustBeCalculated(); } } @@ -759,9 +768,9 @@ void RigCaseCellResultsData::setMustBeCalculated(size_t scalarResultIndex) std::vector::iterator it; for (it = m_resultInfos.begin(); it != m_resultInfos.end(); ++it) { - if (it->m_gridScalarResultIndex == scalarResultIndex) + if (it->gridScalarResultIndex() == scalarResultIndex) { - it->m_mustBeCalculated = true; + it->setMustBeCalculated(true); } } } @@ -774,9 +783,9 @@ void RigCaseCellResultsData::eraseAllSourSimData() for (size_t i = 0; i < m_resultInfos.size(); i++) { RigEclipseResultInfo& ri = m_resultInfos[i]; - if (ri.m_resultType == RiaDefines::SOURSIMRL) + if (ri.resultType() == RiaDefines::SOURSIMRL) { - ri.m_resultType = RiaDefines::REMOVED; + ri.setResultType(RiaDefines::REMOVED); } } } @@ -1102,7 +1111,7 @@ size_t RigCaseCellResultsData::findOrLoadScalarResult(RiaDefines::ResultCatType if (m_readerInterface.notNull()) { // Add one more result to result container - size_t timeStepCount = this->infoForEachResultIndex()[scalarResultIndex].m_timeStepInfos.size(); + size_t timeStepCount = this->infoForEachResultIndex()[scalarResultIndex].timeStepInfos().size(); bool resultLoadingSucess = true; @@ -1145,7 +1154,7 @@ size_t RigCaseCellResultsData::findOrLoadScalarResult(RiaDefines::ResultCatType RifReaderEclipseOutput* eclReader = dynamic_cast(m_readerInterface.p()); if (eclReader) { - size_t timeStepCount = this->infoForEachResultIndex()[scalarResultIndex].m_timeStepInfos.size(); + size_t timeStepCount = this->infoForEachResultIndex()[scalarResultIndex].timeStepInfos().size(); this->cellScalarResults(scalarResultIndex).resize(timeStepCount); @@ -1202,7 +1211,7 @@ size_t RigCaseCellResultsData::findOrLoadScalarResultForTimeStep(RiaDefines::Res if (m_readerInterface.notNull()) { - size_t timeStepCount = this->infoForEachResultIndex()[scalarResultIndex].m_timeStepInfos.size(); + size_t timeStepCount = this->infoForEachResultIndex()[scalarResultIndex].timeStepInfos().size(); bool resultLoadingSucess = true; @@ -1244,7 +1253,7 @@ size_t RigCaseCellResultsData::findOrLoadScalarResultForTimeStep(RiaDefines::Res RifReaderEclipseOutput* eclReader = dynamic_cast(m_readerInterface.p()); if (eclReader) { - size_t timeStepCount = this->infoForEachResultIndex()[scalarResultIndex].m_timeStepInfos.size(); + size_t timeStepCount = this->infoForEachResultIndex()[scalarResultIndex].timeStepInfos().size(); this->cellScalarResults(scalarResultIndex).resize(timeStepCount); @@ -1289,7 +1298,7 @@ void RigCaseCellResultsData::computeSOILForTimeStep(size_t timeStepIndex) if (swatForTimeStep.size() > 0) { soilResultValueCount = swatForTimeStep.size(); - soilTimeStepCount = this->infoForEachResultIndex()[scalarIndexSWAT].m_timeStepInfos.size(); + soilTimeStepCount = this->infoForEachResultIndex()[scalarIndexSWAT].timeStepInfos().size(); } } @@ -1300,7 +1309,7 @@ void RigCaseCellResultsData::computeSOILForTimeStep(size_t timeStepIndex) { soilResultValueCount = qMax(soilResultValueCount, sgasForTimeStep.size()); - size_t sgasTimeStepCount = this->infoForEachResultIndex()[scalarIndexSGAS].m_timeStepInfos.size(); + size_t sgasTimeStepCount = this->infoForEachResultIndex()[scalarIndexSGAS].timeStepInfos().size(); soilTimeStepCount = qMax(soilTimeStepCount, sgasTimeStepCount); } } @@ -1409,7 +1418,7 @@ void RigCaseCellResultsData::testAndComputeSgasForTimeStep(size_t timeStepIndex) if (swatForTimeStep.size() > 0) { swatResultValueCount = swatForTimeStep.size(); - swatTimeStepCount = this->infoForEachResultIndex()[scalarIndexSWAT].m_timeStepInfos.size(); + swatTimeStepCount = this->infoForEachResultIndex()[scalarIndexSWAT].timeStepInfos().size(); } } diff --git a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.h b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.h index 5d0d420319..73ffb874fe 100644 --- a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.h +++ b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.h @@ -107,6 +107,7 @@ public: void computeDepthRelatedResults(); void clearScalarResult(RiaDefines::ResultCatType type, const QString & resultName); + void clearScalarResult(const RigEclipseResultInfo& resultInfo); void clearAllResults(); void freeAllocatedResultsData(); diff --git a/ApplicationCode/ReservoirDataModel/RigEclipseResultInfo.cpp b/ApplicationCode/ReservoirDataModel/RigEclipseResultInfo.cpp index 249ac41204..d7373b30c4 100644 --- a/ApplicationCode/ReservoirDataModel/RigEclipseResultInfo.cpp +++ b/ApplicationCode/ReservoirDataModel/RigEclipseResultInfo.cpp @@ -53,9 +53,8 @@ std::vector RigEclipseTimeStepInfo::createTimeStepInfos( //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -RigEclipseResultInfo::RigEclipseResultInfo(RiaDefines::ResultCatType resultType, bool needsToBeStored, bool mustBeCalculated, - QString resultName, size_t gridScalarResultIndex) - : m_resultType(resultType), +RigEclipseResultInfo::RigEclipseResultInfo(RiaDefines::ResultCatType resultType, + QString resultName, bool needsToBeStored, bool mustBeCalculated, size_t gridScalarResultIndex) : m_resultType(resultType), m_needsToBeStored(needsToBeStored), m_mustBeCalculated(mustBeCalculated), m_resultName(resultName), @@ -63,6 +62,104 @@ RigEclipseResultInfo::RigEclipseResultInfo(RiaDefines::ResultCatType resultType, { } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RiaDefines::ResultCatType RigEclipseResultInfo::resultType() const +{ + return m_resultType; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigEclipseResultInfo::setResultType(RiaDefines::ResultCatType newType) +{ + m_resultType = newType; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const QString& RigEclipseResultInfo::resultName() const +{ + return m_resultName; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigEclipseResultInfo::setResultName(const QString& name) +{ + m_resultName = name; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RigEclipseResultInfo::needsToBeStored() const +{ + return m_needsToBeStored; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigEclipseResultInfo::setNeedsToBeStored(bool store) +{ + m_needsToBeStored = store; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RigEclipseResultInfo::mustBeCalculated() const +{ + return m_mustBeCalculated; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigEclipseResultInfo::setMustBeCalculated(bool mustCalculate) +{ + m_mustBeCalculated = mustCalculate; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +size_t RigEclipseResultInfo::gridScalarResultIndex() const +{ + return m_gridScalarResultIndex; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigEclipseResultInfo::setGridScalarResultIndex(size_t index) +{ + m_gridScalarResultIndex = index; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const std::vector& RigEclipseResultInfo::timeStepInfos() const +{ + return m_timeStepInfos; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigEclipseResultInfo::setTimeStepInfos(const std::vector& timeSteps) +{ + m_timeStepInfos = timeSteps; +} + + + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -107,4 +204,3 @@ std::vector RigEclipseResultInfo::reportNumbers() const return values; } - diff --git a/ApplicationCode/ReservoirDataModel/RigEclipseResultInfo.h b/ApplicationCode/ReservoirDataModel/RigEclipseResultInfo.h index 009442e2eb..46d70bd197 100644 --- a/ApplicationCode/ReservoirDataModel/RigEclipseResultInfo.h +++ b/ApplicationCode/ReservoirDataModel/RigEclipseResultInfo.h @@ -49,14 +49,31 @@ public: class RigEclipseResultInfo { public: - RigEclipseResultInfo(RiaDefines::ResultCatType resultType, bool needsToBeStored, bool mustBeCalculated, - QString resultName, size_t gridScalarResultIndex); + RigEclipseResultInfo(RiaDefines::ResultCatType resultType, + QString resultName, + bool needsToBeStored = false, + bool mustBeCalculated = false, + size_t gridScalarResultIndex = 0u); - std::vector dates() const; - std::vector daysSinceSimulationStarts() const; - std::vector reportNumbers() const; + RiaDefines::ResultCatType resultType() const; + void setResultType(RiaDefines::ResultCatType newType); + const QString& resultName() const; + void setResultName(const QString& name); + bool needsToBeStored() const; + void setNeedsToBeStored(bool store); + bool mustBeCalculated() const; + void setMustBeCalculated(bool mustCalculate); + size_t gridScalarResultIndex() const; + void setGridScalarResultIndex(size_t index); + + const std::vector& timeStepInfos() const; + void setTimeStepInfos(const std::vector& timeSteps); -public: + std::vector dates() const; + std::vector daysSinceSimulationStarts() const; + std::vector reportNumbers() const; + +private: RiaDefines::ResultCatType m_resultType; bool m_needsToBeStored; bool m_mustBeCalculated;