From 7faf950dc7e655879ce954d365ea34945dc7ad23 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 11 Jun 2014 12:06:15 +0200 Subject: [PATCH] riGetActiveCellProperty: Fix for input properties Only read values for active cells if we have result values for all cells --- .../RifEclipseInputFileTools.cpp | 40 ++++++++++++++++++- .../RiaPropertyDataCommands.cpp | 36 +++++++++++------ 2 files changed, 63 insertions(+), 13 deletions(-) diff --git a/ApplicationCode/FileInterface/RifEclipseInputFileTools.cpp b/ApplicationCode/FileInterface/RifEclipseInputFileTools.cpp index 559b1d84bb..5feeb2908c 100644 --- a/ApplicationCode/FileInterface/RifEclipseInputFileTools.cpp +++ b/ApplicationCode/FileInterface/RifEclipseInputFileTools.cpp @@ -62,7 +62,8 @@ size_t findOrCreateResult(const QString& newResultName, RigCaseData* reservoir) //-------------------------------------------------------------------------------------------------- -/// +/// Read all double values from input file. To reduce memory footprint, the alternative method +/// readDoubleValuesForActiveCells() can be used, and will skip all cell values for inactive cells //-------------------------------------------------------------------------------------------------- bool readDoubleValues(RigCaseData* reservoir, size_t resultIndex, ecl_kw_type* eclKeyWordData) { @@ -74,6 +75,43 @@ bool readDoubleValues(RigCaseData* reservoir, size_t resultIndex, ecl_kw_type* e ecl_kw_get_data_as_double(eclKeyWordData, newPropertyData[0].data()); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool readDoubleValuesForActiveCells(RigCaseData* reservoir, size_t resultIndex, ecl_kw_type* eclKeyWordData) +{ + if (resultIndex == cvf::UNDEFINED_SIZE_T) return false; + + std::vector< std::vector >& newPropertyData = reservoir->results(RifReaderInterface::MATRIX_RESULTS)->cellScalarResults(resultIndex); + newPropertyData.push_back(std::vector()); + + RigActiveCellInfo* activeCellInfo = reservoir->activeCellInfo(RifReaderInterface::MATRIX_RESULTS); + if (activeCellInfo->globalCellCount() > 0 && activeCellInfo->globalCellCount() != activeCellInfo->globalActiveCellCount()) + { + std::vector valuesAllCells; + valuesAllCells.resize(ecl_kw_get_size(eclKeyWordData), HUGE_VAL); + ecl_kw_get_data_as_double(eclKeyWordData, valuesAllCells.data()); + + newPropertyData[0].resize(activeCellInfo->globalActiveCellCount(), HUGE_VAL); + std::vector& valuesActiveCells = newPropertyData[0]; + + size_t acIdx = 0; + for (size_t gcIdx = 0; gcIdx < activeCellInfo->globalCellCount(); gcIdx++) + { + size_t activeCellResultIndex = activeCellInfo->cellResultIndex(gcIdx); + if (activeCellResultIndex != cvf::UNDEFINED_SIZE_T) + { + valuesActiveCells[activeCellResultIndex] = valuesAllCells[gcIdx]; + } + } + } + else + { + newPropertyData[0].resize(ecl_kw_get_size(eclKeyWordData), HUGE_VAL); + ecl_kw_get_data_as_double(eclKeyWordData, newPropertyData[0].data()); + } +} + //-------------------------------------------------------------------------------------------------- /// Constructor diff --git a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp index 1d1b1b5420..fa5fc419fd 100644 --- a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp @@ -153,30 +153,42 @@ public: size_t globalCellCount = activeInfo->globalCellCount(); for (size_t tIdx = 0; tIdx < requestedTimesteps.size(); ++tIdx) { + std::vector& doubleValues = scalarResultFrames->at(requestedTimesteps[tIdx]); for (size_t gcIdx = 0; gcIdx < globalCellCount; ++gcIdx) { size_t resultIdx = activeInfo->cellResultIndex(gcIdx); - if (resultIdx != cvf::UNDEFINED_SIZE_T) + if (resultIdx == cvf::UNDEFINED_SIZE_T) continue; + + if (resultIdx < doubleValues.size()) { - if (resultIdx < scalarResultFrames->at(requestedTimesteps[tIdx]).size()) + if (doubleValues.size() == activeInfo->globalCellCount()) { - values[valueIndex] = scalarResultFrames->at(requestedTimesteps[tIdx])[resultIdx]; + // When reading data from input text files, result data is read for all grid cells + // Read out values from data vector using global cell index instead of active cell result index + // When data is written back to ResInsight using RiaSetActiveCellProperty, the resulting + // data vector will have activeCellCount data values, which is potentially smaller + // than total number of cells + values[valueIndex] = doubleValues[gcIdx]; } else { - values[valueIndex] = HUGE_VAL; + values[valueIndex] = doubleValues[resultIdx]; } + } + else + { + values[valueIndex] = HUGE_VAL; + } - valueIndex++; - if (valueIndex >= valueCount) + valueIndex++; + if (valueIndex >= valueCount) + { + if (!RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)values.data(), valueIndex * sizeof(double))) { - if (!RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)values.data(), valueIndex * sizeof(double))) - { - return false; - } - - valueIndex = 0; + return false; } + + valueIndex = 0; } } }