diff --git a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp index d71ba04e49..ae96319e30 100644 --- a/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp +++ b/ApplicationCode/ProjectDataModel/RimReservoirCellResultsStorage.cpp @@ -332,20 +332,26 @@ size_t RimReservoirCellResultsStorage::findOrLoadScalarResult(RimDefines::Result 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++) + if (m_cellResults->mustBeCalculated(scalarResultIndex)) { - computeSOILForTimeStep(timeStepIdx); + // 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"); + + m_cellResults->cellScalarResults(scalarResultIndex).resize(m_cellResults->maxTimeStepCount()); + for (size_t timeStepIdx = 0; timeStepIdx < m_cellResults->maxTimeStepCount(); timeStepIdx++) + { + std::vector& values = m_cellResults->cellScalarResults(scalarResultIndex)[timeStepIdx]; + if (values.size() == 0) + { + computeSOILForTimeStep(timeStepIdx); + } + } + + return scalarResultIndex; } - - return scalarResultIndex; } - - if (type == RimDefines::GENERATED) { return cvf::UNDEFINED_SIZE_T; @@ -405,11 +411,17 @@ size_t RimReservoirCellResultsStorage::findOrLoadScalarResultForTimeStep(RimDefi if (type == RimDefines::DYNAMIC_NATIVE && resultName.toUpper() == "SOIL") { size_t soilScalarResultIndex = m_cellResults->findScalarResultIndex(type, resultName); - { - computeSOILForTimeStep(timeStepIndex); - } - return soilScalarResultIndex; + if (m_cellResults->mustBeCalculated(soilScalarResultIndex)) + { + std::vector& values = m_cellResults->cellScalarResults(soilScalarResultIndex)[timeStepIndex]; + if (values.size() == 0) + { + computeSOILForTimeStep(timeStepIndex); + } + + return soilScalarResultIndex; + } } size_t scalarResultIndex = m_cellResults->findScalarResultIndex(type, resultName); @@ -552,7 +564,7 @@ void RimReservoirCellResultsStorage::computeSOILForTimeStep(size_t timeStepIndex soilValue -= swatForTimeStep->at(idx); } - soilForTimeStep[idx] = soilValue; + soilForTimeStep[idx] = cvf::Math::clamp(soilValue, 0.0, 1.0); } } diff --git a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp index da2a395c32..32defa4943 100644 --- a/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp +++ b/ApplicationCode/ReservoirDataModel/RigCaseCellResultsData.cpp @@ -522,12 +522,17 @@ void RigCaseCellResultsData::createPlaceholderResultEntries() { // SOIL { - 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) + size_t soilIndex = findScalarResultIndex(RimDefines::DYNAMIC_NATIVE, "SOIL"); + if (soilIndex == cvf::UNDEFINED_SIZE_T) { - addEmptyScalarResult(RimDefines::DYNAMIC_NATIVE, "SOIL", false); + 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) + { + soilIndex = addEmptyScalarResult(RimDefines::DYNAMIC_NATIVE, "SOIL", false); + this->setMustBeCalculated(soilIndex); + } } }