diff --git a/ApplicationCode/ProjectDataModel/RimCase.cpp b/ApplicationCode/ProjectDataModel/RimCase.cpp index f7561fb37d..aa0aeec7b8 100644 --- a/ApplicationCode/ProjectDataModel/RimCase.cpp +++ b/ApplicationCode/ProjectDataModel/RimCase.cpp @@ -539,3 +539,26 @@ QString RimCase::relocateFile(const QString& orgFileName, const QString& orgNew return fileName; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimCase::openReserviorCase() +{ + if (!openEclipseGridFile()) + { + return false; + } + + { + RimReservoirCellResultsStorage* results = this->results(RifReaderInterface::MATRIX_RESULTS); + if (results->cellResults()) results->cellResults()->createPlaceholderResultEntries(); + + } + { + RimReservoirCellResultsStorage* results = this->results(RifReaderInterface::FRACTURE_RESULTS); + if (results->cellResults()) results->cellResults()->createPlaceholderResultEntries(); + } + + return true; +} diff --git a/ApplicationCode/ProjectDataModel/RimCase.h b/ApplicationCode/ProjectDataModel/RimCase.h index efb5801ba5..3de3d04c49 100644 --- a/ApplicationCode/ProjectDataModel/RimCase.h +++ b/ApplicationCode/ProjectDataModel/RimCase.h @@ -57,7 +57,8 @@ public: caf::PdmField > filesContainingFaults; - virtual bool openEclipseGridFile() { return false;}; // Should be pure virtual but PDM does not allow that. + bool openReserviorCase(); + virtual bool openEclipseGridFile() { return false; }; // Should be pure virtual but PDM does not allow that. RigCaseData* reservoirData(); const RigCaseData* reservoirData() const; diff --git a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp index 42be9598c7..c4f2e8a7a5 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp +++ b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp @@ -226,24 +226,12 @@ size_t RimReservoirCellResultsStorage::findOrLoadScalarResultForTimeStep(RimDefi if (type == RimDefines::DYNAMIC_NATIVE && resultName.toUpper() == "SOIL") { size_t soilScalarResultIndex = m_cellResults->findScalarResultIndex(type, resultName); - - // If SOIL is not found, try to compute and return computed scalar index - // Will return cvf::UNDEFINED_SIZE_T if no SGAS/SWAT is found - if (soilScalarResultIndex == cvf::UNDEFINED_SIZE_T) + if (!isDataPresent(soilScalarResultIndex)) { computeSOILForTimeStep(timeStepIndex); - - soilScalarResultIndex = m_cellResults->findScalarResultIndex(type, resultName); - return soilScalarResultIndex; } - // If we have found SOIL and SOIL must be calculated, calculate and return - if (soilScalarResultIndex != cvf::UNDEFINED_SIZE_T && m_cellResults->mustBeCalculated(soilScalarResultIndex)) - { - computeSOILForTimeStep(timeStepIndex); - - return soilScalarResultIndex; - } + return soilScalarResultIndex; } size_t scalarResultIndex = m_cellResults->findScalarResultIndex(type, resultName); @@ -305,14 +293,24 @@ size_t RimReservoirCellResultsStorage::findOrLoadScalarResult(RimDefines::Result size_t scalarResultIndex = m_cellResults->findScalarResultIndex(type, resultName); if (scalarResultIndex == cvf::UNDEFINED_SIZE_T) return cvf::UNDEFINED_SIZE_T; - // If we have any results on any timestep, assume we have loaded results already - - for (size_t tsIdx = 0; tsIdx < m_cellResults->timeStepCount(scalarResultIndex); ++tsIdx) + // If we have any results on any time step, assume we have loaded results already + if (isDataPresent(scalarResultIndex)) { - if (m_cellResults->cellScalarResults(scalarResultIndex, tsIdx).size()) + return scalarResultIndex; + } + + if (resultName == "SOIL") + { + // Trigger loading of SWAT, SGAS to establish time step count if no data has been loaded from file at this point + findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, "SWAT"); + findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, "SGAS"); + + for (size_t timeStepIdx = 0; timeStepIdx < m_cellResults->maxTimeStepCount(); timeStepIdx++) { - return scalarResultIndex; + computeSOILForTimeStep(timeStepIdx); } + + return scalarResultIndex; } if (type == RimDefines::GENERATED) @@ -362,25 +360,6 @@ size_t RimReservoirCellResultsStorage::findOrLoadScalarResult(RimDefines::Result return scalarResultIndex; } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimReservoirCellResultsStorage::loadOrComputeSOIL() -{ - size_t scalarIndexSOIL = findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, "SOIL"); - if (scalarIndexSOIL != cvf::UNDEFINED_SIZE_T) - { - return; - } - - for (size_t timeStepIdx = 0; timeStepIdx < m_cellResults->maxTimeStepCount(); timeStepIdx++) - { - computeSOILForTimeStep(timeStepIdx); - } -} - - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -422,21 +401,18 @@ void RimReservoirCellResultsStorage::computeSOILForTimeStep(size_t timeStepIndex } } - size_t soilResultScalarIndex = findOrLoadScalarResult(RimDefines::DYNAMIC_NATIVE, "SOIL"); - if (soilResultScalarIndex == cvf::UNDEFINED_SIZE_T) + size_t soilResultScalarIndex = m_cellResults->findScalarResultIndex(RimDefines::DYNAMIC_NATIVE, "SOIL"); + if (m_cellResults->cellScalarResults(soilResultScalarIndex, timeStepIndex).size() == 0) { - soilResultScalarIndex = m_cellResults->addEmptyScalarResult(RimDefines::DYNAMIC_NATIVE, "SOIL", false); - CVF_ASSERT(soilResultScalarIndex != cvf::UNDEFINED_SIZE_T); +// // Set this result to be calculated +// m_cellResults->setMustBeCalculated(soilResultScalarIndex); +// +// m_cellResults->cellScalarResults(soilResultScalarIndex).resize(soilTimeStepCount); - // Set this result to be calculated - m_cellResults->setMustBeCalculated(soilResultScalarIndex); - - m_cellResults->cellScalarResults(soilResultScalarIndex).resize(soilTimeStepCount); - - for (size_t timeStepIdx = 0; timeStepIdx < soilTimeStepCount; timeStepIdx++) - { - m_cellResults->cellScalarResults(soilResultScalarIndex, timeStepIdx).resize(soilResultValueCount); - } +// for (size_t timeStepIdx = 0; timeStepIdx < soilTimeStepCount; timeStepIdx++) +// { + m_cellResults->cellScalarResults(soilResultScalarIndex, timeStepIndex).resize(soilResultValueCount); +// } } @@ -720,6 +696,29 @@ size_t RimReservoirCellResultsStorage::storedResultsCount() return m_resultCacheMetaData.size(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RimReservoirCellResultsStorage::isDataPresent(size_t scalarResultIndex) const +{ + if (scalarResultIndex >= m_cellResults->resultCount()) + { + return false; + } + + const std::vector< std::vector > data = m_cellResults->cellScalarResults(scalarResultIndex); + + for (size_t tsIdx = 0; tsIdx < data.size(); ++tsIdx) + { + if (data[tsIdx].size()) + { + return true; + } + } + + return false; +} + CAF_PDM_SOURCE_INIT(RimReservoirCellResultsStorageEntryInfo, "ResultStorageEntryInfo"); diff --git a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.h b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.h index aa90e062e8..55713ce290 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.h +++ b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.h @@ -52,8 +52,8 @@ public: void setReaderInterface(RifReaderInterface* readerInterface); RifReaderInterface* readerInterface(); - void loadOrComputeSOIL(); void computeDepthRelatedResults(); + bool isDataPresent(size_t scalarResultIndex) const; size_t findOrLoadScalarResultForTimeStep(RimDefines::ResultCatType type, const QString& resultName, size_t timeStepIndex); size_t findOrLoadScalarResult(RimDefines::ResultCatType type, const QString& resultName); @@ -65,6 +65,7 @@ protected: private: void computeSOILForTimeStep(size_t timeStepIndex); + void computeSOILForAllTimeStep(); QString getValidCacheFileName(); QString getCacheDirectoryPath(); diff --git a/ApplicationCode/ProjectDataModel/RimReservoirView.cpp b/ApplicationCode/ProjectDataModel/RimReservoirView.cpp index 9edd98f1a7..6f6b6bd678 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirView.cpp +++ b/ApplicationCode/ProjectDataModel/RimReservoirView.cpp @@ -905,7 +905,7 @@ void RimReservoirView::loadDataAndUpdate() if (m_reservoir) { - if (!m_reservoir->openEclipseGridFile()) + if (!m_reservoir->openReserviorCase()) { QMessageBox::warning(RiuMainWindow::instance(), "Error when opening project file", @@ -913,30 +913,6 @@ void RimReservoirView::loadDataAndUpdate() m_reservoir = NULL; return; } - else - { - RiaApplication* app = RiaApplication::instance(); - - { - RimReservoirCellResultsStorage* results = m_reservoir->results(RifReaderInterface::MATRIX_RESULTS); - if (results->cellResults()) results->cellResults()->createPlaceholderResultEntries(); - - if (app->preferences()->autocomputeSOIL) - { - results->loadOrComputeSOIL(); - } - } - { - RimReservoirCellResultsStorage* results = m_reservoir->results(RifReaderInterface::FRACTURE_RESULTS); - if (results->cellResults()) results->cellResults()->createPlaceholderResultEntries(); - - if (app->preferences()->autocomputeSOIL) - { - results->loadOrComputeSOIL(); - } - } - - } } CVF_ASSERT(this->cellResult() != NULL); diff --git a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp index 331aa53c55..97f80208d9 100644 --- a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp +++ b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp @@ -512,6 +512,20 @@ void RigCaseCellResultsData::setMustBeCalculated(size_t scalarResultIndex) //-------------------------------------------------------------------------------------------------- void RigCaseCellResultsData::createPlaceholderResultEntries() { + { + size_t soilIndex = findScalarResultIndex(RimDefines::DYNAMIC_NATIVE, "SOIL"); + if (soilIndex == cvf::UNDEFINED_SIZE_T) + { + size_t swatIndex = findScalarResultIndex(RimDefines::DYNAMIC_NATIVE, "SWAT"); + size_t sgasIndex = findScalarResultIndex(RimDefines::DYNAMIC_NATIVE, "SGAS"); + + if (swatIndex != cvf::UNDEFINED_SIZE_T || sgasIndex != cvf::UNDEFINED_SIZE_T) + { + addEmptyScalarResult(RimDefines::DYNAMIC_NATIVE, "SOIL", false); + } + } + } + { size_t combinedTransmissibilityIndex = findScalarResultIndex(RimDefines::STATIC_NATIVE, RimDefines::combinedTransmissibilityResultName()); if (combinedTransmissibilityIndex == cvf::UNDEFINED_SIZE_T)