diff --git a/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp b/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp index 5a3c8bc8b7..2ca72a655d 100644 --- a/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp +++ b/ApplicationCode/SocketInterface/RiaGeometryCommands.cpp @@ -87,11 +87,14 @@ public: // dv(2) = cellCountK; // dv(3) = 3; - std::vector cellCenterValues(doubleValueCount); cvf::Vec3d cornerVerts[8]; - quint64 coordCount = 0; + size_t blockByteCount = cellCount * sizeof(double); + std::vector doubleValues(blockByteCount); + for (int coordIdx = 0; coordIdx < 3; coordIdx++) { + quint64 valueIndex = 0; + for (size_t k = 0; k < cellCountK; k++) { for (size_t j = 0; j < cellCountJ; j++) @@ -101,16 +104,16 @@ public: size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); cvf::Vec3d center = rigGrid->cell(localCellIdx).center(); - cellCenterValues[coordCount++] = center[coordIdx]; + doubleValues[valueIndex++] = center[coordIdx]; } } } + + CVF_ASSERT(valueIndex == cellCount); + + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount); } - CVF_ASSERT(coordCount == doubleValueCount); - - RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCenterValues.data(), byteCount); - return true; } }; @@ -152,6 +155,11 @@ public: size_t activeCellCount = actCellInfo->globalActiveCellCount(); size_t doubleValueCount = activeCellCount * 3; + socketStream << (quint64)activeCellCount; + quint64 byteCount = doubleValueCount * sizeof(double); + socketStream << byteCount; + + // This structure is supposed to be received by Octave using a NDArray. The ordering of this loop is // defined by the ordering of the receiving NDArray // @@ -162,28 +170,26 @@ public: // dv(0) = coordCount; // dv(1) = 3; - std::vector cellCenterValues(doubleValueCount); - quint64 coordCount = 0; + size_t blockByteCount = activeCellCount * sizeof(double); + std::vector doubleValues(blockByteCount); + for (int coordIdx = 0; coordIdx < 3; coordIdx++) { + quint64 valueIndex = 0; + for (size_t globalCellIdx = 0; globalCellIdx < mainGrid->cells().size(); globalCellIdx++) { if (!actCellInfo->isActive(globalCellIdx)) continue; cvf::Vec3d center = mainGrid->cells()[globalCellIdx].center(); - cellCenterValues[coordCount++] = center[coordIdx]; + doubleValues[valueIndex++] = center[coordIdx]; } + + CVF_ASSERT(valueIndex == activeCellCount); + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount); } - CVF_ASSERT(coordCount == doubleValueCount); - - socketStream << (quint64)activeCellCount; - quint64 byteCount = doubleValueCount * sizeof(double); - socketStream << byteCount; - - RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCenterValues.data(), byteCount); - return true; } @@ -244,67 +250,37 @@ public: // dv(3) = 8; // dv(4) = 3; - cvf::Timer timer; + cvf::Vec3d cornerVerts[8]; + size_t blockByteCount = cellCount * sizeof(double); + std::vector doubleValues(blockByteCount); - if (RiaApplication::instance()->preferences()->useStreamTransfer()) + for (int coordIdx = 0; coordIdx < 3; coordIdx++) { - cvf::Vec3d cornerVerts[8]; - for (int coordIdx = 0; coordIdx < 3; coordIdx++) + for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) { - for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) + size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; + + quint64 valueIndex = 0; + + for (size_t k = 0; k < cellCountK; k++) { - size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; - - for (size_t k = 0; k < cellCountK; k++) + for (size_t j = 0; j < cellCountJ; j++) { - for (size_t j = 0; j < cellCountJ; j++) + for (size_t i = 0; i < cellCountI; i++) { - for (size_t i = 0; i < cellCountI; i++) - { - size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); - rigGrid->cellCornerVertices(localCellIdx, cornerVerts); + size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); + rigGrid->cellCornerVertices(localCellIdx, cornerVerts); - socketStream << cornerVerts[cornerIndexMapping][coordIdx]; - } + doubleValues[valueIndex++] = cornerVerts[cornerIndexMapping][coordIdx]; } } } + + CVF_ASSERT(valueIndex, cellCount); + + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount); } } - else - { - std::vector cellCornerValues(doubleValueCount); - cvf::Vec3d cornerVerts[8]; - quint64 coordCount = 0; - for (int coordIdx = 0; coordIdx < 3; coordIdx++) - { - for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) - { - size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; - - for (size_t k = 0; k < cellCountK; k++) - { - for (size_t j = 0; j < cellCountJ; j++) - { - for (size_t i = 0; i < cellCountI; i++) - { - size_t localCellIdx = rigGrid->cellIndexFromIJK(i, j, k); - rigGrid->cellCornerVertices(localCellIdx, cornerVerts); - - cellCornerValues[coordCount++] = cornerVerts[cornerIndexMapping][coordIdx]; - } - } - } - } - } - - RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCornerValues.data(), byteCount); - } - - double totalTimeMS = timer.time() * 1000.0; - QString resultInfo = QString("Total time '%1 ms'").arg(totalTimeMS); - - server->errorMessageDialog()->showMessage(resultInfo); return true; } @@ -348,6 +324,10 @@ public: size_t activeCellCount = actCellInfo->globalActiveCellCount(); size_t doubleValueCount = activeCellCount * 3 * 8; + socketStream << (quint64)activeCellCount; + quint64 byteCount = doubleValueCount * sizeof(double); + socketStream << byteCount; + // This structure is supposed to be received by Octave using a NDArray. The ordering of this loop is // defined by the ordering of the receiving NDArray // @@ -359,32 +339,33 @@ public: // dv(1) = 8; // dv(2) = 3; - std::vector cellCornerValues(doubleValueCount); cvf::Vec3d cornerVerts[8]; - quint64 coordCount = 0; + size_t blockByteCount = activeCellCount * sizeof(double); + std::vector doubleValues(blockByteCount); + for (int coordIdx = 0; coordIdx < 3; coordIdx++) { for (size_t cornerIdx = 0; cornerIdx < 8; cornerIdx++) { size_t cornerIndexMapping = cellCornerMappingEclipse[cornerIdx]; + quint64 valueIndex = 0; + for (size_t globalCellIdx = 0; globalCellIdx < mainGrid->cells().size(); globalCellIdx++) { if (!actCellInfo->isActive(globalCellIdx)) continue; mainGrid->cellCornerVertices(globalCellIdx, cornerVerts); - cellCornerValues[coordCount++] = cornerVerts[cornerIndexMapping][coordIdx]; + doubleValues[valueIndex++] = cornerVerts[cornerIndexMapping][coordIdx]; } + + CVF_ASSERT(valueIndex == activeCellCount); + + RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)doubleValues.data(), blockByteCount); } } - socketStream << (quint64)activeCellCount; - quint64 byteCount = doubleValueCount * sizeof(double); - socketStream << byteCount; - - RiaSocketTools::writeBlockData(server, server->currentClient(), (const char *)cellCornerValues.data(), byteCount); - return true; } diff --git a/OctavePlugin/riGetActiveCellCenters.cpp b/OctavePlugin/riGetActiveCellCenters.cpp index 90c1631f30..a98ba06bac 100644 --- a/OctavePlugin/riGetActiveCellCenters.cpp +++ b/OctavePlugin/riGetActiveCellCenters.cpp @@ -1,7 +1,10 @@ #include +#include + #include #include "riSettings.h" +#include "riSocketTools.h" void getActiveCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 port, const qint32& caseId, const QString& porosityModel) @@ -61,24 +64,16 @@ void getActiveCellCenters(NDArray& cellCenterValues, const QString &hostName, qu cellCenterValues.resize(dv); - while (socket.bytesAvailable() < (qint64)(byteCount)) - { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) - { - error((("Waiting for data: ") + socket.errorString()).toLatin1().data()); - return; - } - OCTAVE_QUIT; - } - - quint64 bytesRead = 0; double* internalMatrixData = cellCenterValues.fortran_vec(); - bytesRead = socket.read((char*)(internalMatrixData), byteCount); - - if (byteCount != bytesRead) + QStringList errorMessages; + if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) { - error("Could not read binary double data properly from socket"); - octave_stdout << "Active cell count: " << activeCellCount << std::endl; + for (int i = 0; i < errorMessages.size(); i++) + { + error(errorMessages[i].toLatin1().data()); + } + + OCTAVE_QUIT; } return; diff --git a/OctavePlugin/riGetActiveCellCorners.cpp b/OctavePlugin/riGetActiveCellCorners.cpp index 6fb285cc4a..47ffad52bc 100644 --- a/OctavePlugin/riGetActiveCellCorners.cpp +++ b/OctavePlugin/riGetActiveCellCorners.cpp @@ -1,7 +1,10 @@ #include +#include + #include #include "riSettings.h" +#include "riSocketTools.h" void getActiveCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 port, const qint32& caseId, const QString& porosityModel) @@ -61,24 +64,16 @@ void getActiveCellCorners(NDArray& cellCornerValues, const QString &hostName, qu dv(2) = 3; cellCornerValues.resize(dv); - while (socket.bytesAvailable() < (qint64)(byteCount)) - { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) - { - error((("Waiting for data: ") + socket.errorString()).toLatin1().data()); - return; - } - OCTAVE_QUIT; - } - - quint64 bytesRead = 0; double* internalMatrixData = cellCornerValues.fortran_vec(); - bytesRead = socket.read((char*)(internalMatrixData), byteCount); - - if (byteCount != bytesRead) + QStringList errorMessages; + if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) { - error("Could not read binary double data properly from socket"); - octave_stdout << "Active cell count: " << activeCellCount << std::endl; + for (int i = 0; i < errorMessages.size(); i++) + { + error(errorMessages[i].toLatin1().data()); + } + + OCTAVE_QUIT; } return; diff --git a/OctavePlugin/riGetCellCenters.cpp b/OctavePlugin/riGetCellCenters.cpp index cb65de3d01..4f57d08a2b 100644 --- a/OctavePlugin/riGetCellCenters.cpp +++ b/OctavePlugin/riGetCellCenters.cpp @@ -1,7 +1,10 @@ #include +#include + #include #include "riSettings.h" +#include "riSocketTools.h" void getCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 port, const qint32& caseId, const quint32& gridIndex) @@ -66,39 +69,19 @@ void getCellCenters(NDArray& cellCenterValues, const QString &hostName, quint16 dv(3) = 3; cellCenterValues.resize(dv); - while (socket.bytesAvailable() < (qint64)(byteCount)) + + double* internalMatrixData = cellCenterValues.fortran_vec(); + QStringList errorMessages; + if (!readBlockData(socket, (char*)(internalMatrixData), byteCount, errorMessages)) { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) + for (int i = 0; i < errorMessages.size(); i++) { - error((("Waiting for data: ") + socket.errorString()).toLatin1().data()); - return; + error(errorMessages[i].toLatin1().data()); } + OCTAVE_QUIT; } - //octave_stdout << " riGetCellCenters : I = " << cellCountI <<" J = " << cellCountJ << " K = " << cellCountK << std::endl; - //octave_stdout << " riGetCellCenters : numDoubles = " << valueCount << std::endl; - - double* internalMatrixData = cellCenterValues.fortran_vec(); - -#if 0 - octave_idx_type valueCount = cellCenterValues.length(); - double val; - for (octave_idx_type i = 0; i < valueCount; i++) - { - socketStream >> internalMatrixData[i]; - } -#else - quint64 bytesRead = 0; - bytesRead = socket.read((char*)(internalMatrixData), byteCount); - - if (byteCount != bytesRead) - { - error("Could not read binary double data properly from socket"); - octave_stdout << "Cell count: " << cellCount << std::endl; - } - -#endif return; } diff --git a/OctavePlugin/riGetCellCorners.cpp b/OctavePlugin/riGetCellCorners.cpp index f5e3b2c356..2571371a76 100644 --- a/OctavePlugin/riGetCellCorners.cpp +++ b/OctavePlugin/riGetCellCorners.cpp @@ -84,41 +84,6 @@ void getCellCorners(NDArray& cellCornerValues, const QString &hostName, quint16 OCTAVE_QUIT; } - octave_stdout << "Bytes count processed : " << byteCount << std::endl; - - - /* - while (socket.bytesAvailable() < (qint64)(byteCount)) - { - if (!socket.waitForReadyRead(riOctavePlugin::longTimeOutMilliSecs)) - { - error((("Waiting for data: ") + socket.errorString()).toLatin1().data()); - return; - } - OCTAVE_QUIT; - } - - double* internalMatrixData = cellCornerValues.fortran_vec(); - -#if 0 - double val; - for (octave_idx_type i = 0; i < valueCount; i++) - { - socketStream >> internalMatrixData[i]; - } -#else - quint64 bytesRead = 0; - bytesRead = socket.read((char*)(internalMatrixData), byteCount); - - if (byteCount != bytesRead) - { - error("Could not read binary double data properly from socket"); - octave_stdout << "Cell count: " << cellCount << std::endl; - } - -#endif - */ - return; }