diff --git a/ApplicationCode/Application/RiaMemoryCleanup.cpp b/ApplicationCode/Application/RiaMemoryCleanup.cpp index 476828124c..8f8564af41 100644 --- a/ApplicationCode/Application/RiaMemoryCleanup.cpp +++ b/ApplicationCode/Application/RiaMemoryCleanup.cpp @@ -81,10 +81,10 @@ void RiaMemoryCleanup::clearSelectedResultsFromMemory() RigCaseCellResultsData* caseData = eclipseCase->results(RiaDefines::MATRIX_MODEL); if (caseData) { - std::vector resultsToDelete = selectedEclipseResults(); - for (const RigEclipseResultInfo& resultInfo : resultsToDelete) + std::vector resultsToDelete = selectedEclipseResults(); + for (const RigEclipseResultAddress& resultAddr : resultsToDelete) { - caseData->clearScalarResult(resultInfo); + caseData->clearScalarResult(resultAddr); } } } @@ -129,9 +129,9 @@ std::vector RiaMemoryCleanup::selectedGeoMechResults() cons //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RiaMemoryCleanup::selectedEclipseResults() const +std::vector RiaMemoryCleanup::selectedEclipseResults() const { - std::vector results; + std::vector results; if (dynamic_cast(m_case())) { for (size_t index : m_resultsToDelete()) @@ -170,20 +170,23 @@ std::set RiaMemoryCleanup::findGeoMechCaseResultsInUse() co //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::set RiaMemoryCleanup::findEclipseResultsInUse() const +std::set RiaMemoryCleanup::findEclipseResultsInUse() const { - std::set resultsInUse; + std::set resultsInUse; RimEclipseCase* eclipseCase = dynamic_cast(m_case()); if (eclipseCase) { + RigCaseCellResultsData* caseData = eclipseCase->results(RiaDefines::MATRIX_MODEL); + std::vector eclipseResultDefs; eclipseCase->descendantsIncludingThisOfType(eclipseResultDefs); for (RimEclipseResultDefinition* resultDef : eclipseResultDefs) { - RigEclipseResultInfo resultInfo(resultDef->resultType(), resultDef->resultVariable()); - resultsInUse.insert(resultInfo); + RigEclipseResultAddress resultAddr(caseData->findScalarResultIndex(resultDef->resultType(), resultDef->resultVariable())); + resultsInUse.insert(resultAddr); } } + return resultsInUse; } @@ -237,20 +240,23 @@ QList RiaMemoryCleanup::calculateValueOptions(const caf: RimGeoMechCase* geoMechCase = dynamic_cast(m_case()); if (eclipseCase) { - std::set resultsInUse = findEclipseResultsInUse(); + std::set resultsInUse = findEclipseResultsInUse(); RigCaseCellResultsData* caseData = eclipseCase->results(RiaDefines::MATRIX_MODEL); if (caseData) { - m_eclipseResultAddresses = caseData->infoForEachResultIndex(); + m_eclipseResultAddresses = caseData->existingResults(); for (size_t i = 0; i < m_eclipseResultAddresses.size(); ++i) { - const RigEclipseResultInfo& result = m_eclipseResultAddresses[i]; - if (caseData->isResultLoaded(result)) + const RigEclipseResultAddress& resultAddr = m_eclipseResultAddresses[i]; + if (caseData->isResultLoaded(resultAddr)) { - bool inUse = resultsInUse.count(result); - QString posText = caf::AppEnum::uiTextFromIndex(result.resultType()); - QString resultsText = QString("%1, %2").arg(posText).arg(result.resultName()); + bool inUse = resultsInUse.count(resultAddr); + + const RigEclipseResultInfo* resInfo = caseData->resultInfo(resultAddr); + + QString posText = caf::AppEnum::uiTextFromIndex(resInfo->resultType()); + QString resultsText = QString("%1, %2").arg(posText).arg(resInfo->resultName()); if (inUse) { resultsText += QString(" [used in view]"); diff --git a/ApplicationCode/Application/RiaMemoryCleanup.h b/ApplicationCode/Application/RiaMemoryCleanup.h index a2c97641e8..81ae0b5b29 100644 --- a/ApplicationCode/Application/RiaMemoryCleanup.h +++ b/ApplicationCode/Application/RiaMemoryCleanup.h @@ -20,6 +20,7 @@ #include "RigFemResultAddress.h" #include "RigEclipseResultInfo.h" +#include "RigEclipseResultAddress.h" #include "cafPdmField.h" #include "cafPdmChildArrayField.h" @@ -42,9 +43,9 @@ protected: void fieldChangedByUi(const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue) override; private: std::vector selectedGeoMechResults() const; - std::vector selectedEclipseResults() const; + std::vector selectedEclipseResults() const; std::set findGeoMechCaseResultsInUse() const; - std::set findEclipseResultsInUse() const; + std::set findEclipseResultsInUse() const; QList calculateValueOptions(const caf::PdmFieldHandle* fieldNeedingOptions, bool* useOptionsOnly) override; @@ -54,6 +55,6 @@ private: caf::PdmPtrField m_case; caf::PdmField> m_resultsToDelete; std::vector m_geomResultAddresses; - std::vector m_eclipseResultAddresses; + std::vector m_eclipseResultAddresses; caf::PdmField m_performDelete; }; \ No newline at end of file diff --git a/ApplicationCode/ProjectDataModel/RimEclipseStatisticsCase.cpp b/ApplicationCode/ProjectDataModel/RimEclipseStatisticsCase.cpp index 619c2cde4f..26d320dd5e 100644 --- a/ApplicationCode/ProjectDataModel/RimEclipseStatisticsCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimEclipseStatisticsCase.cpp @@ -665,8 +665,8 @@ void RimEclipseStatisticsCase::updatePercentileUiVisibility() bool RimEclipseStatisticsCase::hasComputedStatistics() const { if ( eclipseCaseData() - && ( eclipseCaseData()->results(RiaDefines::MATRIX_MODEL)->resultCount() - || eclipseCaseData()->results(RiaDefines::FRACTURE_MODEL)->resultCount())) + && ( eclipseCaseData()->results(RiaDefines::MATRIX_MODEL)->existingResults().size() + || eclipseCaseData()->results(RiaDefines::FRACTURE_MODEL)->existingResults().size())) { return true; } diff --git a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp index dad45cfc5b..62cf73f9a4 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp +++ b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp @@ -91,19 +91,19 @@ void RimReservoirCellResultsStorage::setupBeforeSave() if (!m_cellResults) return; - const std::vector& resInfo = m_cellResults->infoForEachResultIndex(); + const std::vector& resAddrs = m_cellResults->existingResults(); bool hasResultsToStore = false; - for (size_t rIdx = 0; rIdx < resInfo.size(); ++rIdx) + for (size_t rIdx = 0; rIdx < resAddrs.size(); ++rIdx) { - if (resInfo[rIdx].needsToBeStored()) + if ( m_cellResults->resultInfo(resAddrs[rIdx])->needsToBeStored() ) { hasResultsToStore = true; break; } } - if(resInfo.size() && hasResultsToStore) + if(resAddrs.size() && hasResultsToStore) { QDir::root().mkpath(getCacheDirectoryPath()); @@ -122,38 +122,39 @@ void RimReservoirCellResultsStorage::setupBeforeSave() stream << (quint32)0xCEECAC4E; // magic number stream << (quint32)1; // Version number. Increment if needing to extend the format in ways that can not be handled generically by the reader - caf::ProgressInfo progInfo(resInfo.size(), "Saving generated and imported properties"); + caf::ProgressInfo progInfo(resAddrs.size(), "Saving generated and imported properties"); - for (size_t rIdx = 0; rIdx < resInfo.size(); ++rIdx) + for (size_t rIdx = 0; rIdx < resAddrs.size(); ++rIdx) { // 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(RigEclipseResultAddress(resInfo[rIdx].gridScalarResultIndex())).size(); + size_t timestepCount = m_cellResults->cellScalarResults(resAddrs[rIdx]).size(); + const RigEclipseResultInfo* resInfo = m_cellResults->resultInfo(resAddrs[rIdx]); - if (timestepCount && resInfo[rIdx].needsToBeStored()) + if (timestepCount && resInfo->needsToBeStored()) { - progInfo.setProgressDescription(resInfo[rIdx].resultName()); + progInfo.setProgressDescription(resInfo->resultName()); // Create and setup the cache information for this result RimReservoirCellResultsStorageEntryInfo* cacheEntry = new RimReservoirCellResultsStorageEntryInfo; m_resultCacheMetaData.push_back(cacheEntry); - cacheEntry->m_resultType = resInfo[rIdx].resultType(); - cacheEntry->m_resultName = resInfo[rIdx].resultName(); - cacheEntry->m_timeStepDates = resInfo[rIdx].dates(); - cacheEntry->m_daysSinceSimulationStart = resInfo[rIdx].daysSinceSimulationStarts(); + cacheEntry->m_resultType = resInfo->resultType(); + cacheEntry->m_resultName = resInfo->resultName(); + cacheEntry->m_timeStepDates = resInfo->dates(); + cacheEntry->m_daysSinceSimulationStart = resInfo->daysSinceSimulationStarts(); // Take note of the file position for fast lookup later cacheEntry->m_filePosition = cacheFile.pos(); // Write all the scalar values for each time step to the stream, // starting with the number of values - for (size_t tsIdx = 0; tsIdx < resInfo[rIdx].dates().size() ; ++tsIdx) + for (size_t tsIdx = 0; tsIdx < resInfo->dates().size() ; ++tsIdx) { const std::vector* data = nullptr; if (tsIdx < timestepCount) { - data = &(m_cellResults->cellScalarResults(RigEclipseResultAddress(resInfo[rIdx].gridScalarResultIndex()), tsIdx)); + data = &(m_cellResults->cellScalarResults(resAddrs[rIdx], tsIdx)); } if (data && data->size()) diff --git a/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake b/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake index 02bd7dcb45..1091bb68f8 100644 --- a/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake +++ b/ApplicationCode/ReservoirDataModel/CMakeLists_files.cmake @@ -53,6 +53,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RigTesselatorTools.h ${CMAKE_CURRENT_LIST_DIR}/RigCellGeometryTools.h ${CMAKE_CURRENT_LIST_DIR}/RigWellPathIntersectionTools.h ${CMAKE_CURRENT_LIST_DIR}/RigEclipseResultInfo.h +${CMAKE_CURRENT_LIST_DIR}/RigEclipseResultAddress.h ${CMAKE_CURRENT_LIST_DIR}/RigTofAccumulatedPhaseFractionsCalculator.h ${CMAKE_CURRENT_LIST_DIR}/RigTransmissibilityEquations.h ${CMAKE_CURRENT_LIST_DIR}/RigNumberOfFloodedPoreVolumesCalculator.h diff --git a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp index f7cdb06c74..626b3f10cd 100644 --- a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp +++ b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp @@ -659,7 +659,18 @@ QString RigCaseCellResultsData::makeResultNameUnique(const QString& resultNamePr void RigCaseCellResultsData::clearScalarResult(RiaDefines::ResultCatType type, const QString& resultName) { size_t scalarResultIndex = this->findScalarResultIndex(type, resultName); - if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) return; + + clearScalarResult(RigEclipseResultAddress(scalarResultIndex)); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RigCaseCellResultsData::clearScalarResult(const RigEclipseResultAddress& resultAddress) +{ + if (!resultAddress.isValid()) return; + + size_t scalarResultIndex = resultAddress.scalarResultIndex; for (size_t tsIdx = 0; tsIdx < m_cellScalarResults[scalarResultIndex].size(); ++tsIdx) { @@ -670,14 +681,6 @@ void RigCaseCellResultsData::clearScalarResult(RiaDefines::ResultCatType type, c recalculateStatistics(RigEclipseResultAddress(scalarResultIndex)); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RigCaseCellResultsData::clearScalarResult(const RigEclipseResultInfo& resultInfo) -{ - clearScalarResult(resultInfo.resultType(), resultInfo.resultName()); -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -708,9 +711,10 @@ void RigCaseCellResultsData::freeAllocatedResultsData() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -bool RigCaseCellResultsData::isResultLoaded(const RigEclipseResultInfo& resultInfo) const +bool RigCaseCellResultsData::isResultLoaded(const RigEclipseResultAddress& resultAddr) const { - size_t scalarResultIndex = this->findScalarResultIndex(resultInfo.resultType(), resultInfo.resultName()); + size_t scalarResultIndex = resultAddr.scalarResultIndex;//this->findScalarResultIndex(resultAddr.resultType(), resultAddr.resultName()); + CVF_TIGHT_ASSERT(scalarResultIndex != cvf::UNDEFINED_SIZE_T); if (scalarResultIndex != cvf::UNDEFINED_SIZE_T) { @@ -1014,6 +1018,28 @@ bool RigCaseCellResultsData::findTransmissibilityResults(size_t& tranX, size_t& return true; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RigCaseCellResultsData::existingResults() const +{ + std::vector addresses; + for (const auto & ri: m_resultInfos) + { + addresses.emplace_back(RigEclipseResultAddress(ri.gridScalarResultIndex())); + } + + return addresses; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const RigEclipseResultInfo* RigCaseCellResultsData::resultInfo(const RigEclipseResultAddress& resVarAddr) const +{ + return &(m_resultInfos[resVarAddr.scalarResultIndex]); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.h b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.h index 1c35a67085..7dad641bdd 100644 --- a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.h +++ b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.h @@ -29,6 +29,7 @@ #include #include +#include "RigEclipseResultAddress.h" class RifReaderInterface; @@ -41,36 +42,6 @@ class RigEclipseCaseData; class RimEclipseCase; -class RigEclipseResultAddress -{ -public: - RigEclipseResultAddress() - : scalarResultIndex(-1) - , m_resultCatType(RiaDefines::UNDEFINED) - {} - - explicit RigEclipseResultAddress(size_t ascalarResultIndex) - : scalarResultIndex(ascalarResultIndex) - , m_resultCatType(RiaDefines::UNDEFINED) - {} - - explicit RigEclipseResultAddress(RiaDefines::ResultCatType type, const QString& resultName) - : scalarResultIndex(-1) - , m_resultCatType(type) - , m_resultName(resultName) - {} - - bool isValid() const - { - return (scalarResultIndex != -1); - // Todo - } - - size_t scalarResultIndex; - - RiaDefines::ResultCatType m_resultCatType; - QString m_resultName; -}; //================================================================================================== @@ -133,16 +104,15 @@ public: void computeCellVolumes(); void clearScalarResult(RiaDefines::ResultCatType type, const QString & resultName); - void clearScalarResult(const RigEclipseResultInfo& resultInfo); + void clearScalarResult(const RigEclipseResultAddress& resultAddress); void clearAllResults(); void freeAllocatedResultsData(); - bool isResultLoaded(const RigEclipseResultInfo& resultInfo) const; + bool isResultLoaded(const RigEclipseResultAddress& resultAddress) const; void eraseAllSourSimData(); bool updateResultName(RiaDefines::ResultCatType resultType, QString& oldName, const QString& newName); // Index based stuff to rewrite/hide --> - size_t resultCount() const; size_t findOrLoadScalarResultForTimeStep(RiaDefines::ResultCatType type, const QString& resultName, size_t timeStepIndex); size_t findOrLoadScalarResult(RiaDefines::ResultCatType type, const QString& resultName); @@ -169,7 +139,6 @@ public: RiaDefines::PorosityModelType poroModel, std::vector destinationCases); - const std::vector& infoForEachResultIndex(); size_t addStaticScalarResult(RiaDefines::ResultCatType type, const QString& resultName, @@ -180,7 +149,14 @@ public: // <--- + std::vector existingResults() const; + const RigEclipseResultInfo* resultInfo(const RigEclipseResultAddress& resVarAddr) const; + private: + + const std::vector& infoForEachResultIndex(); + size_t resultCount() const; + bool mustBeCalculated(size_t scalarResultIndex) const; void setMustBeCalculated(size_t scalarResultIndex); diff --git a/ApplicationCode/ReservoirDataModel/RigEclipseResultAddress.h b/ApplicationCode/ReservoirDataModel/RigEclipseResultAddress.h new file mode 100644 index 0000000000..f0c2136c6d --- /dev/null +++ b/ApplicationCode/ReservoirDataModel/RigEclipseResultAddress.h @@ -0,0 +1,70 @@ +///////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) 2019- Equinor ASA +// +// ResInsight is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. +// +// See the GNU General Public License at +// for more details. +// +///////////////////////////////////////////////////////////////////////////////// +#pragma once + +#include "RiaDefines.h" +#include + +class RigEclipseResultAddress +{ +public: + RigEclipseResultAddress() + : scalarResultIndex(-1) + , m_resultCatType(RiaDefines::UNDEFINED) + {} + + explicit RigEclipseResultAddress(size_t ascalarResultIndex) + : scalarResultIndex(ascalarResultIndex) + , m_resultCatType(RiaDefines::UNDEFINED) + {} + + explicit RigEclipseResultAddress(RiaDefines::ResultCatType type, const QString& resultName) + : scalarResultIndex(-1) + , m_resultCatType(type) + , m_resultName(resultName) + {} + + bool isValid() const + { + return (scalarResultIndex != -1); + // Todo + } + + bool operator< (const RigEclipseResultAddress& other ) const + { + // Todo + if (scalarResultIndex != other.scalarResultIndex) + { + return (scalarResultIndex < other.scalarResultIndex); + } + + if (m_resultCatType != other.m_resultCatType) + { + return (m_resultCatType < other.m_resultCatType); + } + + return (m_resultName < other.m_resultName); + } + + size_t scalarResultIndex; + + RiaDefines::ResultCatType m_resultCatType; + QString m_resultName; +}; + + diff --git a/ApplicationCode/ReservoirDataModel/RigEclipseResultInfo.h b/ApplicationCode/ReservoirDataModel/RigEclipseResultInfo.h index 62c920712a..a181f4c281 100644 --- a/ApplicationCode/ReservoirDataModel/RigEclipseResultInfo.h +++ b/ApplicationCode/ReservoirDataModel/RigEclipseResultInfo.h @@ -56,23 +56,26 @@ public: size_t gridScalarResultIndex = 0u); RiaDefines::ResultCatType resultType() const; - void setResultType(RiaDefines::ResultCatType newType); const QString& resultName() const; - void setResultName(const QString& name); bool needsToBeStored() const; - bool mustBeCalculated() const; - void setMustBeCalculated(bool mustCalculate); - size_t gridScalarResultIndex() const; - - const std::vector& timeStepInfos() const; - void setTimeStepInfos(const std::vector& timeSteps); std::vector dates() const; std::vector daysSinceSimulationStarts() const; std::vector reportNumbers() const; bool operator<(const RigEclipseResultInfo& rhs) const; + private: + friend class RigCaseCellResultsData; + void setResultType(RiaDefines::ResultCatType newType); + void setResultName(const QString& name); + bool mustBeCalculated() const; + void setMustBeCalculated(bool mustCalculate); + size_t gridScalarResultIndex() const; + + const std::vector& timeStepInfos() const; + void setTimeStepInfos(const std::vector& timeSteps); + RiaDefines::ResultCatType m_resultType; bool m_needsToBeStored; bool m_mustBeCalculated;