From 770f70680345d00c4b6c828e1e36f3f12000a390 Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 3 Apr 2014 11:56:01 +0200 Subject: [PATCH] Updated riGetGridProperty --- .../RiaPropertyDataCommands.cpp | 57 +++--------- OctavePlugin/riGetGridProperty.cpp | 92 ++----------------- 2 files changed, 22 insertions(+), 127 deletions(-) diff --git a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp index 00210e4e21..87cf148f7c 100644 --- a/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaPropertyDataCommands.cpp @@ -306,61 +306,28 @@ public: quint64 timestepCount = (quint64)requestedTimesteps.size(); socketStream << timestepCount; - size_t valueIdx = 0; - cvf::Timer timer; - - if (RiaApplication::instance()->preferences()->useStreamTransfer()) + for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) { - for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) + cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); + if (cellCenterDataAccessObject.isNull()) { - cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); - if (cellCenterDataAccessObject.isNull()) - { - continue; - } - - for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) - { - double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); - if (cellValue == HUGE_VAL) - { - cellValue = 0.0; - } - - socketStream << cellValue; - } + continue; } - } - else - { - for (size_t tsIdx = 0; tsIdx < timestepCount; tsIdx++) + std::vector values(rigGrid->cellCount()); + for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) { - cvf::ref cellCenterDataAccessObject = rimCase->reservoirData()->dataAccessObject(rigGrid, porosityModelEnum, requestedTimesteps[tsIdx], scalarResultIndex); - if (cellCenterDataAccessObject.isNull()) + double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); + if (cellValue == HUGE_VAL) { - continue; + cellValue = 0.0; } - - std::vector values(rigGrid->cellCount()); - for (size_t cellIdx = 0; cellIdx < rigGrid->cellCount(); cellIdx++) - { - double cellValue = cellCenterDataAccessObject->cellScalar(cellIdx); - if (cellValue == HUGE_VAL) - { - cellValue = 0.0; - } - values[valueIdx++] = cellValue; - } - RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)values.data(), values.size() * sizeof(double)); + values[cellIdx] = cellValue; } + + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)values.data(), values.size() * sizeof(double)); } - double totalTimeMS = timer.time() * 1000.0; - QString resultInfo = QString("Total time '%1 ms'").arg(totalTimeMS); - - server->errorMessageDialog()->showMessage(resultInfo); - return true; } }; diff --git a/OctavePlugin/riGetGridProperty.cpp b/OctavePlugin/riGetGridProperty.cpp index 3b1fbc589f..e477cd767a 100644 --- a/OctavePlugin/riGetGridProperty.cpp +++ b/OctavePlugin/riGetGridProperty.cpp @@ -1,6 +1,11 @@ #include +#include + #include + #include "riSettings.h" +#include "riSocketTools.h" + void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 serverPort, const int& caseId, int gridIdx, QString propertyName, const int32NDArray& requestedTimeSteps, QString porosityModel) @@ -61,8 +66,6 @@ void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 totalByteCount = cellCountI*cellCountJ*cellCountK*timestepCount*sizeof(double); - qint64 timestepByteCount = cellCountI*cellCountJ*cellCountK*sizeof(double); - if (!(totalByteCount)) { error ("Could not find the requested data in ResInsight"); @@ -78,93 +81,18 @@ void getGridProperty(NDArray& propertyFrames, const QString &serverName, quint16 propertyFrames.resize(dv); - -#if 1 - // Wait for available data for each timestep, then read data for each timestep - - qint64 totalBytesRead = 0; - - for (size_t tIdx = 0; tIdx < timestepCount; ++tIdx) + double* internalMatrixData = propertyFrames.fortran_vec(); + QStringList errorMessages; + if (!readBlockData(socket, (char*)(internalMatrixData), totalByteCount, errorMessages)) { - qint64 bytesAvailable = socket.bytesAvailable() ; - - while ( bytesAvailable < (qint64)timestepByteCount) + for (int i = 0; i < errorMessages.size(); i++) { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) - { - error((("Waiting for timestep data number: ") + QString::number(tIdx)+ ": " + socket.errorString()).toLatin1().data()); - octave_stdout << "Cellcount: " << cellCountI*cellCountJ*cellCountK << ", Timesteps: " << timestepCount << std::endl; - return ; - } - - bytesAvailable = socket.bytesAvailable(); - - OCTAVE_QUIT; + error(errorMessages[i].toLatin1().data()); } - qint64 bytesRead = 0; - double * internalMatrixData = propertyFrames.fortran_vec(); - - // Raw data transfer. Faster. Not possible when dealing with coarsening - bytesRead = socket.read(((char*)(internalMatrixData)) + tIdx * timestepByteCount, timestepByteCount); - - if ((qint64)timestepByteCount != bytesRead) - { - error("Could not read binary double data properly from socket"); - octave_stdout << "Cellcount: " << cellCountI*cellCountJ*cellCountK << ", Timesteps count: " << timestepCount << std::endl; - octave_stdout << "Timestep : " << tIdx << std::endl; - } - - totalBytesRead += bytesRead; - - OCTAVE_QUIT; - } - - if ((qint64)totalByteCount != totalBytesRead) - { - error("Could not read binary double data properly from socket"); - } - - #else - - // Wait for available data - qint64 bytesAvailable = socket.bytesAvailable() ; - - while (bytesAvailable < (qint64)totalByteCount) - { - octave_stdout << "Waiting for data. Has : " << bytesAvailable << " Needs :" << totalByteCount << std::endl; - if (!socket.waitForReadyRead(riOctavePlugin::shortTimeOutMilliSecs)) - { - //error(("Waiting for data : " + socket.errorString()).toLatin1().data()); - //return ; - } - - bytesAvailable = socket.bytesAvailable() ; OCTAVE_QUIT; } - qint64 bytesRead = 0; - double * internalMatrixData = propertyFrames.fortran_vec(); - -#if 0 - - char* dataBuffer = new char[totalByteCount]; - bytesRead = socket.read(dataBuffer, totalByteCount); - - -#else - - // Raw data transfer. Faster. - bytesRead = socket.read((char*)(internalMatrixData ), totalByteCount); -#endif - - - if ((qint64)totalByteCount != bytesRead) - { - error("Could not read binary double data properly from socket"); - } - -#endif QString tmp = QString("riGetGridProperty : Read %1").arg(propertyName); if (caseId < 0)